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