ac1329867e9732aa027105b506193e0a4f7fa9e0
[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     virtual void dbg_newdata(char*newdata);
51    
52     // CommonOutputDev:
53     virtual void setDevice(gfxdevice_t*dev);
54     virtual void setMove(int x,int y);
55     virtual void setClip(int x1,int y1,int x2,int y2);
56     virtual void setParameter(const char*key, const char*value);
57     virtual void setPageMap(int*page2page, int pagemap_size);
58
59     // OutputDev:
60     virtual GBool upsideDown();
61     virtual GBool useDrawChar();
62     virtual GBool useTilingPatternFill();
63     virtual GBool useShadedFills();
64     virtual GBool useDrawForm();
65     virtual GBool interpretType3Chars();
66     virtual GBool needNonText();
67     virtual void setDefaultCTM(double *ctm);
68 /*    virtual GBool checkPageSlice(Page *page, double hDPI, double vDPI,
69                                int rotate, GBool useMediaBox, GBool crop,
70                                int sliceX, int sliceY, int sliceW, int sliceH,
71                                GBool printing, Catalog *catalog,
72                                GBool (*abortCheckCbk)(void *data) = NULL,
73                                void *abortCheckCbkData = NULL);*/
74
75     virtual void startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2);
76     virtual void endPage();
77     virtual void finishPage();
78
79     virtual void saveState(GfxState *state);
80     virtual void restoreState(GfxState *state);
81
82     virtual void updateAll(GfxState *state);
83     virtual void updateCTM(GfxState *state, double m11, double m12, double m21, double m22, double m31, double m32);
84     virtual void updateLineDash(GfxState *state);
85     virtual void updateFlatness(GfxState *state);
86     virtual void updateLineJoin(GfxState *state);
87     virtual void updateLineCap(GfxState *state);
88     virtual void updateMiterLimit(GfxState *state);
89     virtual void updateLineWidth(GfxState *state);
90     virtual void updateStrokeAdjust(GfxState *state);
91     virtual void updateFillColorSpace(GfxState *state);
92     virtual void updateStrokeColorSpace(GfxState *state);
93     virtual void updateFillColor(GfxState *state);
94     virtual void updateStrokeColor(GfxState *state);
95     virtual void updateBlendMode(GfxState *state);
96     virtual void updateFillOpacity(GfxState *state);
97     virtual void updateStrokeOpacity(GfxState *state);
98     virtual void updateFillOverprint(GfxState *state);
99     virtual void updateStrokeOverprint(GfxState *state);
100     virtual void updateTransfer(GfxState *state);
101     virtual void updateFont(GfxState *state);
102     virtual void updateTextMat(GfxState *state);
103     virtual void updateCharSpace(GfxState *state);
104     virtual void updateRender(GfxState *state);
105     virtual void updateRise(GfxState *state);
106     virtual void updateWordSpace(GfxState *state);
107     virtual void updateHorizScaling(GfxState *state);
108     virtual void updateTextPos(GfxState *state);
109     virtual void updateTextShift(GfxState *state, double shift);
110
111     virtual void stroke(GfxState *state);
112     virtual void fill(GfxState *state);
113     virtual void eoFill(GfxState *state);
114 #if (xpdfMajorVersion < 3) || (xpdfMinorVersion < 2) || (xpdfUpdateVersion < 7)
115     virtual void tilingPatternFill(GfxState *state, Object *str,
116                                int paintType, Dict *resDict,
117                                double *mat, double *bbox,
118                                int x0, int y0, int x1, int y1,
119                                double xStep, double yStep);
120 #else
121     virtual void tilingPatternFill(GfxState *state, Gfx *gfx, Object *str,
122                                int paintType, Dict *resDict,
123                                double *mat, double *bbox,
124                                int x0, int y0, int x1, int y1,
125                                double xStep, double yStep);
126 #endif
127
128     virtual GBool functionShadedFill(GfxState *state,
129                                      GfxFunctionShading *shading);
130     virtual GBool axialShadedFill(GfxState *state, GfxAxialShading *shading);
131     virtual GBool radialShadedFill(GfxState *state, GfxRadialShading *shading);
132
133     virtual void clip(GfxState *state);
134     virtual void eoClip(GfxState *state);
135     virtual void clipToStrokePath(GfxState *state);
136
137     virtual void beginStringOp(GfxState *state);
138     virtual void endStringOp(GfxState *state);
139     virtual void beginString(GfxState *state, GString *s);
140     virtual void endString(GfxState *state);
141     virtual void drawChar(GfxState *state, double x, double y,
142                           double dx, double dy,
143                           double originX, double originY,
144                           CharCode code, int nBytes, Unicode *u, int uLen);
145     virtual void drawString(GfxState *state, GString *s);
146     virtual GBool beginType3Char(GfxState *state, double x, double y,
147                                  double dx, double dy,
148                                  CharCode code, Unicode *u, int uLen);
149     virtual void endType3Char(GfxState *state);
150     virtual void endTextObject(GfxState *state);
151
152     virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
153                                int width, int height, GBool invert,
154                                GBool inlineImg);
155     virtual void drawImage(GfxState *state, Object *ref, Stream *str,
156                            int width, int height, GfxImageColorMap *colorMap,
157                            int *maskColors, GBool inlineImg);
158     virtual void drawMaskedImage(GfxState *state, Object *ref, Stream *str,
159                                  int width, int height,
160                                  GfxImageColorMap *colorMap,
161                                  Stream *maskStr, int maskWidth, int maskHeight,
162                                  GBool maskInvert);
163     virtual void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
164                                      int width, int height,
165                                      GfxImageColorMap *colorMap,
166                                      Stream *maskStr,
167                                      int maskWidth, int maskHeight,
168                                      GfxImageColorMap *maskColorMap);
169
170     virtual void type3D0(GfxState *state, double wx, double wy);
171     virtual void type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury);
172
173     virtual void drawForm(Ref id);
174
175     virtual void beginTransparencyGroup(GfxState *state, double *bbox,
176                                         GfxColorSpace *blendingColorSpace,
177                                         GBool isolated, GBool knockout,
178                                         GBool forSoftMask);
179     virtual void endTransparencyGroup(GfxState *state);
180     virtual void paintTransparencyGroup(GfxState *state, double *bbox);
181     virtual void setSoftMask(GfxState *state, double *bbox, GBool alpha, Function *transferFunc, GfxColor *backdropColor);
182     virtual void clearSoftMask(GfxState *state);
183
184     virtual void processLink(Link *link, Catalog *catalog);
185   
186     virtual void setVectorAntialias(GBool vaa);
187     virtual GBool getVectorAntialias();
188
189     
190 private:
191     void clearClips();
192     void clearBoolPolyDev();
193     void clearBoolTextDev();
194     void flushText();
195     void flushBitmap();
196     GBool checkNewText(int x1, int y1, int x2, int y2);
197     GBool checkNewBitmap(int x1, int y1, int x2, int y2);
198     GBool clip0and1differ(int x1,int y1,int x2,int y2);
199     GBool intersection(SplashBitmap*boolpoly, SplashBitmap*booltext, int x1, int y1, int x2, int y2);
200     
201     virtual gfxbbox_t getImageBBox(GfxState*state);
202     virtual gfxbbox_t getBBox(GfxState*state);
203
204     char config_extrafontdata;
205
206     int layerstate;
207     GBool emptypage;
208
209     SplashPath*bboxpath;
210
211     PDFDoc*doc;
212     XRef*xref;
213     SplashOutputDev*rgbdev;
214     SplashOutputDev*clip0dev;
215     SplashOutputDev*clip1dev;
216     SplashOutputDev*boolpolydev;
217     SplashOutputDev*booltextdev;
218
219     SplashBitmap*rgbbitmap;
220     SplashBitmap*clip0bitmap;
221     SplashBitmap*clip1bitmap;
222     SplashBitmap*boolpolybitmap;
223     SplashBitmap*stalepolybitmap;
224     SplashBitmap*booltextbitmap;
225     SplashBitmap*staletextbitmap;
226
227     gfxdevice_t* gfxoutput;
228     GFXOutputDev*gfxdev;
229     InfoOutputDev*info;
230     gfxdevice_t*dev;
231
232     int movex, movey;
233     int width, height;
234
235     int user_movex, user_movey;
236     int user_clipx1, user_clipy1;
237     int user_clipx2, user_clipy2;
238
239     //ClipState*clipstates;
240 };
241
242 #endif