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