From 9abeb886e83c7ab54699d3fb43be26020c40675f Mon Sep 17 00:00:00 2001 From: Oliver Sander Date: Fri, 20 Apr 2018 16:14:21 +0200 Subject: [PATCH 3/3] Implement Type3-Font support using beginType3Char/endType3Char This is *much* simpler than the previous implementation using drawChar. --- qt5/src/ArthurOutputDev.cc | 38 ++++++++++++++++++++++++++++++++++++++ qt5/src/ArthurOutputDev.h | 6 +++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/qt5/src/ArthurOutputDev.cc b/qt5/src/ArthurOutputDev.cc index f4f6b141..24e2c09a 100644 --- a/qt5/src/ArthurOutputDev.cc +++ b/qt5/src/ArthurOutputDev.cc @@ -1041,6 +1041,44 @@ void ArthurOutputDev::drawChar(GfxState *state, double x, double y, } } +GBool ArthurOutputDev::beginType3Char(GfxState *state, double x, double y, + double dx, double dy, + CharCode code, Unicode *u, int uLen) +{ + // Store the QPainter state; we need to modify it temporarily + m_painter.top()->save(); + + // Make the glyph position the coordinate origin -- that's our center of scaling + m_painter.top()->translate(QPointF(x, y)); + + const double* mat = state->getFont()->getFontMatrix(); + QTransform fontMatrix(mat[0], mat[1], mat[2], mat[3], mat[4], mat[5]); + + // Scale with the font size + fontMatrix.scale(state->getFontSize(), state->getFontSize()); + m_painter.top()->setTransform(fontMatrix,true); + + // Apply the text matrix on top + const double *textMat = state->getTextMat(); + + QTransform textTransform(textMat[0] * state->getHorizScaling(), + textMat[1] * state->getHorizScaling(), + textMat[2], + textMat[3], + 0, + 0); + + m_painter.top()->setTransform(textTransform,true); + + return gFalse; +} + +void ArthurOutputDev::endType3Char(GfxState *state) +{ + // Restore transformation + m_painter.top()->restore(); +} + void ArthurOutputDev::type3D0(GfxState *state, double wx, double wy) { } diff --git a/qt5/src/ArthurOutputDev.h b/qt5/src/ArthurOutputDev.h index 6d20fb7b..4b8bb369 100644 --- a/qt5/src/ArthurOutputDev.h +++ b/qt5/src/ArthurOutputDev.h @@ -94,7 +94,7 @@ public: // Does this device use beginType3Char/endType3Char? Otherwise, // text in Type 3 fonts will be drawn with drawChar/drawString. - GBool interpretType3Chars() override { return gFalse; } + GBool interpretType3Chars() override { return gTrue; } //----- initialization and control @@ -166,6 +166,10 @@ public: GBool maskInterpolate) override; //----- Type 3 font operators + GBool beginType3Char(GfxState *state, double x, double y, + double dx, double dy, + CharCode code, Unicode *u, int uLen) override; + void endType3Char(GfxState *state) override; void type3D0(GfxState *state, double wx, double wy) override; void type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury) override; -- 2.17.0