1 //========================================================================
5 //========================================================================
12 #ifdef USE_GCC_PRAGMAS
16 #include "SplashTypes.h"
17 #include "SplashClip.h"
21 struct SplashGlyphBitmap
;
30 //------------------------------------------------------------------------
32 // Retrieves the next line of pixels in an image mask. Normally,
33 // fills in *<line> and returns true. If the image stream is
34 // exhausted, returns false.
35 typedef GBool (*SplashImageMaskSource
)(void *data
, SplashColorPtr pixel
);
37 // Retrieves the next line of pixels in an image. Normally, fills in
38 // *<line> and returns true. If the image stream is exhausted,
40 typedef GBool (*SplashImageSource
)(void *data
, SplashColorPtr colorLine
,
43 //------------------------------------------------------------------------
45 enum SplashPipeResultColorCtrl
{
47 splashPipeResultColorNoAlphaBlendCMYK
,
49 splashPipeResultColorNoAlphaBlendRGB
,
50 splashPipeResultColorNoAlphaBlendMono
,
51 splashPipeResultColorAlphaNoBlendMono
,
52 splashPipeResultColorAlphaNoBlendRGB
,
54 splashPipeResultColorAlphaNoBlendCMYK
,
56 splashPipeResultColorAlphaBlendMono
,
57 splashPipeResultColorAlphaBlendRGB
60 splashPipeResultColorAlphaBlendCMYK
64 //------------------------------------------------------------------------
66 //------------------------------------------------------------------------
71 // Create a new rasterizer object.
72 Splash(SplashBitmap
*bitmapA
, GBool vectorAntialiasA
,
73 SplashScreenParams
*screenParams
= NULL
);
74 Splash(SplashBitmap
*bitmapA
, GBool vectorAntialiasA
,
75 SplashScreen
*screenA
);
81 SplashCoord
*getMatrix();
82 SplashPattern
*getStrokePattern();
83 SplashPattern
*getFillPattern();
84 SplashScreen
*getScreen();
85 SplashBlendFunc
getBlendFunc();
86 SplashCoord
getStrokeAlpha();
87 SplashCoord
getFillAlpha();
88 SplashCoord
getLineWidth();
91 SplashCoord
getMiterLimit();
92 SplashCoord
getFlatness();
93 SplashCoord
*getLineDash();
94 int getLineDashLength();
95 SplashCoord
getLineDashPhase();
96 SplashClip
*getClip();
97 SplashBitmap
*getSoftMask();
98 GBool
getInNonIsolatedGroup();
102 void setMatrix(SplashCoord
*matrix
);
103 void setStrokePattern(SplashPattern
*strokeColor
);
104 void setFillPattern(SplashPattern
*fillColor
);
105 void setScreen(SplashScreen
*screen
);
106 void setBlendFunc(SplashBlendFunc func
);
107 void setStrokeAlpha(SplashCoord alpha
);
108 void setFillAlpha(SplashCoord alpha
);
109 void setLineWidth(SplashCoord lineWidth
);
110 void setLineCap(int lineCap
);
111 void setLineJoin(int lineJoin
);
112 void setMiterLimit(SplashCoord miterLimit
);
113 void setFlatness(SplashCoord flatness
);
114 // the <lineDash> array will be copied
115 void setLineDash(SplashCoord
*lineDash
, int lineDashLength
,
116 SplashCoord lineDashPhase
);
117 void setStrokeAdjust(GBool strokeAdjust
);
118 // NB: uses transformed coordinates.
119 void clipResetToRect(SplashCoord x0
, SplashCoord y0
,
120 SplashCoord x1
, SplashCoord y1
);
121 // NB: uses transformed coordinates.
122 SplashError
clipToRect(SplashCoord x0
, SplashCoord y0
,
123 SplashCoord x1
, SplashCoord y1
);
124 // NB: uses untransformed coordinates.
125 SplashError
clipToPath(SplashPath
*path
, GBool eo
);
126 void setSoftMask(SplashBitmap
*softMask
);
127 void setInNonIsolatedGroup(SplashBitmap
*alpha0BitmapA
,
128 int alpha0XA
, int alpha0YA
);
130 //----- state save/restore
133 SplashError
restoreState();
135 //----- drawing operations
137 // Fill the bitmap with <color>. This is not subject to clipping.
138 void clear(SplashColorPtr color
, Guchar alpha
= 0x00);
140 // Stroke a path using the current stroke pattern.
141 SplashError
stroke(SplashPath
*path
);
143 // Fill a path using the current fill pattern.
144 SplashError
fill(SplashPath
*path
, GBool eo
);
146 // Fill a path, XORing with the current fill pattern.
147 SplashError
xorFill(SplashPath
*path
, GBool eo
);
149 // Draw a character, using the current fill pattern.
150 SplashError
fillChar(SplashCoord x
, SplashCoord y
, int c
, SplashFont
*font
);
152 // Draw a glyph, using the current fill pattern. This function does
153 // not free any data, i.e., it ignores glyph->freeData.
154 SplashError
fillGlyph(SplashCoord x
, SplashCoord y
,
155 SplashGlyphBitmap
*glyph
);
157 // Draws an image mask using the fill color. This will read <h>
158 // lines of <w> pixels from <src>, starting with the top line. "1"
159 // pixels will be drawn with the current fill color; "0" pixels are
160 // transparent. The matrix:
161 // [ mat[0] mat[1] 0 ]
162 // [ mat[2] mat[3] 0 ]
163 // [ mat[4] mat[5] 1 ]
164 // maps a unit square to the desired destination for the image, in
166 // [x' y' 1] = [x y 1] * mat
167 // Note that the Splash y axis points downward, and the image source
168 // is assumed to produce pixels in raster order, starting from the
170 SplashError
fillImageMask(SplashImageMaskSource src
, void *srcData
,
171 int w
, int h
, SplashCoord
*mat
,
174 // Draw an image. This will read <h> lines of <w> pixels from
175 // <src>, starting with the top line. These pixels are assumed to
176 // be in the source mode, <srcMode>. If <srcAlpha> is true, the
177 // alpha values returned by <src> are used; otherwise they are
178 // ignored. The following combinations of source and target modes
183 // Mono8 Mono1 -- with dithering
188 // The matrix behaves as for fillImageMask.
189 SplashError
drawImage(SplashImageSource src
, void *srcData
,
190 SplashColorMode srcMode
, GBool srcAlpha
,
191 int w
, int h
, SplashCoord
*mat
);
193 // Composite a rectangular region from <src> onto this Splash
195 SplashError
composite(SplashBitmap
*src
, int xSrc
, int ySrc
,
196 int xDest
, int yDest
, int w
, int h
,
197 GBool noClip
, GBool nonIsolated
);
199 // Composite this Splash object onto a background color. The
200 // background alpha is assumed to be 1.
201 void compositeBackground(SplashColorPtr color
);
203 // Copy a rectangular region from <src> onto the bitmap belonging to
204 // this Splash object. The destination alpha values are all set to
206 SplashError
blitTransparent(SplashBitmap
*src
, int xSrc
, int ySrc
,
207 int xDest
, int yDest
, int w
, int h
);
211 // Construct a path for a stroke, given the path to be stroked, and
212 // using the current line parameters. If <flatten> is true, this
213 // function will first flatten the path and handle the linedash.
214 SplashPath
*makeStrokePath(SplashPath
*path
, GBool flatten
= gTrue
);
216 // Return the associated bitmap.
217 SplashBitmap
*getBitmap() { return bitmap
; }
219 // Get a bounding box which includes all modifications since the
220 // last call to clearModRegion.
221 void getModRegion(int *xMin
, int *yMin
, int *xMax
, int *yMax
)
222 { *xMin
= modXMin
; *yMin
= modYMin
; *xMax
= modXMax
; *yMax
= modYMax
; }
224 // Clear the modified region bounding box.
225 void clearModRegion();
227 // Get clipping status for the last drawing operation subject to
229 SplashClipResult
getClipRes() { return opClipRes
; }
231 // Toggle debug mode on or off.
232 void setDebugMode(GBool debugModeA
) { debugMode
= debugModeA
; }
234 #if 1 //~tmp: turn off anti-aliasing temporarily
235 GBool
getVectorAntialias() { return vectorAntialias
; }
236 void setVectorAntialias(GBool vaa
) { vectorAntialias
= vaa
; }
241 void pipeInit(SplashPipe
*pipe
, int x
, int y
,
242 SplashPattern
*pattern
, SplashColorPtr cSrc
,
243 SplashCoord aInput
, GBool usesShape
,
244 GBool nonIsolatedGroup
);
245 void pipeRun(SplashPipe
*pipe
);
246 void pipeSetXY(SplashPipe
*pipe
, int x
, int y
);
247 void pipeIncX(SplashPipe
*pipe
);
248 void drawPixel(SplashPipe
*pipe
, int x
, int y
, GBool noClip
);
249 void drawAAPixelInit();
250 void drawAAPixel(SplashPipe
*pipe
, int x
, int y
);
251 void drawSpan(SplashPipe
*pipe
, int x0
, int x1
, int y
, GBool noClip
);
252 void drawAALine(SplashPipe
*pipe
, int x0
, int x1
, int y
);
253 void transform(SplashCoord
*matrix
, SplashCoord xi
, SplashCoord yi
,
254 SplashCoord
*xo
, SplashCoord
*yo
);
255 void updateModX(int x
);
256 void updateModY(int y
);
257 void strokeNarrow(SplashPath
*path
);
258 void strokeWide(SplashPath
*path
);
259 SplashPath
*flattenPath(SplashPath
*path
, SplashCoord
*matrix
,
260 SplashCoord flatness
);
261 void flattenCurve(SplashCoord x0
, SplashCoord y0
,
262 SplashCoord x1
, SplashCoord y1
,
263 SplashCoord x2
, SplashCoord y2
,
264 SplashCoord x3
, SplashCoord y3
,
265 SplashCoord
*matrix
, SplashCoord flatness2
,
267 SplashPath
*makeDashedPath(SplashPath
*xPath
);
268 SplashError
fillWithPattern(SplashPath
*path
, GBool eo
,
269 SplashPattern
*pattern
, SplashCoord alpha
);
270 SplashError
fillGlyph2(int x0
, int y0
, SplashGlyphBitmap
*glyph
);
271 void dumpPath(SplashPath
*path
);
272 void dumpXPath(SplashXPath
*path
);
274 static SplashPipeResultColorCtrl pipeResultColorNoAlphaBlend
[];
275 static SplashPipeResultColorCtrl pipeResultColorAlphaNoBlend
[];
276 static SplashPipeResultColorCtrl pipeResultColorAlphaBlend
[];
277 static int pipeNonIsoGroupCorrection
[];
279 SplashBitmap
*bitmap
;
283 SplashBitmap
*alpha0Bitmap
; // for non-isolated groups, this is the
284 // bitmap containing the alpha0 values
285 int alpha0X
, alpha0Y
; // offset within alpha0Bitmap
286 SplashCoord aaGamma
[splashAASize
* splashAASize
+ 1];
287 int modXMin
, modYMin
, modXMax
, modYMax
;
288 SplashClipResult opClipRes
;
289 GBool vectorAntialias
;