Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //========================================================================
0002 //
0003 // OutputDev.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) 2006 Thorkild Stray <thorkild@ifi.uio.no>
0018 // Copyright (C) 2007 Jeff Muizelaar <jeff@infidigm.net>
0019 // Copyright (C) 2007, 2011, 2017, 2021 Adrian Johnson <ajohnson@redneon.com>
0020 // Copyright (C) 2009-2013, 2015 Thomas Freitag <Thomas.Freitag@alfa.de>
0021 // Copyright (C) 2009, 2011 Carlos Garcia Campos <carlosgc@gnome.org>
0022 // Copyright (C) 2009, 2012, 2013, 2018, 2019, 2021 Albert Astals Cid <aacid@kde.org>
0023 // Copyright (C) 2010 Christian Feuersänger <cfeuersaenger@googlemail.com>
0024 // Copyright (C) 2012 Fabio D'Urso <fabiodurso@hotmail.it>
0025 // Copyright (C) 2012 William Bader <williambader@hotmail.com>
0026 // Copyright (C) 2017, 2018, 2020 Oliver Sander <oliver.sander@tu-dresden.de>
0027 // 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
0028 // Copyright (C) 2018 Adam Reichold <adam.reichold@t-online.de>
0029 // Copyright (C) 2020 Philipp Knechtges <philipp-dev@knechtges.com>
0030 //
0031 // To see a description of the changes please see the Changelog file that
0032 // came with your tarball or type make ChangeLog if you are building from git
0033 //
0034 //========================================================================
0035 
0036 #ifndef OUTPUTDEV_H
0037 #define OUTPUTDEV_H
0038 
0039 #include "poppler-config.h"
0040 #include "poppler_private_export.h"
0041 #include "CharTypes.h"
0042 #include "Object.h"
0043 #include "PopplerCache.h"
0044 #include "ProfileData.h"
0045 #include "GfxState.h"
0046 #include <memory>
0047 #include <unordered_map>
0048 #include <string>
0049 
0050 class Annot;
0051 class Dict;
0052 class GooString;
0053 class Gfx;
0054 class Stream;
0055 class Links;
0056 class AnnotLink;
0057 class Catalog;
0058 class Page;
0059 class Function;
0060 
0061 //------------------------------------------------------------------------
0062 // OutputDev
0063 //------------------------------------------------------------------------
0064 
0065 class POPPLER_PRIVATE_EXPORT OutputDev
0066 {
0067 public:
0068     // Constructor.
0069     OutputDev();
0070 
0071     // Destructor.
0072     virtual ~OutputDev();
0073 
0074     //----- get info about output device
0075 
0076     // Does this device use upside-down coordinates?
0077     // (Upside-down means (0,0) is the top left corner of the page.)
0078     virtual bool upsideDown() = 0;
0079 
0080     // Does this device use drawChar() or drawString()?
0081     virtual bool useDrawChar() = 0;
0082 
0083     // Does this device use tilingPatternFill()?  If this returns false,
0084     // tiling pattern fills will be reduced to a series of other drawing
0085     // operations.
0086     virtual bool useTilingPatternFill() { return false; }
0087 
0088     // Does this device support specific shading types?
0089     // see gouraudTriangleShadedFill() and patchMeshShadedFill()
0090     virtual bool useShadedFills(int type) { return false; }
0091 
0092     // Does this device use FillColorStop()?
0093     virtual bool useFillColorStop() { return false; }
0094 
0095     // Does this device use drawForm()?  If this returns false,
0096     // form-type XObjects will be interpreted (i.e., unrolled).
0097     virtual bool useDrawForm() { return false; }
0098 
0099     // Does this device use beginType3Char/endType3Char?  Otherwise,
0100     // text in Type 3 fonts will be drawn with drawChar/drawString.
0101     virtual bool interpretType3Chars() = 0;
0102 
0103     // Does this device need non-text content?
0104     virtual bool needNonText() { return true; }
0105 
0106     // Does this device require incCharCount to be called for text on
0107     // non-shown layers?
0108     virtual bool needCharCount() { return false; }
0109 
0110     // Does this device need to clip pages to the crop box even when the
0111     // box is the crop box?
0112     virtual bool needClipToCropBox() { return false; }
0113 
0114     //----- initialization and control
0115 
0116     // Set default transform matrix.
0117     virtual void setDefaultCTM(const double *ctm);
0118 
0119     // Check to see if a page slice should be displayed.  If this
0120     // returns false, the page display is aborted.  Typically, an
0121     // OutputDev will use some alternate means to display the page
0122     // before returning false.
0123     virtual bool checkPageSlice(Page *page, double hDPI, double vDPI, int rotate, bool useMediaBox, bool crop, int sliceX, int sliceY, int sliceW, int sliceH, bool printing, bool (*abortCheckCbk)(void *data) = nullptr,
0124                                 void *abortCheckCbkData = nullptr, bool (*annotDisplayDecideCbk)(Annot *annot, void *user_data) = nullptr, void *annotDisplayDecideCbkData = nullptr)
0125     {
0126         return true;
0127     }
0128 
0129     // Start a page.
0130     virtual void startPage(int pageNum, GfxState *state, XRef *xref) { }
0131 
0132     // End a page.
0133     virtual void endPage() { }
0134 
0135     // Dump page contents to display.
0136     virtual void dump() { }
0137 
0138     virtual void initGfxState(GfxState *state)
0139     {
0140 #ifdef USE_CMS
0141         state->setDisplayProfile(displayprofile);
0142 
0143         auto invalidref = Ref::INVALID();
0144         if (defaultGrayProfile) {
0145             auto cs = new GfxICCBasedColorSpace(1, new GfxDeviceGrayColorSpace(), &invalidref);
0146 
0147             cs->setProfile(defaultGrayProfile);
0148             cs->buildTransforms(state); // needs to happen after state->setDisplayProfile has been called
0149             state->setDefaultGrayColorSpace(cs);
0150         }
0151 
0152         if (defaultRGBProfile) {
0153             auto cs = new GfxICCBasedColorSpace(3, new GfxDeviceRGBColorSpace(), &invalidref);
0154 
0155             cs->setProfile(defaultRGBProfile);
0156             cs->buildTransforms(state); // needs to happen after state->setDisplayProfile has been called
0157             state->setDefaultRGBColorSpace(cs);
0158         }
0159 
0160         if (defaultCMYKProfile) {
0161             auto cs = new GfxICCBasedColorSpace(4, new GfxDeviceCMYKColorSpace(), &invalidref);
0162 
0163             cs->setProfile(defaultCMYKProfile);
0164             cs->buildTransforms(state); // needs to happen after state->setDisplayProfile has been called
0165             state->setDefaultCMYKColorSpace(cs);
0166         }
0167 #endif
0168     }
0169 
0170     //----- coordinate conversion
0171 
0172     // Convert between device and user coordinates.
0173     virtual void cvtDevToUser(double dx, double dy, double *ux, double *uy);
0174     virtual void cvtUserToDev(double ux, double uy, int *dx, int *dy);
0175 
0176     const double *getDefCTM() const { return defCTM; }
0177     const double *getDefICTM() const { return defICTM; }
0178 
0179     //----- save/restore graphics state
0180     virtual void saveState(GfxState * /*state*/) { }
0181     virtual void restoreState(GfxState * /*state*/) { }
0182 
0183     //----- update graphics state
0184     virtual void updateAll(GfxState *state);
0185 
0186     // Update the Current Transformation Matrix (CTM), i.e., the new matrix
0187     // given in m11, ..., m32 is combined with the current value of the CTM.
0188     // At the same time, when this method is called, state->getCTM() already
0189     // contains the correct new CTM, so one may as well replace the
0190     // CTM of the renderer with that.
0191     virtual void updateCTM(GfxState * /*state*/, double /*m11*/, double /*m12*/, double /*m21*/, double /*m22*/, double /*m31*/, double /*m32*/) { }
0192     virtual void updateLineDash(GfxState * /*state*/) { }
0193     virtual void updateFlatness(GfxState * /*state*/) { }
0194     virtual void updateLineJoin(GfxState * /*state*/) { }
0195     virtual void updateLineCap(GfxState * /*state*/) { }
0196     virtual void updateMiterLimit(GfxState * /*state*/) { }
0197     virtual void updateLineWidth(GfxState * /*state*/) { }
0198     virtual void updateStrokeAdjust(GfxState * /*state*/) { }
0199     virtual void updateAlphaIsShape(GfxState * /*state*/) { }
0200     virtual void updateTextKnockout(GfxState * /*state*/) { }
0201     virtual void updateFillColorSpace(GfxState * /*state*/) { }
0202     virtual void updateStrokeColorSpace(GfxState * /*state*/) { }
0203     virtual void updateFillColor(GfxState * /*state*/) { }
0204     virtual void updateStrokeColor(GfxState * /*state*/) { }
0205     virtual void updateBlendMode(GfxState * /*state*/) { }
0206     virtual void updateFillOpacity(GfxState * /*state*/) { }
0207     virtual void updateStrokeOpacity(GfxState * /*state*/) { }
0208     virtual void updatePatternOpacity(GfxState * /*state*/) { }
0209     virtual void clearPatternOpacity(GfxState * /*state*/) { }
0210     virtual void updateFillOverprint(GfxState * /*state*/) { }
0211     virtual void updateStrokeOverprint(GfxState * /*state*/) { }
0212     virtual void updateOverprintMode(GfxState * /*state*/) { }
0213     virtual void updateTransfer(GfxState * /*state*/) { }
0214     virtual void updateFillColorStop(GfxState * /*state*/, double /*offset*/) { }
0215 
0216     //----- update text state
0217     virtual void updateFont(GfxState * /*state*/) { }
0218     virtual void updateTextMat(GfxState * /*state*/) { }
0219     virtual void updateCharSpace(GfxState * /*state*/) { }
0220     virtual void updateRender(GfxState * /*state*/) { }
0221     virtual void updateRise(GfxState * /*state*/) { }
0222     virtual void updateWordSpace(GfxState * /*state*/) { }
0223     virtual void updateHorizScaling(GfxState * /*state*/) { }
0224     virtual void updateTextPos(GfxState * /*state*/) { }
0225     virtual void updateTextShift(GfxState * /*state*/, double /*shift*/) { }
0226     virtual void saveTextPos(GfxState * /*state*/) { }
0227     virtual void restoreTextPos(GfxState * /*state*/) { }
0228 
0229     //----- path painting
0230     virtual void stroke(GfxState * /*state*/) { }
0231     virtual void fill(GfxState * /*state*/) { }
0232     virtual void eoFill(GfxState * /*state*/) { }
0233     virtual bool tilingPatternFill(GfxState * /*state*/, Gfx * /*gfx*/, Catalog * /*cat*/, GfxTilingPattern * /*tPat*/, const double * /*mat*/, int /*x0*/, int /*y0*/, int /*x1*/, int /*y1*/, double /*xStep*/, double /*yStep*/)
0234     {
0235         return false;
0236     }
0237     virtual bool functionShadedFill(GfxState * /*state*/, GfxFunctionShading * /*shading*/) { return false; }
0238     virtual bool axialShadedFill(GfxState * /*state*/, GfxAxialShading * /*shading*/, double /*tMin*/, double /*tMax*/) { return false; }
0239     virtual bool axialShadedSupportExtend(GfxState * /*state*/, GfxAxialShading * /*shading*/) { return false; }
0240     virtual bool radialShadedFill(GfxState * /*state*/, GfxRadialShading * /*shading*/, double /*sMin*/, double /*sMax*/) { return false; }
0241     virtual bool radialShadedSupportExtend(GfxState * /*state*/, GfxRadialShading * /*shading*/) { return false; }
0242     virtual bool gouraudTriangleShadedFill(GfxState *state, GfxGouraudTriangleShading *shading) { return false; }
0243     virtual bool patchMeshShadedFill(GfxState *state, GfxPatchMeshShading *shading) { return false; }
0244 
0245     //----- path clipping
0246 
0247     // Update the clipping path.  The new path is the intersection of the old path
0248     // with the path given in 'state'.
0249     // Additionally, set the clipping mode to the 'nonzero winding number rule'.
0250     // That is, a point is inside the clipping region if its winding number
0251     // with respect to the clipping path is nonzero.
0252     virtual void clip(GfxState * /*state*/) { }
0253 
0254     // Update the clipping path.  The new path is the intersection of the old path
0255     // with the path given in 'state'.
0256     // Additionally, set the clipping mode to the 'even-odd rule'.  That is, a point is
0257     // inside the clipping region if a ray from it to infinity will cross the clipping
0258     // path an odd number of times (disregarding the path orientation).
0259     virtual void eoClip(GfxState * /*state*/) { }
0260 
0261     // Update the clipping path.  Unlike for the previous two methods, the clipping region
0262     // is not the region surrounded by the path in 'state', but rather the path itself,
0263     // rendered with the current pen settings.
0264     virtual void clipToStrokePath(GfxState * /*state*/) { }
0265 
0266     //----- text drawing
0267     virtual void beginStringOp(GfxState * /*state*/) { }
0268     virtual void endStringOp(GfxState * /*state*/) { }
0269     virtual void beginString(GfxState * /*state*/, const GooString * /*s*/) { }
0270     virtual void endString(GfxState * /*state*/) { }
0271 
0272     // Draw one glyph at a specified position
0273     //
0274     // Arguments are:
0275     // CharCode code: This is the character code in the content stream. It needs to be mapped back to a glyph index.
0276     // int nBytes: The text strings in the content stream can consists of either 8-bit or 16-bit
0277     //             character codes depending on the font. nBytes is the number of bytes in the character code.
0278     // Unicode *u: The UCS-4 mapping used for text extraction (TextOutputDev).
0279     // int uLen: The number of unicode entries in u.  Usually '1', for a single character,
0280     //           but it may also have larger values, for example for ligatures.
0281     virtual 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*/) { }
0282     virtual void drawString(GfxState * /*state*/, const GooString * /*s*/) { }
0283     virtual bool beginType3Char(GfxState * /*state*/, double /*x*/, double /*y*/, double /*dx*/, double /*dy*/, CharCode /*code*/, const Unicode * /*u*/, int /*uLen*/);
0284     virtual void endType3Char(GfxState * /*state*/) { }
0285     virtual void beginTextObject(GfxState * /*state*/) { }
0286     virtual void endTextObject(GfxState * /*state*/) { }
0287     virtual void incCharCount(int /*nChars*/) { }
0288     virtual void beginActualText(GfxState * /*state*/, const GooString * /*text*/) { }
0289     virtual void endActualText(GfxState * /*state*/) { }
0290 
0291     //----- image drawing
0292     // Draw an image mask.  An image mask is a one-bit-per-pixel image, where each pixel
0293     // can only be 'fill color' or 'transparent'.
0294     //
0295     // If 'invert' is false, a sample value of 0 marks the page with the current color,
0296     // and a 1 leaves the previous contents unchanged. If 'invert' is true, these meanings are reversed.
0297     virtual void drawImageMask(GfxState *state, Object *ref, Stream *str, int width, int height, bool invert, bool interpolate, bool inlineImg);
0298     virtual void setSoftMaskFromImageMask(GfxState *state, Object *ref, Stream *str, int width, int height, bool invert, bool inlineImg, double *baseMatrix);
0299     virtual void unsetSoftMaskFromImageMask(GfxState *state, double *baseMatrix);
0300     virtual void drawImage(GfxState *state, Object *ref, Stream *str, int width, int height, GfxImageColorMap *colorMap, bool interpolate, const int *maskColors, bool inlineImg);
0301     virtual void drawMaskedImage(GfxState *state, Object *ref, Stream *str, int width, int height, GfxImageColorMap *colorMap, bool interpolate, Stream *maskStr, int maskWidth, int maskHeight, bool maskInvert, bool maskInterpolate);
0302     virtual void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str, int width, int height, GfxImageColorMap *colorMap, bool interpolate, Stream *maskStr, int maskWidth, int maskHeight, GfxImageColorMap *maskColorMap,
0303                                      bool maskInterpolate);
0304 
0305     //----- grouping operators
0306 
0307     virtual void endMarkedContent(GfxState *state);
0308     virtual void beginMarkedContent(const char *name, Dict *properties);
0309     virtual void markPoint(const char *name);
0310     virtual void markPoint(const char *name, Dict *properties);
0311 
0312 #ifdef OPI_SUPPORT
0313     //----- OPI functions
0314     virtual void opiBegin(GfxState *state, Dict *opiDict);
0315     virtual void opiEnd(GfxState *state, Dict *opiDict);
0316 #endif
0317 
0318     //----- Type 3 font operators
0319     virtual void type3D0(GfxState * /*state*/, double /*wx*/, double /*wy*/) { }
0320     virtual void type3D1(GfxState * /*state*/, double /*wx*/, double /*wy*/, double /*llx*/, double /*lly*/, double /*urx*/, double /*ury*/) { }
0321 
0322     //----- form XObjects
0323     virtual void beginForm(Ref /*id*/) { }
0324     virtual void drawForm(Ref /*id*/) { }
0325     virtual void endForm(Ref /*id*/) { }
0326 
0327     //----- PostScript XObjects
0328     virtual void psXObject(Stream * /*psStream*/, Stream * /*level1Stream*/) { }
0329 
0330     //----- Profiling
0331     void startProfile();
0332     std::unordered_map<std::string, ProfileData> *getProfileHash() const { return profileHash.get(); }
0333     std::unique_ptr<std::unordered_map<std::string, ProfileData>> endProfile();
0334 
0335     //----- transparency groups and soft masks
0336     virtual bool checkTransparencyGroup(GfxState * /*state*/, bool /*knockout*/) { return true; }
0337     virtual void beginTransparencyGroup(GfxState * /*state*/, const double * /*bbox*/, GfxColorSpace * /*blendingColorSpace*/, bool /*isolated*/, bool /*knockout*/, bool /*forSoftMask*/) { }
0338     virtual void endTransparencyGroup(GfxState * /*state*/) { }
0339     virtual void paintTransparencyGroup(GfxState * /*state*/, const double * /*bbox*/) { }
0340     virtual void setSoftMask(GfxState * /*state*/, const double * /*bbox*/, bool /*alpha*/, Function * /*transferFunc*/, GfxColor * /*backdropColor*/) { }
0341     virtual void clearSoftMask(GfxState * /*state*/) { }
0342 
0343     //----- links
0344     virtual void processLink(AnnotLink * /*link*/) { }
0345 
0346 #if 1 //~tmp: turn off anti-aliasing temporarily
0347     virtual bool getVectorAntialias() { return false; }
0348     virtual void setVectorAntialias(bool /*vaa*/) { }
0349 #endif
0350 
0351 #ifdef USE_CMS
0352     void setDisplayProfile(const GfxLCMSProfilePtr &profile) { displayprofile = profile; }
0353     GfxLCMSProfilePtr getDisplayProfile() const { return displayprofile; }
0354     void setDefaultGrayProfile(const GfxLCMSProfilePtr &profile) { defaultGrayProfile = profile; }
0355     GfxLCMSProfilePtr getDefaultGrayProfile() const { return defaultGrayProfile; }
0356     void setDefaultRGBProfile(const GfxLCMSProfilePtr &profile) { defaultRGBProfile = profile; }
0357     GfxLCMSProfilePtr getDefaultRGBProfile() const { return defaultRGBProfile; }
0358     void setDefaultCMYKProfile(const GfxLCMSProfilePtr &profile) { defaultCMYKProfile = profile; }
0359     GfxLCMSProfilePtr getDefaultCMYKProfile() const { return defaultCMYKProfile; }
0360 
0361     PopplerCache<Ref, GfxICCBasedColorSpace> *getIccColorSpaceCache() { return &iccColorSpaceCache; }
0362 #endif
0363 
0364 private:
0365     double defCTM[6]; // default coordinate transform matrix
0366     double defICTM[6]; // inverse of default CTM
0367     std::unique_ptr<std::unordered_map<std::string, ProfileData>> profileHash;
0368 
0369 #ifdef USE_CMS
0370     GfxLCMSProfilePtr displayprofile;
0371     GfxLCMSProfilePtr defaultGrayProfile;
0372     GfxLCMSProfilePtr defaultRGBProfile;
0373     GfxLCMSProfilePtr defaultCMYKProfile;
0374 
0375     PopplerCache<Ref, GfxICCBasedColorSpace> iccColorSpaceCache;
0376 #endif
0377 };
0378 
0379 #endif