tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sdext / source / pdfimport / xpdfwrapper / pdfioutdev_gpl.hxx
blobeb0e3e29f5f54a3301d2fee0485e5360b883b3d4
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 #pragma warning(disable : 4310) // cast truncates constant value
34 #endif
36 #include <GfxState.h>
37 #include <GfxFont.h>
38 #include <UnicodeMap.h>
39 #include <Link.h>
40 #include <Object.h>
41 #include <OutputDev.h>
42 #include <GlobalParams.h>
43 #include <PDFDoc.h>
45 #if defined __GNUC__ || defined __clang__
46 # pragma GCC diagnostic pop
47 #elif defined _MSC_VER
48 #pragma warning(pop)
49 #endif
51 #include <unordered_map>
52 #include <vector>
53 #include <memory>
55 class GfxPath;
56 class GfxFont;
57 class PDFDoc;
58 #include <cpp/poppler-version.h>
59 #define POPPLER_CHECK_VERSION(major,minor,micro) \
60 (POPPLER_VERSION_MAJOR > (major) || \
61 (POPPLER_VERSION_MAJOR == (major) && POPPLER_VERSION_MINOR > (minor)) || \
62 (POPPLER_VERSION_MAJOR == (major) && POPPLER_VERSION_MINOR == (minor) && POPPLER_VERSION_MICRO >= (micro)))
64 namespace pdfi
66 struct FontAttributes
68 FontAttributes() :
69 familyName(),
70 isEmbedded(false),
71 maFontWeight(GfxFont::W400),
72 isItalic(false),
73 isUnderline(false),
74 size(0.0)
77 // xpdf goo stuff is so totally borked...
78 // ...need to hand-code assignment
79 FontAttributes( const FontAttributes& rSrc ) :
80 familyName(),
81 isEmbedded(rSrc.isEmbedded),
82 maFontWeight(rSrc.maFontWeight),
83 isItalic(rSrc.isItalic),
84 isUnderline(rSrc.isUnderline),
85 size(rSrc.size)
87 familyName.append(&rSrc.getFamilyName());
90 FontAttributes& operator=( const FontAttributes& rSrc )
92 familyName.clear();
93 familyName.append(&rSrc.getFamilyName());
95 isEmbedded = rSrc.isEmbedded;
96 maFontWeight= rSrc.maFontWeight;
97 isItalic = rSrc.isItalic;
98 isUnderline = rSrc.isUnderline;
99 size = rSrc.size;
101 return *this;
104 bool operator==(const FontAttributes& rFont) const
106 return getFamilyName().cmp(&rFont.getFamilyName())==0 &&
107 isEmbedded == rFont.isEmbedded &&
108 maFontWeight == rFont.maFontWeight &&
109 isItalic == rFont.isItalic &&
110 isUnderline == rFont.isUnderline &&
111 size == rFont.size;
114 GooString familyName;
115 bool isEmbedded;
116 GfxFont::Weight maFontWeight;
117 bool isItalic;
118 bool isUnderline;
119 double size;
121 private:
122 // Work around const-ness issues in the GooString API:
123 GooString & getFamilyName() const
124 { return const_cast<GooString &>(familyName); }
127 // Versions before 0.15 defined GBool as int; 0.15 redefined it as bool; 0.71 dropped GBool
128 #if POPPLER_VERSION_MAJOR == 0 && POPPLER_VERSION_MINOR < 71
129 typedef GBool poppler_bool;
130 #else
131 typedef bool poppler_bool;
132 #endif
134 class PDFOutDev : public OutputDev
136 // not owned by this class
137 PDFDoc* m_pDoc;
138 mutable std::unordered_map< long long,
139 FontAttributes > m_aFontMap;
140 std::unique_ptr<UnicodeMap> m_pUtf8Map;
141 bool m_bSkipImages;
143 int parseFont( long long nNewId, GfxFont* pFont, const GfxState* state ) const;
144 void writeFontFile( GfxFont* gfxFont ) const;
145 #if POPPLER_CHECK_VERSION(0, 83, 0)
146 static void printPath( const GfxPath* pPath );
147 #else
148 static void printPath( GfxPath* pPath );
149 #endif
151 public:
152 explicit PDFOutDev( PDFDoc* pDoc );
153 virtual ~PDFOutDev() override;
155 //----- get info about output device
157 // Does this device use upside-down coordinates?
158 // (Upside-down means (0,0) is the top left corner of the page.)
159 virtual poppler_bool upsideDown() override { return true; }
161 // Does this device use drawChar() or drawString()?
162 virtual poppler_bool useDrawChar() override { return true; }
164 // Does this device use beginType3Char/endType3Char? Otherwise,
165 // text in Type 3 fonts will be drawn with drawChar/drawString.
166 virtual poppler_bool interpretType3Chars() override { return false; }
168 // Does this device need non-text content?
169 virtual poppler_bool needNonText() override { return true; }
171 //----- initialization and control
173 // Set default transform matrix.
174 #if POPPLER_CHECK_VERSION(0, 71, 0)
175 virtual void setDefaultCTM(const double *ctm) override;
176 #else
177 virtual void setDefaultCTM(double *ctm) override;
178 #endif
180 // Start a page.
181 virtual void startPage(int pageNum, GfxState *state
182 #if POPPLER_CHECK_VERSION(0, 23, 0)
183 , XRef *xref
184 #endif
185 ) override;
187 // End a page.
188 virtual void endPage() override;
190 //----- link borders
191 #if POPPLER_CHECK_VERSION(0, 19, 0)
192 virtual void processLink(AnnotLink *link) override;
193 #elif POPPLER_CHECK_VERSION(0, 17, 0)
194 virtual void processLink(AnnotLink *link, Catalog *catalog) override;
195 #else
196 virtual void processLink(Link *link, Catalog *catalog) override;
197 #endif
199 //----- save/restore graphics state
200 virtual void saveState(GfxState *state) override;
201 virtual void restoreState(GfxState *state) override;
203 //----- update graphics state
204 virtual void updateCTM(GfxState *state, double m11, double m12,
205 double m21, double m22, double m31, double m32) override;
206 virtual void updateLineDash(GfxState *state) override;
207 virtual void updateFlatness(GfxState *state) override;
208 virtual void updateLineJoin(GfxState *state) override;
209 virtual void updateLineCap(GfxState *state) override;
210 virtual void updateMiterLimit(GfxState *state) override;
211 virtual void updateLineWidth(GfxState *state) override;
212 virtual void updateFillColor(GfxState *state) override;
213 virtual void updateStrokeColor(GfxState *state) override;
214 virtual void updateFillOpacity(GfxState *state) override;
215 virtual void updateStrokeOpacity(GfxState *state) override;
216 virtual void updateBlendMode(GfxState *state) override;
218 //----- update text state
219 virtual void updateFont(GfxState *state) override;
220 virtual void updateRender(GfxState *state) override;
222 //----- path painting
223 virtual void stroke(GfxState *state) override;
224 virtual void fill(GfxState *state) override;
225 virtual void eoFill(GfxState *state) override;
227 //----- path clipping
228 virtual void clip(GfxState *state) override;
229 virtual void eoClip(GfxState *state) override;
230 virtual void clipToStrokePath(GfxState *state) override;
232 //----- text drawing
233 #if POPPLER_CHECK_VERSION(0, 82, 0)
234 virtual void drawChar(GfxState *state, double x, double y,
235 double dx, double dy,
236 double originX, double originY,
237 CharCode code, int nBytes, const Unicode *u, int uLen) override;
238 #else
239 virtual void drawChar(GfxState *state, double x, double y,
240 double dx, double dy,
241 double originX, double originY,
242 CharCode code, int nBytes, Unicode *u, int uLen) override;
243 #endif
244 #if POPPLER_CHECK_VERSION(0, 64, 0)
245 virtual void drawString(GfxState *state, const GooString *s) override;
246 #else
247 virtual void drawString(GfxState *state, GooString *s) override;
248 #endif
249 virtual void endTextObject(GfxState *state) override;
251 //----- image drawing
252 virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
253 int width, int height, poppler_bool invert,
254 poppler_bool interpolate,
255 poppler_bool inlineImg) override;
256 #if POPPLER_CHECK_VERSION(0, 82, 0)
257 virtual void drawImage(GfxState *state, Object *ref, Stream *str,
258 int width, int height, GfxImageColorMap *colorMap,
259 poppler_bool interpolate,
260 const int* maskColors, poppler_bool inlineImg) override;
261 #else
262 virtual void drawImage(GfxState *state, Object *ref, Stream *str,
263 int width, int height, GfxImageColorMap *colorMap,
264 poppler_bool interpolate,
265 int* maskColors, poppler_bool inlineImg) override;
266 #endif
267 virtual void drawMaskedImage(GfxState *state, Object *ref, Stream *str,
268 int width, int height,
269 GfxImageColorMap *colorMap,
270 poppler_bool interpolate,
271 Stream *maskStr, int maskWidth, int maskHeight,
272 poppler_bool maskInvert,
273 poppler_bool maskInterpolate
274 ) override;
275 virtual void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
276 int width, int height,
277 GfxImageColorMap *colorMap,
278 poppler_bool interpolate,
279 Stream *maskStr,
280 int maskWidth, int maskHeight,
281 GfxImageColorMap *maskColorMap
282 , poppler_bool maskInterpolate
283 ) override;
285 static void setPageNum( int nNumPages );
286 void setSkipImages ( bool bSkipImages );
287 #if POPPLER_CHECK_VERSION(21, 3, 0)
288 poppler_bool useTilingPatternFill() override { return true; };
289 poppler_bool tilingPatternFill(GfxState *state, Gfx *gfx, Catalog *cat,
290 GfxTilingPattern *tPat, const double *mat,
291 int x0, int y0, int x1, int y1,
292 double xStep, double yStep) override;
293 #endif
297 extern FILE* g_binary_out;
299 // note: if you ever change Output_t, please keep in mind that the current code
300 // relies on it being of 8 bit size
301 typedef unsigned char Output_t;
302 typedef std::vector< Output_t > OutputBuffer;
304 #if !POPPLER_CHECK_VERSION(0, 73, 0)
305 static_assert(std::is_same_v<Guchar, unsigned char>, "unexpected typedef");
306 #endif
308 #endif // INCLUDED_SDEXT_SOURCE_PDFIMPORT_XPDFWRAPPER_PDFIOUTDEV_GPL_HXX
310 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */