2 * Copyright (c) 2024 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/math/math-utils.h>
26 #include <dali/public-api/rendering/geometry.h>
27 #include <dali/public-api/rendering/renderer.h>
31 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
32 #include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
33 #include <dali-toolkit/internal/text/glyph-metrics-helper.h>
34 #include <dali-toolkit/internal/text/glyph-run.h>
35 #include <dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager.h>
36 #include <dali-toolkit/internal/text/rendering/atlas/atlas-mesh-factory.h>
37 #include <dali-toolkit/internal/text/rendering/styles/strikethrough-helper-functions.h>
38 #include <dali-toolkit/internal/text/rendering/styles/underline-helper-functions.h>
39 #include <dali-toolkit/internal/text/text-view.h>
42 using namespace Dali::Toolkit;
43 using namespace Dali::Toolkit::Text;
47 #if defined(DEBUG_ENABLED)
48 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_RENDERING");
51 const float ZERO(0.0f);
52 const float HALF(0.5f);
53 const float ONE(1.0f);
54 const float ONE_AND_A_HALF(1.5f);
55 const uint32_t DOUBLE_PIXEL_PADDING = 4u; //Padding will be added twice to Atlas
56 const uint16_t NO_OUTLINE = 0u;
59 struct AtlasRenderer::Impl
75 AtlasManager::Mesh2D mMesh;
79 * brief Struct used to generate the underline/striketthrough mesh.
80 * There is one Extent per line of text.
88 mUnderlinePosition(0.0f),
91 mUnderlineChunkId(0u),
92 mStrikethroughPosition(0.0f),
93 mStrikethroughChunkId(0u)
100 float mUnderlinePosition;
101 float mLineThickness;
102 uint32_t mMeshRecordIndex;
103 uint32_t mUnderlineChunkId;
104 float mStrikethroughPosition;
105 uint32_t mStrikethroughChunkId;
112 mNeededBlockWidth(0),
113 mNeededBlockHeight(0)
118 uint32_t mNeededBlockWidth;
119 uint32_t mNeededBlockHeight;
131 Text::GlyphIndex mIndex;
134 struct TextCacheEntry
147 Text::GlyphIndex mIndex;
149 uint16_t mOutlineWidth;
157 mGlyphManager = AtlasGlyphManager::Get();
158 mFontClient = TextAbstraction::FontClient::Get();
160 mQuadVertexFormat["aPosition"] = Property::VECTOR2;
161 mQuadVertexFormat["aTexCoord"] = Property::VECTOR2;
162 mQuadVertexFormat["aColor"] = Property::VECTOR4;
165 void CacheGlyph(const GlyphInfo& glyph, FontId lastFontId, const AtlasGlyphManager::GlyphStyle& style, AtlasManager::AtlasSlot& slot)
167 const Size& defaultTextAtlasSize = mFontClient.GetDefaultTextAtlasSize(); //Retrieve default size of text-atlas-block from font-client.
168 const Size& maximumTextAtlasSize = mFontClient.GetMaximumTextAtlasSize(); //Retrieve maximum size of text-atlas-block from font-client.
170 const bool glyphNotCached = !mGlyphManager.IsCached(glyph.fontId, glyph.index, style, slot); // Check FontGlyphRecord vector for entry with glyph index and fontId
172 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "AddGlyphs fontID[%u] glyphIndex[%u] [%s]\n", glyph.fontId, glyph.index, (glyphNotCached) ? "not cached" : "cached");
176 MaxBlockSize& blockSize = mBlockSizes[0u];
178 if(lastFontId != glyph.fontId)
181 // 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.
182 // CalculateBlocksSize() above ensures a block size entry exists.
183 for(std::vector<MaxBlockSize>::const_iterator it = mBlockSizes.begin(),
184 endIt = mBlockSizes.end();
188 const MaxBlockSize& blockSizeEntry = *it;
189 if(blockSizeEntry.mFontId == glyph.fontId)
191 blockSize = mBlockSizes[index];
196 // Create a new image for the glyph
199 // Whether the glyph is an outline.
200 const bool isOutline = 0u != style.outline;
202 // Whether the current glyph is a color one.
203 const bool isColorGlyph = mFontClient.IsColorGlyph(glyph.fontId, glyph.index);
205 if(!isOutline || (isOutline && !isColorGlyph))
207 // Retrieve the emoji's bitmap.
208 TextAbstraction::GlyphBufferData glyphBufferData;
209 glyphBufferData.width = isColorGlyph ? glyph.width : 0; // Desired width and height.
210 glyphBufferData.height = isColorGlyph ? glyph.height : 0;
212 mFontClient.CreateBitmap(glyph.fontId,
214 glyph.isItalicRequired,
215 glyph.isBoldRequired,
219 uint32_t glyphBufferSize = glyphBufferData.width * glyphBufferData.height * Pixel::GetBytesPerPixel(glyphBufferData.format);
220 // If glyph buffer data don't have ownership, Or if we need to decompress, create new memory and replace ownership.
221 if(!glyphBufferData.isBufferOwned || glyphBufferData.compressionType != TextAbstraction::GlyphBufferData::CompressionType::NO_COMPRESSION)
223 uint8_t* newBuffer = (uint8_t*)malloc(glyphBufferSize);
224 if(DALI_LIKELY(newBuffer != nullptr))
226 TextAbstraction::GlyphBufferData::Decompress(glyphBufferData, newBuffer);
227 if(glyphBufferData.isBufferOwned)
229 // Release previous buffer
230 free(glyphBufferData.buffer);
232 glyphBufferData.isBufferOwned = true;
233 glyphBufferData.buffer = newBuffer;
234 glyphBufferData.compressionType = TextAbstraction::GlyphBufferData::CompressionType::NO_COMPRESSION;
238 // Create the pixel data.
239 bitmap = PixelData::New(glyphBufferData.buffer,
241 glyphBufferData.width,
242 glyphBufferData.height,
243 glyphBufferData.format,
246 // Change buffer ownership.
247 glyphBufferData.isBufferOwned = false;
251 // Ensure that the next image will fit into the current block size
252 if(bitmap.GetWidth() > blockSize.mNeededBlockWidth)
254 blockSize.mNeededBlockWidth = bitmap.GetWidth();
257 if(bitmap.GetHeight() > blockSize.mNeededBlockHeight)
259 blockSize.mNeededBlockHeight = bitmap.GetHeight();
262 // If CheckAtlas in AtlasManager::Add can't fit the bitmap in the current atlas it will create a new atlas
264 // Setting the block size and size of new atlas does not mean a new one will be created. An existing atlas may still surffice.
265 uint32_t default_width = defaultTextAtlasSize.width;
266 uint32_t default_height = defaultTextAtlasSize.height;
269 (blockSize.mNeededBlockWidth >= (default_width - (DOUBLE_PIXEL_PADDING + 1u)) ||
270 blockSize.mNeededBlockHeight >= (default_height - (DOUBLE_PIXEL_PADDING + 1u))) &&
271 (default_width < maximumTextAtlasSize.width &&
272 default_height < maximumTextAtlasSize.height))
274 default_width <<= 1u;
275 default_height <<= 1u;
277 mGlyphManager.SetNewAtlasSize(default_width,
279 blockSize.mNeededBlockWidth,
280 blockSize.mNeededBlockHeight);
282 // Locate a new slot for our glyph
283 mGlyphManager.Add(glyph, style, bitmap, slot); // slot will be 0 is glyph not added
289 // We have 2+ copies of the same glyph
290 mGlyphManager.AdjustReferenceCount(glyph.fontId, glyph.index, style, 1); //increment
294 void GenerateMesh(const GlyphInfo& glyph,
295 const Vector2& position,
296 const Vector4& color,
298 AtlasManager::AtlasSlot& slot,
299 bool decorationlineGlyph,
300 float currentUnderlinePosition,
301 float currentlineThickness,
302 std::vector<MeshRecord>& meshContainer,
303 Vector<TextCacheEntry>& newTextCache,
304 Vector<Extent>& extents,
305 uint32_t underlineChunkId,
307 uint32_t strikethroughChunkId)
309 // Generate mesh data for this quad, plugging in our supplied position
310 AtlasManager::Mesh2D newMesh;
311 mGlyphManager.GenerateMeshData(slot.mImageId, position, newMesh);
315 TextCacheEntry textCacheEntry;
316 textCacheEntry.mFontId = glyph.fontId;
317 textCacheEntry.mImageId = slot.mImageId;
318 textCacheEntry.mIndex = glyph.index;
319 textCacheEntry.mOutlineWidth = outline;
320 textCacheEntry.isItalic = glyph.isItalicRequired;
321 textCacheEntry.isBold = glyph.isBoldRequired;
323 newTextCache.PushBack(textCacheEntry);
326 AtlasManager::Vertex2D* verticesBuffer = newMesh.mVertices.Begin();
328 for(unsigned int index = 0u, size = newMesh.mVertices.Count();
332 AtlasManager::Vertex2D& vertex = *(verticesBuffer + index);
334 // Set the color of the vertex.
335 vertex.mColor = color;
338 // Since Free Type font doesn't contain the strikethrough-position property,
339 // strikethrough position will be calculated by moving the underline position upwards by half the value of the line height.
340 float strikethroughStartingYPosition = (position.y + glyph.yBearing + currentUnderlinePosition) - ((glyph.height) * HALF);
342 // Find an existing mesh data object to attach to ( or create a new one, if we can't find one using the same atlas)
343 StitchTextMesh(meshContainer,
346 position.y + glyph.yBearing,
348 currentUnderlinePosition,
349 currentlineThickness,
352 strikethroughStartingYPosition,
353 strikethroughChunkId);
356 void CreateActors(const std::vector<MeshRecord>& meshContainer,
357 const Size& textSize,
358 const Vector4& color,
359 const Vector4& shadowColor,
360 const Vector2& shadowOffset,
362 Property::Index animatablePropertyIndex,
367 // Create a container actor to act as a common parent for text and shadow, to avoid color inheritence issues.
368 mActor = Actor::New();
369 mActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
370 mActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
371 mActor.SetProperty(Actor::Property::SIZE, textSize);
372 mActor.SetProperty(Actor::Property::COLOR_MODE, USE_OWN_MULTIPLY_PARENT_COLOR);
375 for(std::vector<MeshRecord>::const_iterator it = meshContainer.begin(),
376 endIt = meshContainer.end();
380 const MeshRecord& meshRecord = *it;
382 Actor actor = CreateMeshActor(textControl, animatablePropertyIndex, color, meshRecord, textSize, STYLE_NORMAL);
384 // Whether the actor has renderers.
385 const bool hasRenderer = actor.GetRendererCount() > 0u;
387 // Create an effect if necessary
391 // Change the color of the vertices.
392 for(Vector<AtlasManager::Vertex2D>::Iterator vIt = meshRecord.mMesh.mVertices.Begin(),
393 vEndIt = meshRecord.mMesh.mVertices.End();
397 AtlasManager::Vertex2D& vertex = *vIt;
399 vertex.mColor = shadowColor;
402 Actor shadowActor = CreateMeshActor(textControl, animatablePropertyIndex, color, meshRecord, textSize, STYLE_DROP_SHADOW);
403 #if defined(DEBUG_ENABLED)
404 shadowActor.SetProperty(Dali::Actor::Property::NAME, "Text Shadow renderable actor");
406 // Offset shadow in x and y
407 shadowActor.RegisterProperty("uOffset", shadowOffset);
408 Dali::Renderer renderer(shadowActor.GetRendererAt(0));
409 int depthIndex = renderer.GetProperty<int>(Dali::Renderer::Property::DEPTH_INDEX);
410 renderer.SetProperty(Dali::Renderer::Property::DEPTH_INDEX, depthIndex - 1);
411 mActor.Add(shadowActor);
421 void AddGlyphs(Text::ViewInterface& view,
423 Property::Index animatablePropertyIndex,
424 const Vector<Vector2>& positions,
425 const Vector<GlyphInfo>& glyphs,
426 const Vector4& defaultColor,
427 const Vector4* const colorsBuffer,
428 const ColorIndex* const colorIndicesBuffer,
432 AtlasManager::AtlasSlot slot;
436 AtlasManager::AtlasSlot slotOutline;
437 slotOutline.mImageId = 0u;
438 slotOutline.mAtlasId = 0u;
440 std::vector<MeshRecord> meshContainer;
441 std::vector<MeshRecord> meshContainerOutline;
442 Vector<Extent> extents;
443 Vector<Extent> strikethroughExtents;
446 const Vector2& textSize(view.GetLayoutSize());
447 const Vector2 halfTextSize(textSize * 0.5f);
448 const Vector2& shadowOffset(view.GetShadowOffset());
449 const Vector4& shadowColor(view.GetShadowColor());
450 const bool underlineEnabled = view.IsUnderlineEnabled();
451 const uint16_t outlineWidth = view.GetOutlineWidth();
452 const Vector4& outlineColor(view.GetOutlineColor());
453 const bool isOutline = 0u != outlineWidth;
454 const GlyphInfo* hyphens = view.GetHyphens();
455 const Length* hyphenIndices = view.GetHyphenIndices();
456 const Length hyphensCount = view.GetHyphensCount();
457 const bool strikethroughEnabled = view.IsStrikethroughEnabled();
458 const float characterSpacing(view.GetCharacterSpacing());
460 // Elided text info. Indices according to elided text.
461 const auto startIndexOfGlyphs = view.GetStartIndexOfElidedGlyphs();
462 const auto firstMiddleIndexOfElidedGlyphs = view.GetFirstMiddleIndexOfElidedGlyphs();
463 const auto secondMiddleIndexOfElidedGlyphs = view.GetSecondMiddleIndexOfElidedGlyphs();
465 const bool useDefaultColor = (NULL == colorsBuffer);
467 // Get a handle of the font client. Used to retrieve the bitmaps of the glyphs.
468 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
470 // Get the underline runs.
471 const Length numberOfUnderlineRuns = view.GetNumberOfUnderlineRuns();
472 Vector<UnderlinedGlyphRun> underlineRuns;
473 underlineRuns.Resize(numberOfUnderlineRuns);
474 view.GetUnderlineRuns(underlineRuns.Begin(),
476 numberOfUnderlineRuns);
478 // Aggregate underline-style-properties from view
479 const UnderlineStyleProperties viewUnderlineProperties{view.GetUnderlineType(),
480 view.GetUnderlineColor(),
481 view.GetUnderlineHeight(),
482 view.GetDashedUnderlineGap(),
483 view.GetDashedUnderlineWidth(),
490 float maxUnderlineHeight = viewUnderlineProperties.height;
492 // Get the strikethrough runs.
493 const Length numberOfStrikethroughRuns = view.GetNumberOfStrikethroughRuns();
494 Vector<StrikethroughGlyphRun> strikethroughRuns;
495 strikethroughRuns.Resize(numberOfStrikethroughRuns);
496 view.GetStrikethroughRuns(strikethroughRuns.Begin(), 0u, numberOfStrikethroughRuns);
498 const StrikethroughStyleProperties viewStrikethroughProperties{view.GetStrikethroughColor(),
499 view.GetStrikethroughHeight(),
503 float maxStrikethroughHeight = viewStrikethroughProperties.height;
505 FontId lastFontId = 0;
506 Style style = STYLE_NORMAL;
507 float currentUnderlinePosition = ZERO;
508 bool thereAreUnderlinedGlyphs = false;
509 bool thereAreStrikethroughGlyphs = false;
511 if(fabsf(shadowOffset.x) > Math::MACHINE_EPSILON_1 || fabsf(shadowOffset.y) > Math::MACHINE_EPSILON_1)
513 style = STYLE_DROP_SHADOW;
516 CalculateBlocksSize(glyphs);
518 // Avoid emptying mTextCache (& removing references) until after incremented references for the new text
519 Vector<TextCacheEntry> newTextCache;
520 const GlyphInfo* const glyphsBuffer = glyphs.Begin();
521 const Vector2* const positionsBuffer = positions.Begin();
522 const Vector2 lineOffsetPosition(minLineOffset, 0.f);
523 uint32_t hyphenIndex = 0;
525 //For septated underlined chunks. (this is for Markup case)
526 uint32_t underlineChunkId = 0u; // give id for each chunk.
527 bool isPreUnderlined = false; // status of underlined for previous glyph.
528 std::map<uint32_t, UnderlineStyleProperties> mapUnderlineChunkIdWithProperties; // mapping underlineChunkId with UnderlineStyleProperties to get properties of underlined chunk
529 UnderlineStyleProperties preUnderlineProperties = viewUnderlineProperties; // the previous UnderlineStyleProperties
531 //For septated strikethrough chunks. (this is for Markup case)
532 uint32_t strikethroughChunkId = 0u; // give id for each chunk.
533 bool isPreStrikethrough = false; // status of strikethrough for previous glyph.
534 std::map<uint32_t, StrikethroughStyleProperties> mapStrikethroughChunkIdWithProperties; // mapping strikethroughChunkId with StrikethroughStyleProperties to get properties of strikethrough chunk
535 StrikethroughStyleProperties preStrikethroughProperties = viewStrikethroughProperties; // the previous StrikethroughStyleProperties
537 const Character* textBuffer = view.GetTextBuffer();
538 float calculatedAdvance = 0.f;
539 const Vector<CharacterIndex>& glyphToCharacterMap = view.GetGlyphsToCharacters();
540 const CharacterIndex* glyphToCharacterMapBuffer = glyphToCharacterMap.Begin();
542 //Skip hyphenIndices less than startIndexOfGlyphs or between two middle of elided text
545 while((hyphenIndex < hyphensCount) && (hyphenIndices[hyphenIndex] < startIndexOfGlyphs ||
546 (hyphenIndices[hyphenIndex] > firstMiddleIndexOfElidedGlyphs && hyphenIndices[hyphenIndex] < secondMiddleIndexOfElidedGlyphs)))
552 //To keep the last fontMetrics of lastDecorativeLinesFontId
553 FontId lastDecorativeLinesFontId = 0; // DecorativeLines like Undeline and Strikethrough
554 FontMetrics lastDecorativeLinesFontMetrics;
555 fontClient.GetFontMetrics(lastDecorativeLinesFontId, lastDecorativeLinesFontMetrics);
557 // Iteration on glyphs
558 for(uint32_t i = 0, glyphSize = glyphs.Size(); i < glyphSize; ++i)
561 bool addHyphen = ((hyphenIndex < hyphensCount) && hyphenIndices && ((i + startIndexOfGlyphs) == hyphenIndices[hyphenIndex]));
562 // TODO : Shouldn't we have to control here when i == 0 cases?
563 if(addHyphen && hyphens && i > 0u)
565 glyph = hyphens[hyphenIndex];
570 glyph = *(glyphsBuffer + i);
573 Vector<UnderlinedGlyphRun>::ConstIterator currentUnderlinedGlyphRunIt = underlineRuns.End();
574 const bool isGlyphUnderlined = underlineEnabled || IsGlyphUnderlined(i, underlineRuns, currentUnderlinedGlyphRunIt);
575 const UnderlineStyleProperties currentUnderlineProperties = GetCurrentUnderlineProperties(i, isGlyphUnderlined, underlineRuns, currentUnderlinedGlyphRunIt, viewUnderlineProperties);
576 float currentUnderlineHeight = currentUnderlineProperties.height;
577 thereAreUnderlinedGlyphs = thereAreUnderlinedGlyphs || isGlyphUnderlined;
579 Vector<StrikethroughGlyphRun>::ConstIterator currentStrikethroughGlyphRunIt = strikethroughRuns.End();
580 const bool isGlyphStrikethrough = strikethroughEnabled || IsGlyphStrikethrough(i, strikethroughRuns, currentStrikethroughGlyphRunIt);
581 const StrikethroughStyleProperties currentStrikethroughProperties = GetCurrentStrikethroughProperties(i, isGlyphStrikethrough, strikethroughRuns, currentStrikethroughGlyphRunIt, viewStrikethroughProperties);
582 float currentStrikethroughHeight = currentStrikethroughProperties.height;
583 thereAreStrikethroughGlyphs = thereAreStrikethroughGlyphs || isGlyphStrikethrough;
585 // No operation for white space
586 if(!Dali::EqualsZero(glyph.width) && !Dali::EqualsZero(glyph.height))
588 // Check and update decorative-lines informations
589 if(isGlyphUnderlined || isGlyphStrikethrough)
591 bool isDecorativeLinesFontIdUpdated = false;
592 // Are we still using the same fontId as previous
593 if(glyph.fontId != lastDecorativeLinesFontId)
595 // We need to fetch fresh font metrics
596 lastDecorativeLinesFontId = glyph.fontId;
597 isDecorativeLinesFontIdUpdated = true;
598 fontClient.GetFontMetrics(lastDecorativeLinesFontId, lastDecorativeLinesFontMetrics);
600 if(isGlyphStrikethrough || isGlyphUnderlined)
602 //The currentUnderlinePosition will be used for both Underline and/or Strikethrough
603 currentUnderlinePosition = FetchUnderlinePositionFromFontMetrics(lastDecorativeLinesFontMetrics);
607 if(isGlyphUnderlined && (isDecorativeLinesFontIdUpdated || !(currentUnderlineProperties.IsHeightEqualTo(preUnderlineProperties))))
609 //If the Underline Height is changed then we need to recalculate height.
610 if(!(currentUnderlineProperties.IsHeightEqualTo(preUnderlineProperties)))
612 maxUnderlineHeight = currentUnderlineHeight;
615 CalcualteUnderlineHeight(lastDecorativeLinesFontMetrics, currentUnderlineHeight, maxUnderlineHeight);
618 if(isGlyphStrikethrough && (isDecorativeLinesFontIdUpdated || !(currentStrikethroughProperties.IsHeightEqualTo(preStrikethroughProperties))))
620 //If the Strikethrough Height is changed then we need to recalculate height.
621 if(!(currentStrikethroughProperties.IsHeightEqualTo(preStrikethroughProperties)))
623 maxStrikethroughHeight = currentStrikethroughHeight;
626 CalcualteStrikethroughHeight(currentStrikethroughHeight, maxStrikethroughHeight);
628 } // decorative-lines
630 AtlasGlyphManager::GlyphStyle style;
631 style.isItalic = glyph.isItalicRequired;
632 style.isBold = glyph.isBoldRequired;
634 // Retrieves and caches the glyph's bitmap.
635 CacheGlyph(glyph, lastFontId, style, slot);
637 // Retrieves and caches the outline glyph's bitmap.
640 style.outline = outlineWidth;
641 CacheGlyph(glyph, lastFontId, style, slotOutline);
644 // Move the origin (0,0) of the mesh to the center of the actor
645 Vector2 position = *(positionsBuffer + i);
649 GlyphInfo tempInfo = *(glyphsBuffer + i);
650 calculatedAdvance = GetCalculatedAdvance(*(textBuffer + (*(glyphToCharacterMapBuffer + i))), characterSpacing, tempInfo.advance);
651 position.x = position.x + calculatedAdvance - tempInfo.xBearing + glyph.xBearing;
652 position.y += tempInfo.yBearing - glyph.yBearing;
655 position = Vector2(roundf(position.x), position.y) - halfTextSize - lineOffsetPosition; // roundf() avoids pixel alignment issues.
657 if(0u != slot.mImageId) // invalid slot id, glyph has failed to be added to atlas
659 Vector2 positionPlusOutlineOffset = position;
662 // Add an offset to the text.
663 const float outlineWidthOffset = static_cast<float>(outlineWidth);
664 positionPlusOutlineOffset += Vector2(outlineWidthOffset, outlineWidthOffset);
667 // Get the color of the character.
668 const ColorIndex colorIndex = useDefaultColor ? 0u : *(colorIndicesBuffer + i);
669 const Vector4& color = (useDefaultColor || (0u == colorIndex)) ? defaultColor : *(colorsBuffer + colorIndex - 1u);
671 //The new underlined chunk. Add new id if they are not consecutive indices (this is for Markup case)
672 // Examples: "Hello <u>World</u> Hello <u>World</u>", "<u>World</u> Hello <u>World</u>", "<u> World</u> Hello <u>World</u>"
673 if((!isPreUnderlined && isGlyphUnderlined) || (isGlyphUnderlined && (preUnderlineProperties != currentUnderlineProperties)))
676 mapUnderlineChunkIdWithProperties.insert(std::pair<uint32_t, UnderlineStyleProperties>(underlineChunkId, currentUnderlineProperties));
679 //Keep status of underlined for previous glyph to check consecutive indices
680 isPreUnderlined = isGlyphUnderlined;
681 preUnderlineProperties = currentUnderlineProperties;
684 positionPlusOutlineOffset,
689 currentUnderlinePosition,
698 if(isGlyphStrikethrough)
700 //The new strikethrough chunk. Add new id if they are not consecutive indices (this is for Markup case)
701 // Examples: "Hello <s>World</s> Hello <s>World</s>", "<s>World</s> Hello <s>World</s>", "<s> World</s> Hello <s>World</s>"
702 if((!isPreStrikethrough) || (preStrikethroughProperties != currentStrikethroughProperties))
704 strikethroughChunkId++;
705 mapStrikethroughChunkIdWithProperties.insert(std::pair<uint32_t, StrikethroughStyleProperties>(strikethroughChunkId, currentStrikethroughProperties));
709 positionPlusOutlineOffset,
713 isGlyphStrikethrough,
715 maxStrikethroughHeight,
718 strikethroughExtents,
721 strikethroughChunkId);
724 //Keep status of Strikethrough for previous glyph to check consecutive indices
725 isPreStrikethrough = isGlyphStrikethrough;
726 preStrikethroughProperties = currentStrikethroughProperties;
728 lastFontId = glyph.fontId; // Prevents searching for existing blocksizes when string of the same fontId.
731 if(isOutline && (0u != slotOutline.mImageId)) // invalid slot id, glyph has failed to be added to atlas
739 currentUnderlinePosition,
741 meshContainerOutline,
756 // Now remove references for the old text
758 mTextCache.Swap(newTextCache);
760 if(thereAreUnderlinedGlyphs)
762 // Check to see if any of the text needs an underline
763 GenerateUnderlines(meshContainer, extents, viewUnderlineProperties, mapUnderlineChunkIdWithProperties);
766 if(thereAreStrikethroughGlyphs)
768 // Check to see if any of the text needs a strikethrough
769 GenerateStrikethrough(meshContainer, strikethroughExtents, viewStrikethroughProperties, mapStrikethroughChunkIdWithProperties);
772 // For each MeshData object, create a mesh actor and add to the renderable actor
773 bool isShadowDrawn = false;
774 if(!meshContainerOutline.empty())
776 const bool drawShadow = STYLE_DROP_SHADOW == style;
777 CreateActors(meshContainerOutline,
783 animatablePropertyIndex,
786 isShadowDrawn = drawShadow;
789 // For each MeshData object, create a mesh actor and add to the renderable actor
790 if(!meshContainer.empty())
792 const bool drawShadow = !isShadowDrawn && (STYLE_DROP_SHADOW == style);
793 CreateActors(meshContainer,
799 animatablePropertyIndex,
803 #if defined(DEBUG_ENABLED)
804 Toolkit::AtlasGlyphManager::Metrics metrics = mGlyphManager.GetMetrics();
805 DALI_LOG_INFO(gLogFilter, Debug::General, "TextAtlasRenderer::GlyphManager::GlyphCount: %i, AtlasCount: %i, TextureMemoryUse: %iK\n", metrics.mGlyphCount, metrics.mAtlasMetrics.mAtlasCount, metrics.mAtlasMetrics.mTextureMemoryUsed / 1024);
807 if(gLogFilter->IsEnabledFor(Debug::Verbose))
809 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "%s\n", metrics.mVerboseGlyphCounts.c_str());
811 for(uint32_t i = 0; i < metrics.mAtlasMetrics.mAtlasCount; ++i)
813 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);
821 for(Vector<TextCacheEntry>::Iterator oldTextIter = mTextCache.Begin(); oldTextIter != mTextCache.End(); ++oldTextIter)
823 AtlasGlyphManager::GlyphStyle style;
824 style.outline = oldTextIter->mOutlineWidth;
825 style.isItalic = oldTextIter->isItalic;
826 style.isBold = oldTextIter->isBold;
827 mGlyphManager.AdjustReferenceCount(oldTextIter->mFontId, oldTextIter->mIndex, style, -1 /*decrement*/);
829 mTextCache.Resize(0);
832 Actor CreateMeshActor(Actor textControl, Property::Index animatablePropertyIndex, const Vector4& defaultColor, const MeshRecord& meshRecord, const Vector2& actorSize, Style style)
834 VertexBuffer quadVertices = VertexBuffer::New(mQuadVertexFormat);
835 quadVertices.SetData(const_cast<AtlasManager::Vertex2D*>(&meshRecord.mMesh.mVertices[0]), meshRecord.mMesh.mVertices.Size());
837 Geometry quadGeometry = Geometry::New();
838 quadGeometry.AddVertexBuffer(quadVertices);
839 quadGeometry.SetIndexBuffer(&meshRecord.mMesh.mIndices[0], meshRecord.mMesh.mIndices.Size());
841 TextureSet textureSet(mGlyphManager.GetTextures(meshRecord.mAtlasId));
843 // Choose the shader to use.
844 const bool isColorShader = (STYLE_DROP_SHADOW != style) && (Pixel::BGRA8888 == mGlyphManager.GetPixelFormat(meshRecord.mAtlasId));
848 // The glyph is an emoji and is not a shadow.
851 mShaderRgba = Shader::New(SHADER_TEXT_ATLAS_SHADER_VERT, SHADER_TEXT_ATLAS_RGBA_SHADER_FRAG, Shader::Hint::NONE, "TEXT_ATLAS_RGBA");
853 shader = mShaderRgba;
857 // The glyph is text or a shadow.
860 mShaderL8 = Shader::New(SHADER_TEXT_ATLAS_SHADER_VERT, SHADER_TEXT_ATLAS_L8_SHADER_FRAG, Shader::Hint::NONE, "TEXT_ATLAS_L8");
865 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "defaultColor[%f, %f, %f, %f ]\n", defaultColor.r, defaultColor.g, defaultColor.b, defaultColor.a);
867 Dali::Property::Index shaderTextColorIndex = shader.RegisterProperty("textColorAnimatable", defaultColor);
869 if(animatablePropertyIndex != Property::INVALID_INDEX)
871 // create constraint for the animatable text's color Property with textColorAnimatable in the shader.
872 if(shaderTextColorIndex)
874 Constraint constraint = Constraint::New<Vector4>(shader, shaderTextColorIndex, EqualToConstraint());
875 constraint.AddSource(Source(textControl, animatablePropertyIndex));
881 // If not animating the text colour then set to 1's so shader uses the current vertex color
882 shader.RegisterProperty("textColorAnimatable", Vector4(1.0, 1.0, 1.0, 1.0));
885 Dali::Renderer renderer = Dali::Renderer::New(quadGeometry, shader);
886 renderer.SetTextures(textureSet);
887 renderer.SetProperty(Dali::Renderer::Property::BLEND_MODE, BlendMode::ON);
888 renderer.SetProperty(Dali::Renderer::Property::DEPTH_INDEX, DepthIndex::CONTENT + mDepth);
890 Actor actor = Actor::New();
891 #if defined(DEBUG_ENABLED)
892 actor.SetProperty(Dali::Actor::Property::NAME, "Text renderable actor");
894 actor.AddRenderer(renderer);
895 // Keep all of the origins aligned
896 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
897 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
898 actor.SetProperty(Actor::Property::SIZE, actorSize);
899 actor.RegisterProperty("uOffset", Vector2::ZERO);
900 actor.SetProperty(Actor::Property::COLOR_MODE, USE_OWN_MULTIPLY_PARENT_COLOR);
905 void StitchTextMesh(std::vector<MeshRecord>& meshContainer,
906 AtlasManager::Mesh2D& newMesh,
907 Vector<Extent>& extents,
909 bool decorationlineGlyph,
910 float underlinePosition,
912 AtlasManager::AtlasSlot& slot,
913 uint32_t underlineChunkId,
914 float strikethroughPosition,
915 uint32_t strikethroughChunkId)
919 float left = newMesh.mVertices[0].mPosition.x;
920 float right = newMesh.mVertices[1].mPosition.x;
922 // Check to see if there's a mesh data object that references the same atlas ?
924 for(std::vector<MeshRecord>::iterator mIt = meshContainer.begin(),
925 mEndIt = meshContainer.end();
929 if(slot.mAtlasId == mIt->mAtlasId)
931 // Append the mesh to the existing mesh and adjust any extents
932 Toolkit::Internal::AtlasMeshFactory::AppendMesh(mIt->mMesh, newMesh);
934 if(decorationlineGlyph)
936 AdjustExtents(extents,
945 strikethroughPosition,
946 strikethroughChunkId);
953 // No mesh data object currently exists that references this atlas, so create a new one
954 MeshRecord meshRecord;
955 meshRecord.mAtlasId = slot.mAtlasId;
956 meshRecord.mMesh = newMesh;
957 meshContainer.push_back(meshRecord);
959 if(decorationlineGlyph)
961 // Adjust extents for this new meshrecord
962 AdjustExtents(extents,
964 meshContainer.size() - 1u,
971 strikethroughPosition,
972 strikethroughChunkId);
977 void AdjustExtents(Vector<Extent>& extents,
978 std::vector<MeshRecord>& meshRecords,
983 float underlinePosition,
985 uint32_t underlineChunkId,
986 float strikethroughPosition,
987 uint32_t strikethroughChunkId)
989 bool foundExtent = false;
990 for(Vector<Extent>::Iterator eIt = extents.Begin(),
991 eEndIt = extents.End();
995 if(Equals(baseLine, eIt->mBaseLine) && underlineChunkId == eIt->mUnderlineChunkId && strikethroughChunkId == eIt->mStrikethroughChunkId)
998 if(left < eIt->mLeft)
1002 if(right > eIt->mRight)
1004 eIt->mRight = right;
1007 if(underlinePosition > eIt->mUnderlinePosition)
1009 eIt->mUnderlinePosition = underlinePosition;
1011 if(lineThickness > eIt->mLineThickness)
1013 eIt->mLineThickness = lineThickness;
1020 extent.mLeft = left;
1021 extent.mRight = right;
1022 extent.mBaseLine = baseLine;
1023 extent.mUnderlinePosition = underlinePosition;
1024 extent.mMeshRecordIndex = index;
1025 extent.mUnderlineChunkId = underlineChunkId;
1026 extent.mLineThickness = lineThickness;
1027 extent.mStrikethroughPosition = strikethroughPosition;
1028 extent.mStrikethroughChunkId = strikethroughChunkId;
1029 extents.PushBack(extent);
1033 void CalculateBlocksSize(const Vector<GlyphInfo>& glyphs)
1035 for(Vector<GlyphInfo>::ConstIterator glyphIt = glyphs.Begin(),
1036 glyphEndIt = glyphs.End();
1037 glyphIt != glyphEndIt;
1040 const FontId fontId = (*glyphIt).fontId;
1041 bool foundFont = false;
1043 for(std::vector<MaxBlockSize>::const_iterator blockIt = mBlockSizes.begin(),
1044 blockEndIt = mBlockSizes.end();
1045 blockIt != blockEndIt;
1048 if((*blockIt).mFontId == fontId) // Different size fonts will have a different fontId
1050 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Text::AtlasRenderer::CalculateBlocksSize match found fontID(%u) glyphIndex(%u)\n", fontId, (*glyphIt).index);
1058 FontMetrics fontMetrics;
1059 mFontClient.GetFontMetrics(fontId, fontMetrics);
1061 MaxBlockSize maxBlockSize;
1062 maxBlockSize.mNeededBlockWidth = static_cast<uint32_t>(fontMetrics.height);
1063 maxBlockSize.mNeededBlockHeight = maxBlockSize.mNeededBlockWidth;
1064 maxBlockSize.mFontId = fontId;
1065 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Text::AtlasRenderer::CalculateBlocksSize New font with no matched blocksize, setting blocksize[%u]\n", maxBlockSize.mNeededBlockWidth);
1066 mBlockSizes.push_back(maxBlockSize);
1071 void GenerateUnderlines(std::vector<MeshRecord>& meshRecords,
1072 Vector<Extent>& extents,
1073 const UnderlineStyleProperties& viewUnderlineProperties,
1074 const std::map<uint32_t, UnderlineStyleProperties>& mapUnderlineChunkIdWithProperties)
1076 AtlasManager::Mesh2D newMesh;
1077 unsigned short faceIndex = 0;
1079 for(Vector<Extent>::ConstIterator eIt = extents.Begin(),
1080 eEndIt = extents.End();
1084 AtlasManager::Vertex2D vert;
1085 uint32_t index = eIt->mMeshRecordIndex;
1086 Vector2 uv = mGlyphManager.GetAtlasSize(meshRecords[index].mAtlasId);
1088 auto pairUnderlineChunkIdWithProperties = mapUnderlineChunkIdWithProperties.find(eIt->mUnderlineChunkId);
1090 const UnderlineStyleProperties underlineProperties = (pairUnderlineChunkIdWithProperties == mapUnderlineChunkIdWithProperties.end())
1091 ? viewUnderlineProperties
1092 : pairUnderlineChunkIdWithProperties->second;
1094 const Vector4& underlineColor = underlineProperties.colorDefined ? underlineProperties.color : viewUnderlineProperties.color;
1095 const Text::Underline::Type& underlineType = underlineProperties.typeDefined ? underlineProperties.type : viewUnderlineProperties.type;
1096 const float& dashedUnderlineGap = underlineProperties.dashGapDefined ? underlineProperties.dashGap : viewUnderlineProperties.dashGap;
1097 const float& dashedUnderlineWidth = underlineProperties.dashWidthDefined ? underlineProperties.dashWidth : viewUnderlineProperties.dashWidth;
1099 // Make sure we don't hit texture edge for single pixel texture ( filled pixel is in top left of every atlas )
1100 float u = HALF / uv.x;
1101 float v = HALF / uv.y;
1102 float thickness = eIt->mLineThickness;
1103 float ShiftLineBy = (underlineType == Text::Underline::Type::DOUBLE) ? (thickness * ONE_AND_A_HALF) : (thickness * HALF);
1104 float baseLine = eIt->mBaseLine + eIt->mUnderlinePosition - ShiftLineBy;
1105 float tlx = eIt->mLeft;
1106 float brx = eIt->mRight;
1108 if(underlineType == Text::Underline::Type::DASHED)
1110 float dashTlx = tlx;
1111 float dashBrx = tlx;
1113 while((dashTlx >= tlx) && (dashTlx < brx) && ((dashTlx + dashedUnderlineWidth) <= brx))
1115 dashBrx = dashTlx + dashedUnderlineWidth;
1117 //The top left edge of the underline
1118 vert.mPosition.x = dashTlx;
1119 vert.mPosition.y = baseLine;
1120 vert.mTexCoords.x = ZERO;
1121 vert.mTexCoords.y = ZERO;
1122 vert.mColor = underlineColor;
1123 newMesh.mVertices.PushBack(vert);
1125 //The top right edge of the underline
1126 vert.mPosition.x = dashBrx;
1127 vert.mPosition.y = baseLine;
1128 vert.mTexCoords.x = u;
1129 vert.mColor = underlineColor;
1130 newMesh.mVertices.PushBack(vert);
1132 //The bottom left edge of the underline
1133 vert.mPosition.x = dashTlx;
1134 vert.mPosition.y = baseLine + thickness;
1135 vert.mTexCoords.x = ZERO;
1136 vert.mTexCoords.y = v;
1137 vert.mColor = underlineColor;
1138 newMesh.mVertices.PushBack(vert);
1140 //The bottom right edge of the underline
1141 vert.mPosition.x = dashBrx;
1142 vert.mPosition.y = baseLine + thickness;
1143 vert.mTexCoords.x = u;
1144 vert.mColor = underlineColor;
1145 newMesh.mVertices.PushBack(vert);
1147 dashTlx = dashBrx + dashedUnderlineGap; // The next dash will start at the right of the current dash plus the gap
1149 // Six indices in counter clockwise winding
1150 newMesh.mIndices.PushBack(faceIndex + 1u);
1151 newMesh.mIndices.PushBack(faceIndex);
1152 newMesh.mIndices.PushBack(faceIndex + 2u);
1153 newMesh.mIndices.PushBack(faceIndex + 2u);
1154 newMesh.mIndices.PushBack(faceIndex + 3u);
1155 newMesh.mIndices.PushBack(faceIndex + 1u);
1159 Toolkit::Internal::AtlasMeshFactory::AppendMesh(meshRecords[index].mMesh, newMesh);
1164 // It's either SOLID or DOUBLE so we need to generate the first solid underline anyway.
1165 vert.mPosition.x = tlx;
1166 vert.mPosition.y = baseLine;
1167 vert.mTexCoords.x = ZERO;
1168 vert.mTexCoords.y = ZERO;
1169 vert.mColor = underlineColor;
1170 newMesh.mVertices.PushBack(vert);
1172 vert.mPosition.x = brx;
1173 vert.mPosition.y = baseLine;
1174 vert.mTexCoords.x = u;
1175 vert.mColor = underlineColor;
1176 newMesh.mVertices.PushBack(vert);
1178 vert.mPosition.x = tlx;
1179 vert.mPosition.y = baseLine + thickness;
1180 vert.mTexCoords.x = ZERO;
1181 vert.mTexCoords.y = v;
1182 vert.mColor = underlineColor;
1183 newMesh.mVertices.PushBack(vert);
1185 vert.mPosition.x = brx;
1186 vert.mPosition.y = baseLine + thickness;
1187 vert.mTexCoords.x = u;
1188 vert.mColor = underlineColor;
1189 newMesh.mVertices.PushBack(vert);
1191 // Six indices in counter clockwise winding
1192 newMesh.mIndices.PushBack(faceIndex + 1u);
1193 newMesh.mIndices.PushBack(faceIndex);
1194 newMesh.mIndices.PushBack(faceIndex + 2u);
1195 newMesh.mIndices.PushBack(faceIndex + 2u);
1196 newMesh.mIndices.PushBack(faceIndex + 3u);
1197 newMesh.mIndices.PushBack(faceIndex + 1u);
1200 Toolkit::Internal::AtlasMeshFactory::AppendMesh(meshRecords[index].mMesh, newMesh);
1202 if(underlineType == Text::Underline::Type::DOUBLE)
1204 baseLine += 2 * thickness;
1206 //The top left edge of the underline
1207 vert.mPosition.x = tlx;
1208 vert.mPosition.y = baseLine; // Vertical start of the second underline
1209 vert.mTexCoords.x = ZERO;
1210 vert.mTexCoords.y = ZERO;
1211 vert.mColor = underlineColor;
1212 newMesh.mVertices.PushBack(vert);
1214 //The top right edge of the underline
1215 vert.mPosition.x = brx;
1216 vert.mPosition.y = baseLine;
1217 vert.mTexCoords.x = u;
1218 vert.mColor = underlineColor;
1219 newMesh.mVertices.PushBack(vert);
1221 //The bottom left edge of the underline
1222 vert.mPosition.x = tlx;
1223 vert.mPosition.y = baseLine + thickness; // Vertical End of the second underline
1224 vert.mTexCoords.x = ZERO;
1225 vert.mTexCoords.y = v;
1226 vert.mColor = underlineColor;
1227 newMesh.mVertices.PushBack(vert);
1229 //The bottom right edge of the underline
1230 vert.mPosition.x = brx;
1231 vert.mPosition.y = baseLine + thickness;
1232 vert.mTexCoords.x = u;
1233 vert.mColor = underlineColor;
1234 newMesh.mVertices.PushBack(vert);
1236 // Six indices in counter clockwise winding
1237 newMesh.mIndices.PushBack(faceIndex + 1u);
1238 newMesh.mIndices.PushBack(faceIndex);
1239 newMesh.mIndices.PushBack(faceIndex + 2u);
1240 newMesh.mIndices.PushBack(faceIndex + 2u);
1241 newMesh.mIndices.PushBack(faceIndex + 3u);
1242 newMesh.mIndices.PushBack(faceIndex + 1u);
1246 Toolkit::Internal::AtlasMeshFactory::AppendMesh(meshRecords[index].mMesh, newMesh);
1252 void GenerateStrikethrough(std::vector<MeshRecord>& meshRecords,
1253 Vector<Extent>& extents,
1254 const StrikethroughStyleProperties& viewStrikethroughProperties,
1255 const std::map<uint32_t, StrikethroughStyleProperties>& mapStrikethroughChunkIdWithProperties)
1257 AtlasManager::Mesh2D newMesh;
1258 unsigned short faceIndex = 0;
1259 for(Vector<Extent>::ConstIterator eIt = extents.Begin(),
1260 eEndIt = extents.End();
1264 AtlasManager::Vertex2D vert;
1265 uint32_t index = eIt->mMeshRecordIndex;
1266 Vector2 uv = mGlyphManager.GetAtlasSize(meshRecords[index].mAtlasId);
1268 auto pairStrikethroughChunkIdWithProperties = mapStrikethroughChunkIdWithProperties.find(eIt->mStrikethroughChunkId);
1270 const StrikethroughStyleProperties strikethroughProperties = (pairStrikethroughChunkIdWithProperties == mapStrikethroughChunkIdWithProperties.end())
1271 ? viewStrikethroughProperties
1272 : pairStrikethroughChunkIdWithProperties->second;
1274 const Vector4& strikethroughColor = strikethroughProperties.colorDefined ? strikethroughProperties.color : viewStrikethroughProperties.color;
1276 // Make sure we don't hit texture edge for single pixel texture ( filled pixel is in top left of every atlas )
1277 float u = HALF / uv.x;
1278 float v = HALF / uv.y;
1279 float thickness = eIt->mLineThickness;
1280 float tlx = eIt->mLeft;
1281 float brx = eIt->mRight;
1282 float strikethroughPosition = eIt->mStrikethroughPosition;
1284 vert.mPosition.x = tlx;
1285 vert.mPosition.y = strikethroughPosition;
1286 vert.mTexCoords.x = ZERO;
1287 vert.mTexCoords.y = ZERO;
1288 vert.mColor = strikethroughColor;
1289 newMesh.mVertices.PushBack(vert);
1291 vert.mPosition.x = brx;
1292 vert.mPosition.y = strikethroughPosition;
1293 vert.mTexCoords.x = u;
1294 vert.mColor = strikethroughColor;
1295 newMesh.mVertices.PushBack(vert);
1297 vert.mPosition.x = tlx;
1298 vert.mPosition.y = strikethroughPosition + thickness;
1299 vert.mTexCoords.x = ZERO;
1300 vert.mTexCoords.y = v;
1301 vert.mColor = strikethroughColor;
1302 newMesh.mVertices.PushBack(vert);
1304 vert.mPosition.x = brx;
1305 vert.mPosition.y = strikethroughPosition + thickness;
1306 vert.mTexCoords.x = u;
1307 vert.mColor = strikethroughColor;
1308 newMesh.mVertices.PushBack(vert);
1310 // Six indices in counter clockwise winding
1311 newMesh.mIndices.PushBack(faceIndex + 1u);
1312 newMesh.mIndices.PushBack(faceIndex);
1313 newMesh.mIndices.PushBack(faceIndex + 2u);
1314 newMesh.mIndices.PushBack(faceIndex + 2u);
1315 newMesh.mIndices.PushBack(faceIndex + 3u);
1316 newMesh.mIndices.PushBack(faceIndex + 1u);
1319 Toolkit::Internal::AtlasMeshFactory::AppendMesh(meshRecords[index].mMesh, newMesh);
1323 Actor mActor; ///< The actor parent which renders the text
1324 AtlasGlyphManager mGlyphManager; ///< Glyph Manager to handle upload and caching
1325 TextAbstraction::FontClient mFontClient; ///< The font client used to supply glyph information
1326 Shader mShaderL8; ///< The shader for glyphs and emoji's shadows.
1327 Shader mShaderRgba; ///< The shader for emojis.
1328 std::vector<MaxBlockSize> mBlockSizes; ///< Maximum size needed to contain a glyph in a block within a new atlas
1329 Vector<TextCacheEntry> mTextCache; ///< Caches data from previous render
1330 Property::Map mQuadVertexFormat; ///< Describes the vertex format for text
1331 int mDepth; ///< DepthIndex passed by control when connect to stage
1334 Text::RendererPtr AtlasRenderer::New()
1336 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Text::AtlasRenderer::New()\n");
1338 return Text::RendererPtr(new AtlasRenderer());
1341 Actor AtlasRenderer::Render(Text::ViewInterface& view,
1343 Property::Index animatablePropertyIndex,
1344 float& alignmentOffset,
1347 DALI_LOG_INFO(gLogFilter, Debug::General, "Text::AtlasRenderer::Render()\n");
1349 UnparentAndReset(mImpl->mActor);
1351 Length numberOfGlyphs = view.GetNumberOfGlyphs();
1353 if(numberOfGlyphs > 0u)
1355 Vector<GlyphInfo> glyphs;
1356 glyphs.Resize(numberOfGlyphs);
1358 Vector<Vector2> positions;
1359 positions.Resize(numberOfGlyphs);
1361 numberOfGlyphs = view.GetGlyphs(glyphs.Begin(),
1367 glyphs.Resize(numberOfGlyphs);
1368 positions.Resize(numberOfGlyphs);
1370 const Vector4* const colorsBuffer = view.GetColors();
1371 const ColorIndex* const colorIndicesBuffer = view.GetColorIndices();
1372 const Vector4& defaultColor = view.GetTextColor();
1374 mImpl->AddGlyphs(view,
1376 animatablePropertyIndex,
1385 /* In the case where AddGlyphs does not create a renderable Actor for example when glyphs are all whitespace create a new Actor. */
1386 /* 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. */
1389 mImpl->mActor = Actor::New();
1393 return mImpl->mActor;
1396 AtlasRenderer::AtlasRenderer()
1401 AtlasRenderer::~AtlasRenderer()
1403 mImpl->RemoveText();