| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef SkPdfGraphicsState_DEFINED | 8 #ifndef SkPdfGraphicsState_DEFINED |
| 9 #define SkPdfGraphicsState_DEFINED | 9 #define SkPdfGraphicsState_DEFINED |
| 10 | 10 |
| 11 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
| 12 #include "SkPaint.h" | 12 #include "SkPaint.h" |
| 13 #include "SkPdfConfig.h" | 13 #include "SkPdfConfig.h" |
| 14 #include "SkPdfUtils.h" | 14 #include "SkPdfUtils.h" |
| 15 | 15 |
| 16 class SkPdfAllocator; |
| 16 class SkPdfFont; | 17 class SkPdfFont; |
| 17 class SkPdfDoc; | 18 class SkPdfDoc; |
| 19 class SkPdfNativeDoc; |
| 18 class SkPdfNativeObject; | 20 class SkPdfNativeObject; |
| 19 class SkPdfResourceDictionary; | 21 class SkPdfResourceDictionary; |
| 20 class SkPdfSoftMaskDictionary; | 22 class SkPdfSoftMaskDictionary; |
| 23 #include "SkTypes.h" |
| 21 | 24 |
| 22 class SkPdfNativeDoc; | |
| 23 class SkPdfAllocator; | |
| 24 | 25 |
| 25 // TODO(edisonn): move this class in include/core? | 26 // TODO(edisonn): move SkTDStackNester class in its own private file |
| 26 // Ref objects can't be dealt unless we use a specific class initialization | |
| 27 // The difference between SkTDStackNew and SkTDStack is that SkTDStackNew uses n
ew/delete | |
| 28 // to be a manage c++ stuff (like initializations) | |
| 29 | 27 |
| 30 // Adobe limits it to 28, so 256 should be more than enough | 28 // Adobe limits it to 28, so 256 should be more than enough |
| 31 #define MAX_NESTING 256 | 29 #define MAX_NESTING 256 |
| 32 | 30 |
| 33 #include "SkTypes.h" | 31 /** \class SkTDStackNester |
| 34 template <typename T> class SkTDStackNew : SkNoncopyable { | 32 * |
| 33 * The difference between SkTDStackNester and SkTDStack is that: |
| 34 * - SkTDStackNester uses new/delete to manage initializations |
| 35 * - Supports nest/unnest which simulates a stack of stack. unnest will pop al
l the |
| 36 * objects pushed since the last nest |
| 37 */ |
| 38 |
| 39 template <typename T> class SkTDStackNester : SkNoncopyable { |
| 35 public: | 40 public: |
| 36 SkTDStackNew() : fCount(0), fTotalCount(0), fLocalCount(0) { | 41 SkTDStackNester() : fCount(0), fTotalCount(0), fLocalCount(0) { |
| 37 fInitialRec.fNext = NULL; | 42 fInitialRec.fNext = NULL; |
| 38 fRec = &fInitialRec; | 43 fRec = &fInitialRec; |
| 39 | 44 |
| 40 // fCount = kSlotCount; | 45 // fCount = kSlotCount; |
| 41 } | 46 } |
| 42 | 47 |
| 43 ~SkTDStackNew() { | 48 ~SkTDStackNester() { |
| 44 Rec* rec = fRec; | 49 Rec* rec = fRec; |
| 45 while (rec != &fInitialRec) { | 50 while (rec != &fInitialRec) { |
| 46 Rec* next = rec->fNext; | 51 Rec* next = rec->fNext; |
| 47 delete rec; | 52 delete rec; |
| 48 rec = next; | 53 rec = next; |
| 49 } | 54 } |
| 50 } | 55 } |
| 51 | 56 |
| 52 int count() const { return fLocalCount; } | 57 int count() const { return fLocalCount; } |
| 53 int depth() const { return fLocalCount; } | 58 int depth() const { return fLocalCount; } |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 Rec* fNext; | 155 Rec* fNext; |
| 151 T fSlots[kSlotCount]; | 156 T fSlots[kSlotCount]; |
| 152 }; | 157 }; |
| 153 Rec fInitialRec; | 158 Rec fInitialRec; |
| 154 Rec* fRec; | 159 Rec* fRec; |
| 155 int fCount, fTotalCount, fLocalCount; | 160 int fCount, fTotalCount, fLocalCount; |
| 156 int fNestings[MAX_NESTING]; | 161 int fNestings[MAX_NESTING]; |
| 157 int fNestingLevel; | 162 int fNestingLevel; |
| 158 }; | 163 }; |
| 159 | 164 |
| 160 // TODO(edisonn): better class design. | 165 /** \class SkTDStackNester |
| 166 * Operates on stroking or non-stroking properties. |
| 167 */ |
| 161 class SkPdfColorOperator { | 168 class SkPdfColorOperator { |
| 162 | 169 |
| 163 /* | 170 /* |
| 164 color space name or array The current color space in which color value
s are to be interpreted | 171 color space name or array The current color space in which color value
s are to be interpreted |
| 165 (see Section 4.5, “Color Spaces”). There are
two separate color space | 172 (see Section 4.5, “Color Spaces”). There are
two separate color space |
| 166 parameters: one for stroking and one for all
other painting opera- | 173 parameters: one for stroking and one for all
other painting opera- |
| 167 tions. Initial value: DeviceGray. | 174 tions. Initial value: DeviceGray. |
| 168 */ | 175 */ |
| 169 | 176 |
| 170 // TODO(edisonn): implement the array part too | 177 // TODO(edisonn): implement the array part too |
| 171 // does not own the char* | |
| 172 // TODO(edisonn): remove this public, let fields be private | 178 // TODO(edisonn): remove this public, let fields be private |
| 173 // TODO(edisonn): make color space an enum! | |
| 174 public: | 179 public: |
| 175 NotOwnedString fColorSpace; | 180 NotOwnedString fColorSpace; |
| 176 SkPdfNativeObject* fPattern; | 181 SkPdfNativeObject* fPattern; |
| 177 | 182 |
| 178 /* | 183 /* |
| 179 color (various) The current color to be used during painting
operations (see Section | 184 color (various) The current color to be used during painting
operations (see Section |
| 180 4.5, “Color Spaces”). The type and interpret
ation of this parameter | 185 4.5, “Color Spaces”). The type and interpret
ation of this parameter |
| 181 depend on the current color space; for most
color spaces, a color | 186 depend on the current color space; for most
color spaces, a color |
| 182 value consists of one to four numbers. There
are two separate color | 187 value consists of one to four numbers. There
are two separate color |
| 183 parameters: one for stroking and one for all
other painting opera- | 188 parameters: one for stroking and one for all
other painting opera- |
| 184 tions. Initial value: black. | 189 tions. Initial value: black. |
| 185 */ | 190 */ |
| 186 | 191 |
| 187 SkColor fColor; | 192 SkColor fColor; |
| 188 double fOpacity; // ca or CA | 193 double fOpacity; // ca or CA |
| 189 | 194 |
| 190 // TODO(edisonn): add here other color space options. | |
| 191 | |
| 192 public: | 195 public: |
| 193 void setRGBColor(SkColor color) { | 196 void setRGBColor(SkColor color) { |
| 194 // TODO(edisonn): ASSERT DeviceRGB is the color space. | 197 // TODO(edisonn): ASSERT DeviceRGB is the color space. |
| 195 fPattern = NULL; | 198 fPattern = NULL; |
| 196 fColor = color; | 199 fColor = color; |
| 197 } | 200 } |
| 198 // TODO(edisonn): double check the default values for all fields. | 201 |
| 202 // TODO(edisonn): implement the default values for all fields. |
| 199 SkPdfColorOperator() : fPattern(NULL), fColor(SK_ColorBLACK), fOpacity(1) { | 203 SkPdfColorOperator() : fPattern(NULL), fColor(SK_ColorBLACK), fOpacity(1) { |
| 200 NotOwnedString::init(&fColorSpace, "DeviceRGB"); | 204 NotOwnedString::init(&fColorSpace, "DeviceRGB"); |
| 201 } | 205 } |
| 202 | 206 |
| 203 void setColorSpace(NotOwnedString* colorSpace) { | 207 void setColorSpace(NotOwnedString* colorSpace) { |
| 204 fColorSpace = *colorSpace; | 208 fColorSpace = *colorSpace; |
| 205 fPattern = NULL; | 209 fPattern = NULL; |
| 206 } | 210 } |
| 207 | 211 |
| 208 void setPatternColorSpace(SkPdfNativeObject* pattern) { | 212 void setPatternColorSpace(SkPdfNativeObject* pattern) { |
| 209 fColorSpace.fBuffer = (const unsigned char*)"Pattern"; | 213 fColorSpace.fBuffer = (const unsigned char*)"Pattern"; |
| 210 fColorSpace.fBytes = 7; // strlen("Pattern") | 214 fColorSpace.fBytes = 7; // strlen("Pattern") |
| 211 fPattern = pattern; | 215 fPattern = pattern; |
| 212 } | 216 } |
| 213 | 217 |
| 214 void applyGraphicsState(SkPaint* paint) { | 218 void applyGraphicsState(SkPaint* paint) { |
| 215 paint->setColor(SkColorSetA(fColor, (U8CPU)(fOpacity * 255))); | 219 paint->setColor(SkColorSetA(fColor, (U8CPU)(fOpacity * 255))); |
| 216 } | 220 } |
| 217 }; | 221 }; |
| 218 | 222 |
| 219 // TODO(edisonn): better class design. | 223 /** \class SkTDStackNester |
| 224 * Operates on stroking or non-stroking properties. |
| 225 */ |
| 220 struct SkPdfGraphicsState { | 226 struct SkPdfGraphicsState { |
| 221 // TODO(edisonn): deprecate and remove these! | 227 // TODO(edisonn): deprecate and remove these! |
| 222 double fCurPosX; | 228 double fCurPosX; |
| 223 double fCurPosY; | 229 double fCurPosY; |
| 224 | 230 |
| 225 double fCurFontSize; | 231 double fCurFontSize; |
| 226 bool fTextBlock; | 232 bool fTextBlock; |
| 227 SkPdfFont* fSkFont; | 233 SkPdfFont* fSkFont; |
| 228 SkPath fPath; | 234 SkPath fPath; |
| 229 bool fPathClosed; | 235 bool fPathClosed; |
| 230 | 236 |
| 231 double fTextLeading; | 237 double fTextLeading; |
| 232 double fWordSpace; | 238 double fWordSpace; |
| 233 double fCharSpace; | 239 double fCharSpace; |
| 234 | 240 |
| 235 SkPdfResourceDictionary* fResources; | 241 SkPdfResourceDictionary* fResources; |
| 236 | 242 |
| 237 | 243 |
| 238 // TODO(edisonn): move most of these in canvas/paint? | 244 // TODO(edisonn): Can we move most of these in canvas/paint? |
| 239 // we could have some in canvas (matrixes?), | 245 // Might need to strore some properties in 2 paints (stroking paint and non
stroking paint) |
| 240 // some in 2 paints (stroking paint and non stroking paint) | |
| 241 | 246 |
| 242 // TABLE 4.2 Device-independent graphics state parameters | 247 // TABLE 4.2 Device-independent graphics state parameters |
| 243 /* | 248 /* |
| 244 * CTM array The current transformation matrix, which maps
positions from user | 249 * CTM array The current transformation matrix, which maps
positions from user |
| 245 coordinates to device coordinates (see Section 4
.2, “Coordinate Sys- | 250 coordinates to device coordinates (see Section 4
.2, “Coordinate Sys- |
| 246 tems”). This matrix is modified by each applicati
on of the coordi- | 251 tems”). This matrix is modified by each applicati
on of the coordi- |
| 247 nate transformation operator, cm. Initial value:
a matrix that | 252 nate transformation operator, cm. Initial value:
a matrix that |
| 248 transforms default user coordinates to device co
ordinates. | 253 transforms default user coordinates to device co
ordinates. |
| 249 */ | 254 */ |
| 250 SkMatrix fCTM; | 255 SkMatrix fCTM; |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 /* | 455 /* |
| 451 smoothness number (PDF 1.3) The precision with which col
or gradients are to be ren- | 456 smoothness number (PDF 1.3) The precision with which col
or gradients are to be ren- |
| 452 dered on the output device (see Sectio
n 6.5.2, “Smoothness Toler- | 457 dered on the output device (see Sectio
n 6.5.2, “Smoothness Toler- |
| 453 ance”). The value of this parameter gi
ves the maximum error | 458 ance”). The value of this parameter gi
ves the maximum error |
| 454 tolerance, expressed as a fraction of
the range of each color compo- | 459 tolerance, expressed as a fraction of
the range of each color compo- |
| 455 nent; smaller numbers give smoother co
lor transitions at the | 460 nent; smaller numbers give smoother co
lor transitions at the |
| 456 expense of more computation and memory
use. Initial value: | 461 expense of more computation and memory
use. Initial value: |
| 457 installation-dependent. | 462 installation-dependent. |
| 458 */ | 463 */ |
| 459 | 464 |
| 460 | |
| 461 | |
| 462 // TODO(edisonn): some defaults are contextual, they could on colorspace, pd
f version, ... | 465 // TODO(edisonn): some defaults are contextual, they could on colorspace, pd
f version, ... |
| 463 | |
| 464 SkPdfGraphicsState() { | 466 SkPdfGraphicsState() { |
| 465 fCurPosX = 0.0; | 467 fCurPosX = 0.0; |
| 466 fCurPosY = 0.0; | 468 fCurPosY = 0.0; |
| 467 fCurFontSize = 0.0; | 469 fCurFontSize = 0.0; |
| 468 fTextBlock = false; | 470 fTextBlock = false; |
| 469 fCTM = SkMatrix::I(); | 471 fCTM = SkMatrix::I(); |
| 470 fMatrixTm = SkMatrix::I(); | 472 fMatrixTm = SkMatrix::I(); |
| 471 fMatrixTlm = SkMatrix::I(); | 473 fMatrixTlm = SkMatrix::I(); |
| 472 fPathClosed = true; | 474 fPathClosed = true; |
| 473 fLineWidth = 0; | 475 fLineWidth = 0; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 486 fDashPhase = 0; | 488 fDashPhase = 0; |
| 487 fBlendModesLength = 1; | 489 fBlendModesLength = 1; |
| 488 fBlendModes[0] = SkXfermode::kSrc_Mode; // PDF: Normal Blend mode | 490 fBlendModes[0] = SkXfermode::kSrc_Mode; // PDF: Normal Blend mode |
| 489 fSMask = NULL; | 491 fSMask = NULL; |
| 490 } | 492 } |
| 491 | 493 |
| 492 // TODO(edisonn): make two functions instead, stroking and non stoking, avoi
d branching | 494 // TODO(edisonn): make two functions instead, stroking and non stoking, avoi
d branching |
| 493 void applyGraphicsState(SkPaint* paint, bool stroking); | 495 void applyGraphicsState(SkPaint* paint, bool stroking); |
| 494 }; | 496 }; |
| 495 | 497 |
| 498 /** \class SkPdfContext |
| 499 * The context of the drawing. The document we draw from, the current stack of
objects, ... |
| 500 */ |
| 496 class SkPdfContext { | 501 class SkPdfContext { |
| 497 public: | 502 public: |
| 498 SkTDStackNew<SkPdfNativeObject*> fObjectStack; | 503 SkTDStackNester<SkPdfNativeObject*> fObjectStack; |
| 499 SkTDStackNew<SkPdfGraphicsState> fStateStack; | 504 SkTDStackNester<SkPdfGraphicsState> fStateStack; |
| 500 SkPdfGraphicsState fGraphicsState; | 505 SkPdfGraphicsState fGraphicsState; |
| 501 SkPdfNativeDoc* fPdfDoc; | 506 SkPdfNativeDoc* fPdfDoc; |
| 502 // TODO(edisonn): the allocator, could be freed after the page is done drawi
ng, so we have the | |
| 503 // pixels on the screen asap. | |
| 504 SkPdfAllocator* fTmpPageAllocator; | 507 SkPdfAllocator* fTmpPageAllocator; |
| 505 SkMatrix fOriginalMatrix; | 508 SkMatrix fOriginalMatrix; |
| 506 | 509 |
| 507 SkPdfContext(SkPdfNativeDoc* doc); | 510 SkPdfContext(SkPdfNativeDoc* doc); |
| 508 ~SkPdfContext(); | 511 ~SkPdfContext(); |
| 509 }; | 512 }; |
| 510 | 513 |
| 511 #endif // SkPdfGraphicsState_DEFINED | 514 #endif // SkPdfGraphicsState_DEFINED |
| OLD | NEW |