[poppler] qt5/src
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Fri Apr 10 22:01:03 UTC 2020
qt5/src/ArthurOutputDev.cc | 6 +++---
qt5/src/ArthurOutputDev.h | 14 ++------------
qt5/src/poppler-page.cc | 19 +++++++++++++++++++
3 files changed, 24 insertions(+), 15 deletions(-)
New commits:
commit 162fdf21717a92428f4fc0c1bf7e86610b9ea703
Author: Oliver Sander <oliver.sander at tu-dresden.de>
Date: Fri Apr 10 22:01:00 2020 +0000
[arthur] Fix font hinting
Previously, the ArthurOutputDev would always use the Qt default value
for the QFont hinting preference. At the same time, it contained
a custom enum type with various hinting levels that didn't do anything
at all. This patch removes the custom enum, uses
QFont::HintingPreference instead, and actually passes the chosen value
to the font renderer.
diff --git a/qt5/src/ArthurOutputDev.cc b/qt5/src/ArthurOutputDev.cc
index 3d84e75a..9469f82e 100644
--- a/qt5/src/ArthurOutputDev.cc
+++ b/qt5/src/ArthurOutputDev.cc
@@ -150,7 +150,7 @@ const QPicture& ArthurType3Font::getGlyph(int gid) const
ArthurOutputDev::ArthurOutputDev(QPainter *painter):
m_lastTransparencyGroupPicture(nullptr),
- m_fontHinting(NoHinting)
+ m_hintingPreference(QFont::PreferDefaultHinting)
{
m_painter.push(painter);
m_currentBrush = QBrush(Qt::SolidPattern);
@@ -481,7 +481,7 @@ void ArthurOutputDev::updateFont(GfxState *state)
int fontDataLen;
const char* fontData = gfxFont->readEmbFontFile(xref, &fontDataLen);
- m_rawFont = new QRawFont(QByteArray(fontData, fontDataLen), fontSize);
+ m_rawFont = new QRawFont(QByteArray(fontData, fontDataLen), fontSize, m_hintingPreference);
m_rawFontCache.insert(std::make_pair(fontID,std::unique_ptr<QRawFont>(m_rawFont)));
// Free the font data, it was copied in the QByteArray constructor
@@ -490,7 +490,7 @@ void ArthurOutputDev::updateFont(GfxState *state)
}
case gfxFontLocExternal:{ // font is in an external font file
QString fontFile(fontLoc->path->c_str());
- m_rawFont = new QRawFont(fontFile, fontSize);
+ m_rawFont = new QRawFont(fontFile, fontSize, m_hintingPreference);
m_rawFontCache.insert(std::make_pair(fontID,std::unique_ptr<QRawFont>(m_rawFont)));
break;
}
diff --git a/qt5/src/ArthurOutputDev.h b/qt5/src/ArthurOutputDev.h
index b6285775..b380cb5d 100644
--- a/qt5/src/ArthurOutputDev.h
+++ b/qt5/src/ArthurOutputDev.h
@@ -55,23 +55,13 @@ class ArthurType3Font;
class ArthurOutputDev: public OutputDev {
public:
- /**
- * Describes how fonts are distorted (aka hinted) to fit the pixel grid.
- * More hinting means sharper edges and less adherence to the true letter shapes.
- */
- enum FontHinting {
- NoHinting = 0, ///< Font shapes are left unchanged
- SlightHinting, ///< Font shapes are distorted vertically only
- FullHinting ///< Font shapes are distorted horizontally and vertically
- };
-
// Constructor.
ArthurOutputDev(QPainter *painter );
// Destructor.
~ArthurOutputDev() override;
- void setFontHinting(FontHinting hinting) { m_fontHinting = hinting; }
+ void setHintingPreference(QFont::HintingPreference hintingPreference) { m_hintingPreference = hintingPreference; }
//----- get info about output device
@@ -195,7 +185,7 @@ private:
// it here for later use in paintTransparencyGroup.
QPicture* m_lastTransparencyGroupPicture;
- FontHinting m_fontHinting;
+ QFont::HintingPreference m_hintingPreference;
QPen m_currentPen;
// The various stacks are used to implement the 'saveState' and 'restoreState' methods
diff --git a/qt5/src/poppler-page.cc b/qt5/src/poppler-page.cc
index 30e03509..35bec6c9 100644
--- a/qt5/src/poppler-page.cc
+++ b/qt5/src/poppler-page.cc
@@ -511,6 +511,19 @@ QImage Page::renderToImage(double xres, double yres, int x, int y, int w, int h,
return renderToImage(xres, yres, x, y, w, h, rotate, partialUpdateCallback, shouldDoPartialUpdateCallback, nullptr, payload);
}
+// Translate the text hinting settings from poppler-speak to Qt-speak
+static QFont::HintingPreference QFontHintingFromPopplerHinting(int renderHints)
+{
+ QFont::HintingPreference result = QFont::PreferNoHinting;
+
+ if (renderHints & Document::TextHinting)
+ {
+ result = (renderHints & Document::TextSlightHinting) ? QFont::PreferVerticalHinting : QFont::PreferFullHinting;
+ }
+
+ return result;
+}
+
QImage Page::renderToImage(double xres, double yres, int xPos, int yPos, int w, int h, Rotation rotate, RenderToImagePartialUpdateFunc partialUpdateCallback, ShouldRenderToImagePartialQueryFunc shouldDoPartialUpdateCallback, ShouldAbortQueryFunc shouldAbortRenderCallback, const QVariant &payload) const
{
int rotation = (int)rotate * 90;
@@ -604,6 +617,9 @@ QImage Page::renderToImage(double xres, double yres, int xPos, int yPos, int w,
QPainter painter(&tmpimg);
QImageDumpingArthurOutputDev arthur_output(&painter, &tmpimg);
+
+ arthur_output.setHintingPreference(QFontHintingFromPopplerHinting(m_page->parentDoc->m_hints));
+
arthur_output.setCallbacks(partialUpdateCallback, shouldDoPartialUpdateCallback, shouldAbortRenderCallback, payload);
renderToArthur(&arthur_output, &painter, m_page, xres, yres, xPos, yPos, w, h, rotate, DontSaveAndRestore);
painter.end();
@@ -630,6 +646,9 @@ bool Page::renderToPainter(QPainter* painter, double xres, double yres, int x, i
case Poppler::Document::ArthurBackend:
{
QImageDumpingArthurOutputDev arthur_output(painter, nullptr);
+
+ arthur_output.setHintingPreference(QFontHintingFromPopplerHinting(m_page->parentDoc->m_hints));
+
return renderToArthur(&arthur_output, painter, m_page, xres, yres, x, y, w, h, rotate, flags);
}
}
More information about the poppler
mailing list