1 //========================================================================
5 // Copyright 2003 Glyph & Cog, LLC
6 // Copyright 2004 Red Hat, INC
8 //========================================================================
10 //========================================================================
12 // Modified under the Poppler project - http://poppler.freedesktop.org
14 // All changes made under the Poppler project to this file are licensed
15 // under GPL version 2 or later
17 // Copyright (C) 2005-2008 Jeff Muizelaar <jeff@infidigm.net>
18 // Copyright (C) 2005, 2006 Kristian Høgsberg <krh@redhat.com>
19 // Copyright (C) 2005 Nickolay V. Shmyrev <nshmyrev@yandex.ru>
20 // Copyright (C) 2006-2011, 2013 Carlos Garcia Campos <carlosgc@gnome.org>
21 // Copyright (C) 2008, 2009, 2011-2015 Adrian Johnson <ajohnson@redneon.com>
22 // Copyright (C) 2008 Michael Vrable <mvrable@cs.ucsd.edu>
23 // Copyright (C) 2010-2013 Thomas Freitag <Thomas.Freitag@alfa.de>
24 // Copyright (C) 2015 Suzuki Toshiya <mpsuzuki@hiroshima-u.ac.jp>
26 // To see a description of the changes please see the Changelog file that
27 // came with your tarball or type make ChangeLog if you are building from git
29 //========================================================================
31 #ifndef CAIROOUTPUTDEV_H
32 #define CAIROOUTPUTDEV_H
34 #ifdef USE_GCC_PRAGMAS
38 #include "goo/gtypes.h"
40 #include "OutputDev.h"
41 #include "TextOutputDev.h"
49 class CairoFontEngine
;
52 //------------------------------------------------------------------------
54 //------------------------------------------------------------------------
56 //------------------------------------------------------------------------
60 CairoImage (double x1
, double y1
, double x2
, double y2
);
65 // Set the image cairo surface
66 void setImage (cairo_surface_t
*image
);
68 // Get the image cairo surface
69 cairo_surface_t
*getImage () const { return image
; }
71 // Get the image rectangle
72 void getRect (double *xa1
, double *ya1
, double *xa2
, double *ya2
)
73 { *xa1
= x1
; *ya1
= y1
; *xa2
= x2
; *ya2
= y2
; }
76 cairo_surface_t
*image
; // image cairo surface
77 double x1
, y1
; // upper left corner
78 double x2
, y2
; // lower right corner
82 //------------------------------------------------------------------------
84 //------------------------------------------------------------------------
86 class CairoOutputDev
: public OutputDev
{
93 virtual ~CairoOutputDev();
95 //----- get info about output device
97 // Does this device use upside-down coordinates?
98 // (Upside-down means (0,0) is the top left corner of the page.)
99 virtual GBool
upsideDown() { return gTrue
; }
101 // Does this device use drawChar() or drawString()?
102 virtual GBool
useDrawChar() { return gTrue
; }
104 // Does this device use tilingPatternFill()? If this returns false,
105 // tiling pattern fills will be reduced to a series of other drawing
107 virtual GBool
useTilingPatternFill() { return gTrue
; }
109 // Does this device use functionShadedFill(), axialShadedFill(), and
110 // radialShadedFill()? If this returns false, these shaded fills
111 // will be reduced to a series of other drawing operations.
112 #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 12, 0)
113 virtual GBool
useShadedFills(int type
) { return type
<= 7; }
115 virtual GBool
useShadedFills(int type
) { return type
> 1 && type
< 4; }
118 // Does this device use FillColorStop()?
119 virtual GBool
useFillColorStop() { return gTrue
; }
121 // Does this device use beginType3Char/endType3Char? Otherwise,
122 // text in Type 3 fonts will be drawn with drawChar/drawString.
123 virtual GBool
interpretType3Chars() { return gFalse
; }
125 // Does this device need to clip pages to the crop box even when the
126 // box is the crop box?
127 virtual GBool
needClipToCropBox() { return gTrue
; }
129 //----- initialization and control
132 virtual void startPage(int pageNum
, GfxState
*state
, XRef
*xref
);
135 virtual void endPage();
137 //----- save/restore graphics state
138 virtual void saveState(GfxState
*state
);
139 virtual void restoreState(GfxState
*state
);
141 //----- update graphics state
142 virtual void updateAll(GfxState
*state
);
143 virtual void setDefaultCTM(double *ctm
);
144 virtual void updateCTM(GfxState
*state
, double m11
, double m12
,
145 double m21
, double m22
, double m31
, double m32
);
146 virtual void updateLineDash(GfxState
*state
);
147 virtual void updateFlatness(GfxState
*state
);
148 virtual void updateLineJoin(GfxState
*state
);
149 virtual void updateLineCap(GfxState
*state
);
150 virtual void updateMiterLimit(GfxState
*state
);
151 virtual void updateLineWidth(GfxState
*state
);
152 virtual void updateFillColor(GfxState
*state
);
153 virtual void updateStrokeColor(GfxState
*state
);
154 virtual void updateFillOpacity(GfxState
*state
);
155 virtual void updateStrokeOpacity(GfxState
*state
);
156 virtual void updateFillColorStop(GfxState
*state
, double offset
);
157 virtual void updateBlendMode(GfxState
*state
);
159 //----- update text state
160 virtual void updateFont(GfxState
*state
);
162 //----- path painting
163 virtual void stroke(GfxState
*state
);
164 virtual void fill(GfxState
*state
);
165 virtual void eoFill(GfxState
*state
);
166 virtual void clipToStrokePath(GfxState
*state
);
167 virtual GBool
tilingPatternFill(GfxState
*state
, Gfx
*gfx
, Catalog
*cat
, Object
*str
,
168 double *pmat
, int paintType
, int tilingType
, Dict
*resDict
,
169 double *mat
, double *bbox
,
170 int x0
, int y0
, int x1
, int y1
,
171 double xStep
, double yStep
);
172 #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 12, 0)
173 virtual GBool
functionShadedFill(GfxState
*state
, GfxFunctionShading
*shading
);
175 virtual GBool
axialShadedFill(GfxState
*state
, GfxAxialShading
*shading
, double tMin
, double tMax
);
176 virtual GBool
axialShadedSupportExtend(GfxState
*state
, GfxAxialShading
*shading
);
177 virtual GBool
radialShadedFill(GfxState
*state
, GfxRadialShading
*shading
, double sMin
, double sMax
);
178 virtual GBool
radialShadedSupportExtend(GfxState
*state
, GfxRadialShading
*shading
);
179 #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 12, 0)
180 virtual GBool
gouraudTriangleShadedFill(GfxState
*state
, GfxGouraudTriangleShading
*shading
);
181 virtual GBool
patchMeshShadedFill(GfxState
*state
, GfxPatchMeshShading
*shading
);
184 //----- path clipping
185 virtual void clip(GfxState
*state
);
186 virtual void eoClip(GfxState
*state
);
189 void beginString(GfxState
*state
, GooString
*s
);
190 void endString(GfxState
*state
);
191 void drawChar(GfxState
*state
, double x
, double y
,
192 double dx
, double dy
,
193 double originX
, double originY
,
194 CharCode code
, int nBytes
, Unicode
*u
, int uLen
);
195 void beginActualText(GfxState
*state
, GooString
*text
);
196 void endActualText(GfxState
*state
);
198 virtual GBool
beginType3Char(GfxState
*state
, double x
, double y
,
199 double dx
, double dy
,
200 CharCode code
, Unicode
*u
, int uLen
);
201 virtual void endType3Char(GfxState
*state
);
202 virtual void beginTextObject(GfxState
*state
);
203 virtual void endTextObject(GfxState
*state
);
205 //----- image drawing
206 virtual void drawImageMask(GfxState
*state
, Object
*ref
, Stream
*str
,
207 int width
, int height
, GBool invert
, GBool interpolate
,
209 virtual void setSoftMaskFromImageMask(GfxState
*state
,
210 Object
*ref
, Stream
*str
,
211 int width
, int height
, GBool invert
,
212 GBool inlineImg
, double *baseMatrix
);
213 virtual void unsetSoftMaskFromImageMask(GfxState
*state
, double *baseMatrix
);
214 void drawImageMaskPrescaled(GfxState
*state
, Object
*ref
, Stream
*str
,
215 int width
, int height
, GBool invert
, GBool interpolate
,
217 void drawImageMaskRegular(GfxState
*state
, Object
*ref
, Stream
*str
,
218 int width
, int height
, GBool invert
, GBool interpolate
,
221 virtual void drawImage(GfxState
*state
, Object
*ref
, Stream
*str
,
222 int width
, int height
, GfxImageColorMap
*colorMap
,
223 GBool interpolate
, int *maskColors
, GBool inlineImg
);
224 virtual void drawSoftMaskedImage(GfxState
*state
, Object
*ref
, Stream
*str
,
225 int width
, int height
,
226 GfxImageColorMap
*colorMap
,
229 int maskWidth
, int maskHeight
,
230 GfxImageColorMap
*maskColorMap
,
231 GBool maskInterpolate
);
233 virtual void drawMaskedImage(GfxState
*state
, Object
*ref
, Stream
*str
,
234 int width
, int height
,
235 GfxImageColorMap
*colorMap
,
238 int maskWidth
, int maskHeight
,
239 GBool maskInvert
, GBool maskInterpolate
);
241 //----- transparency groups and soft masks
242 virtual void beginTransparencyGroup(GfxState
* /*state*/, double * /*bbox*/,
243 GfxColorSpace
* /*blendingColorSpace*/,
244 GBool
/*isolated*/, GBool
/*knockout*/,
245 GBool
/*forSoftMask*/);
246 virtual void endTransparencyGroup(GfxState
* /*state*/);
247 void popTransparencyGroup();
248 virtual void paintTransparencyGroup(GfxState
* /*state*/, double * /*bbox*/);
249 virtual void setSoftMask(GfxState
* /*state*/, double * /*bbox*/, GBool
/*alpha*/,
250 Function
* /*transferFunc*/, GfxColor
* /*backdropColor*/);
251 virtual void clearSoftMask(GfxState
* /*state*/);
253 //----- Type 3 font operators
254 virtual void type3D0(GfxState
*state
, double wx
, double wy
);
255 virtual void type3D1(GfxState
*state
, double wx
, double wy
,
256 double llx
, double lly
, double urx
, double ury
);
258 //----- special access
260 // Called to indicate that a new PDF document has been loaded.
261 void startDoc(PDFDoc
*docA
, CairoFontEngine
*fontEngine
= NULL
);
263 GBool
isReverseVideo() { return gFalse
; }
265 void setCairo (cairo_t
*cr
);
266 void setTextPage (TextPage
*text
);
267 void setPrinting (GBool printing
) { this->printing
= printing
; needFontUpdate
= gTrue
; }
269 void setInType3Char(GBool inType3Char
) { this->inType3Char
= inType3Char
; }
270 void getType3GlyphWidth (double *wx
, double *wy
) { *wx
= t3_glyph_wx
; *wy
= t3_glyph_wy
; }
271 GBool
hasType3GlyphBBox () { return t3_glyph_has_bbox
; }
272 double *getType3GlyphBBox () { return t3_glyph_bbox
; }
275 void doPath(cairo_t
*cairo
, GfxState
*state
, GfxPath
*path
);
276 cairo_surface_t
*downscaleSurface(cairo_surface_t
*orig_surface
);
277 void getScaledSize(const cairo_matrix_t
*matrix
,
278 int orig_width
, int orig_height
,
279 int *scaledWidth
, int *scaledHeight
);
280 cairo_filter_t
getFilterForSurface(cairo_surface_t
*image
,
282 GBool
getStreamData (Stream
*str
, char **buffer
, int *length
);
283 void setMimeData(GfxState
*state
, Stream
*str
, Object
*ref
,
284 GfxImageColorMap
*colorMap
, cairo_surface_t
*image
);
285 void fillToStrokePathClip(GfxState
*state
);
286 void alignStrokeCoords(GfxSubpath
*subpath
, int i
, double *x
, double *y
);
287 #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 14, 0)
288 GBool
setMimeDataForJBIG2Globals (Stream
*str
, cairo_surface_t
*image
);
291 GfxRGB fill_color
, stroke_color
;
292 cairo_pattern_t
*fill_pattern
, *stroke_pattern
;
294 double stroke_opacity
;
296 GBool adjusted_stroke_width
;
297 GBool align_stroke_coords
;
298 CairoFont
*currentFont
;
301 struct StrokePathClip
{
308 cairo_line_cap_t cap
;
309 cairo_line_join_t join
;
313 PDFDoc
*doc
; // the current document
315 static FT_Library ft_lib
;
316 static GBool ft_lib_initialized
;
318 CairoFontEngine
*fontEngine
;
319 GBool fontEngine_owner
;
322 cairo_matrix_t orig_matrix
;
323 GBool needFontUpdate
; // set when the font needs to be updated
325 GBool use_show_text_glyphs
;
326 GBool text_matrix_valid
;
327 cairo_surface_t
*surface
;
328 cairo_glyph_t
*glyphs
;
330 cairo_text_cluster_t
*clusters
;
335 cairo_path_t
*textClipPath
;
336 GBool inUncoloredPattern
; // inside a uncolored pattern (PaintType = 2)
337 GBool inType3Char
; // inside a Type 3 CharProc
338 double t3_glyph_wx
, t3_glyph_wy
;
339 GBool t3_glyph_has_bbox
;
340 double t3_glyph_bbox
[4];
342 GBool prescaleImages
;
344 TextPage
*text
; // text for the current page
345 ActualText
*actualText
;
347 cairo_pattern_t
*group
;
348 cairo_pattern_t
*shape
;
349 cairo_pattern_t
*mask
;
350 cairo_matrix_t mask_matrix
;
351 cairo_surface_t
*cairo_shape_surface
;
352 cairo_t
*cairo_shape
;
354 struct ColorSpaceStack
{
357 cairo_matrix_t group_matrix
;
358 struct ColorSpaceStack
*next
;
359 } * groupColorSpaceStack
;
362 cairo_pattern_t
*mask
;
363 cairo_matrix_t mask_matrix
;
364 struct MaskStack
*next
;
369 //------------------------------------------------------------------------
370 // CairoImageOutputDev
371 //------------------------------------------------------------------------
373 //XXX: this should ideally not inherit from CairoOutputDev but use it instead perhaps
374 class CairoImageOutputDev
: public CairoOutputDev
{
378 CairoImageOutputDev();
381 virtual ~CairoImageOutputDev();
383 //----- get info about output device
385 // Does this device use upside-down coordinates?
386 // (Upside-down means (0,0) is the top left corner of the page.)
387 virtual GBool
upsideDown() { return gTrue
; }
389 // Does this device use drawChar() or drawString()?
390 virtual GBool
useDrawChar() { return gFalse
; }
392 // Does this device use tilingPatternFill()? If this returns false,
393 // tiling pattern fills will be reduced to a series of other drawing
395 virtual GBool
useTilingPatternFill() { return gTrue
; }
397 // Does this device use functionShadedFill(), axialShadedFill(), and
398 // radialShadedFill()? If this returns false, these shaded fills
399 // will be reduced to a series of other drawing operations.
400 #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 11, 2)
401 virtual GBool
useShadedFills(int type
) { return type
<= 7; }
403 virtual GBool
useShadedFills(int type
) { return type
< 4; }
406 // Does this device use FillColorStop()?
407 virtual GBool
useFillColorStop() { return gFalse
; }
409 // Does this device use beginType3Char/endType3Char? Otherwise,
410 // text in Type 3 fonts will be drawn with drawChar/drawString.
411 virtual GBool
interpretType3Chars() { return gFalse
; }
413 // Does this device need non-text content?
414 virtual GBool
needNonText() { return gTrue
; }
416 //----- save/restore graphics state
417 virtual void saveState(GfxState
*state
) { }
418 virtual void restoreState(GfxState
*state
) { }
420 //----- update graphics state
421 virtual void updateAll(GfxState
*state
) { }
422 virtual void setDefaultCTM(double *ctm
) { }
423 virtual void updateCTM(GfxState
*state
, double m11
, double m12
,
424 double m21
, double m22
, double m31
, double m32
) { }
425 virtual void updateLineDash(GfxState
*state
) { }
426 virtual void updateFlatness(GfxState
*state
) { }
427 virtual void updateLineJoin(GfxState
*state
) { }
428 virtual void updateLineCap(GfxState
*state
) { }
429 virtual void updateMiterLimit(GfxState
*state
) { }
430 virtual void updateLineWidth(GfxState
*state
) { }
431 virtual void updateFillColor(GfxState
*state
) { }
432 virtual void updateStrokeColor(GfxState
*state
) { }
433 virtual void updateFillOpacity(GfxState
*state
) { }
434 virtual void updateStrokeOpacity(GfxState
*state
) { }
435 virtual void updateBlendMode(GfxState
*state
) { }
437 //----- update text state
438 virtual void updateFont(GfxState
*state
) { }
440 //----- path painting
441 virtual void stroke(GfxState
*state
) { }
442 virtual void fill(GfxState
*state
) { }
443 virtual void eoFill(GfxState
*state
) { }
444 virtual void clipToStrokePath(GfxState
*state
) { }
445 virtual GBool
tilingPatternFill(GfxState
*state
, Gfx
*gfx
, Catalog
*cat
, Object
*str
,
446 double *pmat
, int paintType
, int tilingType
, Dict
*resDict
,
447 double *mat
, double *bbox
,
448 int x0
, int y0
, int x1
, int y1
,
449 double xStep
, double yStep
) { return gTrue
; }
450 virtual GBool
axialShadedFill(GfxState
*state
,
451 GfxAxialShading
*shading
,
452 double tMin
, double tMax
) { return gTrue
; }
453 virtual GBool
radialShadedFill(GfxState
*state
,
454 GfxRadialShading
*shading
,
455 double sMin
, double sMax
) { return gTrue
; }
457 //----- path clipping
458 virtual void clip(GfxState
*state
) { }
459 virtual void eoClip(GfxState
*state
) { }
461 //----- image drawing
462 virtual void drawImageMask(GfxState
*state
, Object
*ref
, Stream
*str
,
463 int width
, int height
, GBool invert
,
464 GBool interpolate
, GBool inlineImg
);
465 virtual void drawImage(GfxState
*state
, Object
*ref
, Stream
*str
,
466 int width
, int height
, GfxImageColorMap
*colorMap
,
467 GBool interpolate
, int *maskColors
, GBool inlineImg
);
468 virtual void drawSoftMaskedImage(GfxState
*state
, Object
*ref
, Stream
*str
,
469 int width
, int height
,
470 GfxImageColorMap
*colorMap
,
473 int maskWidth
, int maskHeight
,
474 GfxImageColorMap
*maskColorMap
,
475 GBool maskInterpolate
);
476 virtual void drawMaskedImage(GfxState
*state
, Object
*ref
, Stream
*str
,
477 int width
, int height
,
478 GfxImageColorMap
*colorMap
,
481 int maskWidth
, int maskHeight
,
482 GBool maskInvert
, GBool maskInterpolate
);
483 virtual void setSoftMaskFromImageMask(GfxState
*state
, Object
*ref
, Stream
*str
,
484 int width
, int height
, GBool invert
,
485 GBool inlineImg
, double *baseMatrix
);
486 virtual void unsetSoftMaskFromImageMask(GfxState
*state
, double *baseMatrix
) {}
489 //----- transparency groups and soft masks
490 virtual void beginTransparencyGroup(GfxState
* /*state*/, double * /*bbox*/,
491 GfxColorSpace
* /*blendingColorSpace*/,
492 GBool
/*isolated*/, GBool
/*knockout*/,
493 GBool
/*forSoftMask*/) {}
494 virtual void endTransparencyGroup(GfxState
* /*state*/) {}
495 virtual void paintTransparencyGroup(GfxState
* /*state*/, double * /*bbox*/) {}
496 virtual void setSoftMask(GfxState
* /*state*/, double * /*bbox*/, GBool
/*alpha*/,
497 Function
* /*transferFunc*/, GfxColor
* /*backdropColor*/) {}
498 virtual void clearSoftMask(GfxState
* /*state*/) {}
501 // By default images are not rendred
502 void setImageDrawDecideCbk(GBool (*cbk
)(int img_id
, void *data
),
503 void *data
) { imgDrawCbk
= cbk
; imgDrawCbkData
= data
; }
504 // Iterate through list of images.
505 int getNumImages() const { return numImages
; }
506 CairoImage
*getImage(int i
) const { return images
[i
]; }
509 void saveImage(CairoImage
*image
);
510 void getBBox(GfxState
*state
, int width
, int height
,
511 double *x1
, double *y1
, double *x2
, double *y2
);
516 GBool (*imgDrawCbk
)(int img_id
, void *data
);
517 void *imgDrawCbkData
;