bump product version to 5.0.4.1
[LibreOffice.git] / sdext / source / pdfimport / xpdfwrapper / pdfioutdev_gpl.hxx
blobb5dd4e4328b037133105eccdc7bdfd0b76bc793f
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__
27 # pragma GCC diagnostic push
28 # pragma GCC diagnostic ignored "-Wunused-parameter"
29 #elif defined _MSC_VER
30 #pragma warning(push, 1)
31 #endif
33 #include "GfxState.h"
34 #include "GfxFont.h"
35 #include "UnicodeMap.h"
36 #include "Link.h"
37 #include "Object.h"
38 #include "OutputDev.h"
39 #include "GlobalParams.h"
40 #include "PDFDoc.h"
42 #if defined __GNUC__
43 # pragma GCC diagnostic pop
44 #elif defined _MSC_VER
45 #pragma warning(pop)
46 #endif
48 #include <unordered_map>
49 #include <vector>
51 class GfxPath;
52 class GfxFont;
53 class PDFDoc;
54 #if HAVE_POPPLER_VERSION_H
55 #include <cpp/poppler-version.h>
56 #else
57 #define POPPLER_VERSION "0.12.3"
58 #define POPPLER_VERSION_MAJOR 0
59 #define POPPLER_VERSION_MINOR 12
60 #define POPPLER_VERSION_MICRO 3
61 #endif
62 #define POPPLER_CHECK_VERSION(major,minor,micro) \
63 (POPPLER_VERSION_MAJOR > (major) || \
64 (POPPLER_VERSION_MAJOR == (major) && POPPLER_VERSION_MINOR > (minor)) || \
65 (POPPLER_VERSION_MAJOR == (major) && POPPLER_VERSION_MINOR == (minor) && POPPLER_VERSION_MICRO >= (micro)))
67 namespace pdfi
69 struct FontAttributes
71 FontAttributes( const GooString& familyName_,
72 bool isEmbedded_,
73 bool isBold_,
74 bool isItalic_,
75 bool isUnderline_,
76 double size_ ) :
77 familyName(),
78 isEmbedded(isEmbedded_),
79 isBold(isBold_),
80 isItalic(isItalic_),
81 isUnderline(isUnderline_),
82 size(size_)
84 familyName.append(const_cast<GooString*>(&familyName_));
87 FontAttributes() :
88 familyName(),
89 isEmbedded(false),
90 isBold(false),
91 isItalic(false),
92 isUnderline(false),
93 size(0.0)
96 // xdpf goo stuff is so totally borked...
97 // ...need to hand-code assignment
98 FontAttributes( const FontAttributes& rSrc ) :
99 familyName(),
100 isEmbedded(rSrc.isEmbedded),
101 isBold(rSrc.isBold),
102 isItalic(rSrc.isItalic),
103 isUnderline(rSrc.isUnderline),
104 size(rSrc.size)
106 familyName.append(&rSrc.getFamilyName());
109 FontAttributes& operator=( const FontAttributes& rSrc )
111 familyName.clear();
112 familyName.append(&rSrc.getFamilyName());
114 isEmbedded = rSrc.isEmbedded;
115 isBold = rSrc.isBold;
116 isItalic = rSrc.isItalic;
117 isUnderline = rSrc.isUnderline;
118 size = rSrc.size;
120 return *this;
123 bool operator==(const FontAttributes& rFont) const
125 return getFamilyName().cmp(&rFont.getFamilyName())==0 &&
126 isEmbedded == rFont.isEmbedded &&
127 isBold == rFont.isBold &&
128 isItalic == rFont.isItalic &&
129 isUnderline == rFont.isUnderline &&
130 size == rFont.size;
133 GooString familyName;
134 bool isEmbedded;
135 bool isBold;
136 bool isItalic;
137 bool isUnderline;
138 double size;
140 private:
141 // Work around const-ness issues in the GooString API:
142 GooString & getFamilyName() const
143 { return const_cast<GooString &>(familyName); }
146 class PDFOutDev : public OutputDev
148 // not owned by this class
149 PDFDoc* m_pDoc;
150 mutable std::unordered_map< long long,
151 FontAttributes > m_aFontMap;
152 UnicodeMap* m_pUtf8Map;
153 bool m_bSkipImages;
155 int parseFont( long long nNewId, GfxFont* pFont, GfxState* state ) const;
156 void writeFontFile( GfxFont* gfxFont ) const;
157 static void printPath( GfxPath* pPath );
159 public:
160 explicit PDFOutDev( PDFDoc* pDoc );
161 virtual ~PDFOutDev();
163 //----- get info about output device
165 // Does this device use upside-down coordinates?
166 // (Upside-down means (0,0) is the top left corner of the page.)
167 virtual GBool upsideDown() SAL_OVERRIDE { return gTrue; }
169 // Does this device use drawChar() or drawString()?
170 virtual GBool useDrawChar() SAL_OVERRIDE { return gTrue; }
172 // Does this device use beginType3Char/endType3Char? Otherwise,
173 // text in Type 3 fonts will be drawn with drawChar/drawString.
174 virtual GBool interpretType3Chars() SAL_OVERRIDE { return gFalse; }
176 // Does this device need non-text content?
177 virtual GBool needNonText() SAL_OVERRIDE { return gTrue; }
179 //----- initialization and control
181 // Set default transform matrix.
182 virtual void setDefaultCTM(double *ctm) SAL_OVERRIDE;
184 // Start a page.
185 virtual void startPage(int pageNum, GfxState *state
186 #if POPPLER_CHECK_VERSION(0, 23, 0) || POPPLER_CHECK_VERSION(0, 24, 0)
187 , XRef *xref
188 #endif
189 ) SAL_OVERRIDE;
191 // End a page.
192 virtual void endPage() SAL_OVERRIDE;
194 //----- link borders
195 #if POPPLER_CHECK_VERSION(0, 19, 0)
196 virtual void processLink(AnnotLink *link) SAL_OVERRIDE;
197 #elif POPPLER_CHECK_VERSION(0, 17, 0)
198 virtual void processLink(AnnotLink *link, Catalog *catalog) SAL_OVERRIDE;
199 #else
200 virtual void processLink(Link *link, Catalog *catalog) SAL_OVERRIDE;
201 #endif
203 //----- save/restore graphics state
204 virtual void saveState(GfxState *state) SAL_OVERRIDE;
205 virtual void restoreState(GfxState *state) SAL_OVERRIDE;
207 //----- update graphics state
208 virtual void updateCTM(GfxState *state, double m11, double m12,
209 double m21, double m22, double m31, double m32) SAL_OVERRIDE;
210 virtual void updateLineDash(GfxState *state) SAL_OVERRIDE;
211 virtual void updateFlatness(GfxState *state) SAL_OVERRIDE;
212 virtual void updateLineJoin(GfxState *state) SAL_OVERRIDE;
213 virtual void updateLineCap(GfxState *state) SAL_OVERRIDE;
214 virtual void updateMiterLimit(GfxState *state) SAL_OVERRIDE;
215 virtual void updateLineWidth(GfxState *state) SAL_OVERRIDE;
216 virtual void updateFillColor(GfxState *state) SAL_OVERRIDE;
217 virtual void updateStrokeColor(GfxState *state) SAL_OVERRIDE;
218 virtual void updateFillOpacity(GfxState *state) SAL_OVERRIDE;
219 virtual void updateStrokeOpacity(GfxState *state) SAL_OVERRIDE;
220 virtual void updateBlendMode(GfxState *state) SAL_OVERRIDE;
222 //----- update text state
223 virtual void updateFont(GfxState *state) SAL_OVERRIDE;
224 virtual void updateRender(GfxState *state) SAL_OVERRIDE;
226 //----- path painting
227 virtual void stroke(GfxState *state) SAL_OVERRIDE;
228 virtual void fill(GfxState *state) SAL_OVERRIDE;
229 virtual void eoFill(GfxState *state) SAL_OVERRIDE;
231 //----- path clipping
232 virtual void clip(GfxState *state) SAL_OVERRIDE;
233 virtual void eoClip(GfxState *state) SAL_OVERRIDE;
235 //----- text drawing
236 virtual void drawChar(GfxState *state, double x, double y,
237 double dx, double dy,
238 double originX, double originY,
239 CharCode code, int nBytes, Unicode *u, int uLen) SAL_OVERRIDE;
240 virtual void drawString(GfxState *state, GooString *s) SAL_OVERRIDE;
241 virtual void endTextObject(GfxState *state) SAL_OVERRIDE;
243 //----- image drawing
244 virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
245 int width, int height, GBool invert,
246 #if POPPLER_CHECK_VERSION(0, 12, 0)
247 GBool interpolate,
248 #endif
249 GBool inlineImg) SAL_OVERRIDE;
250 virtual void drawImage(GfxState *state, Object *ref, Stream *str,
251 int width, int height, GfxImageColorMap *colorMap,
252 #if POPPLER_CHECK_VERSION(0, 12, 0)
253 GBool interpolate,
254 #endif
255 int *maskColors, GBool inlineImg) SAL_OVERRIDE;
256 virtual void drawMaskedImage(GfxState *state, Object *ref, Stream *str,
257 int width, int height,
258 GfxImageColorMap *colorMap,
259 #if POPPLER_CHECK_VERSION(0, 12, 0)
260 GBool interpolate,
261 #endif
262 Stream *maskStr, int maskWidth, int maskHeight,
263 GBool maskInvert
264 #if POPPLER_CHECK_VERSION(0, 12, 0)
265 , GBool maskInterpolate
266 #endif
267 ) SAL_OVERRIDE;
268 virtual void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
269 int width, int height,
270 GfxImageColorMap *colorMap,
271 #if POPPLER_CHECK_VERSION(0, 12, 0)
272 GBool interpolate,
273 #endif
274 Stream *maskStr,
275 int maskWidth, int maskHeight,
276 GfxImageColorMap *maskColorMap
277 #if POPPLER_CHECK_VERSION(0, 12, 0)
278 , GBool maskInterpolate
279 #endif
280 ) SAL_OVERRIDE;
282 static void setPageNum( int nNumPages );
283 void setSkipImages ( bool bSkipImages );
287 extern FILE* g_binary_out;
289 // note: if you ever hcange Output_t, please keep in mind that the current code
290 // relies on it being of 8 bit size
291 typedef Guchar Output_t;
292 typedef std::vector< Output_t > OutputBuffer;
294 #endif // INCLUDED_SDEXT_SOURCE_PDFIMPORT_XPDFWRAPPER_PDFIOUTDEV_GPL_HXX
296 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */