fixed z-order problems in poly2bitmap
[swftools.git] / lib / pdf / BitmapOutputDev.h
1 /* BitmapOutputDev.cc
2    Output device which creates a bitmap.
3
4    This file is part of swftools.
5
6    Swftools is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10
11    Swftools is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with swftools; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
19
20 #ifndef __BitmapOutputDev_h__
21 #define __BitmapOutputDev_h__
22
23 #include "../gfxdevice.h"
24 #include "../gfxsource.h"
25 #include "../gfxtools.h"
26
27 #include "config.h"
28 #include "GFXOutputDev.h"
29 #include "InfoOutputDev.h"
30 #include "PDFDoc.h"
31 #include "CommonOutputDev.h"
32
33 struct ClipState
34 {
35     ClipState*next;
36     SplashBitmap*clipbitmap;
37     char written;
38     ClipState();
39 };
40
41 #define STATE_PARALLEL 0
42 #define STATE_TEXT_IS_ABOVE 1
43 #define STATE_BITMAP_IS_ABOVE 2
44
45 class BitmapOutputDev: public CommonOutputDev {
46 public:
47     BitmapOutputDev(InfoOutputDev*info, PDFDoc*doc);
48     virtual ~BitmapOutputDev();
49    
50     // CommonOutputDev:
51     virtual void setDevice(gfxdevice_t*dev);
52     virtual void setMove(int x,int y);
53     virtual void setClip(int x1,int y1,int x2,int y2);
54     virtual void setParameter(const char*key, const char*value);
55     virtual void setPageMap(int*page2page, int pagemap_size);
56
57     // OutputDev:
58     virtual GBool upsideDown();
59     virtual GBool useDrawChar();
60     virtual GBool useTilingPatternFill();
61     virtual GBool useShadedFills();
62     virtual GBool useDrawForm();
63     virtual GBool interpretType3Chars();
64     virtual GBool needNonText();
65     virtual void setDefaultCTM(double *ctm);
66 /*    virtual GBool checkPageSlice(Page *page, double hDPI, double vDPI,
67                                int rotate, GBool useMediaBox, GBool crop,
68                                int sliceX, int sliceY, int sliceW, int sliceH,
69                                GBool printing, Catalog *catalog,
70                                GBool (*abortCheckCbk)(void *data) = NULL,
71                                void *abortCheckCbkData = NULL);*/
72
73     virtual void startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2);
74     virtual void endPage();
75     virtual void finishPage();
76
77     virtual void saveState(GfxState *state);
78     virtual void restoreState(GfxState *state);
79
80     virtual void updateAll(GfxState *state);
81     virtual void updateCTM(GfxState *state, double m11, double m12, double m21, double m22, double m31, double m32);
82     virtual void updateLineDash(GfxState *state);
83     virtual void updateFlatness(GfxState *state);
84     virtual void updateLineJoin(GfxState *state);
85     virtual void updateLineCap(GfxState *state);
86     virtual void updateMiterLimit(GfxState *state);
87     virtual void updateLineWidth(GfxState *state);
88     virtual void updateStrokeAdjust(GfxState *state);
89     virtual void updateFillColorSpace(GfxState *state);
90     virtual void updateStrokeColorSpace(GfxState *state);
91     virtual void updateFillColor(GfxState *state);
92     virtual void updateStrokeColor(GfxState *state);
93     virtual void updateBlendMode(GfxState *state);
94     virtual void updateFillOpacity(GfxState *state);
95     virtual void updateStrokeOpacity(GfxState *state);
96     virtual void updateFillOverprint(GfxState *state);
97     virtual void updateStrokeOverprint(GfxState *state);
98     virtual void updateTransfer(GfxState *state);
99     virtual void updateFont(GfxState *state);
100     virtual void updateTextMat(GfxState *state);
101     virtual void updateCharSpace(GfxState *state);
102     virtual void updateRender(GfxState *state);
103     virtual void updateRise(GfxState *state);
104     virtual void updateWordSpace(GfxState *state);
105     virtual void updateHorizScaling(GfxState *state);
106     virtual void updateTextPos(GfxState *state);
107     virtual void updateTextShift(GfxState *state, double shift);
108
109     virtual void stroke(GfxState *state);
110     virtual void fill(GfxState *state);
111     virtual void eoFill(GfxState *state);
112 #if (xpdfMajorVersion < 3) || (xpdfMinorVersion < 2) || (xpdfUpdateVersion < 7)
113     virtual void tilingPatternFill(GfxState *state, Object *str,
114                                int paintType, Dict *resDict,
115                                double *mat, double *bbox,
116                                int x0, int y0, int x1, int y1,
117                                double xStep, double yStep);
118 #else
119     virtual void tilingPatternFill(GfxState *state, Gfx *gfx, Object *str,
120                                int paintType, Dict *resDict,
121                                double *mat, double *bbox,
122                                int x0, int y0, int x1, int y1,
123                                double xStep, double yStep);
124 #endif
125
126     virtual GBool functionShadedFill(GfxState *state,
127                                      GfxFunctionShading *shading);
128     virtual GBool axialShadedFill(GfxState *state, GfxAxialShading *shading);
129     virtual GBool radialShadedFill(GfxState *state, GfxRadialShading *shading);
130
131     virtual void clip(GfxState *state);
132     virtual void eoClip(GfxState *state);
133     virtual void clipToStrokePath(GfxState *state);
134
135     virtual void beginStringOp(GfxState *state);
136     virtual void endStringOp(GfxState *state);
137     virtual void beginString(GfxState *state, GString *s);
138     virtual void endString(GfxState *state);
139     virtual void drawChar(GfxState *state, double x, double y,
140                           double dx, double dy,
141                           double originX, double originY,
142                           CharCode code, int nBytes, Unicode *u, int uLen);
143     virtual void drawString(GfxState *state, GString *s);
144     virtual GBool beginType3Char(GfxState *state, double x, double y,
145                                  double dx, double dy,
146                                  CharCode code, Unicode *u, int uLen);
147     virtual void endType3Char(GfxState *state);
148     virtual void endTextObject(GfxState *state);
149
150     virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
151                                int width, int height, GBool invert,
152                                GBool inlineImg);
153     virtual void drawImage(GfxState *state, Object *ref, Stream *str,
154                            int width, int height, GfxImageColorMap *colorMap,
155                            int *maskColors, GBool inlineImg);
156     virtual void drawMaskedImage(GfxState *state, Object *ref, Stream *str,
157                                  int width, int height,
158                                  GfxImageColorMap *colorMap,
159                                  Stream *maskStr, int maskWidth, int maskHeight,
160                                  GBool maskInvert);
161     virtual void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
162                                      int width, int height,
163                                      GfxImageColorMap *colorMap,
164                                      Stream *maskStr,
165                                      int maskWidth, int maskHeight,
166                                      GfxImageColorMap *maskColorMap);
167
168     virtual void type3D0(GfxState *state, double wx, double wy);
169     virtual void type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury);
170
171     virtual void drawForm(Ref id);
172
173     virtual void beginTransparencyGroup(GfxState *state, double *bbox,
174                                         GfxColorSpace *blendingColorSpace,
175                                         GBool isolated, GBool knockout,
176                                         GBool forSoftMask);
177     virtual void endTransparencyGroup(GfxState *state);
178     virtual void paintTransparencyGroup(GfxState *state, double *bbox);
179     virtual void setSoftMask(GfxState *state, double *bbox, GBool alpha, Function *transferFunc, GfxColor *backdropColor);
180     virtual void clearSoftMask(GfxState *state);
181
182     virtual void processLink(Link *link, Catalog *catalog);
183   
184     virtual void setVectorAntialias(GBool vaa);
185     virtual GBool getVectorAntialias();
186
187     
188 private:
189     void clearClips();
190     void clearBoolPolyDev();
191     void clearBoolTextDev();
192     void flushText();
193     void flushBitmap();
194     GBool checkNewText(int x1, int y1, int x2, int y2);
195     GBool checkNewBitmap(int x1, int y1, int x2, int y2);
196     GBool clip0and1differ(int x1,int y1,int x2,int y2);
197     GBool intersection(SplashBitmap*boolpoly, SplashBitmap*booltext, int x1, int y1, int x2, int y2);
198     
199     virtual gfxbbox_t getImageBBox(GfxState*state);
200     virtual gfxbbox_t getBBox(GfxState*state);
201
202     char config_extrafontdata;
203
204     int layerstate;
205     GBool emptypage;
206
207     SplashPath*bboxpath;
208
209     PDFDoc*doc;
210     XRef*xref;
211     SplashOutputDev*rgbdev;
212     SplashOutputDev*clip0dev;
213     SplashOutputDev*clip1dev;
214     SplashOutputDev*boolpolydev;
215     SplashOutputDev*booltextdev;
216
217     SplashBitmap*rgbbitmap;
218     SplashBitmap*clip0bitmap;
219     SplashBitmap*clip1bitmap;
220     SplashBitmap*boolpolybitmap;
221     SplashBitmap*stalepolybitmap;
222     SplashBitmap*booltextbitmap;
223     SplashBitmap*staletextbitmap;
224
225     gfxdevice_t* gfxoutput;
226     GFXOutputDev*gfxdev;
227     InfoOutputDev*info;
228     gfxdevice_t*dev;
229
230     int movex, movey;
231     int width, height;
232
233     int user_movex, user_movey;
234     int user_clipx1, user_clipy1;
235     int user_clipx2, user_clipy2;
236
237     //ClipState*clipstates;
238 };
239
240 #endif