| 153 | } |
| 154 | |
| 155 | GraphicContent* TextContentCache::createContent(Frame layerFrame) const { |
| 156 | auto textDocument = sourceText->getValueAt(layerFrame).get(); |
| 157 | auto block = textBlock; |
| 158 | if (block == nullptr) { |
| 159 | auto iter = textBlocks.find(textDocument); |
| 160 | if (iter == textBlocks.end()) { |
| 161 | return nullptr; |
| 162 | } |
| 163 | block = iter->second; |
| 164 | } |
| 165 | auto glyphLines = CopyLines(block); |
| 166 | bool toCalculateBounds = false; |
| 167 | auto textPathRender = TextPathRender::MakeFrom(textDocument, pathOption); |
| 168 | if (textPathRender != nullptr) { |
| 169 | toCalculateBounds = true; |
| 170 | // 强制对齐会导致重新排版 |
| 171 | textPathRender->applyForceAlignmentToGlyphs(glyphLines, layerFrame); |
| 172 | // 由于动画的 position 是在文字路径上平移,而路径文字的映射是需要将排版文字的位置叠加动画位置结合路径进行计算, |
| 173 | // 因此如果先应用路径,再计算动画,还需要计算一次动画位置, |
| 174 | // 最好的方式是先应用动画,结合路径生成最后的矩阵 |
| 175 | TextAnimatorRenderer::ApplyToGlyphs(glyphLines, animators, textDocument->justification, |
| 176 | layerFrame); |
| 177 | textPathRender->applyToGlyphs(glyphLines, layerFrame); |
| 178 | } else { |
| 179 | toCalculateBounds = TextAnimatorRenderer::ApplyToGlyphs( |
| 180 | glyphLines, animators, textDocument->justification, layerFrame); |
| 181 | } |
| 182 | |
| 183 | std::vector<std::shared_ptr<Graphic>> contents = {}; |
| 184 | if (block != textBlock && textDocument->backgroundAlpha > 0) { |
| 185 | auto background = RenderTextBackground(block->assetID(), glyphLines, textDocument); |
| 186 | if (background) { |
| 187 | contents.push_back(background); |
| 188 | } |
| 189 | } |
| 190 | auto [simpleGlyphs, colorGlyphs] = GetGlyphs(glyphLines); |
| 191 | const tgfx::Rect* textBounds = nullptr; |
| 192 | if (!toCalculateBounds && !block->textBounds().isEmpty()) { |
| 193 | textBounds = &block->textBounds(); |
| 194 | } |
| 195 | |
| 196 | auto normalText = Text::MakeFrom(simpleGlyphs, block, textBounds); |
| 197 | if (normalText) { |
| 198 | contents.push_back(normalText); |
| 199 | } |
| 200 | auto graphic = Graphic::MakeCompose(contents); |
| 201 | auto colorText = Text::MakeFrom(colorGlyphs, block); |
| 202 | auto content = new TextContent(std::move(graphic), std::move(colorText)); |
| 203 | if (_cacheEnabled) { |
| 204 | content->colorGlyphs = Picture::MakeFrom(getCacheID(), content->colorGlyphs); |
| 205 | } |
| 206 | return content; |
| 207 | } |
| 208 | } // namespace pag |
nothing calls this directly
no test coverage detected