2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.h>
22 #include <dali/devel-api/text-abstraction/font-client.h>
23 #include <dali/integration-api/debug.h>
24 #include <dali/public-api/animation/constraints.h>
25 #include <dali/public-api/rendering/geometry.h>
26 #include <dali/public-api/rendering/renderer.h>
30 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
31 #include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
32 #include <dali-toolkit/internal/text/glyph-metrics-helper.h>
33 #include <dali-toolkit/internal/text/glyph-run.h>
34 #include <dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager.h>
35 #include <dali-toolkit/internal/text/rendering/atlas/atlas-mesh-factory.h>
36 #include <dali-toolkit/internal/text/rendering/styles/strikethrough-helper-functions.h>
37 #include <dali-toolkit/internal/text/rendering/styles/underline-helper-functions.h>
38 #include <dali-toolkit/internal/text/text-view.h>
41 using namespace Dali::Toolkit;
42 using namespace Dali::Toolkit::Text;
46 #if defined(DEBUG_ENABLED)
47 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_RENDERING");
50 const float ZERO(0.0f);
51 const float HALF(0.5f);
52 const float ONE(1.0f);
53 const float ONE_AND_A_HALF(1.5f);
54 const uint32_t DOUBLE_PIXEL_PADDING = 4u; //Padding will be added twice to Atlas
55 const uint16_t NO_OUTLINE = 0u;
58 struct AtlasRenderer::Impl
74 AtlasManager::Mesh2D mMesh;
78 * brief Struct used to generate the underline/striketthrough mesh.
79 * There is one Extent per line of text.
87 mUnderlinePosition(0.0f),
90 mUnderlineChunkId(0u),
91 mStrikethroughPosition(0.0f),
92 mStrikethroughChunkId(0u)
99 float mUnderlinePosition;
100 float mLineThickness;
101 uint32_t mMeshRecordIndex;
102 uint32_t mUnderlineChunkId;
103 float mStrikethroughPosition;
104 uint32_t mStrikethroughChunkId;
111 mNeededBlockWidth(0),
112 mNeededBlockHeight(0)
117 uint32_t mNeededBlockWidth;
118 uint32_t mNeededBlockHeight;
130 Text::GlyphIndex mIndex;
133 struct TextCacheEntry
146 Text::GlyphIndex mIndex;
148 uint16_t mOutlineWidth;
156 mGlyphManager = AtlasGlyphManager::Get();
157 mFontClient = TextAbstraction::FontClient::Get();
159 mQuadVertexFormat["aPosition"] = Property::VECTOR2;
160 mQuadVertexFormat["aTexCoord"] = Property::VECTOR2;
161 mQuadVertexFormat["aColor"] = Property::VECTOR4;
164 void CacheGlyph(const GlyphInfo& glyph, FontId lastFontId, const AtlasGlyphManager::GlyphStyle& style, AtlasManager::AtlasSlot& slot)
166 const Size& defaultTextAtlasSize = mFontClient.GetDefaultTextAtlasSize(); //Retrieve default size of text-atlas-block from font-client.
167 const Size& maximumTextAtlasSize = mFontClient.GetMaximumTextAtlasSize(); //Retrieve maximum size of text-atlas-block from font-client.
169 const bool glyphNotCached = !mGlyphManager.IsCached(glyph.fontId, glyph.index, style, slot); // Check FontGlyphRecord vector for entry with glyph index and fontId
171 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "AddGlyphs fontID[%u] glyphIndex[%u] [%s]\n", glyph.fontId, glyph.index, (glyphNotCached) ? "not cached" : "cached");
175 MaxBlockSize& blockSize = mBlockSizes[0u];
177 if(lastFontId != glyph.fontId)
180 // Looks through all stored block sizes until finds the one which mataches required glyph font it. Ensures new atlas block size will match existing for same font id.
181 // CalculateBlocksSize() above ensures a block size entry exists.
182 for(std::vector<MaxBlockSize>::const_iterator it = mBlockSizes.begin(),
183 endIt = mBlockSizes.end();
187 const MaxBlockSize& blockSizeEntry = *it;
188 if(blockSizeEntry.mFontId == glyph.fontId)
190 blockSize = mBlockSizes[index];
195 // Create a new image for the glyph
198 // Whether the glyph is an outline.
199 const bool isOutline = 0u != style.outline;
201 // Whether the current glyph is a color one.
202 const bool isColorGlyph = mFontClient.IsColorGlyph(glyph.fontId, glyph.index);
204 if(!isOutline || (isOutline && !isColorGlyph))
206 // Retrieve the emoji's bitmap.
207 TextAbstraction::FontClient::GlyphBufferData glyphBufferData;
208 glyphBufferData.width = isColorGlyph ? glyph.width : 0; // Desired width and height.
209 glyphBufferData.height = isColorGlyph ? glyph.height : 0;
211 mFontClient.CreateBitmap(glyph.fontId,
213 glyph.isItalicRequired,
214 glyph.isBoldRequired,
218 uint32_t glyphBufferSize = glyphBufferData.width * glyphBufferData.height * Pixel::GetBytesPerPixel(glyphBufferData.format);
219 // If glyph buffer data don't have ownership, Or if we need to decompress, create new memory and replace ownership.
220 if(!glyphBufferData.isBufferOwned || glyphBufferData.compressType != TextAbstraction::FontClient::GlyphBufferData::CompressType::NO_COMPRESS)
222 uint8_t* newBuffer = (uint8_t*)malloc(glyphBufferSize);
223 if(DALI_LIKELY(newBuffer != nullptr))
225 TextAbstraction::FontClient::GlyphBufferData::Decompress(glyphBufferData, newBuffer);
226 if(glyphBufferData.isBufferOwned)
228 // Release previous buffer
229 free(glyphBufferData.buffer);
231 glyphBufferData.isBufferOwned = true;
232 glyphBufferData.buffer = newBuffer;
233 glyphBufferData.compressType = TextAbstraction::FontClient::GlyphBufferData::CompressType::NO_COMPRESS;
237 // Create the pixel data.
238 bitmap = PixelData::New(glyphBufferData.buffer,
240 glyphBufferData.width,
241 glyphBufferData.height,
242 glyphBufferData.format,
245 // Change buffer ownership.
246 glyphBufferData.isBufferOwned = false;
250 // Ensure that the next image will fit into the current block size
251 if(bitmap.GetWidth() > blockSize.mNeededBlockWidth)
253 blockSize.mNeededBlockWidth = bitmap.GetWidth();
256 if(bitmap.GetHeight() > blockSize.mNeededBlockHeight)
258 blockSize.mNeededBlockHeight = bitmap.GetHeight();
261 // If CheckAtlas in AtlasManager::Add can't fit the bitmap in the current atlas it will create a new atlas
263 // Setting the block size and size of new atlas does not mean a new one will be created. An existing atlas may still surffice.
264 uint32_t default_width = defaultTextAtlasSize.width;
265 uint32_t default_height = defaultTextAtlasSize.height;
268 (blockSize.mNeededBlockWidth >= (default_width - (DOUBLE_PIXEL_PADDING + 1u)) ||
269 blockSize.mNeededBlockHeight >= (default_height - (DOUBLE_PIXEL_PADDING + 1u))) &&
270 (default_width < maximumTextAtlasSize.width &&
271 default_height < maximumTextAtlasSize.height))
273 default_width <<= 1u;
274 default_height <<= 1u;
276 mGlyphManager.SetNewAtlasSize(default_width,
278 blockSize.mNeededBlockWidth,
279 blockSize.mNeededBlockHeight);
281 // Locate a new slot for our glyph
282 mGlyphManager.Add(glyph, style, bitmap, slot); // slot will be 0 is glyph not added
288 // We have 2+ copies of the same glyph
289 mGlyphManager.AdjustReferenceCount(glyph.fontId, glyph.index, style, 1); //increment
293 void GenerateMesh(const GlyphInfo& glyph,
294 const Vector2& position,
295 const Vector4& color,
297 AtlasManager::AtlasSlot& slot,
298 bool decorationlineGlyph,
299 float currentUnderlinePosition,
300 float currentlineThickness,
301 std::vector<MeshRecord>& meshContainer,
302 Vector<TextCacheEntry>& newTextCache,
303 Vector<Extent>& extents,
304 uint32_t underlineChunkId,
306 uint32_t strikethroughChunkId)
308 // Generate mesh data for this quad, plugging in our supplied position
309 AtlasManager::Mesh2D newMesh;
310 mGlyphManager.GenerateMeshData(slot.mImageId, position, newMesh);
314 TextCacheEntry textCacheEntry;
315 textCacheEntry.mFontId = glyph.fontId;
316 textCacheEntry.mImageId = slot.mImageId;
317 textCacheEntry.mIndex = glyph.index;
318 textCacheEntry.mOutlineWidth = outline;
319 textCacheEntry.isItalic = glyph.isItalicRequired;
320 textCacheEntry.isBold = glyph.isBoldRequired;
322 newTextCache.PushBack(textCacheEntry);
325 AtlasManager::Vertex2D* verticesBuffer = newMesh.mVertices.Begin();
327 for(unsigned int index = 0u, size = newMesh.mVertices.Count();
331 AtlasManager::Vertex2D& vertex = *(verticesBuffer + index);
333 // Set the color of the vertex.
334 vertex.mColor = color;
337 // Since Free Type font doesn't contain the strikethrough-position property,
338 // strikethrough position will be calculated by moving the underline position upwards by half the value of the line height.
339 float strikethroughStartingYPosition = (position.y + glyph.yBearing + currentUnderlinePosition) - ((glyph.height) * HALF);
341 // Find an existing mesh data object to attach to ( or create a new one, if we can't find one using the same atlas)
342 StitchTextMesh(meshContainer,
345 position.y + glyph.yBearing,
347 currentUnderlinePosition,
348 currentlineThickness,
351 strikethroughStartingYPosition,
352 strikethroughChunkId);
355 void CreateActors(const std::vector<MeshRecord>& meshContainer,
356 const Size& textSize,
357 const Vector4& color,
358 const Vector4& shadowColor,
359 const Vector2& shadowOffset,
361 Property::Index animatablePropertyIndex,
366 // Create a container actor to act as a common parent for text and shadow, to avoid color inheritence issues.
367 mActor = Actor::New();
368 mActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
369 mActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
370 mActor.SetProperty(Actor::Property::SIZE, textSize);
371 mActor.SetProperty(Actor::Property::COLOR_MODE, USE_OWN_MULTIPLY_PARENT_COLOR);
374 for(std::vector<MeshRecord>::const_iterator it = meshContainer.begin(),
375 endIt = meshContainer.end();
379 const MeshRecord& meshRecord = *it;
381 Actor actor = CreateMeshActor(textControl, animatablePropertyIndex, color, meshRecord, textSize, STYLE_NORMAL);
383 // Whether the actor has renderers.
384 const bool hasRenderer = actor.GetRendererCount() > 0u;
386 // Create an effect if necessary
390 // Change the color of the vertices.
391 for(Vector<AtlasManager::Vertex2D>::Iterator vIt = meshRecord.mMesh.mVertices.Begin(),
392 vEndIt = meshRecord.mMesh.mVertices.End();
396 AtlasManager::Vertex2D& vertex = *vIt;
398 vertex.mColor = shadowColor;
401 Actor shadowActor = CreateMeshActor(textControl, animatablePropertyIndex, color, meshRecord, textSize, STYLE_DROP_SHADOW);
402 #if defined(DEBUG_ENABLED)
403 shadowActor.SetProperty(Dali::Actor::Property::NAME, "Text Shadow renderable actor");
405 // Offset shadow in x and y
406 shadowActor.RegisterProperty("uOffset", shadowOffset);
407 Dali::Renderer renderer(shadowActor.GetRendererAt(0));
408 int depthIndex = renderer.GetProperty<int>(Dali::Renderer::Property::DEPTH_INDEX);
409 renderer.SetProperty(Dali::Renderer::Property::DEPTH_INDEX, depthIndex - 1);
410 mActor.Add(shadowActor);
420 void AddGlyphs(Text::ViewInterface& view,
422 Property::Index animatablePropertyIndex,
423 const Vector<Vector2>& positions,
424 const Vector<GlyphInfo>& glyphs,
425 const Vector4& defaultColor,
426 const Vector4* const colorsBuffer,
427 const ColorIndex* const colorIndicesBuffer,
431 AtlasManager::AtlasSlot slot;
435 AtlasManager::AtlasSlot slotOutline;
436 slotOutline.mImageId = 0u;
437 slotOutline.mAtlasId = 0u;
439 std::vector<MeshRecord> meshContainer;
440 std::vector<MeshRecord> meshContainerOutline;
441 Vector<Extent> extents;
442 Vector<Extent> strikethroughExtents;
445 const Vector2& textSize(view.GetLayoutSize());
446 const Vector2 halfTextSize(textSize * 0.5f);
447 const Vector2& shadowOffset(view.GetShadowOffset());
448 const Vector4& shadowColor(view.GetShadowColor());
449 const bool underlineEnabled = view.IsUnderlineEnabled();
450 const uint16_t outlineWidth = view.GetOutlineWidth();
451 const Vector4& outlineColor(view.GetOutlineColor());
452 const bool isOutline = 0u != outlineWidth;
453 const GlyphInfo* hyphens = view.GetHyphens();
454 const Length* hyphenIndices = view.GetHyphenIndices();
455 const Length hyphensCount = view.GetHyphensCount();
456 const bool strikethroughEnabled = view.IsStrikethroughEnabled();
457 const float characterSpacing(view.GetCharacterSpacing());
459 // Elided text info. Indices according to elided text.
460 const auto startIndexOfGlyphs = view.GetStartIndexOfElidedGlyphs();
461 const auto firstMiddleIndexOfElidedGlyphs = view.GetFirstMiddleIndexOfElidedGlyphs();
462 const auto secondMiddleIndexOfElidedGlyphs = view.GetSecondMiddleIndexOfElidedGlyphs();
464 const bool useDefaultColor = (NULL == colorsBuffer);
466 // Get a handle of the font client. Used to retrieve the bitmaps of the glyphs.
467 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
469 // Get the underline runs.
470 const Length numberOfUnderlineRuns = view.GetNumberOfUnderlineRuns();
471 Vector<UnderlinedGlyphRun> underlineRuns;
472 underlineRuns.Resize(numberOfUnderlineRuns);
473 view.GetUnderlineRuns(underlineRuns.Begin(),
475 numberOfUnderlineRuns);
477 // Aggregate underline-style-properties from view
478 const UnderlineStyleProperties viewUnderlineProperties{view.GetUnderlineType(),
479 view.GetUnderlineColor(),
480 view.GetUnderlineHeight(),
481 view.GetDashedUnderlineGap(),
482 view.GetDashedUnderlineWidth(),
489 float maxUnderlineHeight = viewUnderlineProperties.height;
491 // Get the strikethrough runs.
492 const Length numberOfStrikethroughRuns = view.GetNumberOfStrikethroughRuns();
493 Vector<StrikethroughGlyphRun> strikethroughRuns;
494 strikethroughRuns.Resize(numberOfStrikethroughRuns);
495 view.GetStrikethroughRuns(strikethroughRuns.Begin(), 0u, numberOfStrikethroughRuns);
497 const StrikethroughStyleProperties viewStrikethroughProperties{view.GetStrikethroughColor(),
498 view.GetStrikethroughHeight(),
502 float maxStrikethroughHeight = viewStrikethroughProperties.height;
504 FontId lastFontId = 0;
505 Style style = STYLE_NORMAL;
506 float currentUnderlinePosition = ZERO;
507 bool thereAreUnderlinedGlyphs = false;
508 bool thereAreStrikethroughGlyphs = false;
510 if(fabsf(shadowOffset.x) > Math::MACHINE_EPSILON_1 || fabsf(shadowOffset.y) > Math::MACHINE_EPSILON_1)
512 style = STYLE_DROP_SHADOW;
515 CalculateBlocksSize(glyphs);
517 // Avoid emptying mTextCache (& removing references) until after incremented references for the new text
518 Vector<TextCacheEntry> newTextCache;
519 const GlyphInfo* const glyphsBuffer = glyphs.Begin();
520 const Vector2* const positionsBuffer = positions.Begin();
521 const Vector2 lineOffsetPosition(minLineOffset, 0.f);
522 uint32_t hyphenIndex = 0;
524 //For septated underlined chunks. (this is for Markup case)
525 uint32_t underlineChunkId = 0u; // give id for each chunk.
526 bool isPreUnderlined = false; // status of underlined for previous glyph.
527 std::map<uint32_t, UnderlineStyleProperties> mapUnderlineChunkIdWithProperties; // mapping underlineChunkId with UnderlineStyleProperties to get properties of underlined chunk
528 UnderlineStyleProperties preUnderlineProperties = viewUnderlineProperties; // the previous UnderlineStyleProperties
530 //For septated strikethrough chunks. (this is for Markup case)
531 uint32_t strikethroughChunkId = 0u; // give id for each chunk.
532 bool isPreStrikethrough = false; // status of strikethrough for previous glyph.
533 std::map<uint32_t, StrikethroughStyleProperties> mapStrikethroughChunkIdWithProperties; // mapping strikethroughChunkId with StrikethroughStyleProperties to get properties of strikethrough chunk
534 StrikethroughStyleProperties preStrikethroughProperties = viewStrikethroughProperties; // the previous StrikethroughStyleProperties
536 const Character* textBuffer = view.GetTextBuffer();
537 float calculatedAdvance = 0.f;
538 const Vector<CharacterIndex>& glyphToCharacterMap = view.GetGlyphsToCharacters();
539 const CharacterIndex* glyphToCharacterMapBuffer = glyphToCharacterMap.Begin();
541 //Skip hyphenIndices less than startIndexOfGlyphs or between two middle of elided text
544 while((hyphenIndex < hyphensCount) && (hyphenIndices[hyphenIndex] < startIndexOfGlyphs ||
545 (hyphenIndices[hyphenIndex] > firstMiddleIndexOfElidedGlyphs && hyphenIndices[hyphenIndex] < secondMiddleIndexOfElidedGlyphs)))
551 //To keep the last fontMetrics of lastDecorativeLinesFontId
552 FontId lastDecorativeLinesFontId = 0; // DecorativeLines like Undeline and Strikethrough
553 FontMetrics lastDecorativeLinesFontMetrics;
554 fontClient.GetFontMetrics(lastDecorativeLinesFontId, lastDecorativeLinesFontMetrics);
556 // Iteration on glyphs
557 for(uint32_t i = 0, glyphSize = glyphs.Size(); i < glyphSize; ++i)
560 bool addHyphen = ((hyphenIndex < hyphensCount) && hyphenIndices && ((i + startIndexOfGlyphs) == hyphenIndices[hyphenIndex]));
561 if(addHyphen && hyphens)
563 glyph = hyphens[hyphenIndex];
568 glyph = *(glyphsBuffer + i);
571 Vector<UnderlinedGlyphRun>::ConstIterator currentUnderlinedGlyphRunIt = underlineRuns.End();
572 const bool isGlyphUnderlined = underlineEnabled || IsGlyphUnderlined(i, underlineRuns, currentUnderlinedGlyphRunIt);
573 const UnderlineStyleProperties currentUnderlineProperties = GetCurrentUnderlineProperties(i, isGlyphUnderlined, underlineRuns, currentUnderlinedGlyphRunIt, viewUnderlineProperties);
574 float currentUnderlineHeight = currentUnderlineProperties.height;
575 thereAreUnderlinedGlyphs = thereAreUnderlinedGlyphs || isGlyphUnderlined;
577 Vector<StrikethroughGlyphRun>::ConstIterator currentStrikethroughGlyphRunIt = strikethroughRuns.End();
578 const bool isGlyphStrikethrough = strikethroughEnabled || IsGlyphStrikethrough(i, strikethroughRuns, currentStrikethroughGlyphRunIt);
579 const StrikethroughStyleProperties currentStrikethroughProperties = GetCurrentStrikethroughProperties(i, isGlyphStrikethrough, strikethroughRuns, currentStrikethroughGlyphRunIt, viewStrikethroughProperties);
580 float currentStrikethroughHeight = currentStrikethroughProperties.height;
581 thereAreStrikethroughGlyphs = thereAreStrikethroughGlyphs || isGlyphStrikethrough;
583 // No operation for white space
584 if(glyph.width && glyph.height)
586 // Check and update decorative-lines informations
587 if(isGlyphUnderlined || isGlyphStrikethrough)
589 bool isDecorativeLinesFontIdUpdated = false;
590 // Are we still using the same fontId as previous
591 if(glyph.fontId != lastDecorativeLinesFontId)
593 // We need to fetch fresh font metrics
594 lastDecorativeLinesFontId = glyph.fontId;
595 isDecorativeLinesFontIdUpdated = true;
596 fontClient.GetFontMetrics(lastDecorativeLinesFontId, lastDecorativeLinesFontMetrics);
598 if(isGlyphStrikethrough || isGlyphUnderlined)
600 //The currentUnderlinePosition will be used for both Underline and/or Strikethrough
601 currentUnderlinePosition = FetchUnderlinePositionFromFontMetrics(lastDecorativeLinesFontMetrics);
605 if(isGlyphUnderlined && (isDecorativeLinesFontIdUpdated || !(currentUnderlineProperties.IsHeightEqualTo(preUnderlineProperties))))
607 //If the Underline Height is changed then we need to recalculate height.
608 if(!(currentUnderlineProperties.IsHeightEqualTo(preUnderlineProperties)))
610 maxUnderlineHeight = currentUnderlineHeight;
613 CalcualteUnderlineHeight(lastDecorativeLinesFontMetrics, currentUnderlineHeight, maxUnderlineHeight);
616 if(isGlyphStrikethrough && (isDecorativeLinesFontIdUpdated || !(currentStrikethroughProperties.IsHeightEqualTo(preStrikethroughProperties))))
618 //If the Strikethrough Height is changed then we need to recalculate height.
619 if(!(currentStrikethroughProperties.IsHeightEqualTo(preStrikethroughProperties)))
621 maxStrikethroughHeight = currentStrikethroughHeight;
624 CalcualteStrikethroughHeight(currentStrikethroughHeight, maxStrikethroughHeight);
626 } // decorative-lines
628 AtlasGlyphManager::GlyphStyle style;
629 style.isItalic = glyph.isItalicRequired;
630 style.isBold = glyph.isBoldRequired;
632 // Retrieves and caches the glyph's bitmap.
633 CacheGlyph(glyph, lastFontId, style, slot);
635 // Retrieves and caches the outline glyph's bitmap.
638 style.outline = outlineWidth;
639 CacheGlyph(glyph, lastFontId, style, slotOutline);
642 // Move the origin (0,0) of the mesh to the center of the actor
643 Vector2 position = *(positionsBuffer + i);
647 GlyphInfo tempInfo = *(glyphsBuffer + i);
648 calculatedAdvance = GetCalculatedAdvance(*(textBuffer + (*(glyphToCharacterMapBuffer + i))), characterSpacing, tempInfo.advance);
649 position.x = position.x + calculatedAdvance - tempInfo.xBearing + glyph.xBearing;
650 position.y += tempInfo.yBearing - glyph.yBearing;
653 position = Vector2(roundf(position.x), position.y) - halfTextSize - lineOffsetPosition; // roundf() avoids pixel alignment issues.
655 if(0u != slot.mImageId) // invalid slot id, glyph has failed to be added to atlas
657 Vector2 positionPlusOutlineOffset = position;
660 // Add an offset to the text.
661 const float outlineWidthOffset = static_cast<float>(outlineWidth);
662 positionPlusOutlineOffset += Vector2(outlineWidthOffset, outlineWidthOffset);
665 // Get the color of the character.
666 const ColorIndex colorIndex = useDefaultColor ? 0u : *(colorIndicesBuffer + i);
667 const Vector4& color = (useDefaultColor || (0u == colorIndex)) ? defaultColor : *(colorsBuffer + colorIndex - 1u);
669 //The new underlined chunk. Add new id if they are not consecutive indices (this is for Markup case)
670 // Examples: "Hello <u>World</u> Hello <u>World</u>", "<u>World</u> Hello <u>World</u>", "<u> World</u> Hello <u>World</u>"
671 if((!isPreUnderlined && isGlyphUnderlined) || (isGlyphUnderlined && (preUnderlineProperties != currentUnderlineProperties)))
674 mapUnderlineChunkIdWithProperties.insert(std::pair<uint32_t, UnderlineStyleProperties>(underlineChunkId, currentUnderlineProperties));
677 //Keep status of underlined for previous glyph to check consecutive indices
678 isPreUnderlined = isGlyphUnderlined;
679 preUnderlineProperties = currentUnderlineProperties;
682 positionPlusOutlineOffset,
687 currentUnderlinePosition,
696 if(isGlyphStrikethrough)
698 //The new strikethrough chunk. Add new id if they are not consecutive indices (this is for Markup case)
699 // Examples: "Hello <s>World</s> Hello <s>World</s>", "<s>World</s> Hello <s>World</s>", "<s> World</s> Hello <s>World</s>"
700 if((!isPreStrikethrough) || (preStrikethroughProperties != currentStrikethroughProperties))
702 strikethroughChunkId++;
703 mapStrikethroughChunkIdWithProperties.insert(std::pair<uint32_t, StrikethroughStyleProperties>(strikethroughChunkId, currentStrikethroughProperties));
707 positionPlusOutlineOffset,
711 isGlyphStrikethrough,
713 maxStrikethroughHeight,
716 strikethroughExtents,
719 strikethroughChunkId);
722 //Keep status of Strikethrough for previous glyph to check consecutive indices
723 isPreStrikethrough = isGlyphStrikethrough;
724 preStrikethroughProperties = currentStrikethroughProperties;
726 lastFontId = glyph.fontId; // Prevents searching for existing blocksizes when string of the same fontId.
729 if(isOutline && (0u != slotOutline.mImageId)) // invalid slot id, glyph has failed to be added to atlas
737 currentUnderlinePosition,
739 meshContainerOutline,
754 // Now remove references for the old text
756 mTextCache.Swap(newTextCache);
758 if(thereAreUnderlinedGlyphs)
760 // Check to see if any of the text needs an underline
761 GenerateUnderlines(meshContainer, extents, viewUnderlineProperties, mapUnderlineChunkIdWithProperties);
764 if(thereAreStrikethroughGlyphs)
766 // Check to see if any of the text needs a strikethrough
767 GenerateStrikethrough(meshContainer, strikethroughExtents, viewStrikethroughProperties, mapStrikethroughChunkIdWithProperties);
770 // For each MeshData object, create a mesh actor and add to the renderable actor
771 bool isShadowDrawn = false;
772 if(!meshContainerOutline.empty())
774 const bool drawShadow = STYLE_DROP_SHADOW == style;
775 CreateActors(meshContainerOutline,
781 animatablePropertyIndex,
784 isShadowDrawn = drawShadow;
787 // For each MeshData object, create a mesh actor and add to the renderable actor
788 if(!meshContainer.empty())
790 const bool drawShadow = !isShadowDrawn && (STYLE_DROP_SHADOW == style);
791 CreateActors(meshContainer,
797 animatablePropertyIndex,
801 #if defined(DEBUG_ENABLED)
802 Toolkit::AtlasGlyphManager::Metrics metrics = mGlyphManager.GetMetrics();
803 DALI_LOG_INFO(gLogFilter, Debug::General, "TextAtlasRenderer::GlyphManager::GlyphCount: %i, AtlasCount: %i, TextureMemoryUse: %iK\n", metrics.mGlyphCount, metrics.mAtlasMetrics.mAtlasCount, metrics.mAtlasMetrics.mTextureMemoryUsed / 1024);
805 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "%s\n", metrics.mVerboseGlyphCounts.c_str());
807 for(uint32_t i = 0; gLogFilter->IsEnabledFor(Debug::Verbose) && i < metrics.mAtlasMetrics.mAtlasCount; ++i)
809 DALI_LOG_INFO(gLogFilter, Debug::Verbose, " Atlas [%i] %sPixels: %s Size: %ix%i, BlockSize: %ix%i, BlocksUsed: %i/%i\n", i + 1, i > 8 ? "" : " ", metrics.mAtlasMetrics.mAtlasMetrics[i].mPixelFormat == Pixel::L8 ? "L8 " : "BGRA", metrics.mAtlasMetrics.mAtlasMetrics[i].mSize.mWidth, metrics.mAtlasMetrics.mAtlasMetrics[i].mSize.mHeight, metrics.mAtlasMetrics.mAtlasMetrics[i].mSize.mBlockWidth, metrics.mAtlasMetrics.mAtlasMetrics[i].mSize.mBlockHeight, metrics.mAtlasMetrics.mAtlasMetrics[i].mBlocksUsed, metrics.mAtlasMetrics.mAtlasMetrics[i].mTotalBlocks);
816 for(Vector<TextCacheEntry>::Iterator oldTextIter = mTextCache.Begin(); oldTextIter != mTextCache.End(); ++oldTextIter)
818 AtlasGlyphManager::GlyphStyle style;
819 style.outline = oldTextIter->mOutlineWidth;
820 style.isItalic = oldTextIter->isItalic;
821 style.isBold = oldTextIter->isBold;
822 mGlyphManager.AdjustReferenceCount(oldTextIter->mFontId, oldTextIter->mIndex, style, -1 /*decrement*/);
824 mTextCache.Resize(0);
827 Actor CreateMeshActor(Actor textControl, Property::Index animatablePropertyIndex, const Vector4& defaultColor, const MeshRecord& meshRecord, const Vector2& actorSize, Style style)
829 VertexBuffer quadVertices = VertexBuffer::New(mQuadVertexFormat);
830 quadVertices.SetData(const_cast<AtlasManager::Vertex2D*>(&meshRecord.mMesh.mVertices[0]), meshRecord.mMesh.mVertices.Size());
832 Geometry quadGeometry = Geometry::New();
833 quadGeometry.AddVertexBuffer(quadVertices);
834 quadGeometry.SetIndexBuffer(&meshRecord.mMesh.mIndices[0], meshRecord.mMesh.mIndices.Size());
836 TextureSet textureSet(mGlyphManager.GetTextures(meshRecord.mAtlasId));
838 // Choose the shader to use.
839 const bool isColorShader = (STYLE_DROP_SHADOW != style) && (Pixel::BGRA8888 == mGlyphManager.GetPixelFormat(meshRecord.mAtlasId));
843 // The glyph is an emoji and is not a shadow.
846 mShaderRgba = Shader::New(SHADER_TEXT_ATLAS_SHADER_VERT, SHADER_TEXT_ATLAS_RGBA_SHADER_FRAG);
848 shader = mShaderRgba;
852 // The glyph is text or a shadow.
855 mShaderL8 = Shader::New(SHADER_TEXT_ATLAS_SHADER_VERT, SHADER_TEXT_ATLAS_L8_SHADER_FRAG);
860 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "defaultColor[%f, %f, %f, %f ]\n", defaultColor.r, defaultColor.g, defaultColor.b, defaultColor.a);
862 Dali::Property::Index shaderTextColorIndex = shader.RegisterProperty("textColorAnimatable", defaultColor);
864 if(animatablePropertyIndex != Property::INVALID_INDEX)
866 // create constraint for the animatable text's color Property with textColorAnimatable in the shader.
867 if(shaderTextColorIndex)
869 Constraint constraint = Constraint::New<Vector4>(shader, shaderTextColorIndex, EqualToConstraint());
870 constraint.AddSource(Source(textControl, animatablePropertyIndex));
876 // If not animating the text colour then set to 1's so shader uses the current vertex color
877 shader.RegisterProperty("textColorAnimatable", Vector4(1.0, 1.0, 1.0, 1.0));
880 Dali::Renderer renderer = Dali::Renderer::New(quadGeometry, shader);
881 renderer.SetTextures(textureSet);
882 renderer.SetProperty(Dali::Renderer::Property::BLEND_MODE, BlendMode::ON);
883 renderer.SetProperty(Dali::Renderer::Property::DEPTH_INDEX, DepthIndex::CONTENT + mDepth);
885 Actor actor = Actor::New();
886 #if defined(DEBUG_ENABLED)
887 actor.SetProperty(Dali::Actor::Property::NAME, "Text renderable actor");
889 actor.AddRenderer(renderer);
890 // Keep all of the origins aligned
891 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
892 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
893 actor.SetProperty(Actor::Property::SIZE, actorSize);
894 actor.RegisterProperty("uOffset", Vector2::ZERO);
895 actor.SetProperty(Actor::Property::COLOR_MODE, USE_OWN_MULTIPLY_PARENT_COLOR);
900 void StitchTextMesh(std::vector<MeshRecord>& meshContainer,
901 AtlasManager::Mesh2D& newMesh,
902 Vector<Extent>& extents,
904 bool decorationlineGlyph,
905 float underlinePosition,
907 AtlasManager::AtlasSlot& slot,
908 uint32_t underlineChunkId,
909 float strikethroughPosition,
910 uint32_t strikethroughChunkId)
914 float left = newMesh.mVertices[0].mPosition.x;
915 float right = newMesh.mVertices[1].mPosition.x;
917 // Check to see if there's a mesh data object that references the same atlas ?
919 for(std::vector<MeshRecord>::iterator mIt = meshContainer.begin(),
920 mEndIt = meshContainer.end();
924 if(slot.mAtlasId == mIt->mAtlasId)
926 // Append the mesh to the existing mesh and adjust any extents
927 Toolkit::Internal::AtlasMeshFactory::AppendMesh(mIt->mMesh, newMesh);
929 if(decorationlineGlyph)
931 AdjustExtents(extents,
940 strikethroughPosition,
941 strikethroughChunkId);
948 // No mesh data object currently exists that references this atlas, so create a new one
949 MeshRecord meshRecord;
950 meshRecord.mAtlasId = slot.mAtlasId;
951 meshRecord.mMesh = newMesh;
952 meshContainer.push_back(meshRecord);
954 if(decorationlineGlyph)
956 // Adjust extents for this new meshrecord
957 AdjustExtents(extents,
959 meshContainer.size() - 1u,
966 strikethroughPosition,
967 strikethroughChunkId);
972 void AdjustExtents(Vector<Extent>& extents,
973 std::vector<MeshRecord>& meshRecords,
978 float underlinePosition,
980 uint32_t underlineChunkId,
981 float strikethroughPosition,
982 uint32_t strikethroughChunkId)
984 bool foundExtent = false;
985 for(Vector<Extent>::Iterator eIt = extents.Begin(),
986 eEndIt = extents.End();
990 if(Equals(baseLine, eIt->mBaseLine) && underlineChunkId == eIt->mUnderlineChunkId && strikethroughChunkId == eIt->mStrikethroughChunkId)
993 if(left < eIt->mLeft)
997 if(right > eIt->mRight)
1002 if(underlinePosition > eIt->mUnderlinePosition)
1004 eIt->mUnderlinePosition = underlinePosition;
1006 if(lineThickness > eIt->mLineThickness)
1008 eIt->mLineThickness = lineThickness;
1015 extent.mLeft = left;
1016 extent.mRight = right;
1017 extent.mBaseLine = baseLine;
1018 extent.mUnderlinePosition = underlinePosition;
1019 extent.mMeshRecordIndex = index;
1020 extent.mUnderlineChunkId = underlineChunkId;
1021 extent.mLineThickness = lineThickness;
1022 extent.mStrikethroughPosition = strikethroughPosition;
1023 extent.mStrikethroughChunkId = strikethroughChunkId;
1024 extents.PushBack(extent);
1028 void CalculateBlocksSize(const Vector<GlyphInfo>& glyphs)
1030 for(Vector<GlyphInfo>::ConstIterator glyphIt = glyphs.Begin(),
1031 glyphEndIt = glyphs.End();
1032 glyphIt != glyphEndIt;
1035 const FontId fontId = (*glyphIt).fontId;
1036 bool foundFont = false;
1038 for(std::vector<MaxBlockSize>::const_iterator blockIt = mBlockSizes.begin(),
1039 blockEndIt = mBlockSizes.end();
1040 blockIt != blockEndIt;
1043 if((*blockIt).mFontId == fontId) // Different size fonts will have a different fontId
1045 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Text::AtlasRenderer::CalculateBlocksSize match found fontID(%u) glyphIndex(%u)\n", fontId, (*glyphIt).index);
1053 FontMetrics fontMetrics;
1054 mFontClient.GetFontMetrics(fontId, fontMetrics);
1056 MaxBlockSize maxBlockSize;
1057 maxBlockSize.mNeededBlockWidth = static_cast<uint32_t>(fontMetrics.height);
1058 maxBlockSize.mNeededBlockHeight = maxBlockSize.mNeededBlockWidth;
1059 maxBlockSize.mFontId = fontId;
1060 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Text::AtlasRenderer::CalculateBlocksSize New font with no matched blocksize, setting blocksize[%u]\n", maxBlockSize.mNeededBlockWidth);
1061 mBlockSizes.push_back(maxBlockSize);
1066 void GenerateUnderlines(std::vector<MeshRecord>& meshRecords,
1067 Vector<Extent>& extents,
1068 const UnderlineStyleProperties& viewUnderlineProperties,
1069 const std::map<uint32_t, UnderlineStyleProperties>& mapUnderlineChunkIdWithProperties)
1071 AtlasManager::Mesh2D newMesh;
1072 unsigned short faceIndex = 0;
1074 for(Vector<Extent>::ConstIterator eIt = extents.Begin(),
1075 eEndIt = extents.End();
1079 AtlasManager::Vertex2D vert;
1080 uint32_t index = eIt->mMeshRecordIndex;
1081 Vector2 uv = mGlyphManager.GetAtlasSize(meshRecords[index].mAtlasId);
1083 auto pairUnderlineChunkIdWithProperties = mapUnderlineChunkIdWithProperties.find(eIt->mUnderlineChunkId);
1085 const UnderlineStyleProperties underlineProperties = (pairUnderlineChunkIdWithProperties == mapUnderlineChunkIdWithProperties.end())
1086 ? viewUnderlineProperties
1087 : pairUnderlineChunkIdWithProperties->second;
1089 const Vector4& underlineColor = underlineProperties.colorDefined ? underlineProperties.color : viewUnderlineProperties.color;
1090 const Text::Underline::Type& underlineType = underlineProperties.typeDefined ? underlineProperties.type : viewUnderlineProperties.type;
1091 const float& dashedUnderlineGap = underlineProperties.dashGapDefined ? underlineProperties.dashGap : viewUnderlineProperties.dashGap;
1092 const float& dashedUnderlineWidth = underlineProperties.dashWidthDefined ? underlineProperties.dashWidth : viewUnderlineProperties.dashWidth;
1094 // Make sure we don't hit texture edge for single pixel texture ( filled pixel is in top left of every atlas )
1095 float u = HALF / uv.x;
1096 float v = HALF / uv.y;
1097 float thickness = eIt->mLineThickness;
1098 float ShiftLineBy = (underlineType == Text::Underline::Type::DOUBLE) ? (thickness * ONE_AND_A_HALF) : (thickness * HALF);
1099 float baseLine = eIt->mBaseLine + eIt->mUnderlinePosition - ShiftLineBy;
1100 float tlx = eIt->mLeft;
1101 float brx = eIt->mRight;
1103 if(underlineType == Text::Underline::Type::DASHED)
1105 float dashTlx = tlx;
1106 float dashBrx = tlx;
1108 while((dashTlx >= tlx) && (dashTlx < brx) && ((dashTlx + dashedUnderlineWidth) <= brx))
1110 dashBrx = dashTlx + dashedUnderlineWidth;
1112 //The top left edge of the underline
1113 vert.mPosition.x = dashTlx;
1114 vert.mPosition.y = baseLine;
1115 vert.mTexCoords.x = ZERO;
1116 vert.mTexCoords.y = ZERO;
1117 vert.mColor = underlineColor;
1118 newMesh.mVertices.PushBack(vert);
1120 //The top right edge of the underline
1121 vert.mPosition.x = dashBrx;
1122 vert.mPosition.y = baseLine;
1123 vert.mTexCoords.x = u;
1124 vert.mColor = underlineColor;
1125 newMesh.mVertices.PushBack(vert);
1127 //The bottom left edge of the underline
1128 vert.mPosition.x = dashTlx;
1129 vert.mPosition.y = baseLine + thickness;
1130 vert.mTexCoords.x = ZERO;
1131 vert.mTexCoords.y = v;
1132 vert.mColor = underlineColor;
1133 newMesh.mVertices.PushBack(vert);
1135 //The bottom right edge of the underline
1136 vert.mPosition.x = dashBrx;
1137 vert.mPosition.y = baseLine + thickness;
1138 vert.mTexCoords.x = u;
1139 vert.mColor = underlineColor;
1140 newMesh.mVertices.PushBack(vert);
1142 dashTlx = dashBrx + dashedUnderlineGap; // The next dash will start at the right of the current dash plus the gap
1144 // Six indices in counter clockwise winding
1145 newMesh.mIndices.PushBack(faceIndex + 1u);
1146 newMesh.mIndices.PushBack(faceIndex);
1147 newMesh.mIndices.PushBack(faceIndex + 2u);
1148 newMesh.mIndices.PushBack(faceIndex + 2u);
1149 newMesh.mIndices.PushBack(faceIndex + 3u);
1150 newMesh.mIndices.PushBack(faceIndex + 1u);
1154 Toolkit::Internal::AtlasMeshFactory::AppendMesh(meshRecords[index].mMesh, newMesh);
1159 // It's either SOLID or DOUBLE so we need to generate the first solid underline anyway.
1160 vert.mPosition.x = tlx;
1161 vert.mPosition.y = baseLine;
1162 vert.mTexCoords.x = ZERO;
1163 vert.mTexCoords.y = ZERO;
1164 vert.mColor = underlineColor;
1165 newMesh.mVertices.PushBack(vert);
1167 vert.mPosition.x = brx;
1168 vert.mPosition.y = baseLine;
1169 vert.mTexCoords.x = u;
1170 vert.mColor = underlineColor;
1171 newMesh.mVertices.PushBack(vert);
1173 vert.mPosition.x = tlx;
1174 vert.mPosition.y = baseLine + thickness;
1175 vert.mTexCoords.x = ZERO;
1176 vert.mTexCoords.y = v;
1177 vert.mColor = underlineColor;
1178 newMesh.mVertices.PushBack(vert);
1180 vert.mPosition.x = brx;
1181 vert.mPosition.y = baseLine + thickness;
1182 vert.mTexCoords.x = u;
1183 vert.mColor = underlineColor;
1184 newMesh.mVertices.PushBack(vert);
1186 // Six indices in counter clockwise winding
1187 newMesh.mIndices.PushBack(faceIndex + 1u);
1188 newMesh.mIndices.PushBack(faceIndex);
1189 newMesh.mIndices.PushBack(faceIndex + 2u);
1190 newMesh.mIndices.PushBack(faceIndex + 2u);
1191 newMesh.mIndices.PushBack(faceIndex + 3u);
1192 newMesh.mIndices.PushBack(faceIndex + 1u);
1195 Toolkit::Internal::AtlasMeshFactory::AppendMesh(meshRecords[index].mMesh, newMesh);
1197 if(underlineType == Text::Underline::Type::DOUBLE)
1199 baseLine += 2 * thickness;
1201 //The top left edge of the underline
1202 vert.mPosition.x = tlx;
1203 vert.mPosition.y = baseLine; // Vertical start of the second underline
1204 vert.mTexCoords.x = ZERO;
1205 vert.mTexCoords.y = ZERO;
1206 vert.mColor = underlineColor;
1207 newMesh.mVertices.PushBack(vert);
1209 //The top right edge of the underline
1210 vert.mPosition.x = brx;
1211 vert.mPosition.y = baseLine;
1212 vert.mTexCoords.x = u;
1213 vert.mColor = underlineColor;
1214 newMesh.mVertices.PushBack(vert);
1216 //The bottom left edge of the underline
1217 vert.mPosition.x = tlx;
1218 vert.mPosition.y = baseLine + thickness; // Vertical End of the second underline
1219 vert.mTexCoords.x = ZERO;
1220 vert.mTexCoords.y = v;
1221 vert.mColor = underlineColor;
1222 newMesh.mVertices.PushBack(vert);
1224 //The bottom right edge of the underline
1225 vert.mPosition.x = brx;
1226 vert.mPosition.y = baseLine + thickness;
1227 vert.mTexCoords.x = u;
1228 vert.mColor = underlineColor;
1229 newMesh.mVertices.PushBack(vert);
1231 // Six indices in counter clockwise winding
1232 newMesh.mIndices.PushBack(faceIndex + 1u);
1233 newMesh.mIndices.PushBack(faceIndex);
1234 newMesh.mIndices.PushBack(faceIndex + 2u);
1235 newMesh.mIndices.PushBack(faceIndex + 2u);
1236 newMesh.mIndices.PushBack(faceIndex + 3u);
1237 newMesh.mIndices.PushBack(faceIndex + 1u);
1241 Toolkit::Internal::AtlasMeshFactory::AppendMesh(meshRecords[index].mMesh, newMesh);
1247 void GenerateStrikethrough(std::vector<MeshRecord>& meshRecords,
1248 Vector<Extent>& extents,
1249 const StrikethroughStyleProperties& viewStrikethroughProperties,
1250 const std::map<uint32_t, StrikethroughStyleProperties>& mapStrikethroughChunkIdWithProperties)
1252 AtlasManager::Mesh2D newMesh;
1253 unsigned short faceIndex = 0;
1254 for(Vector<Extent>::ConstIterator eIt = extents.Begin(),
1255 eEndIt = extents.End();
1259 AtlasManager::Vertex2D vert;
1260 uint32_t index = eIt->mMeshRecordIndex;
1261 Vector2 uv = mGlyphManager.GetAtlasSize(meshRecords[index].mAtlasId);
1263 auto pairStrikethroughChunkIdWithProperties = mapStrikethroughChunkIdWithProperties.find(eIt->mStrikethroughChunkId);
1265 const StrikethroughStyleProperties strikethroughProperties = (pairStrikethroughChunkIdWithProperties == mapStrikethroughChunkIdWithProperties.end())
1266 ? viewStrikethroughProperties
1267 : pairStrikethroughChunkIdWithProperties->second;
1269 const Vector4& strikethroughColor = strikethroughProperties.colorDefined ? strikethroughProperties.color : viewStrikethroughProperties.color;
1271 // Make sure we don't hit texture edge for single pixel texture ( filled pixel is in top left of every atlas )
1272 float u = HALF / uv.x;
1273 float v = HALF / uv.y;
1274 float thickness = eIt->mLineThickness;
1275 float tlx = eIt->mLeft;
1276 float brx = eIt->mRight;
1277 float strikethroughPosition = eIt->mStrikethroughPosition;
1279 vert.mPosition.x = tlx;
1280 vert.mPosition.y = strikethroughPosition;
1281 vert.mTexCoords.x = ZERO;
1282 vert.mTexCoords.y = ZERO;
1283 vert.mColor = strikethroughColor;
1284 newMesh.mVertices.PushBack(vert);
1286 vert.mPosition.x = brx;
1287 vert.mPosition.y = strikethroughPosition;
1288 vert.mTexCoords.x = u;
1289 vert.mColor = strikethroughColor;
1290 newMesh.mVertices.PushBack(vert);
1292 vert.mPosition.x = tlx;
1293 vert.mPosition.y = strikethroughPosition + thickness;
1294 vert.mTexCoords.x = ZERO;
1295 vert.mTexCoords.y = v;
1296 vert.mColor = strikethroughColor;
1297 newMesh.mVertices.PushBack(vert);
1299 vert.mPosition.x = brx;
1300 vert.mPosition.y = strikethroughPosition + thickness;
1301 vert.mTexCoords.x = u;
1302 vert.mColor = strikethroughColor;
1303 newMesh.mVertices.PushBack(vert);
1305 // Six indices in counter clockwise winding
1306 newMesh.mIndices.PushBack(faceIndex + 1u);
1307 newMesh.mIndices.PushBack(faceIndex);
1308 newMesh.mIndices.PushBack(faceIndex + 2u);
1309 newMesh.mIndices.PushBack(faceIndex + 2u);
1310 newMesh.mIndices.PushBack(faceIndex + 3u);
1311 newMesh.mIndices.PushBack(faceIndex + 1u);
1314 Toolkit::Internal::AtlasMeshFactory::AppendMesh(meshRecords[index].mMesh, newMesh);
1318 Actor mActor; ///< The actor parent which renders the text
1319 AtlasGlyphManager mGlyphManager; ///< Glyph Manager to handle upload and caching
1320 TextAbstraction::FontClient mFontClient; ///< The font client used to supply glyph information
1321 Shader mShaderL8; ///< The shader for glyphs and emoji's shadows.
1322 Shader mShaderRgba; ///< The shader for emojis.
1323 std::vector<MaxBlockSize> mBlockSizes; ///< Maximum size needed to contain a glyph in a block within a new atlas
1324 Vector<TextCacheEntry> mTextCache; ///< Caches data from previous render
1325 Property::Map mQuadVertexFormat; ///< Describes the vertex format for text
1326 int mDepth; ///< DepthIndex passed by control when connect to stage
1329 Text::RendererPtr AtlasRenderer::New()
1331 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Text::AtlasRenderer::New()\n");
1333 return Text::RendererPtr(new AtlasRenderer());
1336 Actor AtlasRenderer::Render(Text::ViewInterface& view,
1338 Property::Index animatablePropertyIndex,
1339 float& alignmentOffset,
1342 DALI_LOG_INFO(gLogFilter, Debug::General, "Text::AtlasRenderer::Render()\n");
1344 UnparentAndReset(mImpl->mActor);
1346 Length numberOfGlyphs = view.GetNumberOfGlyphs();
1348 if(numberOfGlyphs > 0u)
1350 Vector<GlyphInfo> glyphs;
1351 glyphs.Resize(numberOfGlyphs);
1353 Vector<Vector2> positions;
1354 positions.Resize(numberOfGlyphs);
1356 numberOfGlyphs = view.GetGlyphs(glyphs.Begin(),
1362 glyphs.Resize(numberOfGlyphs);
1363 positions.Resize(numberOfGlyphs);
1365 const Vector4* const colorsBuffer = view.GetColors();
1366 const ColorIndex* const colorIndicesBuffer = view.GetColorIndices();
1367 const Vector4& defaultColor = view.GetTextColor();
1369 mImpl->AddGlyphs(view,
1371 animatablePropertyIndex,
1380 /* In the case where AddGlyphs does not create a renderable Actor for example when glyphs are all whitespace create a new Actor. */
1381 /* This renderable actor is used to position the text, other "decorations" can rely on there always being an Actor regardless of it is whitespace or regular text. */
1384 mImpl->mActor = Actor::New();
1388 return mImpl->mActor;
1391 AtlasRenderer::AtlasRenderer()
1396 AtlasRenderer::~AtlasRenderer()
1398 mImpl->RemoveText();