| 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 | 7 |
| 7 #include <iostream> | 8 #include <iostream> |
| 8 #include <cstdio> | 9 #include <cstdio> |
| 10 #include <map> |
| 9 #include <stack> | 11 #include <stack> |
| 10 | 12 |
| 11 #define PDF_TRACE | |
| 12 //#define PDF_TRACE_DIFF_IN_PNG | |
| 13 //#define PDF_DEBUG_NO_CLIPING | |
| 14 //#define PDF_DEBUG_NO_PAGE_CLIPING | |
| 15 //#define PDF_DEBUG_3X | |
| 16 | |
| 17 class SkPdfFont; | 13 class SkPdfFont; |
| 18 class SkPdfDoc; | 14 class SkPdfDoc; |
| 19 class SkPdfObject; | 15 class SkPdfObject; |
| 20 class SkPdfResourceDictionary; | 16 class SkPdfResourceDictionary; |
| 21 | 17 |
| 18 class SkPodofoParsedPDF; |
| 19 |
| 22 // TODO(edisonn): better class design. | 20 // TODO(edisonn): better class design. |
| 23 struct PdfColorOperator { | 21 struct SkPdfColorOperator { |
| 24 std::string fColorSpace; // TODO(edisonn): use SkString | 22 std::string fColorSpace; // TODO(edisonn): use SkString |
| 25 SkColor fColor; | 23 SkColor fColor; |
| 26 double fOpacity; // ca or CA | 24 double fOpacity; // ca or CA |
| 27 // TODO(edisonn): add here other color space options. | 25 // TODO(edisonn): add here other color space options. |
| 28 | 26 |
| 29 void setRGBColor(SkColor color) { | 27 void setRGBColor(SkColor color) { |
| 30 // TODO(edisonn): ASSERT DeviceRGB is the color space. | 28 // TODO(edisonn): ASSERT DeviceRGB is the color space. |
| 31 fColor = color; | 29 fColor = color; |
| 32 } | 30 } |
| 33 // TODO(edisonn): double check the default values for all fields. | 31 // TODO(edisonn): double check the default values for all fields. |
| 34 PdfColorOperator() : fColor(SK_ColorBLACK), fOpacity(1) {} | 32 SkPdfColorOperator() : fColor(SK_ColorBLACK), fOpacity(1) {} |
| 35 | 33 |
| 36 void applyGraphicsState(SkPaint* paint) { | 34 void applyGraphicsState(SkPaint* paint) { |
| 37 paint->setColor(SkColorSetA(fColor, fOpacity * 255)); | 35 paint->setColor(SkColorSetA(fColor, fOpacity * 255)); |
| 38 } | 36 } |
| 39 }; | 37 }; |
| 40 | 38 |
| 41 // TODO(edisonn): better class design. | 39 // TODO(edisonn): better class design. |
| 42 struct PdfGraphicsState { | 40 struct SkPdfGraphicsState { |
| 43 SkMatrix fMatrix; | 41 SkMatrix fMatrix; |
| 44 SkMatrix fMatrixTm; | 42 SkMatrix fMatrixTm; |
| 45 SkMatrix fMatrixTlm; | 43 SkMatrix fMatrixTlm; |
| 46 | 44 |
| 47 double fCurPosX; | 45 double fCurPosX; |
| 48 double fCurPosY; | 46 double fCurPosY; |
| 49 | 47 |
| 50 double fCurFontSize; | 48 double fCurFontSize; |
| 51 bool fTextBlock; | 49 bool fTextBlock; |
| 52 SkPdfFont* fSkFont; | 50 SkPdfFont* fSkFont; |
| 53 SkPath fPath; | 51 SkPath fPath; |
| 54 bool fPathClosed; | 52 bool fPathClosed; |
| 55 | 53 |
| 56 // Clip that is applied after the drawing is done!!! | 54 // Clip that is applied after the drawing is done!!! |
| 57 bool fHasClipPathToApply; | 55 bool fHasClipPathToApply; |
| 58 SkPath fClipPath; | 56 SkPath fClipPath; |
| 59 | 57 |
| 60 PdfColorOperator fStroking; | 58 SkPdfColorOperator fStroking; |
| 61 PdfColorOperator fNonStroking; | 59 SkPdfColorOperator fNonStroking; |
| 62 | 60 |
| 63 double fLineWidth; | 61 double fLineWidth; |
| 64 double fTextLeading; | 62 double fTextLeading; |
| 65 double fWordSpace; | 63 double fWordSpace; |
| 66 double fCharSpace; | 64 double fCharSpace; |
| 67 | 65 |
| 68 SkPdfResourceDictionary* fResources; | 66 const SkPdfResourceDictionary* fResources; |
| 69 | 67 |
| 70 SkBitmap fSMask; | 68 SkBitmap fSMask; |
| 71 | 69 |
| 72 PdfGraphicsState() { | 70 SkPdfGraphicsState() { |
| 73 fCurPosX = 0.0; | 71 fCurPosX = 0.0; |
| 74 fCurPosY = 0.0; | 72 fCurPosY = 0.0; |
| 75 fCurFontSize = 0.0; | 73 fCurFontSize = 0.0; |
| 76 fTextBlock = false; | 74 fTextBlock = false; |
| 77 fMatrix = SkMatrix::I(); | 75 fMatrix = SkMatrix::I(); |
| 78 fMatrixTm = SkMatrix::I(); | 76 fMatrixTm = SkMatrix::I(); |
| 79 fMatrixTlm = SkMatrix::I(); | 77 fMatrixTlm = SkMatrix::I(); |
| 80 fPathClosed = true; | 78 fPathClosed = true; |
| 81 fLineWidth = 0; | 79 fLineWidth = 0; |
| 82 fTextLeading = 0; | 80 fTextLeading = 0; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 97 // TODO(edisonn): get this from pdfContext->options, | 95 // TODO(edisonn): get this from pdfContext->options, |
| 98 // or pdfContext->addPaintOptions(&paint); | 96 // or pdfContext->addPaintOptions(&paint); |
| 99 paint->setAntiAlias(true); | 97 paint->setAntiAlias(true); |
| 100 | 98 |
| 101 // TODO(edisonn): dashing, miter, ... | 99 // TODO(edisonn): dashing, miter, ... |
| 102 paint->setStrokeWidth(SkDoubleToScalar(fLineWidth)); | 100 paint->setStrokeWidth(SkDoubleToScalar(fLineWidth)); |
| 103 } | 101 } |
| 104 }; | 102 }; |
| 105 | 103 |
| 106 // TODO(edisonn): better class design. | 104 // TODO(edisonn): better class design. |
| 107 struct PdfInlineImage { | 105 // TODO(edisonn): could we remove it? |
| 106 // TODO(edisonn): rename to SkPdfInlineImage |
| 107 struct SkPdfInlineImage { |
| 108 std::map<std::string, std::string> fKeyValuePairs; | 108 std::map<std::string, std::string> fKeyValuePairs; |
| 109 std::string fImageData; | 109 std::string fImageData; |
| 110 }; | 110 }; |
| 111 | 111 |
| 112 // TODO(edisonn): better class design. | 112 // TODO(edisonn): better class design. |
| 113 // TODO(edisonn): rename to SkPdfContext |
| 113 struct PdfContext { | 114 struct PdfContext { |
| 114 std::stack<SkPdfObject*> fObjectStack; | 115 std::stack<SkPdfObject*> fObjectStack; |
| 115 std::stack<PdfGraphicsState> fStateStack; | 116 std::stack<SkPdfGraphicsState> fStateStack; |
| 116 PdfGraphicsState fGraphicsState; | 117 SkPdfGraphicsState fGraphicsState; |
| 117 SkPdfDoc* fPdfDoc; | 118 const SkPodofoParsedPDF* fPdfDoc; |
| 118 SkMatrix fOriginalMatrix; | 119 SkMatrix fOriginalMatrix; |
| 119 | 120 |
| 120 PdfInlineImage fInlineImage; | 121 SkPdfInlineImage fInlineImage; |
| 121 | 122 |
| 122 PdfContext(SkPdfDoc* doc) : fPdfDoc(doc) {} | 123 PdfContext(const SkPodofoParsedPDF* doc) : fPdfDoc(doc) {} |
| 123 | 124 |
| 124 }; | 125 }; |
| 125 | 126 |
| 126 // TODO(edisonn): temporary code, to report how much of the PDF we actually thi
nk we rendered. | 127 // TODO(edisonn): temporary code, to report how much of the PDF we actually thin
k we rendered. |
| 128 // TODO(edisonn): rename to SkPdfResult |
| 127 enum PdfResult { | 129 enum PdfResult { |
| 128 kOK_PdfResult, | 130 kOK_PdfResult, |
| 129 kPartial_PdfResult, | 131 kPartial_PdfResult, |
| 130 kNYI_PdfResult, | 132 kNYI_PdfResult, |
| 131 kIgnoreError_PdfResult, | 133 kIgnoreError_PdfResult, |
| 132 kError_PdfResult, | 134 kError_PdfResult, |
| 133 kUnsupported_PdfResult, | 135 kUnsupported_PdfResult, |
| 134 | 136 |
| 135 kCount_PdfResult | 137 kCount_PdfResult |
| 136 }; | 138 }; |
| 137 | 139 |
| 138 #endif // __DEFINED__SkPdfBasics | 140 #endif // __DEFINED__SkPdfBasics |
| OLD | NEW |