[poppler] poppler/TextOutputDev.cc poppler/TextOutputDev.h

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Aug 27 19:38:26 UTC 2020


 poppler/TextOutputDev.cc |   35 ++++++++++++++++++++++++++++++-----
 poppler/TextOutputDev.h  |    1 +
 2 files changed, 31 insertions(+), 5 deletions(-)

New commits:
commit 375809c897a66f42880b9ed522df3cb6bad6c305
Author: Nelson Benítez León <nbenitezl at gmail.com>
Date:   Wed Aug 26 14:18:48 2020 -0400

    TextSelectionPainter: support glyphless fonts
    
    in text selections, by:
    
     - Ignoring to draw characters with it.
     - Painting the selection's background as transparent.
    
    Fixes issue #157
    
    Based on inital work by Nelson Benitez and changed
    to be not tesseract specific by Julian Andres Klode.

diff --git a/poppler/TextOutputDev.cc b/poppler/TextOutputDev.cc
index 0277cea9..e00fd4fb 100644
--- a/poppler/TextOutputDev.cc
+++ b/poppler/TextOutputDev.cc
@@ -182,6 +182,11 @@
 // (Or 1/tan(angle) for 90/270 degrees.)
 #define diagonalThreshold 0.1
 
+// How opaque a selection on a glyphless font should be. Since the font is
+// glyphless and overlaid over text in image form, this must enable users
+// to read the underlying image. Issue #157
+#define glyphlessSelectionOpacity 0.4
+
 namespace {
 
 inline bool isAscii7(Unicode uchar)
@@ -405,6 +410,7 @@ TextWord::TextWord(const GfxState *state, int rotA, double fontSizeA)
     len = size = 0;
     spaceAfter = false;
     next = nullptr;
+    invisible = state->getRender() == 3;
 
 #ifdef TEXTOUT_WORD_LIST
     GfxRGB rgb;
@@ -4486,6 +4492,7 @@ private:
     GfxState *state;
     std::vector<TextWordSelection *> *selectionList;
     Matrix ctm, ictm;
+    bool hasGlyphLessFont();
 };
 
 TextSelectionPainter::TextSelectionPainter(TextPage *p, double scale, int rotation, OutputDev *outA, const GfxColor *box_color, const GfxColor *glyph_colorA) : TextSelectionVisitor(p), out(outA), glyph_color(glyph_colorA)
@@ -4548,6 +4555,16 @@ void TextSelectionPainter::visitWord(TextWord *word, int begin, int end, const P
     selectionList->push_back(new TextWordSelection(word, begin, end));
 }
 
+bool TextSelectionPainter::hasGlyphLessFont()
+{
+    if (selectionList && selectionList->size()) {
+        TextWordSelection *sel = (*selectionList)[0];
+        return sel->word->invisible;
+    }
+
+    return false;
+}
+
 void TextSelectionPainter::endPage()
 {
     out->fill(state);
@@ -4558,6 +4575,13 @@ void TextSelectionPainter::endPage()
     state->clearPath();
 
     state->setFillColor(glyph_color);
+
+    bool usingGlyphLessFont = hasGlyphLessFont();
+    /* Paint transparent selection when using tesseract glyphless font. Issue #157 */
+    if (usingGlyphLessFont) {
+        state->setFillOpacity(glyphlessSelectionOpacity);
+    }
+
     out->updateFillColor(state);
 
     for (const TextWordSelection *sel : *selectionList) {
@@ -4582,11 +4606,12 @@ void TextSelectionPainter::endPage()
             GooString *string = new GooString((char *)sel->word->charcode, fEnd - begin);
             out->beginString(state, string);
 
-            for (int j = begin; j < fEnd; j++) {
-                if (j != begin && sel->word->charPos[j] == sel->word->charPos[j - 1])
-                    continue;
-
-                out->drawChar(state, sel->word->textMat[j].m[4], sel->word->textMat[j].m[5], 0, 0, 0, 0, sel->word->charcode[j], 1, nullptr, 0);
+            if (!usingGlyphLessFont) {
+                for (int j = begin; j < fEnd; j++) {
+                    if (j != begin && sel->word->charPos[j] == sel->word->charPos[j - 1])
+                        continue;
+                    out->drawChar(state, sel->word->textMat[j].m[4], sel->word->textMat[j].m[5], 0, 0, 0, 0, sel->word->charcode[j], 1, nullptr, 0);
+                }
             }
             out->endString(state);
             delete string;
diff --git a/poppler/TextOutputDev.h b/poppler/TextOutputDev.h
index 7f39815a..d978d6d3 100644
--- a/poppler/TextOutputDev.h
+++ b/poppler/TextOutputDev.h
@@ -232,6 +232,7 @@ private:
     bool spaceAfter; // set if there is a space between this
                      //   word and the next word on the line
     bool underlined;
+    bool invisible; // whether we are invisible (glyphless)
     TextWord *next; // next word in line
 
 #ifdef TEXTOUT_WORD_LIST


More information about the poppler mailing list