Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(962)

Side by Side Diff: experimental/PdfViewer/SkPdfBasics.h

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

Powered by Google App Engine
This is Rietveld 408576698