OLD | NEW |
1 #ifndef __DEFINED__SkPdfBasics | 1 #ifndef __DEFINED__SkPdfBasics |
2 #define __DEFINED__SkPdfBasics | 2 #define __DEFINED__SkPdfBasics |
3 | 3 |
4 #include "SkCanvas.h" | 4 #include "SkCanvas.h" |
5 #include "SkPaint.h" | 5 #include "SkPaint.h" |
6 #include "SkPdfConfig.h" | 6 #include "SkPdfConfig.h" |
7 | 7 |
8 #include <iostream> | 8 #include <iostream> |
9 #include <cstdio> | 9 #include <cstdio> |
10 #include <map> | 10 #include <map> |
11 #include <stack> | 11 #include <stack> |
12 | 12 |
13 class SkPdfFont; | 13 class SkPdfFont; |
14 class SkPdfDoc; | 14 class SkPdfDoc; |
15 class SkPdfObject; | 15 class SkPdfObject; |
16 class SkPdfResourceDictionary; | 16 class SkPdfResourceDictionary; |
17 | 17 |
18 class SkNativeParsedPDF; | 18 class SkNativeParsedPDF; |
19 class SkPdfAllocator; | 19 class SkPdfAllocator; |
20 | 20 |
21 // TODO(edisonn): better class design. | 21 // TODO(edisonn): better class design. |
22 struct SkPdfColorOperator { | 22 struct SkPdfColorOperator { |
| 23 |
| 24 /* |
| 25 color space name or array The current color space in which color value
s are to be interpreted |
| 26 (see Section 4.5, “Color Spaces”). There are
two separate color space |
| 27 parameters: one for stroking and one for all
other painting opera- |
| 28 tions. Initial value: DeviceGray. |
| 29 */ |
| 30 |
| 31 // TODO(edisonn): implement the array part too |
23 // does not own the char* | 32 // does not own the char* |
24 NotOwnedString fColorSpace; | 33 NotOwnedString fColorSpace; |
| 34 |
| 35 |
| 36 /* |
| 37 color (various) The current color to be used during painting
operations (see Section |
| 38 4.5, “Color Spaces”). The type and interpret
ation of this parameter |
| 39 depend on the current color space; for most
color spaces, a color |
| 40 value consists of one to four numbers. There
are two separate color |
| 41 parameters: one for stroking and one for all
other painting opera- |
| 42 tions. Initial value: black. |
| 43 */ |
| 44 |
25 SkColor fColor; | 45 SkColor fColor; |
26 double fOpacity; // ca or CA | 46 double fOpacity; // ca or CA |
27 // TODO(edisonn): add here other color space options. | 47 // TODO(edisonn): add here other color space options. |
28 | 48 |
29 void setRGBColor(SkColor color) { | 49 void setRGBColor(SkColor color) { |
30 // TODO(edisonn): ASSERT DeviceRGB is the color space. | 50 // TODO(edisonn): ASSERT DeviceRGB is the color space. |
31 fColor = color; | 51 fColor = color; |
32 } | 52 } |
33 // TODO(edisonn): double check the default values for all fields. | 53 // TODO(edisonn): double check the default values for all fields. |
34 SkPdfColorOperator() : fColor(SK_ColorBLACK), fOpacity(1) { | 54 SkPdfColorOperator() : fColor(SK_ColorBLACK), fOpacity(1) { |
35 NotOwnedString::init(&fColorSpace); | 55 NotOwnedString::init(&fColorSpace); |
36 } | 56 } |
37 | 57 |
38 void applyGraphicsState(SkPaint* paint) { | 58 void applyGraphicsState(SkPaint* paint) { |
39 paint->setColor(SkColorSetA(fColor, fOpacity * 255)); | 59 paint->setColor(SkColorSetA(fColor, fOpacity * 255)); |
40 } | 60 } |
41 }; | 61 }; |
42 | 62 |
43 // TODO(edisonn): better class design. | 63 // TODO(edisonn): better class design. |
44 struct SkPdfGraphicsState { | 64 struct SkPdfGraphicsState { |
45 SkMatrix fMatrix; | 65 // TODO(edisonn): deprecate and remove these! |
46 SkMatrix fMatrixTm; | |
47 SkMatrix fMatrixTlm; | |
48 | |
49 double fCurPosX; | 66 double fCurPosX; |
50 double fCurPosY; | 67 double fCurPosY; |
51 | 68 |
52 double fCurFontSize; | 69 double fCurFontSize; |
53 bool fTextBlock; | 70 bool fTextBlock; |
54 SkPdfFont* fSkFont; | 71 SkPdfFont* fSkFont; |
55 SkPath fPath; | 72 SkPath fPath; |
56 bool fPathClosed; | 73 bool fPathClosed; |
57 | 74 |
| 75 |
| 76 |
| 77 double fTextLeading; |
| 78 double fWordSpace; |
| 79 double fCharSpace; |
| 80 |
| 81 SkPdfResourceDictionary* fResources; |
| 82 |
| 83 |
| 84 // TODO(edisonn): move most of these in canvas/paint? |
| 85 // we could have some in canvas (matrixes?), |
| 86 // some in 2 paints (stroking paint and non stroking paint) |
| 87 |
| 88 // TABLE 4.2 Device-independent graphics state parameters |
| 89 /* |
| 90 * CTM array The current transformation matrix, which maps
positions from user |
| 91 coordinates to device coordinates (see Section 4
.2, “Coordinate Sys- |
| 92 tems”). This matrix is modified by each applicati
on of the coordi- |
| 93 nate transformation operator, cm. Initial value:
a matrix that |
| 94 transforms default user coordinates to device co
ordinates. |
| 95 */ |
| 96 SkMatrix fCTM; |
| 97 |
| 98 /* |
| 99 clipping path (internal) The current clipping path, which defines the boun
dary against |
| 100 which all output is to be cropped (see Section 4
.4.3, “Clipping Path |
| 101 Operators”). Initial value: the boundary of the
entire imageable |
| 102 portion of the output page. |
| 103 */ |
58 // Clip that is applied after the drawing is done!!! | 104 // Clip that is applied after the drawing is done!!! |
59 bool fHasClipPathToApply; | 105 bool fHasClipPathToApply; |
60 SkPath fClipPath; | 106 SkPath fClipPath; |
61 | 107 |
62 SkPdfColorOperator fStroking; | 108 SkPdfColorOperator fStroking; |
63 SkPdfColorOperator fNonStroking; | 109 SkPdfColorOperator fNonStroking; |
64 | 110 |
| 111 /* |
| 112 text state (various) A set of nine graphics state parameters that per
tain only to the |
| 113 painting of text. These include parameters that
select the font, scale |
| 114 the glyphs to an appropriate size, and accomplis
h other effects. The |
| 115 text state parameters are described in Section 5
.2, “Text State |
| 116 Parameters and Operators.” |
| 117 */ |
| 118 |
| 119 // TODO(edisonn): add SkPdfTextState class. remove these two existing fields |
| 120 SkMatrix fMatrixTm; |
| 121 SkMatrix fMatrixTlm; |
| 122 |
| 123 |
| 124 /* |
| 125 line width number The thickness, in user space units, of paths to
be stroked (see “Line |
| 126 Width” on page 152). Initial value: 1.0. |
| 127 */ |
65 double fLineWidth; | 128 double fLineWidth; |
66 double fTextLeading; | 129 |
67 double fWordSpace; | 130 |
68 double fCharSpace; | 131 /* |
69 | 132 line cap integer A code specifying the shape of the endpoints for
any open path that |
70 SkPdfResourceDictionary* fResources; | 133 is stroked (see “Line Cap Style” on page 153). I
nitial value: 0, for |
71 | 134 square butt caps. |
| 135 */ |
| 136 // TODO (edisonn): implement defaults - page 153 |
| 137 int fLineCap; |
| 138 |
| 139 /* |
| 140 line join integer A code specifying the shape of joints between co
nnected segments |
| 141 of a stroked path (see “Line Join Style” on page
153). Initial value: 0, |
| 142 for mitered joins. |
| 143 */ |
| 144 // TODO (edisonn): implement defaults - page 153 |
| 145 int fLineJoin; |
| 146 |
| 147 /* |
| 148 miter limit number The maximum length of mitered line joins for str
oked paths (see |
| 149 “Miter Limit” on page 153). This parameter limit
s the length of |
| 150 “spikes” produced when line segments join at sha
rp angles. Initial |
| 151 value: 10.0, for a miter cutoff below approximat
ely 11.5 degrees. |
| 152 */ |
| 153 // TODO (edisonn): implement defaults - page 153 |
| 154 double fMiterLimit; |
| 155 |
| 156 /* |
| 157 dash pattern array and A description of the dash pattern to be used whe
n paths are |
| 158 number stroked (see “Line Dash Pattern” on page 155). I
nitial value: a solid |
| 159 line. |
| 160 */ |
| 161 SkScalar fDashArray[256]; // TODO(edisonn): allocate array? |
| 162 int fDashArrayLength; |
| 163 SkScalar fDashPhase; |
| 164 |
| 165 |
| 166 /* |
| 167 rendering intent name The rendering intent to be used when converting
CIE-based colors |
| 168 to device colors (see “Rendering Intents” on pag
e 197). Default |
| 169 value: RelativeColorimetric. |
| 170 */ |
| 171 // TODO(edisonn): seems paper only. Verify. |
| 172 |
| 173 /* |
| 174 stroke adjustment boolean (PDF 1.2) A flag specifying whether to compensate
for possible ras- |
| 175 terization effects when stroking a path with a l
ine width that is |
| 176 small relative to the pixel resolution of the ou
tput device (see Sec- |
| 177 tion 6.5.4, “Automatic Stroke Adjustment”). Note
that this is con- |
| 178 sidered a device-independent parameter, even tho
ugh the details of |
| 179 its effects are device-dependent. Initial value:
false. |
| 180 */ |
| 181 // TODO(edisonn): stroke adjustment low priority. |
| 182 |
| 183 |
| 184 /* |
| 185 blend mode name or array (PDF 1.4) The current blend mode to be used in t
he transparent |
| 186 imaging model (see Sections 7.2.4, “Blend Mode,”
and 7.5.2, “Spec- |
| 187 ifying Blending Color Space and Blend Mode”). Th
is parameter is |
| 188 implicitly reset to its initial value at the beg
inning of execution of a |
| 189 transparency group XObject (see Section 7.5.5, “
Transparency |
| 190 Group XObjects”). Initial value: Normal. |
| 191 */ |
| 192 SkXfermode::Mode fBlendMode; |
| 193 |
| 194 /* |
| 195 soft mask dictionary (PDF 1.4) A soft-mask dictionary (see “Soft-Mask
Dictionaries” on |
| 196 or name page 445) specifying the mask shape or mask opac
ity values to be |
| 197 used in the transparent imaging model (see “Sour
ce Shape and |
| 198 Opacity” on page 421 and “Mask Shape and Opacity
” on page 443), |
| 199 or the name None if no such mask is specified. Th
is parameter is |
| 200 implicitly reset to its initial value at the beg
inning of execution of a |
| 201 transparency group XObject (see Section 7.5.5, “
Transparency |
| 202 Group XObjects”). Initial value: None. |
| 203 */ |
72 SkBitmap fSMask; | 204 SkBitmap fSMask; |
73 | 205 |
| 206 |
| 207 /* |
| 208 alpha constant number (PDF 1.4) The constant shape or constant opacity
value to be used |
| 209 in the transparent imaging model (see “Source Sh
ape and Opacity” |
| 210 on page 421 and “Constant Shape and Opacity” on
page 444). |
| 211 There are two separate alpha constant parameters
: one for stroking |
| 212 and one for all other painting operations. This
parameter is implic- |
| 213 itly reset to its initial value at the beginning
of execution of a trans- |
| 214 parency group XObject (see Section 7.5.5, “Trans
parency Group |
| 215 XObjects”). Initial value: 1.0. |
| 216 */ |
| 217 double fAphaConstant; |
| 218 |
| 219 /* |
| 220 alpha source boolean (PDF 1.4) A flag specifying whether the current s
oft mask and alpha |
| 221 constant parameters are to be interpreted as sha
pe values (true) or |
| 222 opacity values (false). This flag also governs th
e interpretation of |
| 223 the SMask entry, if any, in an image dictionary
(see Section 4.8.4, |
| 224 “Image Dictionaries”). Initial value: false. |
| 225 */ |
| 226 bool fAlphaSource; |
| 227 |
| 228 |
| 229 // TODO(edisonn): Device-dependent seem to be required only on the actual physic
al printer? |
| 230 // TABLE 4.3 Device-dependent graphics state parameters |
| 231 /* |
| 232 overprint boolean (PDF 1.2) A flag specifying (on output devi
ces that support the |
| 233 overprint control feature) whether paintin
g in one set of colorants |
| 234 should cause the corresponding areas of ot
her colorants to be |
| 235 erased (false) or left unchanged (true); s
ee Section 4.5.6, “Over- |
| 236 print Control.” In PDF 1.3, there are two
separate overprint param- |
| 237 eters: one for stroking and one for all ot
her painting operations. |
| 238 Initial value: false. |
| 239 */ |
| 240 |
| 241 |
| 242 /* |
| 243 overprint mode number (PDF 1.3) A code specifying whether a colo
r component value of 0 |
| 244 in a DeviceCMYK color space should erase t
hat component (0) or |
| 245 leave it unchanged (1) when overprinting (
see Section 4.5.6, “Over- |
| 246 print Control”). Initial value: 0. |
| 247 */ |
| 248 |
| 249 |
| 250 /* |
| 251 black generation function (PDF 1.2) A function that calculates the l
evel of the black color |
| 252 or name component to use when converting RGB color
s to CMYK (see Sec- |
| 253 tion 6.2.3, “Conversion from DeviceRGB to
DeviceCMYK”). Initial |
| 254 value: installation-dependent. |
| 255 */ |
| 256 |
| 257 |
| 258 /* |
| 259 undercolor removal function (PDF 1.2) A function that calculates the r
eduction in the levels of |
| 260 or name the cyan, magenta, and yellow color compon
ents to compensate for |
| 261 the amount of black added by black generat
ion (see Section 6.2.3, |
| 262 “Conversion from DeviceRGB to DeviceCMYK”)
. Initial value: in- |
| 263 stallation-dependent. |
| 264 */ |
| 265 |
| 266 |
| 267 /* |
| 268 transfer function, (PDF 1.2) A function that adjusts device g
ray or color component |
| 269 array, or name levels to compensate for nonlinear respons
e in a particular out- |
| 270 put device (see Section 6.3, “Transfer Fun
ctions”). Initial value: |
| 271 installation-dependent. |
| 272 */ |
| 273 |
| 274 |
| 275 /* |
| 276 halftone dictionary, (PDF 1.2) A halftone screen for gray and c
olor rendering, specified |
| 277 stream, or name as a halftone dictionary or stream (see Se
ction 6.4, “Halftones”). |
| 278 Initial value: installation-dependent. |
| 279 */ |
| 280 |
| 281 |
| 282 /* |
| 283 flatness number The precision with which curves are to be
rendered on the output |
| 284 device (see Section 6.5.1, “Flatness Toler
ance”). The value of this |
| 285 parameter gives the maximum error toleranc
e, measured in output |
| 286 device pixels; smaller numbers give smooth
er curves at the expense |
| 287 of more computation and memory use. Initia
l value: 1.0. |
| 288 */ |
| 289 |
| 290 |
| 291 /* |
| 292 smoothness number (PDF 1.3) The precision with which col
or gradients are to be ren- |
| 293 dered on the output device (see Sectio
n 6.5.2, “Smoothness Toler- |
| 294 ance”). The value of this parameter gi
ves the maximum error |
| 295 tolerance, expressed as a fraction of
the range of each color compo- |
| 296 nent; smaller numbers give smoother co
lor transitions at the |
| 297 expense of more computation and memory
use. Initial value: |
| 298 installation-dependent. |
| 299 */ |
| 300 |
| 301 |
| 302 |
| 303 |
| 304 |
| 305 |
| 306 |
74 SkPdfGraphicsState() { | 307 SkPdfGraphicsState() { |
75 fCurPosX = 0.0; | 308 fCurPosX = 0.0; |
76 fCurPosY = 0.0; | 309 fCurPosY = 0.0; |
77 fCurFontSize = 0.0; | 310 fCurFontSize = 0.0; |
78 fTextBlock = false; | 311 fTextBlock = false; |
79 fMatrix = SkMatrix::I(); | 312 fCTM = SkMatrix::I(); |
80 fMatrixTm = SkMatrix::I(); | 313 fMatrixTm = SkMatrix::I(); |
81 fMatrixTlm = SkMatrix::I(); | 314 fMatrixTlm = SkMatrix::I(); |
82 fPathClosed = true; | 315 fPathClosed = true; |
83 fLineWidth = 0; | 316 fLineWidth = 0; |
84 fTextLeading = 0; | 317 fTextLeading = 0; |
85 fWordSpace = 0; | 318 fWordSpace = 0; |
86 fCharSpace = 0; | 319 fCharSpace = 0; |
87 fHasClipPathToApply = false; | 320 fHasClipPathToApply = false; |
88 fResources = NULL; | 321 fResources = NULL; |
89 fSkFont = NULL; | 322 fSkFont = NULL; |
| 323 fLineCap = 0; |
| 324 fLineJoin = 0; |
| 325 fMiterLimit = 10.0; |
| 326 fAphaConstant = 1.0; |
| 327 fAlphaSource = false; |
| 328 fDashArrayLength = 0; |
| 329 fDashPhase = 0; |
| 330 fBlendMode = SkXfermode::kSrc_Mode; // PDF: Normal Blend mode |
90 } | 331 } |
91 | 332 |
92 void applyGraphicsState(SkPaint* paint, bool stroking) { | 333 // TODO(edisonn): make two functons instead, stroking and non stoking, avoid
branching |
93 if (stroking) { | 334 void applyGraphicsState(SkPaint* paint, bool stroking); |
94 fStroking.applyGraphicsState(paint); | |
95 } else { | |
96 fNonStroking.applyGraphicsState(paint); | |
97 } | |
98 | |
99 // TODO(edisonn): get this from pdfContext->options, | |
100 // or pdfContext->addPaintOptions(&paint); | |
101 paint->setAntiAlias(true); | |
102 | |
103 // TODO(edisonn): dashing, miter, ... | |
104 paint->setStrokeWidth(SkDoubleToScalar(fLineWidth)); | |
105 } | |
106 }; | 335 }; |
107 | 336 |
108 // TODO(edisonn): better class design. | 337 // TODO(edisonn): better class design. |
109 // TODO(edisonn): could we remove it? | 338 // TODO(edisonn): could we remove it? |
110 // TODO(edisonn): rename to SkPdfInlineImage | 339 // TODO(edisonn): rename to SkPdfInlineImage |
111 struct SkPdfInlineImage { | 340 struct SkPdfInlineImage { |
112 std::map<std::string, std::string> fKeyValuePairs; | 341 std::map<std::string, std::string> fKeyValuePairs; |
113 std::string fImageData; | 342 std::string fImageData; |
114 }; | 343 }; |
115 | 344 |
(...skipping 21 matching lines...) Expand all Loading... |
137 kPartial_PdfResult, | 366 kPartial_PdfResult, |
138 kNYI_PdfResult, | 367 kNYI_PdfResult, |
139 kIgnoreError_PdfResult, | 368 kIgnoreError_PdfResult, |
140 kError_PdfResult, | 369 kError_PdfResult, |
141 kUnsupported_PdfResult, | 370 kUnsupported_PdfResult, |
142 | 371 |
143 kCount_PdfResult | 372 kCount_PdfResult |
144 }; | 373 }; |
145 | 374 |
146 #endif // __DEFINED__SkPdfBasics | 375 #endif // __DEFINED__SkPdfBasics |
OLD | NEW |