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 | 3aac1f9 | 2013-07-02 22:42:53 +0000 | [diff] [blame] | 19 | |
edisonn@google.com | b857a0c | 2013-06-25 20:45:40 +0000 | [diff] [blame] | 20 | // TODO(edisonn): better class design. |
edisonn@google.com | 3aac1f9 | 2013-07-02 22:42:53 +0000 | [diff] [blame] | 21 | struct SkPdfColorOperator { |
edisonn@google.com | 571c70b | 2013-07-10 17:09:50 +0000 | [diff] [blame] | 22 | // does not own the char* |
| 23 | const char* fColorSpace; // TODO(edisonn): use SkString, or even char* |
edisonn@google.com | b857a0c | 2013-06-25 20:45:40 +0000 | [diff] [blame] | 24 | SkColor fColor; |
| 25 | double fOpacity; // ca or CA |
| 26 | // TODO(edisonn): add here other color space options. |
| 27 | |
| 28 | void setRGBColor(SkColor color) { |
| 29 | // TODO(edisonn): ASSERT DeviceRGB is the color space. |
| 30 | fColor = color; |
| 31 | } |
| 32 | // TODO(edisonn): double check the default values for all fields. |
edisonn@google.com | 571c70b | 2013-07-10 17:09:50 +0000 | [diff] [blame] | 33 | SkPdfColorOperator() : fColorSpace(NULL), fColor(SK_ColorBLACK), fOpacity(1) {} |
edisonn@google.com | b857a0c | 2013-06-25 20:45:40 +0000 | [diff] [blame] | 34 | |
| 35 | void applyGraphicsState(SkPaint* paint) { |
| 36 | paint->setColor(SkColorSetA(fColor, fOpacity * 255)); |
| 37 | } |
| 38 | }; |
| 39 | |
| 40 | // TODO(edisonn): better class design. |
edisonn@google.com | 3aac1f9 | 2013-07-02 22:42:53 +0000 | [diff] [blame] | 41 | struct SkPdfGraphicsState { |
edisonn@google.com | b857a0c | 2013-06-25 20:45:40 +0000 | [diff] [blame] | 42 | SkMatrix fMatrix; |
| 43 | SkMatrix fMatrixTm; |
| 44 | SkMatrix fMatrixTlm; |
| 45 | |
| 46 | double fCurPosX; |
| 47 | double fCurPosY; |
| 48 | |
| 49 | double fCurFontSize; |
| 50 | bool fTextBlock; |
| 51 | SkPdfFont* fSkFont; |
| 52 | SkPath fPath; |
| 53 | bool fPathClosed; |
| 54 | |
| 55 | // Clip that is applied after the drawing is done!!! |
| 56 | bool fHasClipPathToApply; |
| 57 | SkPath fClipPath; |
| 58 | |
edisonn@google.com | 3aac1f9 | 2013-07-02 22:42:53 +0000 | [diff] [blame] | 59 | SkPdfColorOperator fStroking; |
| 60 | SkPdfColorOperator fNonStroking; |
edisonn@google.com | b857a0c | 2013-06-25 20:45:40 +0000 | [diff] [blame] | 61 | |
| 62 | double fLineWidth; |
| 63 | double fTextLeading; |
| 64 | double fWordSpace; |
| 65 | double fCharSpace; |
| 66 | |
edisonn@google.com | 571c70b | 2013-07-10 17:09:50 +0000 | [diff] [blame] | 67 | SkPdfResourceDictionary* fResources; |
edisonn@google.com | b857a0c | 2013-06-25 20:45:40 +0000 | [diff] [blame] | 68 | |
| 69 | SkBitmap fSMask; |
| 70 | |
edisonn@google.com | 3aac1f9 | 2013-07-02 22:42:53 +0000 | [diff] [blame] | 71 | SkPdfGraphicsState() { |
edisonn@google.com | b857a0c | 2013-06-25 20:45:40 +0000 | [diff] [blame] | 72 | fCurPosX = 0.0; |
| 73 | fCurPosY = 0.0; |
| 74 | fCurFontSize = 0.0; |
| 75 | fTextBlock = false; |
| 76 | fMatrix = SkMatrix::I(); |
| 77 | fMatrixTm = SkMatrix::I(); |
| 78 | fMatrixTlm = SkMatrix::I(); |
| 79 | fPathClosed = true; |
| 80 | fLineWidth = 0; |
| 81 | fTextLeading = 0; |
| 82 | fWordSpace = 0; |
| 83 | fCharSpace = 0; |
| 84 | fHasClipPathToApply = false; |
| 85 | fResources = NULL; |
| 86 | fSkFont = NULL; |
| 87 | } |
| 88 | |
| 89 | void applyGraphicsState(SkPaint* paint, bool stroking) { |
| 90 | if (stroking) { |
| 91 | fStroking.applyGraphicsState(paint); |
| 92 | } else { |
| 93 | fNonStroking.applyGraphicsState(paint); |
| 94 | } |
| 95 | |
| 96 | // TODO(edisonn): get this from pdfContext->options, |
| 97 | // or pdfContext->addPaintOptions(&paint); |
| 98 | paint->setAntiAlias(true); |
| 99 | |
| 100 | // TODO(edisonn): dashing, miter, ... |
| 101 | paint->setStrokeWidth(SkDoubleToScalar(fLineWidth)); |
| 102 | } |
| 103 | }; |
| 104 | |
| 105 | // TODO(edisonn): better class design. |
edisonn@google.com | 3aac1f9 | 2013-07-02 22:42:53 +0000 | [diff] [blame] | 106 | // TODO(edisonn): could we remove it? |
| 107 | // TODO(edisonn): rename to SkPdfInlineImage |
| 108 | struct SkPdfInlineImage { |
edisonn@google.com | b857a0c | 2013-06-25 20:45:40 +0000 | [diff] [blame] | 109 | std::map<std::string, std::string> fKeyValuePairs; |
| 110 | std::string fImageData; |
| 111 | }; |
| 112 | |
| 113 | // TODO(edisonn): better class design. |
edisonn@google.com | 3aac1f9 | 2013-07-02 22:42:53 +0000 | [diff] [blame] | 114 | // TODO(edisonn): rename to SkPdfContext |
edisonn@google.com | b857a0c | 2013-06-25 20:45:40 +0000 | [diff] [blame] | 115 | struct PdfContext { |
| 116 | std::stack<SkPdfObject*> fObjectStack; |
edisonn@google.com | 3aac1f9 | 2013-07-02 22:42:53 +0000 | [diff] [blame] | 117 | std::stack<SkPdfGraphicsState> fStateStack; |
| 118 | SkPdfGraphicsState fGraphicsState; |
edisonn@google.com | 571c70b | 2013-07-10 17:09:50 +0000 | [diff] [blame] | 119 | SkNativeParsedPDF* fPdfDoc; |
edisonn@google.com | b857a0c | 2013-06-25 20:45:40 +0000 | [diff] [blame] | 120 | SkMatrix fOriginalMatrix; |
| 121 | |
edisonn@google.com | 3aac1f9 | 2013-07-02 22:42:53 +0000 | [diff] [blame] | 122 | SkPdfInlineImage fInlineImage; |
edisonn@google.com | b857a0c | 2013-06-25 20:45:40 +0000 | [diff] [blame] | 123 | |
edisonn@google.com | 571c70b | 2013-07-10 17:09:50 +0000 | [diff] [blame] | 124 | PdfContext(SkNativeParsedPDF* doc) : fPdfDoc(doc) {} |
edisonn@google.com | b857a0c | 2013-06-25 20:45:40 +0000 | [diff] [blame] | 125 | |
| 126 | }; |
| 127 | |
edisonn@google.com | 3aac1f9 | 2013-07-02 22:42:53 +0000 | [diff] [blame] | 128 | // TODO(edisonn): temporary code, to report how much of the PDF we actually think we rendered. |
| 129 | // TODO(edisonn): rename to SkPdfResult |
edisonn@google.com | b857a0c | 2013-06-25 20:45:40 +0000 | [diff] [blame] | 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 |