| 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 #include "SkPdfUtils.h" | 7 #include "SkPdfUtils.h" |
| 8 | 8 |
| 9 #include <stack> | 9 //#include "SkTDStack.h" |
| 10 | 10 |
| 11 class SkPdfFont; | 11 class SkPdfFont; |
| 12 class SkPdfDoc; | 12 class SkPdfDoc; |
| 13 class SkPdfNativeObject; | 13 class SkPdfNativeObject; |
| 14 class SkPdfResourceDictionary; | 14 class SkPdfResourceDictionary; |
| 15 class SkPdfSoftMaskDictionary; | 15 class SkPdfSoftMaskDictionary; |
| 16 | 16 |
| 17 class SkPdfNativeDoc; | 17 class SkPdfNativeDoc; |
| 18 class SkPdfAllocator; | 18 class SkPdfAllocator; |
| 19 | 19 |
| 20 // TODO(edisonn): move this class in iclude/core? |
| 21 // Ref objects can't be dealt unless we use a specific class initialization |
| 22 // The difference between SkTDStackNew and SkTDStack is that SkTDStackNew uses n
ew/delete |
| 23 // to be a manage c++ stuff (like initializations) |
| 24 #include "SkTypes.h" |
| 25 template <typename T> class SkTDStackNew : SkNoncopyable { |
| 26 public: |
| 27 SkTDStackNew() : fCount(0), fTotalCount(0) { |
| 28 fInitialRec.fNext = NULL; |
| 29 fRec = &fInitialRec; |
| 30 |
| 31 // fCount = kSlotCount; |
| 32 } |
| 33 |
| 34 ~SkTDStackNew() { |
| 35 Rec* rec = fRec; |
| 36 while (rec != &fInitialRec) { |
| 37 Rec* next = rec->fNext; |
| 38 delete rec; |
| 39 rec = next; |
| 40 } |
| 41 } |
| 42 |
| 43 int count() const { return fTotalCount; } |
| 44 int depth() const { return fTotalCount; } |
| 45 bool empty() const { return fTotalCount == 0; } |
| 46 |
| 47 T* push() { |
| 48 SkASSERT(fCount <= kSlotCount); |
| 49 if (fCount == kSlotCount) { |
| 50 Rec* rec = new Rec(); |
| 51 rec->fNext = fRec; |
| 52 fRec = rec; |
| 53 fCount = 0; |
| 54 } |
| 55 ++fTotalCount; |
| 56 return &fRec->fSlots[fCount++]; |
| 57 } |
| 58 |
| 59 void push(const T& elem) { *this->push() = elem; } |
| 60 |
| 61 const T& index(int idx) const { |
| 62 SkASSERT(fRec && fCount > idx); |
| 63 return fRec->fSlots[fCount - idx - 1]; |
| 64 } |
| 65 |
| 66 T& index(int idx) { |
| 67 SkASSERT(fRec && fCount > idx); |
| 68 return fRec->fSlots[fCount - idx - 1]; |
| 69 } |
| 70 |
| 71 const T& top() const { |
| 72 SkASSERT(fRec && fCount > 0); |
| 73 return fRec->fSlots[fCount - 1]; |
| 74 } |
| 75 |
| 76 T& top() { |
| 77 SkASSERT(fRec && fCount > 0); |
| 78 return fRec->fSlots[fCount - 1]; |
| 79 } |
| 80 |
| 81 void pop(T* elem) { |
| 82 if (elem) { |
| 83 *elem = fRec->fSlots[fCount - 1]; |
| 84 } |
| 85 this->pop(); |
| 86 } |
| 87 |
| 88 void pop() { |
| 89 SkASSERT(fCount > 0 && fRec); |
| 90 --fTotalCount; |
| 91 if (--fCount == 0) { |
| 92 if (fRec != &fInitialRec) { |
| 93 Rec* rec = fRec->fNext; |
| 94 delete fRec; |
| 95 fCount = kSlotCount; |
| 96 fRec = rec; |
| 97 } else { |
| 98 SkASSERT(fTotalCount == 0); |
| 99 } |
| 100 } |
| 101 } |
| 102 |
| 103 private: |
| 104 enum { |
| 105 kSlotCount = 64 |
| 106 }; |
| 107 |
| 108 struct Rec; |
| 109 friend struct Rec; |
| 110 |
| 111 struct Rec { |
| 112 Rec* fNext; |
| 113 T fSlots[kSlotCount]; |
| 114 }; |
| 115 Rec fInitialRec; |
| 116 Rec* fRec; |
| 117 int fCount, fTotalCount; |
| 118 }; |
| 119 |
| 20 // TODO(edisonn): better class design. | 120 // TODO(edisonn): better class design. |
| 21 class SkPdfColorOperator { | 121 class SkPdfColorOperator { |
| 22 | 122 |
| 23 /* | 123 /* |
| 24 color space name or array The current color space in which color value
s are to be interpreted | 124 color space name or array The current color space in which color value
s are to be interpreted |
| 25 (see Section 4.5, “Color Spaces”). There are
two separate color space | 125 (see Section 4.5, “Color Spaces”). There are
two separate color space |
| 26 parameters: one for stroking and one for all
other painting opera- | 126 parameters: one for stroking and one for all
other painting opera- |
| 27 tions. Initial value: DeviceGray. | 127 tions. Initial value: DeviceGray. |
| 28 */ | 128 */ |
| 29 | 129 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 // TODO(edisonn): deprecate and remove these! | 181 // TODO(edisonn): deprecate and remove these! |
| 82 double fCurPosX; | 182 double fCurPosX; |
| 83 double fCurPosY; | 183 double fCurPosY; |
| 84 | 184 |
| 85 double fCurFontSize; | 185 double fCurFontSize; |
| 86 bool fTextBlock; | 186 bool fTextBlock; |
| 87 SkPdfFont* fSkFont; | 187 SkPdfFont* fSkFont; |
| 88 SkPath fPath; | 188 SkPath fPath; |
| 89 bool fPathClosed; | 189 bool fPathClosed; |
| 90 | 190 |
| 91 | |
| 92 | |
| 93 double fTextLeading; | 191 double fTextLeading; |
| 94 double fWordSpace; | 192 double fWordSpace; |
| 95 double fCharSpace; | 193 double fCharSpace; |
| 96 | 194 |
| 97 SkPdfResourceDictionary* fResources; | 195 SkPdfResourceDictionary* fResources; |
| 98 | 196 |
| 99 | 197 |
| 100 // TODO(edisonn): move most of these in canvas/paint? | 198 // TODO(edisonn): move most of these in canvas/paint? |
| 101 // we could have some in canvas (matrixes?), | 199 // we could have some in canvas (matrixes?), |
| 102 // some in 2 paints (stroking paint and non stroking paint) | 200 // some in 2 paints (stroking paint and non stroking paint) |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 } | 452 } |
| 355 | 453 |
| 356 // TODO(edisonn): make two functons instead, stroking and non stoking, avoid
branching | 454 // TODO(edisonn): make two functons instead, stroking and non stoking, avoid
branching |
| 357 void applyGraphicsState(SkPaint* paint, bool stroking); | 455 void applyGraphicsState(SkPaint* paint, bool stroking); |
| 358 }; | 456 }; |
| 359 | 457 |
| 360 // TODO(edisonn): better class design. | 458 // TODO(edisonn): better class design. |
| 361 // TODO(edisonn): rename to SkPdfContext | 459 // TODO(edisonn): rename to SkPdfContext |
| 362 class SkPdfContext { | 460 class SkPdfContext { |
| 363 public: | 461 public: |
| 364 std::stack<SkPdfNativeObject*> fObjectStack; | 462 SkTDStackNew<SkPdfNativeObject*> fObjectStack; |
| 365 std::stack<SkPdfGraphicsState> fStateStack; | 463 SkTDStackNew<SkPdfGraphicsState> fStateStack; |
| 366 SkPdfGraphicsState fGraphicsState; | 464 SkPdfGraphicsState fGraphicsState; |
| 367 SkPdfNativeDoc* fPdfDoc; | 465 SkPdfNativeDoc* fPdfDoc; |
| 368 // TODO(edisonn): the allocator, could be freed after the page is done drawi
ng. | 466 // TODO(edisonn): the allocator, could be freed after the page is done drawi
ng. |
| 369 SkPdfAllocator* fTmpPageAllocator; | 467 SkPdfAllocator* fTmpPageAllocator; |
| 370 SkMatrix fOriginalMatrix; | 468 SkMatrix fOriginalMatrix; |
| 371 | 469 |
| 372 SkPdfContext(SkPdfNativeDoc* doc); | 470 SkPdfContext(SkPdfNativeDoc* doc); |
| 373 ~SkPdfContext(); | 471 ~SkPdfContext(); |
| 374 }; | 472 }; |
| 375 | 473 |
| 376 #endif // __DEFINED__SkPdfBasics | 474 #endif // __DEFINED__SkPdfBasics |
| OLD | NEW |