bump product version to 6.1.0.2
[LibreOffice.git] / sdext / source / pdfimport / xpdfwrapper / pdfioutdev_gpl.hxx
blob7e65f085d28843b1b4f53207db070ebdedd6bbcf
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SDEXT_SOURCE_PDFIMPORT_XPDFWRAPPER_PDFIOUTDEV_GPL_HXX
21 #define INCLUDED_SDEXT_SOURCE_PDFIMPORT_XPDFWRAPPER_PDFIOUTDEV_GPL_HXX
23 #include <sal/types.h>
24 #include <config_poppler.h>
26 #if defined __GNUC__ || defined __clang__
27 # pragma GCC diagnostic push
28 # pragma GCC diagnostic ignored "-Wundef"
29 # pragma GCC diagnostic ignored "-Wunused-parameter"
30 #elif defined _MSC_VER
31 #pragma warning(push)
32 #pragma warning(disable : 4100) // unreferenced formal parameter
33 #endif
35 #include <GfxState.h>
36 #include <GfxFont.h>
37 #include <UnicodeMap.h>
38 #include <Link.h>
39 #include <Object.h>
40 #include <OutputDev.h>
41 #include <GlobalParams.h>
42 #include <PDFDoc.h>
44 #if defined __GNUC__ || defined __clang__
45 # pragma GCC diagnostic pop
46 #elif defined _MSC_VER
47 #pragma warning(pop)
48 #endif
50 #include <unordered_map>
51 #include <vector>
52 #include <memory>
54 class GfxPath;
55 class GfxFont;
56 class PDFDoc;
57 #if HAVE_POPPLER_VERSION_H
58 #include <cpp/poppler-version.h>
59 #else
60 #define POPPLER_VERSION "0.12.3"
61 #define POPPLER_VERSION_MAJOR 0
62 #define POPPLER_VERSION_MINOR 12
63 #define POPPLER_VERSION_MICRO 3
64 #endif
65 #define POPPLER_CHECK_VERSION(major,minor,micro) \
66 (POPPLER_VERSION_MAJOR > (major) || \
67 (POPPLER_VERSION_MAJOR == (major) && POPPLER_VERSION_MINOR > (minor)) || \
68 (POPPLER_VERSION_MAJOR == (major) && POPPLER_VERSION_MINOR == (minor) && POPPLER_VERSION_MICRO >= (micro)))
70 namespace pdfi
72 struct FontAttributes
74 FontAttributes() :
75 familyName(),
76 isEmbedded(false),
77 isBold(false),
78 isItalic(false),
79 isUnderline(false),
80 size(0.0)
83 // xpdf goo stuff is so totally borked...
84 // ...need to hand-code assignment
85 FontAttributes( const FontAttributes& rSrc ) :
86 familyName(),
87 isEmbedded(rSrc.isEmbedded),
88 isBold(rSrc.isBold),
89 isItalic(rSrc.isItalic),
90 isUnderline(rSrc.isUnderline),
91 size(rSrc.size)
93 familyName.append(&rSrc.getFamilyName());
96 FontAttributes& operator=( const FontAttributes& rSrc )
98 familyName.clear();
99 familyName.append(&rSrc.getFamilyName());
101 isEmbedded = rSrc.isEmbedded;
102 isBold = rSrc.isBold;
103 isItalic = rSrc.isItalic;
104 isUnderline = rSrc.isUnderline;
105 size = rSrc.size;
107 return *this;
110 bool operator==(const FontAttributes& rFont) const
112 return getFamilyName().cmp(&rFont.getFamilyName())==0 &&
113 isEmbedded == rFont.isEmbedded &&
114 isBold == rFont.isBold &&
115 isItalic == rFont.isItalic &&
116 isUnderline == rFont.isUnderline &&
117 size == rFont.size;
120 GooString familyName;
121 bool isEmbedded;
122 bool isBold;
123 bool isItalic;
124 bool isUnderline;
125 double size;
127 private:
128 // Work around const-ness issues in the GooString API:
129 GooString & getFamilyName() const
130 { return const_cast<GooString &>(familyName); }
133 class PDFOutDev : public OutputDev
135 // not owned by this class
136 PDFDoc* m_pDoc;
137 mutable std::unordered_map< long long,
138 FontAttributes > m_aFontMap;
139 std::unique_ptr<UnicodeMap> m_pUtf8Map;
140 bool m_bSkipImages;
142 int parseFont( long long nNewId, GfxFont* pFont, GfxState* state ) const;
143 void writeFontFile( GfxFont* gfxFont ) const;
144 static void printPath( GfxPath* pPath );
146 public:
147 explicit PDFOutDev( PDFDoc* pDoc );
148 virtual ~PDFOutDev() override;
150 //----- get info about output device
152 // Does this device use upside-down coordinates?
153 // (Upside-down means (0,0) is the top left corner of the page.)
154 virtual GBool upsideDown() override { return gTrue; }
156 // Does this device use drawChar() or drawString()?
157 virtual GBool useDrawChar() override { return gTrue; }
159 // Does this device use beginType3Char/endType3Char? Otherwise,
160 // text in Type 3 fonts will be drawn with drawChar/drawString.
161 virtual GBool interpretType3Chars() override { return gFalse; }
163 // Does this device need non-text content?
164 virtual GBool needNonText() override { return gTrue; }
166 //----- initialization and control
168 // Set default transform matrix.
169 virtual void setDefaultCTM(double *ctm) override;
171 // Start a page.
172 virtual void startPage(int pageNum, GfxState *state
173 #if POPPLER_CHECK_VERSION(0, 23, 0) || POPPLER_CHECK_VERSION(0, 24, 0)
174 , XRef *xref
175 #endif
176 ) override;
178 // End a page.
179 virtual void endPage() override;
181 //----- link borders
182 #if POPPLER_CHECK_VERSION(0, 19, 0)
183 virtual void processLink(AnnotLink *link) override;
184 #elif POPPLER_CHECK_VERSION(0, 17, 0)
185 virtual void processLink(AnnotLink *link, Catalog *catalog) override;
186 #else
187 virtual void processLink(Link *link, Catalog *catalog) override;
188 #endif
190 //----- save/restore graphics state
191 virtual void saveState(GfxState *state) override;
192 virtual void restoreState(GfxState *state) override;
194 //----- update graphics state
195 virtual void updateCTM(GfxState *state, double m11, double m12,
196 double m21, double m22, double m31, double m32) override;
197 virtual void updateLineDash(GfxState *state) override;
198 virtual void updateFlatness(GfxState *state) override;
199 virtual void updateLineJoin(GfxState *state) override;
200 virtual void updateLineCap(GfxState *state) override;
201 virtual void updateMiterLimit(GfxState *state) override;
202 virtual void updateLineWidth(GfxState *state) override;
203 virtual void updateFillColor(GfxState *state) override;
204 virtual void updateStrokeColor(GfxState *state) override;
205 virtual void updateFillOpacity(GfxState *state) override;
206 virtual void updateStrokeOpacity(GfxState *state) override;
207 virtual void updateBlendMode(GfxState *state) override;
209 //----- update text state
210 virtual void updateFont(GfxState *state) override;
211 virtual void updateRender(GfxState *state) override;
213 //----- path painting
214 virtual void stroke(GfxState *state) override;
215 virtual void fill(GfxState *state) override;
216 virtual void eoFill(GfxState *state) override;
218 //----- path clipping
219 virtual void clip(GfxState *state) override;
220 virtual void eoClip(GfxState *state) override;
222 //----- text drawing
223 virtual void drawChar(GfxState *state, double x, double y,
224 double dx, double dy,
225 double originX, double originY,
226 CharCode code, int nBytes, Unicode *u, int uLen) override;
227 #if POPPLER_CHECK_VERSION(0, 64, 0)
228 virtual void drawString(GfxState *state, const GooString *s) override;
229 #else
230 virtual void drawString(GfxState *state, GooString *s) override;
231 #endif
232 virtual void endTextObject(GfxState *state) override;
234 //----- image drawing
235 virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
236 int width, int height, GBool invert,
237 #if POPPLER_CHECK_VERSION(0, 12, 0)
238 GBool interpolate,
239 #endif
240 GBool inlineImg) override;
241 virtual void drawImage(GfxState *state, Object *ref, Stream *str,
242 int width, int height, GfxImageColorMap *colorMap,
243 #if POPPLER_CHECK_VERSION(0, 12, 0)
244 GBool interpolate,
245 #endif
246 int *maskColors, GBool inlineImg) override;
247 virtual void drawMaskedImage(GfxState *state, Object *ref, Stream *str,
248 int width, int height,
249 GfxImageColorMap *colorMap,
250 #if POPPLER_CHECK_VERSION(0, 12, 0)
251 GBool interpolate,
252 #endif
253 Stream *maskStr, int maskWidth, int maskHeight,
254 GBool maskInvert
255 #if POPPLER_CHECK_VERSION(0, 12, 0)
256 , GBool maskInterpolate
257 #endif
258 ) override;
259 virtual void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
260 int width, int height,
261 GfxImageColorMap *colorMap,
262 #if POPPLER_CHECK_VERSION(0, 12, 0)
263 GBool interpolate,
264 #endif
265 Stream *maskStr,
266 int maskWidth, int maskHeight,
267 GfxImageColorMap *maskColorMap
268 #if POPPLER_CHECK_VERSION(0, 12, 0)
269 , GBool maskInterpolate
270 #endif
271 ) override;
273 static void setPageNum( int nNumPages );
274 void setSkipImages ( bool bSkipImages );
278 extern FILE* g_binary_out;
280 // note: if you ever change Output_t, please keep in mind that the current code
281 // relies on it being of 8 bit size
282 typedef Guchar Output_t;
283 typedef std::vector< Output_t > OutputBuffer;
285 #endif // INCLUDED_SDEXT_SOURCE_PDFIMPORT_XPDFWRAPPER_PDFIOUTDEV_GPL_HXX
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */