Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //========================================================================
0002 //
0003 // SplashOutputDev.h
0004 //
0005 // Copyright 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 Takashi Iwai <tiwai@suse.de>
0017 // Copyright (C) 2009-2016 Thomas Freitag <Thomas.Freitag@alfa.de>
0018 // Copyright (C) 2009 Carlos Garcia Campos <carlosgc@gnome.org>
0019 // Copyright (C) 2010 Christian Feuersänger <cfeuersaenger@googlemail.com>
0020 // Copyright (C) 2011 Andreas Hartmetz <ahartmetz@gmail.com>
0021 // Copyright (C) 2011 Andrea Canciani <ranma42@gmail.com>
0022 // Copyright (C) 2011, 2017 Adrian Johnson <ajohnson@redneon.com>
0023 // Copyright (C) 2012, 2015, 2018-2021 Albert Astals Cid <aacid@kde.org>
0024 // Copyright (C) 2015, 2016 William Bader <williambader@hotmail.com>
0025 // Copyright (C) 2018 Stefan Brüns <stefan.bruens@rwth-aachen.de>
0026 //
0027 // To see a description of the changes please see the Changelog file that
0028 // came with your tarball or type make ChangeLog if you are building from git
0029 //
0030 //========================================================================
0031 
0032 #ifndef SPLASHOUTPUTDEV_H
0033 #define SPLASHOUTPUTDEV_H
0034 
0035 #include "splash/SplashTypes.h"
0036 #include "splash/SplashPattern.h"
0037 #include "poppler-config.h"
0038 #include "poppler_private_export.h"
0039 #include "OutputDev.h"
0040 #include "GfxState.h"
0041 #include "GlobalParams.h"
0042 
0043 class PDFDoc;
0044 class Gfx8BitFont;
0045 class SplashBitmap;
0046 class Splash;
0047 class SplashPath;
0048 class SplashFontEngine;
0049 class SplashFont;
0050 class T3FontCache;
0051 struct T3FontCacheTag;
0052 struct T3GlyphStack;
0053 struct SplashTransparencyGroup;
0054 
0055 //------------------------------------------------------------------------
0056 // Splash dynamic pattern
0057 //------------------------------------------------------------------------
0058 
0059 class SplashFunctionPattern : public SplashPattern
0060 {
0061 public:
0062     SplashFunctionPattern(SplashColorMode colorMode, GfxState *state, GfxFunctionShading *shading);
0063 
0064     SplashPattern *copy() const override { return new SplashFunctionPattern(colorMode, state, (GfxFunctionShading *)shading); }
0065 
0066     ~SplashFunctionPattern() override;
0067 
0068     bool testPosition(int x, int y) override { return true; }
0069 
0070     bool isStatic() override { return false; }
0071 
0072     bool getColor(int x, int y, SplashColorPtr c) override;
0073 
0074     virtual GfxFunctionShading *getShading() { return shading; }
0075 
0076     bool isCMYK() override { return gfxMode == csDeviceCMYK; }
0077 
0078 protected:
0079     Matrix ictm;
0080     double xMin, yMin, xMax, yMax;
0081     GfxFunctionShading *shading;
0082     GfxState *state;
0083     SplashColorMode colorMode;
0084     GfxColorSpaceMode gfxMode;
0085 };
0086 
0087 class SplashUnivariatePattern : public SplashPattern
0088 {
0089 public:
0090     SplashUnivariatePattern(SplashColorMode colorMode, GfxState *state, GfxUnivariateShading *shading);
0091 
0092     ~SplashUnivariatePattern() override;
0093 
0094     bool getColor(int x, int y, SplashColorPtr c) override;
0095 
0096     bool testPosition(int x, int y) override;
0097 
0098     bool isStatic() override { return false; }
0099 
0100     virtual bool getParameter(double xs, double ys, double *t) = 0;
0101 
0102     virtual GfxUnivariateShading *getShading() { return shading; }
0103 
0104     bool isCMYK() override { return gfxMode == csDeviceCMYK; }
0105 
0106 protected:
0107     Matrix ictm;
0108     double t0, t1, dt;
0109     GfxUnivariateShading *shading;
0110     GfxState *state;
0111     SplashColorMode colorMode;
0112     GfxColorSpaceMode gfxMode;
0113 };
0114 
0115 class SplashAxialPattern : public SplashUnivariatePattern
0116 {
0117 public:
0118     SplashAxialPattern(SplashColorMode colorMode, GfxState *state, GfxAxialShading *shading);
0119 
0120     SplashPattern *copy() const override { return new SplashAxialPattern(colorMode, state, (GfxAxialShading *)shading); }
0121 
0122     ~SplashAxialPattern() override;
0123 
0124     bool getParameter(double xc, double yc, double *t) override;
0125 
0126 private:
0127     double x0, y0, x1, y1;
0128     double dx, dy, mul;
0129 };
0130 
0131 // see GfxState.h, GfxGouraudTriangleShading
0132 class SplashGouraudPattern : public SplashGouraudColor
0133 {
0134 public:
0135     SplashGouraudPattern(bool bDirectColorTranslation, GfxState *state, GfxGouraudTriangleShading *shading);
0136 
0137     SplashPattern *copy() const override { return new SplashGouraudPattern(bDirectColorTranslation, state, shading); }
0138 
0139     ~SplashGouraudPattern() override;
0140 
0141     bool getColor(int x, int y, SplashColorPtr c) override { return false; }
0142 
0143     bool testPosition(int x, int y) override { return false; }
0144 
0145     bool isStatic() override { return false; }
0146 
0147     bool isCMYK() override { return gfxMode == csDeviceCMYK; }
0148 
0149     bool isParameterized() override { return shading->isParameterized(); }
0150     int getNTriangles() override { return shading->getNTriangles(); }
0151     void getParametrizedTriangle(int i, double *x0, double *y0, double *color0, double *x1, double *y1, double *color1, double *x2, double *y2, double *color2) override
0152     {
0153         shading->getTriangle(i, x0, y0, color0, x1, y1, color1, x2, y2, color2);
0154     }
0155 
0156     void getNonParametrizedTriangle(int i, SplashColorMode mode, double *x0, double *y0, SplashColorPtr color0, double *x1, double *y1, SplashColorPtr color1, double *x2, double *y2, SplashColorPtr color2) override;
0157 
0158     void getParameterizedColor(double colorinterp, SplashColorMode mode, SplashColorPtr dest) override;
0159 
0160 private:
0161     GfxGouraudTriangleShading *shading;
0162     GfxState *state;
0163     bool bDirectColorTranslation;
0164     GfxColorSpaceMode gfxMode;
0165 };
0166 
0167 // see GfxState.h, GfxRadialShading
0168 class SplashRadialPattern : public SplashUnivariatePattern
0169 {
0170 public:
0171     SplashRadialPattern(SplashColorMode colorMode, GfxState *state, GfxRadialShading *shading);
0172 
0173     SplashPattern *copy() const override { return new SplashRadialPattern(colorMode, state, (GfxRadialShading *)shading); }
0174 
0175     ~SplashRadialPattern() override;
0176 
0177     bool getParameter(double xs, double ys, double *t) override;
0178 
0179 private:
0180     double x0, y0, r0, dx, dy, dr;
0181     double a, inva;
0182 };
0183 
0184 //------------------------------------------------------------------------
0185 
0186 // number of Type 3 fonts to cache
0187 #define splashOutT3FontCacheSize 8
0188 
0189 //------------------------------------------------------------------------
0190 // SplashOutputDev
0191 //------------------------------------------------------------------------
0192 
0193 class POPPLER_PRIVATE_EXPORT SplashOutputDev : public OutputDev
0194 {
0195 public:
0196     // Constructor.
0197     SplashOutputDev(SplashColorMode colorModeA, int bitmapRowPadA, bool reverseVideoA, SplashColorPtr paperColorA, bool bitmapTopDownA = true, SplashThinLineMode thinLineMode = splashThinLineDefault, bool overprintPreviewA = false);
0198 
0199     // Destructor.
0200     ~SplashOutputDev() override;
0201 
0202     //----- get info about output device
0203 
0204     // Does this device use tilingPatternFill()?  If this returns false,
0205     // tiling pattern fills will be reduced to a series of other drawing
0206     // operations.
0207     bool useTilingPatternFill() override { return true; }
0208 
0209     // Does this device use functionShadedFill(), axialShadedFill(), and
0210     // radialShadedFill()?  If this returns false, these shaded fills
0211     // will be reduced to a series of other drawing operations.
0212     bool useShadedFills(int type) override { return (type >= 1 && type <= 5) ? true : false; }
0213 
0214     // Does this device use upside-down coordinates?
0215     // (Upside-down means (0,0) is the top left corner of the page.)
0216     bool upsideDown() override { return bitmapTopDown; }
0217 
0218     // Does this device use drawChar() or drawString()?
0219     bool useDrawChar() override { return true; }
0220 
0221     // Does this device use beginType3Char/endType3Char?  Otherwise,
0222     // text in Type 3 fonts will be drawn with drawChar/drawString.
0223     bool interpretType3Chars() override { return true; }
0224 
0225     //----- initialization and control
0226 
0227     // Start a page.
0228     void startPage(int pageNum, GfxState *state, XRef *xref) override;
0229 
0230     // End a page.
0231     void endPage() override;
0232 
0233     //----- save/restore graphics state
0234     void saveState(GfxState *state) override;
0235     void restoreState(GfxState *state) override;
0236 
0237     //----- update graphics state
0238     void updateAll(GfxState *state) override;
0239     void updateCTM(GfxState *state, double m11, double m12, double m21, double m22, double m31, double m32) override;
0240     void updateLineDash(GfxState *state) override;
0241     void updateFlatness(GfxState *state) override;
0242     void updateLineJoin(GfxState *state) override;
0243     void updateLineCap(GfxState *state) override;
0244     void updateMiterLimit(GfxState *state) override;
0245     void updateLineWidth(GfxState *state) override;
0246     void updateStrokeAdjust(GfxState *state) override;
0247     void updateFillColorSpace(GfxState *state) override;
0248     void updateStrokeColorSpace(GfxState *state) override;
0249     void updateFillColor(GfxState *state) override;
0250     void updateStrokeColor(GfxState *state) override;
0251     void updateBlendMode(GfxState *state) override;
0252     void updateFillOpacity(GfxState *state) override;
0253     void updateStrokeOpacity(GfxState *state) override;
0254     void updatePatternOpacity(GfxState *state) override;
0255     void clearPatternOpacity(GfxState *state) override;
0256     void updateFillOverprint(GfxState *state) override;
0257     void updateStrokeOverprint(GfxState *state) override;
0258     void updateOverprintMode(GfxState *state) override;
0259     void updateTransfer(GfxState *state) override;
0260 
0261     //----- update text state
0262     void updateFont(GfxState *state) override;
0263 
0264     //----- path painting
0265     void stroke(GfxState *state) override;
0266     void fill(GfxState *state) override;
0267     void eoFill(GfxState *state) override;
0268     bool tilingPatternFill(GfxState *state, Gfx *gfx, Catalog *catalog, GfxTilingPattern *tPat, const double *mat, int x0, int y0, int x1, int y1, double xStep, double yStep) override;
0269     bool functionShadedFill(GfxState *state, GfxFunctionShading *shading) override;
0270     bool axialShadedFill(GfxState *state, GfxAxialShading *shading, double tMin, double tMax) override;
0271     bool radialShadedFill(GfxState *state, GfxRadialShading *shading, double tMin, double tMax) override;
0272     bool gouraudTriangleShadedFill(GfxState *state, GfxGouraudTriangleShading *shading) override;
0273 
0274     //----- path clipping
0275     void clip(GfxState *state) override;
0276     void eoClip(GfxState *state) override;
0277     void clipToStrokePath(GfxState *state) override;
0278 
0279     //----- text drawing
0280     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;
0281     bool beginType3Char(GfxState *state, double x, double y, double dx, double dy, CharCode code, const Unicode *u, int uLen) override;
0282     void endType3Char(GfxState *state) override;
0283     void beginTextObject(GfxState *state) override;
0284     void endTextObject(GfxState *state) override;
0285 
0286     //----- image drawing
0287     void drawImageMask(GfxState *state, Object *ref, Stream *str, int width, int height, bool invert, bool interpolate, bool inlineImg) override;
0288     void setSoftMaskFromImageMask(GfxState *state, Object *ref, Stream *str, int width, int height, bool invert, bool inlineImg, double *baseMatrix) override;
0289     void unsetSoftMaskFromImageMask(GfxState *state, double *baseMatrix) override;
0290     void drawImage(GfxState *state, Object *ref, Stream *str, int width, int height, GfxImageColorMap *colorMap, bool interpolate, const int *maskColors, bool inlineImg) override;
0291     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) override;
0292     void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str, int width, int height, GfxImageColorMap *colorMap, bool interpolate, Stream *maskStr, int maskWidth, int maskHeight, GfxImageColorMap *maskColorMap,
0293                              bool maskInterpolate) override;
0294 
0295     //----- Type 3 font operators
0296     void type3D0(GfxState *state, double wx, double wy) override;
0297     void type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury) override;
0298 
0299     //----- transparency groups and soft masks
0300     bool checkTransparencyGroup(GfxState *state, bool knockout) override;
0301     void beginTransparencyGroup(GfxState *state, const double *bbox, GfxColorSpace *blendingColorSpace, bool isolated, bool knockout, bool forSoftMask) override;
0302     void endTransparencyGroup(GfxState *state) override;
0303     void paintTransparencyGroup(GfxState *state, const double *bbox) override;
0304     void setSoftMask(GfxState *state, const double *bbox, bool alpha, Function *transferFunc, GfxColor *backdropColor) override;
0305     void clearSoftMask(GfxState *state) override;
0306 
0307     //----- special access
0308 
0309     // Called to indicate that a new PDF document has been loaded.
0310     void startDoc(PDFDoc *docA);
0311 
0312     void setPaperColor(SplashColorPtr paperColorA);
0313 
0314     bool isReverseVideo() { return reverseVideo; }
0315     void setReverseVideo(bool reverseVideoA) { reverseVideo = reverseVideoA; }
0316 
0317     // Get the bitmap and its size.
0318     SplashBitmap *getBitmap() { return bitmap; }
0319     int getBitmapWidth();
0320     int getBitmapHeight();
0321 
0322     // Returns the last rasterized bitmap, transferring ownership to the
0323     // caller.
0324     SplashBitmap *takeBitmap();
0325 
0326     // Get the Splash object.
0327     Splash *getSplash() { return splash; }
0328 
0329     SplashFont *getCurrentFont() { return font; }
0330 
0331     // If <skipTextA> is true, don't draw horizontal text.
0332     // If <skipRotatedTextA> is true, don't draw rotated (non-horizontal) text.
0333     void setSkipText(bool skipHorizTextA, bool skipRotatedTextA)
0334     {
0335         skipHorizText = skipHorizTextA;
0336         skipRotatedText = skipRotatedTextA;
0337     }
0338 
0339 #if 1 //~tmp: turn off anti-aliasing temporarily
0340     bool getVectorAntialias() override;
0341     void setVectorAntialias(bool vaa) override;
0342 #endif
0343 
0344     bool getFontAntialias() { return fontAntialias; }
0345     void setFontAntialias(bool anti) { fontAntialias = anti; }
0346 
0347     void setFreeTypeHinting(bool enable, bool enableSlightHinting);
0348     void setEnableFreeType(bool enable) { enableFreeType = enable; }
0349 
0350 protected:
0351     void doUpdateFont(GfxState *state);
0352 
0353 private:
0354     bool univariateShadedFill(GfxState *state, SplashUnivariatePattern *pattern, double tMin, double tMax);
0355 
0356     void setupScreenParams(double hDPI, double vDPI);
0357     SplashPattern *getColor(GfxGray gray);
0358     SplashPattern *getColor(GfxRGB *rgb);
0359     SplashPattern *getColor(GfxCMYK *cmyk);
0360     SplashPattern *getColor(GfxColor *deviceN);
0361     static void getMatteColor(SplashColorMode colorMode, GfxImageColorMap *colorMap, const GfxColor *matteColor, SplashColor splashMatteColor);
0362     void setOverprintMask(GfxColorSpace *colorSpace, bool overprintFlag, int overprintMode, const GfxColor *singleColor, bool grayIndexed = false);
0363     SplashPath convertPath(GfxState *state, const GfxPath *path, bool dropEmptySubpaths);
0364     void drawType3Glyph(GfxState *state, T3FontCache *t3Font, T3FontCacheTag *tag, unsigned char *data);
0365 #ifdef USE_CMS
0366     bool useIccImageSrc(void *data);
0367     static void iccTransform(void *data, SplashBitmap *bitmap);
0368     static bool iccImageSrc(void *data, SplashColorPtr colorLine, unsigned char *alphaLine);
0369 #endif
0370     static bool imageMaskSrc(void *data, SplashColorPtr line);
0371     static bool imageSrc(void *data, SplashColorPtr colorLine, unsigned char *alphaLine);
0372     static bool alphaImageSrc(void *data, SplashColorPtr line, unsigned char *alphaLine);
0373     static bool maskedImageSrc(void *data, SplashColorPtr line, unsigned char *alphaLine);
0374     static bool tilingBitmapSrc(void *data, SplashColorPtr line, unsigned char *alphaLine);
0375 
0376     bool keepAlphaChannel; // don't fill with paper color, keep alpha channel
0377 
0378     SplashColorMode colorMode;
0379     int bitmapRowPad;
0380     bool bitmapTopDown;
0381     bool fontAntialias;
0382     bool vectorAntialias;
0383     bool overprintPreview;
0384     bool enableFreeType;
0385     bool enableFreeTypeHinting;
0386     bool enableSlightHinting;
0387     bool reverseVideo; // reverse video mode
0388     SplashColor paperColor; // paper color
0389     SplashScreenParams screenParams;
0390     bool skipHorizText;
0391     bool skipRotatedText;
0392 
0393     PDFDoc *doc; // the current document
0394     XRef *xref; // the xref of the current document
0395 
0396     SplashBitmap *bitmap;
0397     Splash *splash;
0398     SplashFontEngine *fontEngine;
0399 
0400     T3FontCache * // Type 3 font cache
0401             t3FontCache[splashOutT3FontCacheSize];
0402     int nT3Fonts; // number of valid entries in t3FontCache
0403     T3GlyphStack *t3GlyphStack; // Type 3 glyph context stack
0404 
0405     SplashFont *font; // current font
0406     bool needFontUpdate; // set when the font needs to be updated
0407     SplashPath *textClipPath; // clipping path built with text object
0408 
0409     SplashTransparencyGroup * // transparency group stack
0410             transpGroupStack;
0411 };
0412 
0413 #endif