+ void CacheGlyph(const GlyphInfo& glyph, FontId lastFontId, const AtlasGlyphManager::GlyphStyle& style, AtlasManager::AtlasSlot& slot)
+ {
+ const Size& defaultTextAtlasSize = mFontClient.GetDefaultTextAtlasSize(); //Retrieve default size of text-atlas-block from font-client.
+ const Size& maximumTextAtlasSize = mFontClient.GetMaximumTextAtlasSize(); //Retrieve maximum size of text-atlas-block from font-client.
+
+ const bool glyphNotCached = !mGlyphManager.IsCached(glyph.fontId, glyph.index, style, slot); // Check FontGlyphRecord vector for entry with glyph index and fontId
+
+ DALI_LOG_INFO(gLogFilter, Debug::Verbose, "AddGlyphs fontID[%u] glyphIndex[%u] [%s]\n", glyph.fontId, glyph.index, (glyphNotCached) ? "not cached" : "cached");
+
+ if(glyphNotCached)
+ {
+ MaxBlockSize& blockSize = mBlockSizes[0u];
+
+ if(lastFontId != glyph.fontId)
+ {
+ uint32_t index = 0u;
+ // 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.
+ // CalculateBlocksSize() above ensures a block size entry exists.
+ for(std::vector<MaxBlockSize>::const_iterator it = mBlockSizes.begin(),
+ endIt = mBlockSizes.end();
+ it != endIt;
+ ++it, ++index)
+ {
+ const MaxBlockSize& blockSizeEntry = *it;
+ if(blockSizeEntry.mFontId == glyph.fontId)
+ {
+ blockSize = mBlockSizes[index];
+ }
+ }
+ }
+
+ // Create a new image for the glyph
+ PixelData bitmap;
+
+ // Whether the glyph is an outline.
+ const bool isOutline = 0u != style.outline;
+
+ // Whether the current glyph is a color one.
+ const bool isColorGlyph = mFontClient.IsColorGlyph(glyph.fontId, glyph.index);
+
+ if(!isOutline || (isOutline && !isColorGlyph))
+ {
+ // Retrieve the emoji's bitmap.
+ TextAbstraction::FontClient::GlyphBufferData glyphBufferData;
+ glyphBufferData.width = isColorGlyph ? glyph.width : 0; // Desired width and height.
+ glyphBufferData.height = isColorGlyph ? glyph.height : 0;
+
+ mFontClient.CreateBitmap(glyph.fontId,
+ glyph.index,
+ glyph.isItalicRequired,
+ glyph.isBoldRequired,
+ glyphBufferData,
+ style.outline);
+
+ // Create the pixel data.
+ bitmap = PixelData::New(glyphBufferData.buffer,
+ glyphBufferData.width * glyphBufferData.height * GetBytesPerPixel(glyphBufferData.format),
+ glyphBufferData.width,
+ glyphBufferData.height,
+ glyphBufferData.format,
+ PixelData::DELETE_ARRAY);
+
+ if(bitmap)
+ {
+ // Ensure that the next image will fit into the current block size
+ if(bitmap.GetWidth() > blockSize.mNeededBlockWidth)
+ {
+ blockSize.mNeededBlockWidth = bitmap.GetWidth();
+ }
+
+ if(bitmap.GetHeight() > blockSize.mNeededBlockHeight)
+ {
+ blockSize.mNeededBlockHeight = bitmap.GetHeight();
+ }
+
+ // If CheckAtlas in AtlasManager::Add can't fit the bitmap in the current atlas it will create a new atlas
+
+ // Setting the block size and size of new atlas does not mean a new one will be created. An existing atlas may still surffice.
+ uint32_t default_width = defaultTextAtlasSize.width;
+ uint32_t default_height = defaultTextAtlasSize.height;
+
+ while(
+ (blockSize.mNeededBlockWidth >= (default_width - (DOUBLE_PIXEL_PADDING + 1u)) ||
+ blockSize.mNeededBlockHeight >= (default_height - (DOUBLE_PIXEL_PADDING + 1u))) &&
+ (default_width < maximumTextAtlasSize.width &&
+ default_height < maximumTextAtlasSize.height))
+ {
+ default_width <<= 1u;
+ default_height <<= 1u;
+ }
+ mGlyphManager.SetNewAtlasSize(default_width,
+ default_height,
+ blockSize.mNeededBlockWidth,
+ blockSize.mNeededBlockHeight);
+
+ // Locate a new slot for our glyph
+ mGlyphManager.Add(glyph, style, bitmap, slot); // slot will be 0 is glyph not added
+ }
+ }
+ }
+ else
+ {
+ // We have 2+ copies of the same glyph
+ mGlyphManager.AdjustReferenceCount(glyph.fontId, glyph.index, style, 1); //increment
+ }
+ }
+
+ void GenerateMesh(const GlyphInfo& glyph,
+ const Vector2& position,
+ const Vector4& color,
+ uint16_t outline,
+ AtlasManager::AtlasSlot& slot,
+ bool decorationlineGlyph,
+ float currentUnderlinePosition,
+ float currentlineThickness,
+ std::vector<MeshRecord>& meshContainer,
+ Vector<TextCacheEntry>& newTextCache,
+ Vector<Extent>& extents,
+ uint32_t underlineChunkId,
+ bool isGlyphCached,
+ uint32_t strikethroughChunkId)
+ {
+ // Generate mesh data for this quad, plugging in our supplied position
+ AtlasManager::Mesh2D newMesh;
+ mGlyphManager.GenerateMeshData(slot.mImageId, position, newMesh);
+
+ if(!isGlyphCached)
+ {
+ TextCacheEntry textCacheEntry;
+ textCacheEntry.mFontId = glyph.fontId;
+ textCacheEntry.mImageId = slot.mImageId;
+ textCacheEntry.mIndex = glyph.index;
+ textCacheEntry.mOutlineWidth = outline;
+ textCacheEntry.isItalic = glyph.isItalicRequired;
+ textCacheEntry.isBold = glyph.isBoldRequired;
+
+ newTextCache.PushBack(textCacheEntry);
+ }
+
+ AtlasManager::Vertex2D* verticesBuffer = newMesh.mVertices.Begin();
+
+ for(unsigned int index = 0u, size = newMesh.mVertices.Count();
+ index < size;
+ ++index)
+ {
+ AtlasManager::Vertex2D& vertex = *(verticesBuffer + index);
+
+ // Set the color of the vertex.
+ vertex.mColor = color;
+ }
+
+ // Find an existing mesh data object to attach to ( or create a new one, if we can't find one using the same atlas)
+ StitchTextMesh(meshContainer,
+ newMesh,
+ extents,
+ position.y + glyph.yBearing,
+ decorationlineGlyph,
+ currentUnderlinePosition,
+ currentlineThickness,
+ slot,
+ underlineChunkId,
+ position.y + (glyph.height * HALF),
+ strikethroughChunkId);
+ }
+
+ void CreateActors(const std::vector<MeshRecord>& meshContainer,
+ const Size& textSize,
+ const Vector4& color,
+ const Vector4& shadowColor,
+ const Vector2& shadowOffset,
+ Actor textControl,
+ Property::Index animatablePropertyIndex,
+ bool drawShadow)
+ {
+ if(!mActor)
+ {
+ // Create a container actor to act as a common parent for text and shadow, to avoid color inheritence issues.
+ mActor = Actor::New();
+ mActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
+ mActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+ mActor.SetProperty(Actor::Property::SIZE, textSize);
+ mActor.SetProperty(Actor::Property::COLOR_MODE, USE_OWN_MULTIPLY_PARENT_COLOR);
+ }
+
+ for(std::vector<MeshRecord>::const_iterator it = meshContainer.begin(),
+ endIt = meshContainer.end();
+ it != endIt;
+ ++it)
+ {
+ const MeshRecord& meshRecord = *it;
+
+ Actor actor = CreateMeshActor(textControl, animatablePropertyIndex, color, meshRecord, textSize, STYLE_NORMAL);
+
+ // Whether the actor has renderers.
+ const bool hasRenderer = actor.GetRendererCount() > 0u;
+
+ // Create an effect if necessary
+ if(hasRenderer &&
+ drawShadow)
+ {
+ // Change the color of the vertices.
+ for(Vector<AtlasManager::Vertex2D>::Iterator vIt = meshRecord.mMesh.mVertices.Begin(),
+ vEndIt = meshRecord.mMesh.mVertices.End();
+ vIt != vEndIt;
+ ++vIt)
+ {
+ AtlasManager::Vertex2D& vertex = *vIt;
+
+ vertex.mColor = shadowColor;
+ }
+
+ Actor shadowActor = CreateMeshActor(textControl, animatablePropertyIndex, color, meshRecord, textSize, STYLE_DROP_SHADOW);
+#if defined(DEBUG_ENABLED)
+ shadowActor.SetProperty(Dali::Actor::Property::NAME, "Text Shadow renderable actor");
+#endif
+ // Offset shadow in x and y
+ shadowActor.RegisterProperty("uOffset", shadowOffset);
+ Dali::Renderer renderer(shadowActor.GetRendererAt(0));
+ int depthIndex = renderer.GetProperty<int>(Dali::Renderer::Property::DEPTH_INDEX);
+ renderer.SetProperty(Dali::Renderer::Property::DEPTH_INDEX, depthIndex - 1);
+ mActor.Add(shadowActor);
+ }
+
+ if(hasRenderer)
+ {
+ mActor.Add(actor);
+ }
+ }
+ }