1 //========================================================================
5 // Copyright 1996 Derek B. Noonburg
7 //========================================================================
22 //------------------------------------------------------------------------
24 //------------------------------------------------------------------------
29 GfxColor(): r(0), g(0), b(0) {}
32 void setGray(double gray)
34 void setCMYK(double c, double m, double y, double k);
35 void setRGB(double r1, double g1, double b1)
36 { r = r1; g = g1; b = b1; }
39 double getR() { return r; }
40 double getG() { return g; }
41 double getB() { return b; }
42 double getGray() { return 0.299 * r + 0.587 * g + 0.114 * b; }
49 //------------------------------------------------------------------------
51 //------------------------------------------------------------------------
54 colorGray, colorCMYK, colorRGB
60 // Construct a colorspace.
61 GfxColorSpace(Object *colorSpace);
63 // Construct a simple colorspace: DeviceGray, DeviceCMYK, or
65 GfxColorSpace(GfxColorMode mode1);
71 GfxColorSpace *copy() { return new GfxColorSpace(this); }
73 // Is color space valid?
74 GBool isOk() { return ok; }
76 // Get the color mode.
77 GfxColorMode getMode() { return mode; }
79 // Get number of components in pixels of this colorspace.
80 int getNumPixelComps() { return indexed ? 1 : numComps; }
82 // Get number of components in colors of this colorspace.
83 int getNumColorComps() { return numComps; }
85 // Return true if colorspace is indexed.
86 GBool isIndexed() { return indexed; }
88 // Get lookup table (only for indexed colorspaces).
89 int getIndexHigh() { return indexHigh; }
90 Guchar *getLookupVal(int i) { return lookup[i]; }
92 // Convert a pixel to a color.
93 void getColor(double x[4], GfxColor *color);
97 Function *sepFunc; // separation tint transform function
98 GfxColorMode mode; // color mode
99 GBool indexed; // set for indexed colorspaces
100 int numComps; // number of components in colors
101 int indexHigh; // max pixel for indexed colorspace
102 Guchar (*lookup)[4]; // lookup table (only for indexed
104 GBool ok; // is color space valid?
106 GfxColorSpace(GfxColorSpace *colorSpace);
107 void setMode(Object *colorSpace);
110 //------------------------------------------------------------------------
112 //------------------------------------------------------------------------
117 // Create a PDF function object.
118 Function(Object *funcObj);
122 Function *copy() { return new Function(this); }
124 GBool isOk() { return ok; }
126 // Return size of input and output tuples.
127 int getInputSize() { return m; }
128 int getOutputSize() { return n; }
130 // Transform an input tuple into an output tuple.
131 void transform(double *in, double *out);
135 Function(Function *func);
147 //------------------------------------------------------------------------
149 //------------------------------------------------------------------------
151 class GfxImageColorMap {
155 GfxImageColorMap(int bits1, Object *decode, GfxColorSpace *colorSpace1);
160 // Is color map valid?
161 GBool isOk() { return ok; }
163 // Get the color space.
164 GfxColorSpace *getColorSpace() { return colorSpace; }
166 // Get stream decoding info.
167 int getNumPixelComps() { return numComps; }
168 int getBits() { return bits; }
171 double getDecodeLow(int i) { return decodeLow[i]; }
172 double getDecodeHigh(int i) { return decodeLow[i] + decodeRange[i]; }
174 // Convert a pixel to a color.
175 void getColor(Guchar x[4], GfxColor *color);
179 GfxColorSpace *colorSpace; // the image colorspace
180 int bits; // bits per component
181 int numComps; // number of components in a pixel
182 GBool indexed; // set for indexed color space
183 GfxColorMode mode; // color mode
184 double (*lookup)[4]; // lookup table
185 double decodeLow[4]; // minimum values for each component
186 double decodeRange[4]; // max - min value for each component
190 //------------------------------------------------------------------------
191 // GfxSubpath and GfxPath
192 //------------------------------------------------------------------------
198 GfxSubpath(double x1, double y1);
204 GfxSubpath *copy() { return new GfxSubpath(this); }
207 int getNumPoints() { return n; }
208 double getX(int i) { return x[i]; }
209 double getY(int i) { return y[i]; }
210 GBool getCurve(int i) { return curve[i]; }
213 double getLastX() { return x[n-1]; }
214 double getLastY() { return y[n-1]; }
216 // Add a line segment.
217 void lineTo(double x1, double y1);
219 // Add a Bezier curve.
220 void curveTo(double x1, double y1, double x2, double y2,
221 double x3, double y3);
223 // Close the subpath.
225 { if (x[n-1] != x[0] || y[n-1] != y[0]) lineTo(x[0], y[0]); }
229 double *x, *y; // points
230 GBool *curve; // curve[i] => point i is a control point
231 // for a Bezier curve
232 int n; // number of points
233 int size; // size of x/y arrays
235 GfxSubpath(GfxSubpath *subpath);
249 { return new GfxPath(justMoved, firstX, firstY, subpaths, n, size); }
251 // Is there a current point?
252 GBool isCurPt() { return n > 0 || justMoved; }
254 // Is the path non-empty, i.e., is there at least one segment?
255 GBool isPath() { return n > 0; }
258 int getNumSubpaths() { return n; }
259 GfxSubpath *getSubpath(int i) { return subpaths[i]; }
261 // Get last point on last subpath.
262 double getLastX() { return subpaths[n-1]->getLastX(); }
263 double getLastY() { return subpaths[n-1]->getLastY(); }
265 // Move the current point.
266 void moveTo(double x, double y);
268 // Add a segment to the last subpath.
269 void lineTo(double x, double y);
271 // Add a Bezier curve to the last subpath
272 void curveTo(double x1, double y1, double x2, double y2,
273 double x3, double y3);
275 // Close the last subpath.
276 void close() { subpaths[n-1]->close(); }
280 GBool justMoved; // set if a new subpath was just started
281 double firstX, firstY; // first point in new subpath
282 GfxSubpath **subpaths; // subpaths
283 int n; // number of subpaths
284 int size; // size of subpaths array
286 GfxPath(GBool justMoved1, double firstX1, double firstY1,
287 GfxSubpath **subpaths1, int n1, int size1);
290 //------------------------------------------------------------------------
292 //------------------------------------------------------------------------
297 // Construct a default GfxState, for a device with resolution <dpi>,
298 // page box (<x1>,<y1>)-(<x2>,<y2>), page rotation <rotate>, and
299 // coordinate system specified by <upsideDown>.
300 GfxState(int dpi, double px1a, double py1a, double px2a, double py2a,
301 int rotate, GBool upsideDown);
307 GfxState *copy() { return new GfxState(this); }
310 double *getCTM() { return ctm; }
311 double getX1() { return px1; }
312 double getY1() { return py1; }
313 double getX2() { return px2; }
314 double getY2() { return py2; }
315 double getPageWidth() { return pageWidth; }
316 double getPageHeight() { return pageHeight; }
317 GfxColor *getFillColor() { return &fillColor; }
318 GfxColor *getStrokeColor() { return &strokeColor; }
319 double getLineWidth() { return lineWidth; }
320 void getLineDash(double **dash, int *length, double *start)
321 { *dash = lineDash; *length = lineDashLength; *start = lineDashStart; }
322 int getFlatness() { return flatness; }
323 int getLineJoin() { return lineJoin; }
324 int getLineCap() { return lineCap; }
325 double getMiterLimit() { return miterLimit; }
326 GfxFont *getFont() { return font; }
327 double getFontSize() { return fontSize; }
328 double *getTextMat() { return textMat; }
329 double getCharSpace() { return charSpace; }
330 double getWordSpace() { return wordSpace; }
331 double getHorizScaling() { return horizScaling; }
332 double getLeading() { return leading; }
333 double getRise() { return rise; }
334 int getRender() { return render; }
335 GfxPath *getPath() { return path; }
336 double getCurX() { return curX; }
337 double getCurY() { return curY; }
338 double getLineX() { return lineX; }
339 double getLineY() { return lineY; }
341 // Is there a current point/path?
342 GBool isCurPt() { return path->isCurPt(); }
343 GBool isPath() { return path->isPath(); }
346 void transform(double x1, double y1, double *x2, double *y2)
347 { *x2 = ctm[0] * x1 + ctm[2] * y1 + ctm[4];
348 *y2 = ctm[1] * x1 + ctm[3] * y1 + ctm[5]; }
349 void transformDelta(double x1, double y1, double *x2, double *y2)
350 { *x2 = ctm[0] * x1 + ctm[2] * y1;
351 *y2 = ctm[1] * x1 + ctm[3] * y1; }
352 void textTransform(double x1, double y1, double *x2, double *y2)
353 { *x2 = textMat[0] * x1 + textMat[2] * y1 + textMat[4];
354 *y2 = textMat[1] * x1 + textMat[3] * y1 + textMat[5]; }
355 void textTransformDelta(double x1, double y1, double *x2, double *y2)
356 { *x2 = textMat[0] * x1 + textMat[2] * y1;
357 *y2 = textMat[1] * x1 + textMat[3] * y1; }
358 double transformWidth(double w);
359 double getTransformedLineWidth()
360 { return transformWidth(lineWidth); }
361 double getTransformedFontSize();
362 void getFontTransMat(double *m11, double *m12, double *m21, double *m22);
364 // Change state parameters.
365 void concatCTM(double a, double b, double c,
366 double d, double e, double f);
367 void setFillGray(double gray)
368 { fillColor.setGray(gray); }
369 void setFillCMYK(double c, double m, double y, double k)
370 { fillColor.setCMYK(c, m, y, k); }
371 void setFillRGB(double r, double g, double b)
372 { fillColor.setRGB(r, g, b); }
373 void setStrokeGray(double gray)
374 { strokeColor.setGray(gray); }
375 void setStrokeCMYK(double c, double m, double y, double k)
376 { strokeColor.setCMYK(c, m, y, k); }
377 void setStrokeRGB(double r, double g, double b)
378 { strokeColor.setRGB(r, g, b); }
379 void setFillColorSpace(GfxColorSpace *colorSpace);
380 void setStrokeColorSpace(GfxColorSpace *colorSpace);
381 void setFillColor(double x[4])
382 { fillColorSpace->getColor(x, &fillColor); }
383 void setStrokeColor(double x[4])
384 { strokeColorSpace->getColor(x, &strokeColor); }
385 void setLineWidth(double width)
386 { lineWidth = width; }
387 void setLineDash(double *dash, int length, double start);
388 void setFlatness(int flatness1) { flatness = flatness1; }
389 void setLineJoin(int lineJoin1) { lineJoin = lineJoin1; }
390 void setLineCap(int lineCap1) { lineCap = lineCap1; }
391 void setMiterLimit(double miterLimit1) { miterLimit = miterLimit1; }
392 void setFont(GfxFont *font1, double fontSize1)
393 { font = font1; fontSize = fontSize1; }
394 void setTextMat(double a, double b, double c,
395 double d, double e, double f)
396 { textMat[0] = a; textMat[1] = b; textMat[2] = c;
397 textMat[3] = d; textMat[4] = e; textMat[5] = f; }
398 void setCharSpace(double space)
399 { charSpace = space; }
400 void setWordSpace(double space)
401 { wordSpace = space; }
402 void setHorizScaling(double scale)
403 { horizScaling = 0.01 * scale; }
404 void setLeading(double leading1)
405 { leading = leading1; }
406 void setRise(double rise1)
408 void setRender(int render1)
409 { render = render1; }
412 void moveTo(double x, double y)
413 { path->moveTo(curX = x, curY = y); }
414 void lineTo(double x, double y)
415 { path->lineTo(curX = x, curY = y); }
416 void curveTo(double x1, double y1, double x2, double y2,
417 double x3, double y3)
418 { path->curveTo(x1, y1, x2, y2, curX = x3, curY = y3); }
420 { path->close(); curX = path->getLastX(); curY = path->getLastY(); }
424 void textMoveTo(double tx, double ty)
425 { lineX = tx; lineY = ty; textTransform(tx, ty, &curX, &curY); }
426 void textShift(double tx);
428 // Push/pop GfxState on/off stack.
431 GBool hasSaves() { return saved != NULL; }
435 double ctm[6]; // coord transform matrix
436 double px1, py1, px2, py2; // page corners (user coords)
437 double pageWidth, pageHeight; // page size (pixels)
439 GfxColorSpace *fillColorSpace; // fill color space
440 GfxColorSpace *strokeColorSpace; // stroke color space
441 GfxColor fillColor; // fill color
442 GfxColor strokeColor; // stroke color
444 double lineWidth; // line width
445 double *lineDash; // line dash
447 double lineDashStart;
448 int flatness; // curve flatness
449 int lineJoin; // line join style
450 int lineCap; // line cap style
451 double miterLimit; // line miter limit
453 GfxFont *font; // font
454 double fontSize; // font size
455 double textMat[6]; // text matrix
456 double charSpace; // character spacing
457 double wordSpace; // word spacing
458 double horizScaling; // horizontal scaling
459 double leading; // text leading
460 double rise; // text rise
461 int render; // text rendering mode
463 GfxPath *path; // array of path elements
464 double curX, curY; // current point (user coords)
465 double lineX, lineY; // start of current text line (text coords)
467 GfxState *saved; // next GfxState on stack
469 GfxState(GfxState *state);