Commit 162fdf21 authored by Oliver Sander's avatar Oliver Sander Committed by Albert Astals Cid

[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.
parent 17b01bd1
......@@ -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;
}
......
......@@ -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
......
......@@ -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);
}
}
......
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