Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-10 10:23:46

0001 //========================================================================
0002 //
0003 // Gfx.h
0004 //
0005 // Copyright 1996-2003 Glyph & Cog, LLC
0006 //
0007 //========================================================================
0008 
0009 //========================================================================
0010 //
0011 // Modified under the Poppler project - http://poppler.freedesktop.org
0012 //
0013 // All changes made under the Poppler project to this file are licensed
0014 // under GPL version 2 or later
0015 //
0016 // Copyright (C) 2005 Jonathan Blandford <jrb@redhat.com>
0017 // Copyright (C) 2007 Iñigo Martínez <inigomartinez@gmail.com>
0018 // Copyright (C) 2008 Brad Hards <bradh@kde.org>
0019 // Copyright (C) 2008, 2010 Carlos Garcia Campos <carlosgc@gnome.org>
0020 // Copyright (C) 2009-2013, 2017, 2018, 2021 Albert Astals Cid <aacid@kde.org>
0021 // Copyright (C) 2009, 2010, 2012, 2013 Thomas Freitag <Thomas.Freitag@alfa.de>
0022 // Copyright (C) 2010 David Benjamin <davidben@mit.edu>
0023 // Copyright (C) 2010 Christian Feuersänger <cfeuersaenger@googlemail.com>
0024 // Copyright (C) 2013 Fabio D'Urso <fabiodurso@hotmail.it>
0025 // Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by the LiMux project of the city of Munich
0026 // Copyright (C) 2018 Adam Reichold <adam.reichold@t-online.de>
0027 // Copyright (C) 2019, 2022 Oliver Sander <oliver.sander@tu-dresden.de>
0028 // Copyright (C) 2019 Volker Krause <vkrause@kde.org>
0029 //
0030 // To see a description of the changes please see the Changelog file that
0031 // came with your tarball or type make ChangeLog if you are building from git
0032 //
0033 //========================================================================
0034 
0035 #ifndef GFX_H
0036 #define GFX_H
0037 
0038 #include "poppler-config.h"
0039 #include "poppler_private_export.h"
0040 #include "GfxState.h"
0041 #include "Object.h"
0042 #include "PopplerCache.h"
0043 
0044 #include <vector>
0045 
0046 class GooString;
0047 class PDFDoc;
0048 class XRef;
0049 class Array;
0050 class Stream;
0051 class Parser;
0052 class Dict;
0053 class Function;
0054 class OutputDev;
0055 class GfxFontDict;
0056 class GfxFont;
0057 class GfxPattern;
0058 class GfxTilingPattern;
0059 class GfxShadingPattern;
0060 class GfxShading;
0061 class GfxFunctionShading;
0062 class GfxAxialShading;
0063 class GfxRadialShading;
0064 class GfxGouraudTriangleShading;
0065 class GfxPatchMeshShading;
0066 struct GfxPatch;
0067 class GfxState;
0068 struct GfxColor;
0069 class GfxColorSpace;
0070 class Gfx;
0071 class PDFRectangle;
0072 class AnnotBorder;
0073 class AnnotColor;
0074 class Catalog;
0075 struct MarkedContentStack;
0076 
0077 //------------------------------------------------------------------------
0078 
0079 enum GfxClipType
0080 {
0081     clipNone,
0082     clipNormal,
0083     clipEO
0084 };
0085 
0086 enum TchkType
0087 {
0088     tchkBool, // boolean
0089     tchkInt, // integer
0090     tchkNum, // number (integer or real)
0091     tchkString, // string
0092     tchkName, // name
0093     tchkArray, // array
0094     tchkProps, // properties (dictionary or name)
0095     tchkSCN, // scn/SCN args (number of name)
0096     tchkNone // used to avoid empty initializer lists
0097 };
0098 
0099 #define maxArgs 33
0100 
0101 struct Operator
0102 {
0103     char name[4];
0104     int numArgs;
0105     TchkType tchk[maxArgs];
0106     void (Gfx::*func)(Object args[], int numArgs);
0107 };
0108 
0109 //------------------------------------------------------------------------
0110 
0111 class POPPLER_PRIVATE_EXPORT GfxResources
0112 {
0113 public:
0114     GfxResources(XRef *xref, Dict *resDict, GfxResources *nextA);
0115     ~GfxResources();
0116 
0117     GfxResources(const GfxResources &) = delete;
0118     GfxResources &operator=(const GfxResources &other) = delete;
0119 
0120     std::shared_ptr<GfxFont> lookupFont(const char *name);
0121     std::shared_ptr<const GfxFont> lookupFont(const char *name) const;
0122     Object lookupXObject(const char *name);
0123     Object lookupXObjectNF(const char *name);
0124     Object lookupMarkedContentNF(const char *name);
0125     Object lookupColorSpace(const char *name);
0126     GfxPattern *lookupPattern(const char *name, OutputDev *out, GfxState *state);
0127     GfxShading *lookupShading(const char *name, OutputDev *out, GfxState *state);
0128     Object lookupGState(const char *name);
0129     Object lookupGStateNF(const char *name);
0130 
0131     GfxResources *getNext() const { return next; }
0132 
0133 private:
0134     std::shared_ptr<GfxFont> doLookupFont(const char *name) const;
0135 
0136     GfxFontDict *fonts;
0137     Object xObjDict;
0138     Object colorSpaceDict;
0139     Object patternDict;
0140     Object shadingDict;
0141     Object gStateDict;
0142     PopplerCache<Ref, Object> gStateCache;
0143     XRef *xref;
0144     Object propertiesDict;
0145     GfxResources *next;
0146 };
0147 
0148 //------------------------------------------------------------------------
0149 // Gfx
0150 //------------------------------------------------------------------------
0151 
0152 class POPPLER_PRIVATE_EXPORT Gfx
0153 {
0154 public:
0155     // Constructor for regular output.
0156     Gfx(PDFDoc *docA, OutputDev *outA, int pageNum, Dict *resDict, double hDPI, double vDPI, const PDFRectangle *box, const PDFRectangle *cropBox, int rotate, bool (*abortCheckCbkA)(void *data) = nullptr, void *abortCheckCbkDataA = nullptr,
0157         XRef *xrefA = nullptr);
0158 
0159     // Constructor for a sub-page object.
0160     Gfx(PDFDoc *docA, OutputDev *outA, Dict *resDict, const PDFRectangle *box, const PDFRectangle *cropBox, bool (*abortCheckCbkA)(void *data) = nullptr, void *abortCheckCbkDataA = nullptr, Gfx *gfxA = nullptr);
0161 #ifdef USE_CMS
0162     void initDisplayProfile();
0163 #endif
0164     ~Gfx();
0165 
0166     Gfx(const Gfx &) = delete;
0167     Gfx &operator=(const Gfx &other) = delete;
0168 
0169     XRef *getXRef() { return xref; }
0170 
0171     // Interpret a stream or array of streams.
0172     void display(Object *obj, bool topLevel = true);
0173 
0174     // Display an annotation, given its appearance (a Form XObject),
0175     // border style, and bounding box (in default user space).
0176     void drawAnnot(Object *str, AnnotBorder *border, AnnotColor *aColor, double xMin, double yMin, double xMax, double yMax, int rotate);
0177 
0178     // Save graphics state.
0179     void saveState();
0180 
0181     // Push a new state guard
0182     void pushStateGuard();
0183 
0184     // Restore graphics state.
0185     void restoreState();
0186 
0187     // Pop to state guard and pop guard
0188     void popStateGuard();
0189 
0190     // Get the current graphics state object.
0191     GfxState *getState() { return state; }
0192 
0193     bool checkTransparencyGroup(Dict *resDict);
0194 
0195     void drawForm(Object *str, Dict *resDict, const double *matrix, const double *bbox, bool transpGroup = false, bool softMask = false, GfxColorSpace *blendingColorSpace = nullptr, bool isolated = false, bool knockout = false,
0196                   bool alpha = false, Function *transferFunc = nullptr, GfxColor *backdropColor = nullptr);
0197 
0198     void pushResources(Dict *resDict);
0199     void popResources();
0200 
0201 private:
0202     PDFDoc *doc;
0203     XRef *xref; // the xref table for this PDF file
0204     Catalog *catalog; // the Catalog for this PDF file
0205     OutputDev *out; // output device
0206     bool subPage; // is this a sub-page object?
0207     const bool printCommands; // print the drawing commands (for debugging)
0208     const bool profileCommands; // profile the drawing commands (for debugging)
0209     bool commandAborted; // did the previous command abort the drawing?
0210     GfxResources *res; // resource stack
0211     int updateLevel;
0212 
0213     GfxState *state; // current graphics state
0214     int stackHeight; // the height of the current graphics stack
0215     std::vector<int> stateGuards; // a stack of state limits; to guard against unmatched pops
0216     bool fontChanged; // set if font or text matrix has changed
0217     GfxClipType clip; // do a clip?
0218     int ignoreUndef; // current BX/EX nesting level
0219     double baseMatrix[6]; // default matrix for most recent
0220                           //   page/form/pattern
0221     int displayDepth;
0222     bool ocState; // true if drawing is enabled, false if
0223                   //   disabled
0224 
0225     MarkedContentStack *mcStack; // current BMC/EMC stack
0226 
0227     Parser *parser; // parser for page content stream(s)
0228 
0229     std::set<int> formsDrawing; // the forms/patterns that are being drawn
0230     std::set<int> charProcDrawing; // the charProc that are being drawn
0231 
0232     bool // callback to check for an abort
0233             (*abortCheckCbk)(void *data);
0234     void *abortCheckCbkData;
0235 
0236     static const Operator opTab[]; // table of operators
0237 
0238     void go(bool topLevel);
0239     void execOp(Object *cmd, Object args[], int numArgs);
0240     const Operator *findOp(const char *name);
0241     bool checkArg(Object *arg, TchkType type);
0242     Goffset getPos();
0243 
0244     int bottomGuard();
0245 
0246     // graphics state operators
0247     void opSave(Object args[], int numArgs);
0248     void opRestore(Object args[], int numArgs);
0249     void opConcat(Object args[], int numArgs);
0250     void opSetDash(Object args[], int numArgs);
0251     void opSetFlat(Object args[], int numArgs);
0252     void opSetLineJoin(Object args[], int numArgs);
0253     void opSetLineCap(Object args[], int numArgs);
0254     void opSetMiterLimit(Object args[], int numArgs);
0255     void opSetLineWidth(Object args[], int numArgs);
0256     void opSetExtGState(Object args[], int numArgs);
0257     void doSoftMask(Object *str, bool alpha, GfxColorSpace *blendingColorSpace, bool isolated, bool knockout, Function *transferFunc, GfxColor *backdropColor);
0258     void opSetRenderingIntent(Object args[], int numArgs);
0259 
0260     // color operators
0261     void opSetFillGray(Object args[], int numArgs);
0262     void opSetStrokeGray(Object args[], int numArgs);
0263     void opSetFillCMYKColor(Object args[], int numArgs);
0264     void opSetStrokeCMYKColor(Object args[], int numArgs);
0265     void opSetFillRGBColor(Object args[], int numArgs);
0266     void opSetStrokeRGBColor(Object args[], int numArgs);
0267     void opSetFillColorSpace(Object args[], int numArgs);
0268     void opSetStrokeColorSpace(Object args[], int numArgs);
0269     void opSetFillColor(Object args[], int numArgs);
0270     void opSetStrokeColor(Object args[], int numArgs);
0271     void opSetFillColorN(Object args[], int numArgs);
0272     void opSetStrokeColorN(Object args[], int numArgs);
0273 
0274     // path segment operators
0275     void opMoveTo(Object args[], int numArgs);
0276     void opLineTo(Object args[], int numArgs);
0277     void opCurveTo(Object args[], int numArgs);
0278     void opCurveTo1(Object args[], int numArgs);
0279     void opCurveTo2(Object args[], int numArgs);
0280     void opRectangle(Object args[], int numArgs);
0281     void opClosePath(Object args[], int numArgs);
0282 
0283     // path painting operators
0284     void opEndPath(Object args[], int numArgs);
0285     void opStroke(Object args[], int numArgs);
0286     void opCloseStroke(Object args[], int numArgs);
0287     void opFill(Object args[], int numArgs);
0288     void opEOFill(Object args[], int numArgs);
0289     void opFillStroke(Object args[], int numArgs);
0290     void opCloseFillStroke(Object args[], int numArgs);
0291     void opEOFillStroke(Object args[], int numArgs);
0292     void opCloseEOFillStroke(Object args[], int numArgs);
0293     void doPatternFill(bool eoFill);
0294     void doPatternStroke();
0295     void doPatternText();
0296     void doPatternImageMask(Object *ref, Stream *str, int width, int height, bool invert, bool inlineImg);
0297     void doTilingPatternFill(GfxTilingPattern *tPat, bool stroke, bool eoFill, bool text);
0298     void doShadingPatternFill(GfxShadingPattern *sPat, bool stroke, bool eoFill, bool text);
0299     void opShFill(Object args[], int numArgs);
0300     void doFunctionShFill(GfxFunctionShading *shading);
0301     void doFunctionShFill1(GfxFunctionShading *shading, double x0, double y0, double x1, double y1, GfxColor *colors, int depth);
0302     void doAxialShFill(GfxAxialShading *shading);
0303     void doRadialShFill(GfxRadialShading *shading);
0304     void doGouraudTriangleShFill(GfxGouraudTriangleShading *shading);
0305     void gouraudFillTriangle(double x0, double y0, GfxColor *color0, double x1, double y1, GfxColor *color1, double x2, double y2, GfxColor *color2, int nComps, int depth, GfxState::ReusablePathIterator *path);
0306     void gouraudFillTriangle(double x0, double y0, double color0, double x1, double y1, double color1, double x2, double y2, double color2, double refineColorThreshold, int depth, GfxGouraudTriangleShading *shading,
0307                              GfxState::ReusablePathIterator *path);
0308     void doPatchMeshShFill(GfxPatchMeshShading *shading);
0309     void fillPatch(const GfxPatch *patch, int colorComps, int patchColorComps, double refineColorThreshold, int depth, const GfxPatchMeshShading *shading);
0310     void doEndPath();
0311 
0312     // path clipping operators
0313     void opClip(Object args[], int numArgs);
0314     void opEOClip(Object args[], int numArgs);
0315 
0316     // text object operators
0317     void opBeginText(Object args[], int numArgs);
0318     void opEndText(Object args[], int numArgs);
0319 
0320     // text state operators
0321     void opSetCharSpacing(Object args[], int numArgs);
0322     void opSetFont(Object args[], int numArgs);
0323     void opSetTextLeading(Object args[], int numArgs);
0324     void opSetTextRender(Object args[], int numArgs);
0325     void opSetTextRise(Object args[], int numArgs);
0326     void opSetWordSpacing(Object args[], int numArgs);
0327     void opSetHorizScaling(Object args[], int numArgs);
0328 
0329     // text positioning operators
0330     void opTextMove(Object args[], int numArgs);
0331     void opTextMoveSet(Object args[], int numArgs);
0332     void opSetTextMatrix(Object args[], int numArgs);
0333     void opTextNextLine(Object args[], int numArgs);
0334 
0335     // text string operators
0336     void opShowText(Object args[], int numArgs);
0337     void opMoveShowText(Object args[], int numArgs);
0338     void opMoveSetShowText(Object args[], int numArgs);
0339     void opShowSpaceText(Object args[], int numArgs);
0340     void doShowText(const GooString *s);
0341     void doIncCharCount(const GooString *s);
0342 
0343     // XObject operators
0344     void opXObject(Object args[], int numArgs);
0345     void doImage(Object *ref, Stream *str, bool inlineImg);
0346     void doForm(Object *str);
0347 
0348     // in-line image operators
0349     void opBeginImage(Object args[], int numArgs);
0350     Stream *buildImageStream();
0351     void opImageData(Object args[], int numArgs);
0352     void opEndImage(Object args[], int numArgs);
0353 
0354     // type 3 font operators
0355     void opSetCharWidth(Object args[], int numArgs);
0356     void opSetCacheDevice(Object args[], int numArgs);
0357 
0358     // compatibility operators
0359     void opBeginIgnoreUndef(Object args[], int numArgs);
0360     void opEndIgnoreUndef(Object args[], int numArgs);
0361 
0362     // marked content operators
0363     void opBeginMarkedContent(Object args[], int numArgs);
0364     void opEndMarkedContent(Object args[], int numArgs);
0365     void opMarkPoint(Object args[], int numArgs);
0366     GfxState *saveStateStack();
0367     void restoreStateStack(GfxState *oldState);
0368     bool contentIsHidden();
0369     void pushMarkedContent();
0370     void popMarkedContent();
0371 };
0372 
0373 #endif