Commit 375809c8 authored by Nelson Benítez León's avatar Nelson Benítez León
Browse files

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.
parent 55eb5c73
......@@ -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,12 +4606,13 @@ void TextSelectionPainter::endPage()
GooString *string = new GooString((char *)sel->word->charcode, fEnd - begin);
out->beginString(state, string);
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;
begin = fEnd;
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment