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 | 3aac1f9 | 2013-07-02 22:42:53 +0000 | [diff] [blame^] | 18 | class SkPodofoParsedPDF; |
| 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 | b857a0c | 2013-06-25 20:45:40 +0000 | [diff] [blame] | 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. |
edisonn@google.com | 3aac1f9 | 2013-07-02 22:42:53 +0000 | [diff] [blame^] | 32 | SkPdfColorOperator() : fColor(SK_ColorBLACK), fOpacity(1) {} |
edisonn@google.com | b857a0c | 2013-06-25 20:45:40 +0000 | [diff] [blame] | 33 | |
| 34 | void applyGraphicsState(SkPaint* paint) { |
| 35 | paint->setColor(SkColorSetA(fColor, fOpacity * 255)); |
| 36 | } |
| 37 | }; |
| 38 | |
| 39 | // TODO(edisonn): better class design. |
edisonn@google.com | 3aac1f9 | 2013-07-02 22:42:53 +0000 | [diff] [blame^] | 40 | struct SkPdfGraphicsState { |
edisonn@google.com | b857a0c | 2013-06-25 20:45:40 +0000 | [diff] [blame] | 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 | |
edisonn@google.com | 3aac1f9 | 2013-07-02 22:42:53 +0000 | [diff] [blame^] | 58 | SkPdfColorOperator fStroking; |
| 59 | SkPdfColorOperator fNonStroking; |
edisonn@google.com | b857a0c | 2013-06-25 20:45:40 +0000 | [diff] [blame] | 60 | |
| 61 | double fLineWidth; |
| 62 | double fTextLeading; |
| 63 | double fWordSpace; |
| 64 | double fCharSpace; |
| 65 | |
edisonn@google.com | 3aac1f9 | 2013-07-02 22:42:53 +0000 | [diff] [blame^] | 66 | const SkPdfResourceDictionary* fResources; |
edisonn@google.com | b857a0c | 2013-06-25 20:45:40 +0000 | [diff] [blame] | 67 | |
| 68 | SkBitmap fSMask; |
| 69 | |
edisonn@google.com | 3aac1f9 | 2013-07-02 22:42:53 +0000 | [diff] [blame^] | 70 | SkPdfGraphicsState() { |
edisonn@google.com | b857a0c | 2013-06-25 20:45:40 +0000 | [diff] [blame] | 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. |
edisonn@google.com | 3aac1f9 | 2013-07-02 22:42:53 +0000 | [diff] [blame^] | 105 | // TODO(edisonn): could we remove it? |
| 106 | // TODO(edisonn): rename to SkPdfInlineImage |
| 107 | struct SkPdfInlineImage { |
edisonn@google.com | b857a0c | 2013-06-25 20:45:40 +0000 | [diff] [blame] | 108 | std::map<std::string, std::string> fKeyValuePairs; |
| 109 | std::string fImageData; |
| 110 | }; |
| 111 | |
| 112 | // TODO(edisonn): better class design. |
edisonn@google.com | 3aac1f9 | 2013-07-02 22:42:53 +0000 | [diff] [blame^] | 113 | // TODO(edisonn): rename to SkPdfContext |
edisonn@google.com | b857a0c | 2013-06-25 20:45:40 +0000 | [diff] [blame] | 114 | struct PdfContext { |
| 115 | std::stack<SkPdfObject*> fObjectStack; |
edisonn@google.com | 3aac1f9 | 2013-07-02 22:42:53 +0000 | [diff] [blame^] | 116 | std::stack<SkPdfGraphicsState> fStateStack; |
| 117 | SkPdfGraphicsState fGraphicsState; |
| 118 | const SkPodofoParsedPDF* fPdfDoc; |
edisonn@google.com | b857a0c | 2013-06-25 20:45:40 +0000 | [diff] [blame] | 119 | SkMatrix fOriginalMatrix; |
| 120 | |
edisonn@google.com | 3aac1f9 | 2013-07-02 22:42:53 +0000 | [diff] [blame^] | 121 | SkPdfInlineImage fInlineImage; |
edisonn@google.com | b857a0c | 2013-06-25 20:45:40 +0000 | [diff] [blame] | 122 | |
edisonn@google.com | 3aac1f9 | 2013-07-02 22:42:53 +0000 | [diff] [blame^] | 123 | PdfContext(const SkPodofoParsedPDF* doc) : fPdfDoc(doc) {} |
edisonn@google.com | b857a0c | 2013-06-25 20:45:40 +0000 | [diff] [blame] | 124 | |
| 125 | }; |
| 126 | |
edisonn@google.com | 3aac1f9 | 2013-07-02 22:42:53 +0000 | [diff] [blame^] | 127 | // TODO(edisonn): temporary code, to report how much of the PDF we actually think we rendered. |
| 128 | // TODO(edisonn): rename to SkPdfResult |
edisonn@google.com | b857a0c | 2013-06-25 20:45:40 +0000 | [diff] [blame] | 129 | enum PdfResult { |
| 130 | kOK_PdfResult, |
| 131 | kPartial_PdfResult, |
| 132 | kNYI_PdfResult, |
| 133 | kIgnoreError_PdfResult, |
| 134 | kError_PdfResult, |
| 135 | kUnsupported_PdfResult, |
| 136 | |
| 137 | kCount_PdfResult |
| 138 | }; |
| 139 | |
| 140 | #endif // __DEFINED__SkPdfBasics |