[poppler] 2 commits - poppler/Annot.cc

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sat Mar 26 09:06:27 UTC 2022


 poppler/Annot.cc |   54 ++++++++++++++++++------------------------------------
 1 file changed, 18 insertions(+), 36 deletions(-)

New commits:
commit 6f62a002967246cf6f702568ef0dd3436640e5f7
Author: Albert Astals Cid <aacid at kde.org>
Date:   Fri Mar 25 18:20:02 2022 +0100

    Simplify code by ensuring there's always Tm in daToks

diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 5577651f..48d72c49 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -4366,6 +4366,12 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da
         return false;
     }
 
+    if (tmPos < 0) {
+        // Add fake Tm to the DA tokens
+        tmPos = daToks.size();
+        daToks.insert(daToks.end(), { "1", "0", "0", "1", "0", "0", "Tm" });
+    }
+
     // get the border width
     const double borderWidth = border ? border->getWidth() : 0;
 
@@ -4443,21 +4449,14 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da
         const double y = dy - 3;
 
         // set the font matrix
-        if (tmPos >= 0) {
-            daToks[tmPos + 4] = "0";
-            daToks[tmPos + 5] = GooString().format("{0:.2f}", y)->toStr();
-        }
+        daToks[tmPos + 4] = "0";
+        daToks[tmPos + 5] = GooString().format("{0:.2f}", y)->toStr();
 
         // write the DA string
         for (const std::string &daTok : daToks) {
             appearBuf->append(daTok)->append(' ');
         }
 
-        // write the font matrix (if not part of the DA string)
-        if (tmPos < 0) {
-            appearBuf->appendf("1 0 0 1 0 {0:.2f} Tm\n", y);
-        }
-
         // write a series of lines of text
         int i = 0;
         double xPrev = 0;
@@ -4532,21 +4531,14 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da
             const double y = 0.5 * dy - 0.4 * fontSize;
 
             // set the font matrix
-            if (tmPos >= 0) {
-                daToks[tmPos + 4] = GooString().format("{0:.2f}", x)->toStr();
-                daToks[tmPos + 5] = GooString().format("{0:.2f}", y)->toStr();
-            }
+            daToks[tmPos + 4] = GooString().format("{0:.2f}", x)->toStr();
+            daToks[tmPos + 5] = GooString().format("{0:.2f}", y)->toStr();
 
             // write the DA string
             for (const std::string &daTok : daToks) {
                 appearBuf->append(daTok)->append(' ');
             }
 
-            // write the font matrix (if not part of the DA string)
-            if (tmPos < 0) {
-                appearBuf->appendf("1 0 0 1 {0:.2f} {1:.2f} Tm\n", x, y);
-            }
-
             // write the text string
             const char *s = convertedText.c_str();
             int len = convertedText.getLength();
@@ -4614,20 +4606,16 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da
             const double y = 0.5 * dy - 0.4 * fontSize;
 
             // set the font matrix
-            if (tmPos >= 0) {
-                daToks[tmPos + 4] = GooString().format("{0:.2f}", x)->toStr();
-                daToks[tmPos + 5] = GooString().format("{0:.2f}", y)->toStr();
-            }
+            daToks[tmPos + 4] = GooString().format("{0:.2f}", x)->toStr();
+            daToks[tmPos + 5] = GooString().format("{0:.2f}", y)->toStr();
 
             // write the DA string
             for (const std::string &daTok : daToks) {
                 appearBuf->append(daTok)->append(' ');
             }
-
-            // write the font matrix (if not part of the DA string)
-            if (tmPos < 0) {
-                appearBuf->appendf("1 0 0 1 {0:.2f} {1:.2f} Tm\n", x, y);
-            }
+            // This newline is not neeed at all but it makes for easier reading
+            // and our auto tests "wrongly" assume it will be there, so add it anyway
+            appearBuf->append("\n");
 
             // write the text string
             writeString(convertedText.toStr());
commit 3b0611bf6c5be8649591c119f389e243b38f7d91
Author: Albert Astals Cid <aacid at kde.org>
Date:   Fri Mar 25 18:10:18 2022 +0100

    Remove checks for tfPos being >= 0
    
    If it was not, we wouldn't reach this, font would have been null and
    returned earlier in the function

diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 5ab733e3..5577651f 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -4434,9 +4434,7 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da
                     break;
                 }
             }
-            if (tfPos >= 0) {
-                daToks[tfPos + 1] = GooString().format("{0:.2f}", fontSize)->toStr();
-            }
+            daToks[tfPos + 1] = GooString().format("{0:.2f}", fontSize)->toStr();
         }
 
         // starting y coordinate
@@ -4509,9 +4507,7 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da
                     fontSize = w;
                 }
                 fontSize = floor(fontSize);
-                if (tfPos >= 0) {
-                    daToks[tfPos + 1] = GooString().format("{0:.2f}", fontSize)->toStr();
-                }
+                daToks[tfPos + 1] = GooString().format("{0:.2f}", fontSize)->toStr();
             }
 
             int dummy = 0;
@@ -4598,9 +4594,7 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da
                     }
                 }
                 fontSize = floor(fontSize);
-                if (tfPos >= 0) {
-                    daToks[tfPos + 1] = GooString().format("{0:.2f}", fontSize)->toStr();
-                }
+                daToks[tfPos + 1] = GooString().format("{0:.2f}", fontSize)->toStr();
             }
 
             // compute text start position


More information about the poppler mailing list