1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
32 #pragma warning(disable : 4100) // unreferenced formal parameter
37 #include <UnicodeMap.h>
40 #include <OutputDev.h>
41 #include <GlobalParams.h>
44 #if defined __GNUC__ || defined __clang__
45 # pragma GCC diagnostic pop
46 #elif defined _MSC_VER
50 #include <unordered_map>
57 #if HAVE_POPPLER_VERSION_H
58 #include <cpp/poppler-version.h>
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
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)))
83 // xpdf goo stuff is so totally borked...
84 // ...need to hand-code assignment
85 FontAttributes( const FontAttributes
& rSrc
) :
87 isEmbedded(rSrc
.isEmbedded
),
89 isItalic(rSrc
.isItalic
),
90 isUnderline(rSrc
.isUnderline
),
93 familyName
.append(&rSrc
.getFamilyName());
96 FontAttributes
& operator=( const FontAttributes
& rSrc
)
99 familyName
.append(&rSrc
.getFamilyName());
101 isEmbedded
= rSrc
.isEmbedded
;
102 isBold
= rSrc
.isBold
;
103 isItalic
= rSrc
.isItalic
;
104 isUnderline
= rSrc
.isUnderline
;
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
&&
120 GooString familyName
;
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
137 mutable std::unordered_map
< long long,
138 FontAttributes
> m_aFontMap
;
139 std::unique_ptr
<UnicodeMap
> m_pUtf8Map
;
142 int parseFont( long long nNewId
, GfxFont
* pFont
, GfxState
* state
) const;
143 void writeFontFile( GfxFont
* gfxFont
) const;
144 static void printPath( GfxPath
* pPath
);
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
;
172 virtual void startPage(int pageNum
, GfxState
*state
173 #if POPPLER_CHECK_VERSION(0, 23, 0) || POPPLER_CHECK_VERSION(0, 24, 0)
179 virtual void endPage() override
;
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
;
187 virtual void processLink(Link
*link
, Catalog
*catalog
) override
;
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
;
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
;
230 virtual void drawString(GfxState
*state
, GooString
*s
) override
;
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)
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)
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)
253 Stream
*maskStr
, int maskWidth
, int maskHeight
,
255 #if POPPLER_CHECK_VERSION(0, 12, 0)
256 , GBool maskInterpolate
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)
266 int maskWidth
, int maskHeight
,
267 GfxImageColorMap
*maskColorMap
268 #if POPPLER_CHECK_VERSION(0, 12, 0)
269 , GBool maskInterpolate
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: */