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 //#include "SkTDStack.h" | 16 //#include "SkTDStack.h" |
17 | 17 |
18 class SkPdfFont; | 18 class SkPdfFont; |
19 class SkPdfDoc; | 19 class SkPdfDoc; |
20 class SkPdfNativeObject; | 20 class SkPdfNativeObject; |
21 class SkPdfResourceDictionary; | 21 class SkPdfResourceDictionary; |
22 class SkPdfSoftMaskDictionary; | 22 class SkPdfSoftMaskDictionary; |
23 | 23 |
24 class SkPdfNativeDoc; | 24 class SkPdfNativeDoc; |
25 class SkPdfAllocator; | 25 class SkPdfAllocator; |
26 | 26 |
27 // TODO(edisonn): move this class in iclude/core? | 27 // TODO(edisonn): move this class in include/core? |
28 // Ref objects can't be dealt unless we use a specific class initialization | 28 // Ref objects can't be dealt unless we use a specific class initialization |
29 // The difference between SkTDStackNew and SkTDStack is that SkTDStackNew uses n
ew/delete | 29 // The difference between SkTDStackNew and SkTDStack is that SkTDStackNew uses n
ew/delete |
30 // to be a manage c++ stuff (like initializations) | 30 // to be a manage c++ stuff (like initializations) |
| 31 |
| 32 // Adobe limits it to 28, so 256 should be more than enough |
| 33 #define MAX_NESTING 256 |
| 34 |
31 #include "SkTypes.h" | 35 #include "SkTypes.h" |
32 template <typename T> class SkTDStackNew : SkNoncopyable { | 36 template <typename T> class SkTDStackNew : SkNoncopyable { |
33 public: | 37 public: |
34 SkTDStackNew() : fCount(0), fTotalCount(0) { | 38 SkTDStackNew() : fCount(0), fTotalCount(0), fLocalCount(0) { |
35 fInitialRec.fNext = NULL; | 39 fInitialRec.fNext = NULL; |
36 fRec = &fInitialRec; | 40 fRec = &fInitialRec; |
37 | 41 |
38 // fCount = kSlotCount; | 42 // fCount = kSlotCount; |
39 } | 43 } |
40 | 44 |
41 ~SkTDStackNew() { | 45 ~SkTDStackNew() { |
42 Rec* rec = fRec; | 46 Rec* rec = fRec; |
43 while (rec != &fInitialRec) { | 47 while (rec != &fInitialRec) { |
44 Rec* next = rec->fNext; | 48 Rec* next = rec->fNext; |
45 delete rec; | 49 delete rec; |
46 rec = next; | 50 rec = next; |
47 } | 51 } |
48 } | 52 } |
49 | 53 |
50 int count() const { return fTotalCount; } | 54 int count() const { return fLocalCount; } |
51 int depth() const { return fTotalCount; } | 55 int depth() const { return fLocalCount; } |
52 bool empty() const { return fTotalCount == 0; } | 56 bool empty() const { return fLocalCount == 0; } |
| 57 |
| 58 bool nests() { |
| 59 return fNestingLevel; |
| 60 } |
| 61 |
| 62 void nest() { |
| 63 // We are are past max nesting levels, we will still continue to work, b
ut we might fail |
| 64 // to properly ignore errors. Ideally it should only mean poor rendering
in exceptional |
| 65 // cases |
| 66 if (fNestingLevel >= 0 && fNestingLevel < MAX_NESTING) { |
| 67 fNestings[fNestingLevel] = fLocalCount; |
| 68 fLocalCount = 0; |
| 69 } |
| 70 fNestingLevel++; |
| 71 } |
| 72 |
| 73 void unnest() { |
| 74 SkASSERT(fNestingLevel > 0); |
| 75 fNestingLevel--; |
| 76 if (fNestingLevel >= 0 && fNestingLevel < MAX_NESTING) { |
| 77 // TODO(edisonn): warn if fLocal > 0 |
| 78 while (fLocalCount > 0) { |
| 79 pop(); |
| 80 } |
| 81 fLocalCount = fNestings[fNestingLevel]; |
| 82 } |
| 83 } |
53 | 84 |
54 T* push() { | 85 T* push() { |
55 SkASSERT(fCount <= kSlotCount); | 86 SkASSERT(fCount <= kSlotCount); |
56 if (fCount == kSlotCount) { | 87 if (fCount == kSlotCount) { |
57 Rec* rec = new Rec(); | 88 Rec* rec = new Rec(); |
58 rec->fNext = fRec; | 89 rec->fNext = fRec; |
59 fRec = rec; | 90 fRec = rec; |
60 fCount = 0; | 91 fCount = 0; |
61 } | 92 } |
62 ++fTotalCount; | 93 ++fTotalCount; |
| 94 ++fLocalCount; |
63 return &fRec->fSlots[fCount++]; | 95 return &fRec->fSlots[fCount++]; |
64 } | 96 } |
65 | 97 |
66 void push(const T& elem) { *this->push() = elem; } | 98 void push(const T& elem) { *this->push() = elem; } |
67 | 99 |
68 const T& index(int idx) const { | 100 const T& index(int idx) const { |
69 SkASSERT(fRec && fCount > idx); | 101 SkASSERT(fRec && fCount > idx); |
70 return fRec->fSlots[fCount - idx - 1]; | 102 return fRec->fSlots[fCount - idx - 1]; |
71 } | 103 } |
72 | 104 |
(...skipping 14 matching lines...) Expand all Loading... |
87 | 119 |
88 void pop(T* elem) { | 120 void pop(T* elem) { |
89 if (elem) { | 121 if (elem) { |
90 *elem = fRec->fSlots[fCount - 1]; | 122 *elem = fRec->fSlots[fCount - 1]; |
91 } | 123 } |
92 this->pop(); | 124 this->pop(); |
93 } | 125 } |
94 | 126 |
95 void pop() { | 127 void pop() { |
96 SkASSERT(fCount > 0 && fRec); | 128 SkASSERT(fCount > 0 && fRec); |
| 129 --fLocalCount; |
97 --fTotalCount; | 130 --fTotalCount; |
98 if (--fCount == 0) { | 131 if (--fCount == 0) { |
99 if (fRec != &fInitialRec) { | 132 if (fRec != &fInitialRec) { |
100 Rec* rec = fRec->fNext; | 133 Rec* rec = fRec->fNext; |
101 delete fRec; | 134 delete fRec; |
102 fCount = kSlotCount; | 135 fCount = kSlotCount; |
103 fRec = rec; | 136 fRec = rec; |
104 } else { | 137 } else { |
105 SkASSERT(fTotalCount == 0); | 138 SkASSERT(fTotalCount == 0); |
106 } | 139 } |
107 } | 140 } |
108 } | 141 } |
109 | 142 |
110 private: | 143 private: |
111 enum { | 144 enum { |
112 kSlotCount = 64 | 145 kSlotCount = 64 |
113 }; | 146 }; |
114 | 147 |
115 struct Rec; | 148 struct Rec; |
116 friend struct Rec; | 149 friend struct Rec; |
117 | 150 |
118 struct Rec { | 151 struct Rec { |
119 Rec* fNext; | 152 Rec* fNext; |
120 T fSlots[kSlotCount]; | 153 T fSlots[kSlotCount]; |
121 }; | 154 }; |
122 Rec fInitialRec; | 155 Rec fInitialRec; |
123 Rec* fRec; | 156 Rec* fRec; |
124 int fCount, fTotalCount; | 157 int fCount, fTotalCount, fLocalCount; |
| 158 int fNestings[MAX_NESTING]; |
| 159 int fNestingLevel; |
125 }; | 160 }; |
126 | 161 |
127 // TODO(edisonn): better class design. | 162 // TODO(edisonn): better class design. |
128 class SkPdfColorOperator { | 163 class SkPdfColorOperator { |
129 | 164 |
130 /* | 165 /* |
131 color space name or array The current color space in which color value
s are to be interpreted | 166 color space name or array The current color space in which color value
s are to be interpreted |
132 (see Section 4.5, “Color Spaces”). There are
two separate color space | 167 (see Section 4.5, “Color Spaces”). There are
two separate color space |
133 parameters: one for stroking and one for all
other painting opera- | 168 parameters: one for stroking and one for all
other painting opera- |
134 tions. Initial value: DeviceGray. | 169 tions. Initial value: DeviceGray. |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 SkPdfNativeDoc* fPdfDoc; | 507 SkPdfNativeDoc* fPdfDoc; |
473 // TODO(edisonn): the allocator, could be freed after the page is done drawi
ng. | 508 // TODO(edisonn): the allocator, could be freed after the page is done drawi
ng. |
474 SkPdfAllocator* fTmpPageAllocator; | 509 SkPdfAllocator* fTmpPageAllocator; |
475 SkMatrix fOriginalMatrix; | 510 SkMatrix fOriginalMatrix; |
476 | 511 |
477 SkPdfContext(SkPdfNativeDoc* doc); | 512 SkPdfContext(SkPdfNativeDoc* doc); |
478 ~SkPdfContext(); | 513 ~SkPdfContext(); |
479 }; | 514 }; |
480 | 515 |
481 #endif // SkPdfGraphicsState_DEFINED | 516 #endif // SkPdfGraphicsState_DEFINED |
OLD | NEW |