Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_SDEXT_SOURCE_PDFIMPORT_XPDFWRAPPER_PDFIOUTDEV_GPL_HXX
21 : #define INCLUDED_SDEXT_SOURCE_PDFIMPORT_XPDFWRAPPER_PDFIOUTDEV_GPL_HXX
22 :
23 : #include <sal/types.h>
24 :
25 : #if defined __GNUC__
26 : # pragma GCC diagnostic push
27 : # pragma GCC diagnostic ignored "-Wunused-parameter"
28 : #elif defined _MSC_VER
29 : #pragma warning(push, 1)
30 : #endif
31 :
32 : #include "GfxState.h"
33 : #include "GfxFont.h"
34 : #include "UnicodeMap.h"
35 : #include "Link.h"
36 : #include "Object.h"
37 : #include "OutputDev.h"
38 : #include "GlobalParams.h"
39 : #include "PDFDoc.h"
40 :
41 : #if defined __GNUC__
42 : # pragma GCC diagnostic pop
43 : #elif defined _MSC_VER
44 : #pragma warning(pop)
45 : #endif
46 :
47 : #include <boost/unordered_map.hpp>
48 : #include <vector>
49 :
50 : class GfxPath;
51 : class GfxFont;
52 : class PDFDoc;
53 : #include <cpp/poppler-version.h>
54 : #define POPPLER_CHECK_VERSION(major,minor,micro) \
55 : (POPPLER_VERSION_MAJOR > (major) || \
56 : (POPPLER_VERSION_MAJOR == (major) && POPPLER_VERSION_MINOR > (minor)) || \
57 : (POPPLER_VERSION_MAJOR == (major) && POPPLER_VERSION_MINOR == (minor) && POPPLER_VERSION_MICRO >= (micro)))
58 :
59 : namespace pdfi
60 : {
61 102 : struct FontAttributes
62 : {
63 : FontAttributes( const GooString& familyName_,
64 : bool isEmbedded_,
65 : bool isBold_,
66 : bool isItalic_,
67 : bool isUnderline_,
68 : double size_ ) :
69 : familyName(),
70 : isEmbedded(isEmbedded_),
71 : isBold(isBold_),
72 : isItalic(isItalic_),
73 : isUnderline(isUnderline_),
74 : size(size_)
75 : {
76 : familyName.append(const_cast<GooString*>(&familyName_));
77 : }
78 :
79 102 : FontAttributes() :
80 : familyName(),
81 : isEmbedded(false),
82 : isBold(false),
83 : isItalic(false),
84 : isUnderline(false),
85 102 : size(0.0)
86 102 : {}
87 :
88 : // xdpf goo stuff is so totally borked...
89 : // ...need to hand-code assignment
90 : FontAttributes( const FontAttributes& rSrc ) :
91 : familyName(),
92 : isEmbedded(rSrc.isEmbedded),
93 : isBold(rSrc.isBold),
94 : isItalic(rSrc.isItalic),
95 : isUnderline(rSrc.isUnderline),
96 : size(rSrc.size)
97 : {
98 : familyName.append(const_cast<GooString*>(&rSrc.familyName));
99 : }
100 :
101 84 : FontAttributes& operator=( const FontAttributes& rSrc )
102 : {
103 84 : familyName.clear();
104 84 : familyName.append(const_cast<GooString*>(&rSrc.familyName));
105 :
106 84 : isEmbedded = rSrc.isEmbedded;
107 84 : isBold = rSrc.isBold;
108 84 : isItalic = rSrc.isItalic;
109 84 : isUnderline = rSrc.isUnderline;
110 84 : size = rSrc.size;
111 :
112 84 : return *this;
113 : }
114 :
115 : bool operator==(const FontAttributes& rFont) const
116 : {
117 : return const_cast<GooString*>(&familyName)->cmp(
118 : const_cast<GooString*>(&rFont.familyName))==0 &&
119 : isEmbedded == rFont.isEmbedded &&
120 : isBold == rFont.isBold &&
121 : isItalic == rFont.isItalic &&
122 : isUnderline == rFont.isUnderline &&
123 : size == rFont.size;
124 : }
125 :
126 : GooString familyName;
127 : bool isEmbedded;
128 : bool isBold;
129 : bool isItalic;
130 : bool isUnderline;
131 : double size;
132 : };
133 :
134 : class PDFOutDev : public OutputDev
135 : {
136 : // not owned by this class
137 : PDFDoc* m_pDoc;
138 : mutable boost::unordered_map< long long,
139 : FontAttributes > m_aFontMap;
140 : UnicodeMap* m_pUtf8Map;
141 :
142 : int parseFont( long long nNewId, GfxFont* pFont, GfxState* state ) const;
143 : void writeFontFile( GfxFont* gfxFont ) const;
144 : void printPath( GfxPath* pPath ) const;
145 :
146 : public:
147 : explicit PDFOutDev( PDFDoc* pDoc );
148 : virtual ~PDFOutDev();
149 :
150 : //----- get info about output device
151 :
152 : // Does this device use upside-down coordinates?
153 : // (Upside-down means (0,0) is the top left corner of the page.)
154 12 : virtual GBool upsideDown() SAL_OVERRIDE { return gTrue; }
155 :
156 : // Does this device use drawChar() or drawString()?
157 1152 : virtual GBool useDrawChar() SAL_OVERRIDE { return gTrue; }
158 :
159 : // Does this device use beginType3Char/endType3Char? Otherwise,
160 : // text in Type 3 fonts will be drawn with drawChar/drawString.
161 0 : virtual GBool interpretType3Chars() SAL_OVERRIDE { return gFalse; }
162 :
163 : // Does this device need non-text content?
164 12 : virtual GBool needNonText() SAL_OVERRIDE { return gTrue; }
165 :
166 : //----- initialization and control
167 :
168 : // Set default transform matrix.
169 : virtual void setDefaultCTM(double *ctm) SAL_OVERRIDE;
170 :
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 : ) SAL_OVERRIDE;
177 :
178 : // End a page.
179 : virtual void endPage() SAL_OVERRIDE;
180 :
181 : //----- link borders
182 : #if POPPLER_CHECK_VERSION(0, 19, 0)
183 : virtual void processLink(AnnotLink *link) SAL_OVERRIDE;
184 : #elif POPPLER_CHECK_VERSION(0, 17, 0)
185 : virtual void processLink(AnnotLink *link, Catalog *catalog) SAL_OVERRIDE;
186 : #else
187 : virtual void processLink(Link *link, Catalog *catalog) SAL_OVERRIDE;
188 : #endif
189 :
190 : //----- save/restore graphics state
191 : virtual void saveState(GfxState *state) SAL_OVERRIDE;
192 : virtual void restoreState(GfxState *state) SAL_OVERRIDE;
193 :
194 : //----- update graphics state
195 : virtual void updateCTM(GfxState *state, double m11, double m12,
196 : double m21, double m22, double m31, double m32) SAL_OVERRIDE;
197 : virtual void updateLineDash(GfxState *state) SAL_OVERRIDE;
198 : virtual void updateFlatness(GfxState *state) SAL_OVERRIDE;
199 : virtual void updateLineJoin(GfxState *state) SAL_OVERRIDE;
200 : virtual void updateLineCap(GfxState *state) SAL_OVERRIDE;
201 : virtual void updateMiterLimit(GfxState *state) SAL_OVERRIDE;
202 : virtual void updateLineWidth(GfxState *state) SAL_OVERRIDE;
203 : virtual void updateFillColor(GfxState *state) SAL_OVERRIDE;
204 : virtual void updateStrokeColor(GfxState *state) SAL_OVERRIDE;
205 : virtual void updateFillOpacity(GfxState *state) SAL_OVERRIDE;
206 : virtual void updateStrokeOpacity(GfxState *state) SAL_OVERRIDE;
207 : virtual void updateBlendMode(GfxState *state) SAL_OVERRIDE;
208 :
209 : //----- update text state
210 : virtual void updateFont(GfxState *state) SAL_OVERRIDE;
211 : virtual void updateRender(GfxState *state) SAL_OVERRIDE;
212 :
213 : //----- path painting
214 : virtual void stroke(GfxState *state) SAL_OVERRIDE;
215 : virtual void fill(GfxState *state) SAL_OVERRIDE;
216 : virtual void eoFill(GfxState *state) SAL_OVERRIDE;
217 :
218 : //----- path clipping
219 : virtual void clip(GfxState *state) SAL_OVERRIDE;
220 : virtual void eoClip(GfxState *state) SAL_OVERRIDE;
221 :
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) SAL_OVERRIDE;
227 : virtual void drawString(GfxState *state, GooString *s) SAL_OVERRIDE;
228 : virtual void endTextObject(GfxState *state) SAL_OVERRIDE;
229 :
230 : //----- image drawing
231 : virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
232 : int width, int height, GBool invert,
233 : #if POPPLER_CHECK_VERSION(0, 12, 0)
234 : GBool interpolate,
235 : #endif
236 : GBool inlineImg) SAL_OVERRIDE;
237 : virtual void drawImage(GfxState *state, Object *ref, Stream *str,
238 : int width, int height, GfxImageColorMap *colorMap,
239 : #if POPPLER_CHECK_VERSION(0, 12, 0)
240 : GBool interpolate,
241 : #endif
242 : int *maskColors, GBool inlineImg) SAL_OVERRIDE;
243 : virtual void drawMaskedImage(GfxState *state, Object *ref, Stream *str,
244 : int width, int height,
245 : GfxImageColorMap *colorMap,
246 : #if POPPLER_CHECK_VERSION(0, 12, 0)
247 : GBool interpolate,
248 : #endif
249 : Stream *maskStr, int maskWidth, int maskHeight,
250 : GBool maskInvert
251 : #if POPPLER_CHECK_VERSION(0, 12, 0)
252 : , GBool maskInterpolate
253 : #endif
254 : ) SAL_OVERRIDE;
255 : virtual void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
256 : int width, int height,
257 : GfxImageColorMap *colorMap,
258 : #if POPPLER_CHECK_VERSION(0, 12, 0)
259 : GBool interpolate,
260 : #endif
261 : Stream *maskStr,
262 : int maskWidth, int maskHeight,
263 : GfxImageColorMap *maskColorMap
264 : #if POPPLER_CHECK_VERSION(0, 12, 0)
265 : , GBool maskInterpolate
266 : #endif
267 : ) SAL_OVERRIDE;
268 :
269 : void setPageNum( int nNumPages );
270 : };
271 : }
272 :
273 : extern FILE* g_binary_out;
274 :
275 : // note: if you ever hcange Output_t, please keep in mind that the current code
276 : // relies on it being of 8 bit size
277 : typedef Guchar Output_t;
278 : typedef std::vector< Output_t > OutputBuffer;
279 :
280 : #endif // INCLUDED_SDEXT_SOURCE_PDFIMPORT_XPDFWRAPPER_PDFIOUTDEV_GPL_HXX
281 :
282 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|