diff options
author | Erich E. Hoover <erich.e.hoover@gmail.com> | 2022-10-26 11:34:21 -0600 |
---|---|---|
committer | Albert Astals Cid <aacid@kde.org> | 2024-02-18 17:45:13 +0000 |
commit | 4a278246628850d5b7dc0ee3f6cbc9d38999e85a (patch) | |
tree | 8a43e6dc2a17eca90b5ad198e1047ea53176e5a8 | |
parent | 4b109c2fdcd1d170d329178dd2f33ae55cc3fef0 (diff) |
Annot: Pull out the font size calculator into a separate routine
-rw-r--r-- | poppler/Annot.cc | 54 | ||||
-rw-r--r-- | poppler/Annot.h | 2 |
2 files changed, 33 insertions, 23 deletions
diff --git a/poppler/Annot.cc b/poppler/Annot.cc index 2aa4e2ba..144b3edc 100644 --- a/poppler/Annot.cc +++ b/poppler/Annot.cc @@ -3132,6 +3132,36 @@ public: int consumedText; }; +double Annot::calculateFontSize(const Form *form, const GfxFont *font, const GooString *text, double wMax, double hMax, const bool forceZapfDingbats) +{ + const bool isUnicode = text->hasUnicodeMarker(); + double fontSize; + + for (fontSize = 20; fontSize > 1; --fontSize) { + const double availableWidthInFontSize = wMax / fontSize; + double y = hMax - 3; + int i = 0; + while (i < text->getLength()) { + GooString lineText(text->toStr().substr(i)); + if (!lineText.hasUnicodeMarker() && isUnicode) { + lineText.prependUnicodeMarker(); + } + const HorizontalTextLayouter textLayouter(&lineText, form, font, availableWidthInFontSize, forceZapfDingbats); + y -= fontSize; + if (i == 0) { + i += textLayouter.consumedText; + } else { + i += textLayouter.consumedText - (isUnicode ? 2 : 0); + } + } + // approximate the descender for the last line + if (y >= 0.33 * fontSize) { + break; + } + } + return fontSize; +} + struct DrawMultiLineTextResult { std::string text; @@ -4603,32 +4633,10 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const Form *form, c // note: comb is ignored in multiline mode as mentioned in the spec const double wMax = dx - 2 * borderWidth - 4; - const bool isUnicode = text->hasUnicodeMarker(); // compute font autosize if (fontSize == 0) { - for (fontSize = 20; fontSize > 1; --fontSize) { - const double availableWidthInFontSize = wMax / fontSize; - double y = dy - 3; - int i = 0; - while (i < text->getLength()) { - GooString lineText(text->toStr().substr(i)); - if (!lineText.hasUnicodeMarker() && isUnicode) { - lineText.prependUnicodeMarker(); - } - const HorizontalTextLayouter textLayouter(&lineText, form, font, availableWidthInFontSize, forceZapfDingbats); - y -= fontSize; - if (i == 0) { - i += textLayouter.consumedText; - } else { - i += textLayouter.consumedText - (isUnicode ? 2 : 0); - } - } - // approximate the descender for the last line - if (y >= 0.33 * fontSize) { - break; - } - } + fontSize = Annot::calculateFontSize(form, font, text, wMax, dy, forceZapfDingbats); daToks[tfPos + 1] = GooString().appendf("{0:.2f}", fontSize)->toStr(); } diff --git a/poppler/Annot.h b/poppler/Annot.h index b841e833..f15892be 100644 --- a/poppler/Annot.h +++ b/poppler/Annot.h @@ -716,6 +716,8 @@ public: Annot(PDFDoc *docA, Object &&dictObject, const Object *obj); bool isOk() { return ok; } + static double calculateFontSize(const Form *form, const GfxFont *font, const GooString *text, const double wMax, const double hMax, const bool forceZapfDingbats = {}); + void incRefCnt(); void decRefCnt(); |