1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #ifndef INCLUDED_PDFI_OUTDEV_HXX
23 #define INCLUDED_PDFI_OUTDEV_HXX
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 <hash_map>
52 #include <vector>
53 
54 class GfxPath;
55 class GfxFont;
56 class PDFDoc;
57 #ifndef SYSTEM_POPPLER
58 typedef GString GooString;
59 #endif
60 
61 namespace pdfi
62 {
63     struct FontAttributes
64     {
FontAttributespdfi::FontAttributes65         FontAttributes( const GooString& familyName_,
66                         bool           isEmbedded_,
67                         bool           isBold_,
68                         bool           isItalic_,
69                         bool           isUnderline_,
70                         double         size_ ) :
71             familyName(),
72             isEmbedded(isEmbedded_),
73             isBold(isBold_),
74             isItalic(isItalic_),
75             isUnderline(isUnderline_),
76             size(size_)
77         {
78             familyName.append(const_cast<GooString*>(&familyName_));
79         }
80 
FontAttributespdfi::FontAttributes81         FontAttributes() :
82             familyName(),
83             isEmbedded(false),
84             isBold(false),
85             isItalic(false),
86             isUnderline(false),
87             size(0.0)
88         {}
89 
90         // xdpf goo stuff is so totally borked...
91         // ...need to hand-code assignment
FontAttributespdfi::FontAttributes92         FontAttributes( const FontAttributes& rSrc ) :
93             familyName(),
94             isEmbedded(rSrc.isEmbedded),
95             isBold(rSrc.isBold),
96             isItalic(rSrc.isItalic),
97             isUnderline(rSrc.isUnderline),
98             size(rSrc.size)
99         {
100             familyName.append(const_cast<GooString*>(&rSrc.familyName));
101         }
102 
operator =pdfi::FontAttributes103         FontAttributes& operator=( const FontAttributes& rSrc )
104         {
105             familyName.clear();
106             familyName.append(const_cast<GooString*>(&rSrc.familyName));
107 
108             isEmbedded  = rSrc.isEmbedded;
109             isBold      = rSrc.isBold;
110             isItalic    = rSrc.isItalic;
111             isUnderline = rSrc.isUnderline;
112             size        = rSrc.size;
113 
114             return *this;
115         }
116 
operator ==pdfi::FontAttributes117         bool operator==(const FontAttributes& rFont) const
118         {
119             return const_cast<GooString*>(&familyName)->cmp(
120                 const_cast<GooString*>(&rFont.familyName))==0 &&
121                 isEmbedded == rFont.isEmbedded &&
122                 isBold == rFont.isBold &&
123                 isItalic == rFont.isItalic &&
124                 isUnderline == rFont.isUnderline &&
125                 size == rFont.size;
126         }
127 
128         GooString     familyName;
129         bool        isEmbedded;
130         bool        isBold;
131         bool        isItalic;
132         bool        isUnderline;
133         double      size;
134     };
135 
136     class PDFOutDev : public OutputDev
137     {
138         // not owned by this class
139         PDFDoc*                                 m_pDoc;
140         mutable std::hash_map< long long,
141                                FontAttributes > m_aFontMap;
142         UnicodeMap*                             m_pUtf8Map;
143 
144         int  parseFont( long long nNewId, GfxFont* pFont, GfxState* state ) const;
145         void writeFontFile( GfxFont* gfxFont ) const;
146         void printPath( GfxPath* pPath ) const;
147 
148     public:
149         explicit PDFOutDev( PDFDoc* pDoc );
150 
151         //----- get info about output device
152 
153         // Does this device use upside-down coordinates?
154         // (Upside-down means (0,0) is the top left corner of the page.)
upsideDown()155         virtual GBool upsideDown() { return gTrue; }
156 
157         // Does this device use drawChar() or drawString()?
useDrawChar()158         virtual GBool useDrawChar() { return gTrue; }
159 
160         // Does this device use beginType3Char/endType3Char?  Otherwise,
161         // text in Type 3 fonts will be drawn with drawChar/drawString.
interpretType3Chars()162         virtual GBool interpretType3Chars() { return gFalse; }
163 
164         // Does this device need non-text content?
needNonText()165         virtual GBool needNonText() { return gTrue; }
166 
167         //----- initialization and control
168 
169         // Set default transform matrix.
170         virtual void setDefaultCTM(double *ctm);
171 
172         // Start a page.
173         virtual void startPage(int pageNum, GfxState *state);
174 
175         // End a page.
176         virtual void endPage();
177 
178         // Dump page contents to display.
179         // virtual void dump() {}
180 
181         //----- coordinate conversion
182 
183         // Convert between device and user coordinates.
184         // virtual void cvtDevToUser(double dx, double dy, double *ux, double *uy);
185         // virtual void cvtUserToDev(double ux, double uy, int *dx, int *dy);
186 
187         //----- link borders
188         virtual void processLink(Link *link, Catalog *catalog);
189 
190         //----- save/restore graphics state
191         virtual void saveState(GfxState *state);
192         virtual void restoreState(GfxState *state);
193 
194         //----- update graphics state
195         // virtual void updateAll(GfxState *state);
196         virtual void updateCTM(GfxState *state, double m11, double m12,
197                                double m21, double m22, double m31, double m32);
198         virtual void updateLineDash(GfxState *state);
199         virtual void updateFlatness(GfxState *state);
200         virtual void updateLineJoin(GfxState *state);
201         virtual void updateLineCap(GfxState *state);
202         virtual void updateMiterLimit(GfxState *state);
203         virtual void updateLineWidth(GfxState *state);
204         virtual void updateFillColor(GfxState *state);
205         virtual void updateStrokeColor(GfxState *state);
206         virtual void updateFillOpacity(GfxState *state);
207         virtual void updateStrokeOpacity(GfxState *state);
208         virtual void updateBlendMode(GfxState *state);
209 
210         //----- update text state
211         virtual void updateFont(GfxState *state);
212         // virtual void updateTextMat(GfxState *state);
213         // virtual void updateCharSpace(GfxState *state) {}
214         virtual void updateRender(GfxState *state);
215         // virtual void updateRise(GfxState *state) {}
216         // virtual void updateWordSpace(GfxState *state) {}
217         // virtual void updateHorizScaling(GfxState *state) {}
218         // virtual void updateTextPos(GfxState *state) {}
219         // virtual void updateTextShift(GfxState *state, double shift) {}
220 
221         //----- path painting
222         virtual void stroke(GfxState *state);
223         virtual void fill(GfxState *state);
224         virtual void eoFill(GfxState *state);
225 
226         //----- path clipping
227         virtual void clip(GfxState *state);
228         virtual void eoClip(GfxState *state);
229 
230         //----- text drawing
231         virtual void drawChar(GfxState *state, double x, double y,
232                               double dx, double dy,
233                               double originX, double originY,
234                               CharCode code, int nBytes, Unicode *u, int uLen);
235         virtual void drawString(GfxState *state, GooString *s);
236         virtual void endTextObject(GfxState *state);
237 
238         //----- image drawing
239         virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
240                                    int width, int height, GBool invert,
241                                    GBool inlineImg);
242         virtual void drawImage(GfxState *state, Object *ref, Stream *str,
243                                int width, int height, GfxImageColorMap *colorMap,
244                                int *maskColors, GBool inlineImg);
245         virtual void drawMaskedImage(GfxState *state, Object *ref, Stream *str,
246                                      int width, int height,
247                                      GfxImageColorMap *colorMap,
248                                      Stream *maskStr, int maskWidth, int maskHeight,
249                                      GBool maskInvert);
250         virtual void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
251                                          int width, int height,
252                                          GfxImageColorMap *colorMap,
253                                          Stream *maskStr,
254                                          int maskWidth, int maskHeight,
255                                          GfxImageColorMap *maskColorMap);
256 
257         //----- OPI functions
258         // virtual void opiBegin(GfxState *state, Dict *opiDict);
259         // virtual void opiEnd(GfxState *state, Dict *opiDict);
260 
261         //----- Type 3 font operators
262         // virtual void type3D0(GfxState *state, double wx, double wy) {}
263         // virtual void type3D1(GfxState *state, double wx, double wy,
264         //                      double llx, double lly, double urx, double ury) {}
265 
266         //----- PostScript XObjects
267         // virtual void psXObject(Stream *psStream, Stream *level1Stream) {}
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 char Output_t;
278 typedef std::vector< Output_t > OutputBuffer;
279 
280 #endif /* INCLUDED_PDFI_OUTDEV_HXX */
281 
282