File indexing completed on 2025-12-10 10:23:50
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039 #ifndef PSOUTPUTDEV_H
0040 #define PSOUTPUTDEV_H
0041
0042 #include "poppler-config.h"
0043 #include "poppler_private_export.h"
0044 #include <cstddef>
0045 #include "Object.h"
0046 #include "GfxState.h"
0047 #include "GlobalParams.h"
0048 #include "OutputDev.h"
0049 #include "fofi/FoFiBase.h"
0050 #include <set>
0051 #include <map>
0052 #include <vector>
0053 #include <unordered_set>
0054 #include <unordered_map>
0055 #include <string>
0056
0057 #include "splash/Splash.h"
0058
0059 class PDFDoc;
0060 class XRef;
0061 class Function;
0062 class GfxPath;
0063 class GfxFont;
0064 class GfxColorSpace;
0065 class GfxSeparationColorSpace;
0066 class PDFRectangle;
0067 struct PST1FontName;
0068 struct PSFont8Info;
0069 struct PSFont16Enc;
0070 class PSOutCustomColor;
0071 struct PSOutPaperSize;
0072 class PSOutputDev;
0073
0074
0075
0076
0077
0078 enum PSLevel
0079 {
0080 psLevel1,
0081 psLevel1Sep,
0082 psLevel2,
0083 psLevel2Sep,
0084 psLevel3,
0085 psLevel3Sep
0086 };
0087
0088 enum PSOutMode
0089 {
0090 psModePS,
0091 psModeEPS,
0092 psModeForm
0093 };
0094
0095 enum PSFileType
0096 {
0097 psFile,
0098 psPipe,
0099 psStdout,
0100 psGeneric
0101 };
0102
0103 enum PSOutCustomCodeLocation
0104 {
0105 psOutCustomDocSetup,
0106 psOutCustomPageSetup
0107 };
0108
0109 enum PSForceRasterize
0110 {
0111 psRasterizeWhenNeeded,
0112 psAlwaysRasterize,
0113 psNeverRasterize
0114 };
0115
0116 typedef GooString *(*PSOutCustomCodeCbk)(PSOutputDev *psOut, PSOutCustomCodeLocation loc, int n, void *data);
0117
0118 class POPPLER_PRIVATE_EXPORT PSOutputDev : public OutputDev
0119 {
0120 public:
0121
0122
0123 PSOutputDev(const char *fileName, PDFDoc *docA, char *psTitleA, const std::vector<int> &pages, PSOutMode modeA, int paperWidthA = -1, int paperHeightA = -1, bool noCrop = false, bool duplexA = true, int imgLLXA = 0, int imgLLYA = 0,
0124 int imgURXA = 0, int imgURYA = 0, PSForceRasterize forceRasterizeA = psRasterizeWhenNeeded, bool manualCtrlA = false, PSOutCustomCodeCbk customCodeCbkA = nullptr, void *customCodeCbkDataA = nullptr,
0125 PSLevel levelA = psLevel2);
0126
0127
0128 PSOutputDev(int fdA, PDFDoc *docA, char *psTitleA, const std::vector<int> &pages, PSOutMode modeA, int paperWidthA = -1, int paperHeightA = -1, bool noCrop = false, bool duplexA = true, int imgLLXA = 0, int imgLLYA = 0, int imgURXA = 0,
0129 int imgURYA = 0, PSForceRasterize forceRasterizeA = psRasterizeWhenNeeded, bool manualCtrlA = false, PSOutCustomCodeCbk customCodeCbkA = nullptr, void *customCodeCbkDataA = nullptr, PSLevel levelA = psLevel2);
0130
0131
0132
0133 PSOutputDev(FoFiOutputFunc outputFuncA, void *outputStreamA, char *psTitleA, PDFDoc *docA, const std::vector<int> &pages, PSOutMode modeA, int paperWidthA = -1, int paperHeightA = -1, bool noCrop = false, bool duplexA = true,
0134 int imgLLXA = 0, int imgLLYA = 0, int imgURXA = 0, int imgURYA = 0, PSForceRasterize forceRasterizeA = psRasterizeWhenNeeded, bool manualCtrlA = false, PSOutCustomCodeCbk customCodeCbkA = nullptr,
0135 void *customCodeCbkDataA = nullptr, PSLevel levelA = psLevel2);
0136
0137
0138 ~PSOutputDev() override;
0139
0140
0141 virtual bool isOk() { return ok; }
0142
0143
0144
0145
0146
0147 bool upsideDown() override { return false; }
0148
0149
0150 bool useDrawChar() override { return false; }
0151
0152
0153
0154
0155 bool useTilingPatternFill() override { return true; }
0156
0157
0158
0159
0160 bool useShadedFills(int type) override { return (type < 4 && level >= psLevel2) || (type == 7 && level >= psLevel3); }
0161
0162
0163
0164 bool useDrawForm() override { return preloadImagesForms; }
0165
0166
0167
0168 bool interpretType3Chars() override { return false; }
0169
0170 bool needClipToCropBox() override { return mode == psModeEPS; }
0171
0172
0173
0174
0175 void writeHeader(int nPages, const PDFRectangle *mediaBox, const PDFRectangle *cropBox, int pageRotate, const char *title);
0176
0177
0178 void writeXpdfProcset();
0179
0180
0181 void writePageTrailer();
0182
0183
0184 void writeTrailer();
0185
0186
0187
0188
0189
0190
0191
0192 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,
0193 void *abortCheckCbkData = nullptr, bool (*annotDisplayDecideCbk)(Annot *annot, void *user_data) = nullptr, void *annotDisplayDecideCbkData = nullptr) override;
0194
0195
0196 void startPage(int pageNum, GfxState *state, XRef *xref) override;
0197
0198
0199 void endPage() override;
0200
0201
0202 void saveState(GfxState *state) override;
0203 void restoreState(GfxState *state) override;
0204
0205
0206 void updateCTM(GfxState *state, double m11, double m12, double m21, double m22, double m31, double m32) override;
0207 void updateLineDash(GfxState *state) override;
0208 void updateFlatness(GfxState *state) override;
0209 void updateLineJoin(GfxState *state) override;
0210 void updateLineCap(GfxState *state) override;
0211 void updateMiterLimit(GfxState *state) override;
0212 void updateLineWidth(GfxState *state) override;
0213 void updateFillColorSpace(GfxState *state) override;
0214 void updateStrokeColorSpace(GfxState *state) override;
0215 void updateFillColor(GfxState *state) override;
0216 void updateStrokeColor(GfxState *state) override;
0217 void updateFillOverprint(GfxState *state) override;
0218 void updateStrokeOverprint(GfxState *state) override;
0219 void updateOverprintMode(GfxState *state) override;
0220 void updateTransfer(GfxState *state) override;
0221
0222
0223 void updateFont(GfxState *state) override;
0224 void updateTextMat(GfxState *state) override;
0225 void updateCharSpace(GfxState *state) override;
0226 void updateRender(GfxState *state) override;
0227 void updateRise(GfxState *state) override;
0228 void updateWordSpace(GfxState *state) override;
0229 void updateHorizScaling(GfxState *state) override;
0230 void updateTextPos(GfxState *state) override;
0231 void updateTextShift(GfxState *state, double shift) override;
0232 void saveTextPos(GfxState *state) override;
0233 void restoreTextPos(GfxState *state) override;
0234
0235
0236 void stroke(GfxState *state) override;
0237 void fill(GfxState *state) override;
0238 void eoFill(GfxState *state) override;
0239 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) override;
0240 bool functionShadedFill(GfxState *state, GfxFunctionShading *shading) override;
0241 bool axialShadedFill(GfxState *state, GfxAxialShading *shading, double , double ) override;
0242 bool radialShadedFill(GfxState *state, GfxRadialShading *shading, double , double ) override;
0243 bool patchMeshShadedFill(GfxState *state, GfxPatchMeshShading *shading) override;
0244
0245
0246 void clip(GfxState *state) override;
0247 void eoClip(GfxState *state) override;
0248 void clipToStrokePath(GfxState *state) override;
0249
0250
0251 void drawString(GfxState *state, const GooString *s) override;
0252 void beginTextObject(GfxState *state) override;
0253 void endTextObject(GfxState *state) override;
0254
0255
0256 void drawImageMask(GfxState *state, Object *ref, Stream *str, int width, int height, bool invert, bool interpolate, bool inlineImg) override;
0257 void setSoftMaskFromImageMask(GfxState *state, Object *ref, Stream *str, int width, int height, bool invert, bool inlineImg, double *baseMatrix) override;
0258 void unsetSoftMaskFromImageMask(GfxState *state, double *baseMatrix) override;
0259 void drawImage(GfxState *state, Object *ref, Stream *str, int width, int height, GfxImageColorMap *colorMap, bool interpolate, const int *maskColors, bool inlineImg) override;
0260 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;
0261
0262 #ifdef OPI_SUPPORT
0263
0264 void opiBegin(GfxState *state, Dict *opiDict) override;
0265 void opiEnd(GfxState *state, Dict *opiDict) override;
0266 #endif
0267
0268
0269 void type3D0(GfxState *state, double wx, double wy) override;
0270 void type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury) override;
0271
0272
0273 void drawForm(Ref ref) override;
0274
0275
0276 void psXObject(Stream *psStream, Stream *level1Stream) override;
0277
0278
0279 void setOffset(double x, double y)
0280 {
0281 tx0 = x;
0282 ty0 = y;
0283 }
0284 void setScale(double x, double y)
0285 {
0286 xScale0 = x;
0287 yScale0 = y;
0288 }
0289 void setRotate(int rotateA) { rotate0 = rotateA; }
0290 void setClip(double llx, double lly, double urx, double ury)
0291 {
0292 clipLLX0 = llx;
0293 clipLLY0 = lly;
0294 clipURX0 = urx;
0295 clipURY0 = ury;
0296 }
0297 void setUnderlayCbk(void (*cbk)(PSOutputDev *psOut, void *data), void *data)
0298 {
0299 underlayCbk = cbk;
0300 underlayCbkData = data;
0301 }
0302 void setOverlayCbk(void (*cbk)(PSOutputDev *psOut, void *data), void *data)
0303 {
0304 overlayCbk = cbk;
0305 overlayCbkData = data;
0306 }
0307 void setDisplayText(bool display) { displayText = display; }
0308
0309 void setPSCenter(bool center) { psCenter = center; }
0310 void setPSExpandSmaller(bool expand) { psExpandSmaller = expand; }
0311 void setPSShrinkLarger(bool shrink) { psShrinkLarger = shrink; }
0312 void setOverprintPreview(bool overprintPreviewA) { overprintPreview = overprintPreviewA; }
0313 void setRasterAntialias(bool a) { rasterAntialias = a; }
0314 void setForceRasterize(PSForceRasterize f) { forceRasterize = f; }
0315 void setRasterResolution(double r) { rasterResolution = r; }
0316 void setRasterMono(bool b)
0317 {
0318 processColorFormat = splashModeMono8;
0319 processColorFormatSpecified = true;
0320 }
0321
0322 void setUncompressPreloadedImages(bool b) { uncompressPreloadedImages = b; }
0323
0324 bool getEmbedType1() const { return embedType1; }
0325 bool getEmbedTrueType() const { return embedTrueType; }
0326 bool getEmbedCIDPostScript() const { return embedCIDPostScript; }
0327 bool getEmbedCIDTrueType() const { return embedCIDTrueType; }
0328 bool getFontPassthrough() const { return fontPassthrough; }
0329 bool getOptimizeColorSpace() const { return optimizeColorSpace; }
0330 bool getPassLevel1CustomColor() const { return passLevel1CustomColor; }
0331 bool getEnableLZW() const { return enableLZW; };
0332 bool getEnableFlate() const
0333 #ifdef ENABLE_ZLIB
0334 {
0335 return enableFlate;
0336 }
0337 #else
0338 {
0339 return false;
0340 }
0341 #endif
0342 void setEmbedType1(bool b) { embedType1 = b; }
0343 void setEmbedTrueType(bool b) { embedTrueType = b; }
0344 void setEmbedCIDPostScript(bool b) { embedCIDPostScript = b; }
0345 void setEmbedCIDTrueType(bool b) { embedCIDTrueType = b; }
0346 void setFontPassthrough(bool b) { fontPassthrough = b; }
0347 void setOptimizeColorSpace(bool b) { optimizeColorSpace = b; }
0348 void setPassLevel1CustomColor(bool b) { passLevel1CustomColor = b; }
0349 void setPreloadImagesForms(bool b) { preloadImagesForms = b; }
0350 void setGenerateOPI(bool b) { generateOPI = b; }
0351 void setUseASCIIHex(bool b) { useASCIIHex = b; }
0352 void setUseBinary(bool b) { useBinary = b; }
0353 void setEnableLZW(bool b) { enableLZW = b; }
0354 void setEnableFlate(bool b) { enableFlate = b; }
0355
0356 void setProcessColorFormat(SplashColorMode format)
0357 {
0358 processColorFormat = format;
0359 processColorFormatSpecified = true;
0360 }
0361
0362 private:
0363 void init(FoFiOutputFunc outputFuncA, void *outputStreamA, PSFileType fileTypeA, char *psTitleA, PDFDoc *doc, const std::vector<int> &pages, PSOutMode modeA, int imgLLXA, int imgLLYA, int imgURXA, int imgURYA, bool manualCtrlA,
0364 int paperWidthA, int paperHeightA, bool noCropA, bool duplexA, PSLevel levelA);
0365 void postInit();
0366 void setupResources(Dict *resDict);
0367 void setupFonts(Dict *resDict);
0368 void setupFont(GfxFont *font, Dict *parentResDict);
0369 void setupEmbeddedType1Font(Ref *id, GooString *psName);
0370 void updateFontMaxValidGlyph(GfxFont *font, int maxValidGlyph);
0371 void setupExternalType1Font(const GooString *fileName, GooString *psName);
0372 void setupEmbeddedType1CFont(GfxFont *font, Ref *id, GooString *psName);
0373 void setupEmbeddedOpenTypeT1CFont(GfxFont *font, Ref *id, GooString *psName);
0374 void setupEmbeddedTrueTypeFont(GfxFont *font, Ref *id, GooString *psName);
0375 void setupExternalTrueTypeFont(GfxFont *font, const GooString *fileName, GooString *psName);
0376 void setupEmbeddedCIDType0Font(GfxFont *font, Ref *id, GooString *psName);
0377 void setupEmbeddedCIDTrueTypeFont(GfxFont *font, Ref *id, GooString *psName, bool needVerticalMetrics);
0378 void setupExternalCIDTrueTypeFont(GfxFont *font, const GooString *fileName, GooString *psName, bool needVerticalMetrics);
0379 void setupEmbeddedOpenTypeCFFFont(GfxFont *font, Ref *id, GooString *psName);
0380 void setupType3Font(GfxFont *font, GooString *psName, Dict *parentResDict);
0381 GooString *makePSFontName(GfxFont *font, const Ref *id);
0382 void setupImages(Dict *resDict);
0383 void setupImage(Ref id, Stream *str, bool mask);
0384 void setupForms(Dict *resDict);
0385 void setupForm(Ref id, Object *strObj);
0386 void addProcessColor(double c, double m, double y, double k);
0387 void addCustomColor(GfxSeparationColorSpace *sepCS);
0388 void doPath(const GfxPath *path);
0389 void maskToClippingPath(Stream *maskStr, int maskWidth, int maskHeight, bool maskInvert);
0390 void doImageL1(Object *ref, GfxImageColorMap *colorMap, bool invert, bool inlineImg, Stream *str, int width, int height, int len, const int *maskColors, Stream *maskStr, int maskWidth, int maskHeight, bool maskInvert);
0391 void doImageL1Sep(Object *ref, GfxImageColorMap *colorMap, bool invert, bool inlineImg, Stream *str, int width, int height, int len, const int *maskColors, Stream *maskStr, int maskWidth, int maskHeight, bool maskInvert);
0392 void doImageL2(GfxState *state, Object *ref, GfxImageColorMap *colorMap, bool invert, bool inlineImg, Stream *str, int width, int height, int len, const int *maskColors, Stream *maskStr, int maskWidth, int maskHeight, bool maskInvert);
0393 void doImageL3(GfxState *state, Object *ref, GfxImageColorMap *colorMap, bool invert, bool inlineImg, Stream *str, int width, int height, int len, const int *maskColors, Stream *maskStr, int maskWidth, int maskHeight, bool maskInvert);
0394 void dumpColorSpaceL2(GfxState *state, GfxColorSpace *colorSpace, bool genXform, bool updateColors, bool map01);
0395 bool tilingPatternFillL1(GfxState *state, Catalog *cat, Object *str, const double *pmat, int paintType, int tilingType, Dict *resDict, const double *mat, const double *bbox, int x0, int y0, int x1, int y1, double xStep, double yStep);
0396 bool tilingPatternFillL2(GfxState *state, Catalog *cat, Object *str, const double *pmat, int paintType, int tilingType, Dict *resDict, const double *mat, const double *bbox, int x0, int y0, int x1, int y1, double xStep, double yStep);
0397
0398 #ifdef OPI_SUPPORT
0399 void opiBegin20(GfxState *state, Dict *dict);
0400 void opiBegin13(GfxState *state, Dict *dict);
0401 void opiTransform(GfxState *state, double x0, double y0, double *x1, double *y1);
0402 #endif
0403 void cvtFunction(const Function *func, bool invertPSFunction = false);
0404 GooString *filterPSName(const std::string &name);
0405
0406
0407 void writeDocSetup(Catalog *catalog, const std::vector<int> &pageList, bool duplexA);
0408
0409 void writePSChar(char c);
0410 void writePS(const char *s);
0411 void writePSBuf(const char *s, int len);
0412 void writePSFmt(const char *fmt, ...);
0413 void writePSString(const std::string &s);
0414 void writePSName(const char *s);
0415 GooString *filterPSLabel(GooString *label, bool *needParens = nullptr);
0416 void writePSTextLine(const GooString *s);
0417
0418 PSLevel level;
0419 PSOutMode mode;
0420 int paperWidth;
0421 int paperHeight;
0422 bool paperMatch;
0423 int prevWidth;
0424
0425 int prevHeight;
0426
0427 int imgLLX, imgLLY,
0428 imgURX, imgURY;
0429 bool noCrop;
0430 bool duplex;
0431 std::vector<int> pages;
0432 char *psTitle;
0433 bool postInitDone;
0434
0435 FoFiOutputFunc outputFunc;
0436 void *outputStream;
0437 PSFileType fileType;
0438 bool manualCtrl;
0439 int seqPage;
0440 void (*underlayCbk)(PSOutputDev *psOut, void *data);
0441 void *underlayCbkData;
0442 void (*overlayCbk)(PSOutputDev *psOut, void *data);
0443 void *overlayCbkData;
0444 GooString *(*customCodeCbk)(PSOutputDev *psOut, PSOutCustomCodeLocation loc, int n, void *data);
0445 void *customCodeCbkData;
0446
0447 PDFDoc *doc;
0448 XRef *xref;
0449
0450 std::vector<Ref> fontIDs;
0451 std::set<int> resourceIDs;
0452 std::unordered_set<std::string> fontNames;
0453 std::unordered_map<std::string, int> perFontMaxValidGlyph;
0454 PST1FontName *t1FontNames;
0455 int t1FontNameLen;
0456 int t1FontNameSize;
0457 PSFont8Info *font8Info;
0458 int font8InfoLen;
0459 int font8InfoSize;
0460 PSFont16Enc *font16Enc;
0461 int font16EncLen;
0462 int font16EncSize;
0463 Ref *imgIDs;
0464 int imgIDLen;
0465 int imgIDSize;
0466 Ref *formIDs;
0467 int formIDLen;
0468 int formIDSize;
0469 int numSaves;
0470 int numTilingPatterns;
0471 int nextFunc;
0472
0473 std::vector<PSOutPaperSize *> *paperSizes;
0474
0475 std::map<int, int> pagePaperSize;
0476 double tx0, ty0;
0477 double xScale0, yScale0;
0478 int rotate0;
0479 double clipLLX0, clipLLY0, clipURX0, clipURY0;
0480 double tx, ty;
0481 double xScale, yScale;
0482 int rotate;
0483 double epsX1, epsY1,
0484 epsX2, epsY2;
0485
0486 GooString *embFontList;
0487
0488 int processColors;
0489 PSOutCustomColor
0490 *customColors;
0491
0492 bool haveTextClip;
0493
0494
0495 bool inType3Char;
0496 bool inUncoloredPattern;
0497 GooString *t3String;
0498 double t3WX, t3WY,
0499 t3LLX, t3LLY, t3URX, t3URY;
0500 bool t3FillColorOnly;
0501 bool t3Cacheable;
0502 bool t3NeedsRestore;
0503 PSForceRasterize forceRasterize;
0504 bool displayText;
0505 bool psCenter;
0506 bool psExpandSmaller = false;
0507 bool psShrinkLarger = true;
0508 bool overprintPreview = false;
0509 bool rasterAntialias;
0510 bool uncompressPreloadedImages;
0511 double rasterResolution;
0512 bool embedType1;
0513 bool embedTrueType;
0514 bool embedCIDPostScript;
0515 bool embedCIDTrueType;
0516 bool fontPassthrough;
0517 bool optimizeColorSpace;
0518
0519 bool passLevel1CustomColor;
0520
0521
0522 bool preloadImagesForms;
0523
0524 bool generateOPI;
0525 bool useASCIIHex;
0526 bool useBinary;
0527 bool enableLZW;
0528 bool enableFlate;
0529
0530 SplashColorMode processColorFormat;
0531 bool processColorFormatSpecified;
0532
0533 std::unordered_set<std::string> iccEmitted;
0534
0535 #ifdef OPI_SUPPORT
0536 int opi13Nest;
0537 int opi20Nest;
0538 #endif
0539
0540 bool ok;
0541 std::set<int> patternsBeingTiled;
0542
0543 friend class WinPDFPrinter;
0544 };
0545
0546 #endif