Bringing apdf from vendor into main branch.
[AROS-Contrib.git] / apdf / splash / Splash.h
blobfd3ec80da63aa06a40a4f1ebe57aa21ebf629520
1 //========================================================================
2 //
3 // Splash.h
4 //
5 //========================================================================
7 #ifndef SPLASH_H
8 #define SPLASH_H
10 #include <aconf.h>
12 #ifdef USE_GCC_PRAGMAS
13 #pragma interface
14 #endif
16 #include "SplashTypes.h"
17 #include "SplashClip.h"
19 class SplashBitmap;
20 struct SplashGlyphBitmap;
21 class SplashState;
22 class SplashPattern;
23 class SplashScreen;
24 class SplashPath;
25 class SplashXPath;
26 class SplashFont;
28 //------------------------------------------------------------------------
30 // Retrieves the next line of pixels in an image mask. Normally,
31 // fills in *<line> and returns true. If the image stream is
32 // exhausted, returns false.
33 typedef GBool (*SplashImageMaskSource)(void *data, SplashColorPtr pixel);
35 // Retrieves the next line of pixels in an image. Normally, fills in
36 // *<line> and returns true. If the image stream is exhausted,
37 // returns false.
38 typedef GBool (*SplashImageSource)(void *data, SplashColorPtr line);
40 //------------------------------------------------------------------------
41 // Splash
42 //------------------------------------------------------------------------
44 class Splash {
45 public:
47 // Create a new rasterizer object.
48 Splash(SplashBitmap *bitmapA);
50 ~Splash();
52 //----- state read
54 SplashPattern *getStrokePattern();
55 SplashPattern *getFillPattern();
56 SplashScreen *getScreen();
57 SplashBlendFunc getBlendFunc();
58 SplashCoord getStrokeAlpha();
59 SplashCoord getFillAlpha();
60 SplashCoord getLineWidth();
61 int getLineCap();
62 int getLineJoin();
63 SplashCoord getMiterLimit();
64 SplashCoord getFlatness();
65 SplashCoord *getLineDash();
66 int getLineDashLength();
67 SplashCoord getLineDashPhase();
68 SplashClip *getClip();
70 //----- state write
72 void setStrokePattern(SplashPattern *strokeColor);
73 void setFillPattern(SplashPattern *fillColor);
74 void setScreen(SplashScreen *screen);
75 void setBlendFunc(SplashBlendFunc func);
76 void setStrokeAlpha(SplashCoord alpha);
77 void setFillAlpha(SplashCoord alpha);
78 void setLineWidth(SplashCoord lineWidth);
79 void setLineCap(int lineCap);
80 void setLineJoin(int lineJoin);
81 void setMiterLimit(SplashCoord miterLimit);
82 void setFlatness(SplashCoord flatness);
83 // the <lineDash> array will be copied
84 void setLineDash(SplashCoord *lineDash, int lineDashLength,
85 SplashCoord lineDashPhase);
86 void clipResetToRect(SplashCoord x0, SplashCoord y0,
87 SplashCoord x1, SplashCoord y1);
88 SplashError clipToRect(SplashCoord x0, SplashCoord y0,
89 SplashCoord x1, SplashCoord y1);
90 SplashError clipToPath(SplashPath *path, GBool eo);
92 //----- state save/restore
94 void saveState();
95 SplashError restoreState();
97 //----- soft mask
99 void setSoftMask(SplashBitmap *softMaskA);
101 //----- drawing operations
103 // Fill the bitmap with <color>. This is not subject to clipping.
104 void clear(SplashColorPtr color);
106 // Stroke a path using the current stroke pattern.
107 SplashError stroke(SplashPath *path);
109 // Fill a path using the current fill pattern.
110 SplashError fill(SplashPath *path, GBool eo);
112 // Fill a path, XORing with the current fill pattern.
113 SplashError xorFill(SplashPath *path, GBool eo);
115 // Draw a character, using the current fill pattern.
116 SplashError fillChar(SplashCoord x, SplashCoord y, int c, SplashFont *font);
118 // Draw a glyph, using the current fill pattern. This function does
119 // not free any data, i.e., it ignores glyph->freeData.
120 SplashError fillGlyph(SplashCoord x, SplashCoord y,
121 SplashGlyphBitmap *glyph);
123 // Draws an image mask using the fill color. This will read <h>
124 // lines of <w> pixels from <src>, starting with the top line. "1"
125 // pixels will be drawn with the current fill color; "0" pixels are
126 // transparent. The matrix:
127 // [ mat[0] mat[1] 0 ]
128 // [ mat[2] mat[3] 0 ]
129 // [ mat[4] mat[5] 1 ]
130 // maps a unit square to the desired destination for the image, in
131 // PostScript style:
132 // [x' y' 1] = [x y 1] * mat
133 // Note that the Splash y axis points downward, and the image source
134 // is assumed to produce pixels in raster order, starting from the
135 // top line.
136 SplashError fillImageMask(SplashImageMaskSource src, void *srcData,
137 int w, int h, SplashCoord *mat);
139 // Draw an image. This will read <h> lines of <w> pixels from
140 // <src>, starting with the top line. These pixels are assumed to
141 // be in the source mode, <srcMode>. The following combinations of
142 // source and target modes are supported:
143 // source target
144 // ------ ------
145 // Mono1 Mono1
146 // Mono8 Mono1 -- with dithering
147 // Mono8 Mono8
148 // RGB8 RGB8
149 // BGR8 BGR8
150 // ARGB8 RGB8 -- with source alpha (masking)
151 // BGRA8 BGR8 -- with source alpha (masking)
152 // The matrix behaves as for fillImageMask.
153 SplashError drawImage(SplashImageSource src, void *srcData,
154 SplashColorMode srcMode,
155 int w, int h, SplashCoord *mat);
157 //----- misc
159 // Return the associated bitmap.
160 SplashBitmap *getBitmap() { return bitmap; }
162 // Get a bounding box which includes all modifications since the
163 // last call to clearModRegion.
164 void getModRegion(int *xMin, int *yMin, int *xMax, int *yMax)
165 { *xMin = modXMin; *yMin = modYMin; *xMax = modXMax; *yMax = modYMax; }
167 // Clear the modified region bounding box.
168 void clearModRegion();
170 // Get clipping status for the last drawing operation subject to
171 // clipping.
172 SplashClipResult getClipRes() { return opClipRes; }
174 // Toggle debug mode on or off.
175 void setDebugMode(GBool debugModeA) { debugMode = debugModeA; }
177 private:
179 void updateModX(int x);
180 void updateModY(int y);
181 void strokeNarrow(SplashXPath *xPath);
182 void strokeWide(SplashXPath *xPath);
183 SplashXPath *makeDashedPath(SplashXPath *xPath);
184 SplashError fillWithPattern(SplashPath *path, GBool eo,
185 SplashPattern *pattern, SplashCoord alpha);
186 void drawPixel(int x, int y, SplashColorPtr color,
187 SplashCoord alpha, GBool noClip);
188 void drawPixel(int x, int y, SplashPattern *pattern,
189 SplashCoord alpha, GBool noClip);
190 void drawSpan(int x0, int x1, int y, SplashPattern *pattern,
191 SplashCoord alpha, GBool noClip);
192 void xorSpan(int x0, int x1, int y, SplashPattern *pattern, GBool noClip);
193 void dumpPath(SplashPath *path);
194 void dumpXPath(SplashXPath *path);
196 SplashBitmap *bitmap;
197 SplashState *state;
198 SplashBitmap *softMask;
199 int modXMin, modYMin, modXMax, modYMax;
200 SplashClipResult opClipRes;
201 GBool debugMode;
204 #endif