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