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