MCPcopy Create free account
hub / github.com/Tencent/libpag / AdjustToFitBox

Function AdjustToFitBox

src/rendering/renderers/TextRenderer.cpp:176–205  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

174}
175
176static void AdjustToFitBox(TextLayout* layout, std::vector<GlyphInfo>* glyphInfos, float fontSize) {
177 auto boxYOffset = layout->firstBaseLine - layout->boxRect.top;
178 auto boxTextLines = floorf((layout->boxRect.height() - boxYOffset) / layout->lineGap) + 1;
179 auto visibleTop = layout->firstBaseLine + layout->fontTop;
180 auto visibleBottom =
181 layout->firstBaseLine + layout->lineGap * (boxTextLines - 1) + layout->fontBottom;
182 float totalTextLines = 0;
183 auto scaleFactor =
184 CalculateGlyphScale(layout, *glyphInfos, fontSize, layout->fontTop, layout->fontBottom,
185 visibleTop, visibleBottom, &totalTextLines);
186 if (scaleFactor != 1) {
187 layout->glyphScale = scaleFactor;
188 layout->firstBaseLine = visibleTop + -layout->fontTop * scaleFactor;
189 if (totalTextLines == 1) {
190 layout->firstBaseLine += (1 - scaleFactor) * 0.5f * layout->lineGap;
191 }
192 layout->fontTop *= scaleFactor;
193 layout->fontBottom *= scaleFactor;
194 layout->tracking *= scaleFactor;
195 layout->lineGap *= scaleFactor;
196 for (auto& glyph : *glyphInfos) {
197 glyph.advance *= scaleFactor;
198 glyph.bounds.scale(scaleFactor, scaleFactor);
199 }
200 } else {
201 if (totalTextLines < boxTextLines) {
202 layout->firstBaseLine += (boxTextLines - totalTextLines) * layout->lineGap * 0.5f;
203 }
204 }
205}
206
207static float CalculateDrawX(ParagraphJustification justification, float lineWidth, bool isLastLine,
208 const tgfx::Rect& boxRect) {

Callers 1

TextRenderer.cppFile · 0.85

Calls 3

CalculateGlyphScaleFunction · 0.85
heightMethod · 0.45
scaleMethod · 0.45

Tested by

no test coverage detected