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>
27 # pragma GCC diagnostic push
28 # pragma GCC diagnostic ignored "-Wunused-parameter"
29 #elif defined _MSC_VER
30 #pragma warning(push, 1)
35 #include "UnicodeMap.h"
38 #include "OutputDev.h"
39 #include "GlobalParams.h"
43 # pragma GCC diagnostic pop
44 #elif defined _MSC_VER
48 #include <unordered_map>
54 #if HAVE_POPPLER_VERSION_H
55 #include <cpp/poppler-version.h>
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
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)))
71 FontAttributes( const GooString
& familyName_
,
78 isEmbedded(isEmbedded_
),
81 isUnderline(isUnderline_
),
84 familyName
.append(const_cast<GooString
*>(&familyName_
));
96 // xdpf goo stuff is so totally borked...
97 // ...need to hand-code assignment
98 FontAttributes( const FontAttributes
& rSrc
) :
100 isEmbedded(rSrc
.isEmbedded
),
102 isItalic(rSrc
.isItalic
),
103 isUnderline(rSrc
.isUnderline
),
106 familyName
.append(&rSrc
.getFamilyName());
109 FontAttributes
& operator=( const FontAttributes
& rSrc
)
112 familyName
.append(&rSrc
.getFamilyName());
114 isEmbedded
= rSrc
.isEmbedded
;
115 isBold
= rSrc
.isBold
;
116 isItalic
= rSrc
.isItalic
;
117 isUnderline
= rSrc
.isUnderline
;
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
&&
133 GooString familyName
;
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
150 mutable std::unordered_map
< long long,
151 FontAttributes
> m_aFontMap
;
152 UnicodeMap
* m_pUtf8Map
;
155 int parseFont( long long nNewId
, GfxFont
* pFont
, GfxState
* state
) const;
156 void writeFontFile( GfxFont
* gfxFont
) const;
157 static void printPath( GfxPath
* pPath
);
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
;
185 virtual void startPage(int pageNum
, GfxState
*state
186 #if POPPLER_CHECK_VERSION(0, 23, 0) || POPPLER_CHECK_VERSION(0, 24, 0)
192 virtual void endPage() SAL_OVERRIDE
;
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
;
200 virtual void processLink(Link
*link
, Catalog
*catalog
) SAL_OVERRIDE
;
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
;
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)
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)
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)
262 Stream
*maskStr
, int maskWidth
, int maskHeight
,
264 #if POPPLER_CHECK_VERSION(0, 12, 0)
265 , GBool maskInterpolate
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)
275 int maskWidth
, int maskHeight
,
276 GfxImageColorMap
*maskColorMap
277 #if POPPLER_CHECK_VERSION(0, 12, 0)
278 , GBool maskInterpolate
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: */