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