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

Function AdjustFirstBaseLine

exporter/src/export/data/TextProperty.cpp:541–571  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

539}
540
541static void AdjustFirstBaseLine(pag::TextDocumentHandle textDocument, bool hasBias) {
542 if (textDocument->boxTextSize.x <= 0.001f || textDocument->boxTextSize.y <= 0.001f) {
543 textDocument->firstBaseLine = 0.0f;
544 return;
545 }
546
547 if (textDocument->direction == pag::TextDirection::Vertical) {
548 auto rightLine = textDocument->boxTextPos.x + textDocument->boxTextSize.x;
549 float fontHeight = rightLine + textDocument->firstBaseLine;
550
551 bool needToAdjust = hasBias || fontHeight < textDocument->fontSize / 3.0f ||
552 fontHeight > textDocument->fontSize;
553 if (needToAdjust) {
554 float newHeight = textDocument->fontSize * 0.4f;
555 textDocument->fontSize = rightLine - newHeight;
556 }
557 } else {
558 float fontHeight = textDocument->firstBaseLine - textDocument->boxTextPos.y;
559 bool needToAdjust = hasBias || fontHeight < textDocument->fontSize * 0.2f ||
560 fontHeight > textDocument->fontSize;
561 if (needToAdjust) {
562 float ascend = 0.0f;
563 float descent = 0.0f;
564 pag::CalculateTextAscentAndDescent(textDocument.get(), &ascend, &descent);
565
566 auto factor = -ascend / (descent - ascend);
567 float newHeight = textDocument->fontSize * factor * 0.9f;
568 textDocument->firstBaseLine = textDocument->boxTextPos.y + newHeight;
569 }
570 }
571}
572
573static void GetFirstBaseLineByPos(pag::TextDocumentHandle textDocument,
574 std::vector<pag::TextAnimator*>* animators, pag::Frame frame) {

Callers 1

GetFirstBaseLineByPosFunction · 0.85

Calls 2

getMethod · 0.45

Tested by

no test coverage detected