| 1 |
//======================================================================== |
| 2 |
// |
| 3 |
// QPainterOutputDev.h |
| 4 |
// |
| 5 |
// Copyright 2003 Glyph & Cog, LLC |
| 6 |
// |
| 7 |
//======================================================================== |
| 8 |
|
| 9 |
//======================================================================== |
| 10 |
// |
| 11 |
// Modified under the Poppler project - http://poppler.freedesktop.org |
| 12 |
// |
| 13 |
// All changes made under the Poppler project to this file are licensed |
| 14 |
// under GPL version 2 or later |
| 15 |
// |
| 16 |
// Copyright (C) 2005 Brad Hards <[email protected]> |
| 17 |
// Copyright (C) 2005, 2018, 2019, 2021, 2025 Albert Astals Cid <[email protected]> |
| 18 |
// Copyright (C) 2009, 2011 Carlos Garcia Campos <[email protected]> |
| 19 |
// Copyright (C) 2010 Pino Toscano <[email protected]> |
| 20 |
// Copyright (C) 2011 Andreas Hartmetz <[email protected]> |
| 21 |
// Copyright (C) 2013 Thomas Freitag <[email protected]> |
| 22 |
// Copyright (C) 2013 Mihai Niculescu <[email protected]> |
| 23 |
// Copyright (C) 2017, 2018, 2020 Oliver Sander <[email protected]> |
| 24 |
// Copyright (C) 2025 g10 Code GmbH, Author: Sune Stolborg Vuorela <[email protected]> |
| 25 |
// |
| 26 |
// To see a description of the changes please see the Changelog file that |
| 27 |
// came with your tarball or type make ChangeLog if you are building from git |
| 28 |
// |
| 29 |
//======================================================================== |
| 30 |
|
| 31 |
#ifndef QPAINTEROUTPUTDEV_H |
| 32 |
#define QPAINTEROUTPUTDEV_H |
| 33 |
|
| 34 |
#include <memory> |
| 35 |
#include <map> |
| 36 |
#include <stack> |
| 37 |
|
| 38 |
#include "OutputDev.h" |
| 39 |
#include "GfxState.h" |
| 40 |
|
| 41 |
#include <ft2build.h> |
| 42 |
#include FT_FREETYPE_H |
| 43 |
|
| 44 |
#include <QtGui/QPainter> |
| 45 |
|
| 46 |
class GfxState; |
| 47 |
class PDFDoc; |
| 48 |
|
| 49 |
class QRawFont; |
| 50 |
|
| 51 |
class QPainterOutputDevType3Font; |
| 52 |
|
| 53 |
//------------------------------------------------------------------------ |
| 54 |
// QPainterOutputDev - QPainter renderer |
| 55 |
//------------------------------------------------------------------------ |
| 56 |
|
| 57 |
class QPainterOutputDev : public OutputDev |
| 58 |
{ |
| 59 |
public: |
| 60 |
// Constructor. |
| 61 |
explicit QPainterOutputDev(QPainter *painter); |
| 62 |
|
| 63 |
// Destructor. |
| 64 |
~QPainterOutputDev() override; |
| 65 |
|
| 66 |
void setHintingPreference(QFont::HintingPreference hintingPreference) { m_hintingPreference = hintingPreference; } |
| 67 |
|
| 68 |
//----- get info about output device |
| 69 |
|
| 70 |
// Does this device use upside-down coordinates? |
| 71 |
// (Upside-down means (0,0) is the top left corner of the page.) |
| 72 |
bool upsideDown() override { return true; } |
| 73 |
|
| 74 |
// Does this device use drawChar() or drawString()? |
| 75 |
bool useDrawChar() override { return true; } |
| 76 |
|
| 77 |
// Does this device implement shaded fills (aka gradients) natively? |
| 78 |
// If this returns false, these shaded fills |
| 79 |
// will be reduced to a series of other drawing operations. |
| 80 |
// type==2 is 'axial shading' |
| 81 |
bool useShadedFills(int type) override { return type == 2; } |
| 82 |
|
| 83 |
// Does this device use beginType3Char/endType3Char? Otherwise, |
| 84 |
// text in Type 3 fonts will be drawn with drawChar/drawString. |
| 85 |
bool interpretType3Chars() override { return false; } |
| 86 |
|
| 87 |
//----- initialization and control |
| 88 |
|
| 89 |
// Set Current Transformation Matrix to a fixed matrix given in ctm[0],...,ctm[5] |
| 90 |
void setDefaultCTM(const double *ctm) override; |
| 91 |
|
| 92 |
// Start a page. |
| 93 |
void startPage(int pageNum, GfxState *state, XRef *xref) override; |
| 94 |
|
| 95 |
// End a page. |
| 96 |
void endPage() override; |
| 97 |
|
| 98 |
//----- save/restore graphics state |
| 99 |
void saveState(GfxState *state) override; |
| 100 |
void restoreState(GfxState *state) override; |
| 101 |
|
| 102 |
//----- update graphics state |
| 103 |
void updateAll(GfxState *state) override; |
| 104 |
void updateCTM(GfxState *state, double m11, double m12, double m21, double m22, double m31, double m32) override; |
| 105 |
void updateLineDash(GfxState *state) override; |
| 106 |
void updateFlatness(GfxState *state) override; |
| 107 |
void updateLineJoin(GfxState *state) override; |
| 108 |
void updateLineCap(GfxState *state) override; |
| 109 |
void updateMiterLimit(GfxState *state) override; |
| 110 |
void updateLineWidth(GfxState *state) override; |
| 111 |
void updateFillColor(GfxState *state) override; |
| 112 |
void updateStrokeColor(GfxState *state) override; |
| 113 |
void updateBlendMode(GfxState *state) override; |
| 114 |
void updateFillOpacity(GfxState *state) override; |
| 115 |
void updateStrokeOpacity(GfxState *state) override; |
| 116 |
|
| 117 |
//----- update text state |
| 118 |
void updateFont(GfxState *state) override; |
| 119 |
|
| 120 |
//----- path painting |
| 121 |
void stroke(GfxState *state) override; |
| 122 |
void fill(GfxState *state) override; |
| 123 |
void eoFill(GfxState *state) override; |
| 124 |
bool axialShadedFill(GfxState *state, GfxAxialShading *shading, double tMin, double tMax) override; |
| 125 |
|
| 126 |
//----- path clipping |
| 127 |
void clip(GfxState *state) override; |
| 128 |
void eoClip(GfxState *state) override; |
| 129 |
void clipToStrokePath(GfxState *state) override; |
| 130 |
|
| 131 |
//----- text drawing |
| 132 |
// virtual void drawString(GfxState *state, GooString *s); |
| 133 |
void drawChar(GfxState *state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, const Unicode *u, int uLen) override; |
| 134 |
void endTextObject(GfxState *state) override; |
| 135 |
|
| 136 |
//----- image drawing |
| 137 |
void drawImageMask(GfxState *state, Object *ref, Stream *str, int width, int height, bool invert, bool interpolate, bool inlineImg) override; |
| 138 |
void drawImage(GfxState *state, Object *ref, Stream *str, int width, int height, GfxImageColorMap *colorMap, bool interpolate, const int *maskColors, bool inlineImg) override; |
| 139 |
|
| 140 |
void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str, int width, int height, GfxImageColorMap *colorMap, bool interpolate, Stream *maskStr, int maskWidth, int maskHeight, GfxImageColorMap *maskColorMap, |
| 141 |
bool maskInterpolate) override; |
| 142 |
|
| 143 |
//----- Type 3 font operators |
| 144 |
void type3D0(GfxState *state, double wx, double wy) override; |
| 145 |
void type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury) override; |
| 146 |
|
| 147 |
//----- transparency groups and soft masks |
| 148 |
void beginTransparencyGroup(GfxState *state, const std::array<double, 4> &bbox, GfxColorSpace *blendingColorSpace, bool isolated, bool knockout, bool forSoftMask) override; |
| 149 |
void endTransparencyGroup(GfxState *state) override; |
| 150 |
void paintTransparencyGroup(GfxState *state, const std::array<double, 4> &bbox) override; |
| 151 |
|
| 152 |
//----- special access |
| 153 |
|
| 154 |
// Called to indicate that a new PDF document has been loaded. |
| 155 |
void startDoc(PDFDoc *doc); |
| 156 |
|
| 157 |
bool isReverseVideo() { return false; } |
| 158 |
|
| 159 |
private: |
| 160 |
// The stack of QPainters is used to implement transparency groups. When such a group |
| 161 |
// is opened, annew Painter that paints onto a QPicture is pushed onto the stack. |
| 162 |
// It is popped again when the transparency group ends. |
| 163 |
std::stack<QPainter *> m_painter; |
| 164 |
|
| 165 |
// This is the corresponding stack of QPicture objects |
| 166 |
std::stack<QPicture *> m_qpictures; |
| 167 |
|
| 168 |
// endTransparencyGroup removes a QPicture from the stack, but stores |
| 169 |
// it here for later use in paintTransparencyGroup. |
| 170 |
QPicture *m_lastTransparencyGroupPicture; |
| 171 |
|
| 172 |
QFont::HintingPreference m_hintingPreference; |
| 173 |
|
| 174 |
QPen m_currentPen; |
| 175 |
// The various stacks are used to implement the 'saveState' and 'restoreState' methods |
| 176 |
std::stack<QPen> m_currentPenStack; |
| 177 |
|
| 178 |
QBrush m_currentBrush; |
| 179 |
std::stack<QBrush> m_currentBrushStack; |
| 180 |
|
| 181 |
bool m_needFontUpdate; // set when the font needs to be updated |
| 182 |
PDFDoc *m_doc; |
| 183 |
XRef *xref; // xref table for current document |
| 184 |
|
| 185 |
// The current font in use |
| 186 |
QRawFont *m_rawFont; |
| 187 |
std::stack<QRawFont *> m_rawFontStack; |
| 188 |
|
| 189 |
QPainterOutputDevType3Font *m_currentType3Font; |
| 190 |
std::stack<QPainterOutputDevType3Font *> m_type3FontStack; |
| 191 |
|
| 192 |
// Cache all fonts by their Ref and font size |
| 193 |
using QPainterFontID = std::pair<Ref, double>; |
| 194 |
std::map<QPainterFontID, std::unique_ptr<QRawFont>> m_rawFontCache; |
| 195 |
std::map<QPainterFontID, std::unique_ptr<QPainterOutputDevType3Font>> m_type3FontCache; |
| 196 |
std::map<Ref, std::vector<int>> m_codeToGIDCache; |
| 197 |
|
| 198 |
// The table that maps character codes to glyph indexes |
| 199 |
const std::vector<int> *m_codeToGID; |
| 200 |
std::stack<const std::vector<int> *> m_codeToGIDStack; |
| 201 |
|
| 202 |
FT_Library m_ftLibrary; |
| 203 |
// as of FT 2.1.8, CID fonts are indexed by CID instead of GID |
| 204 |
bool m_useCIDs; |
| 205 |
}; |
| 206 |
|
| 207 |
#endif |