| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkPdfRenderer.h" | 8 #include "SkPdfRenderer.h" |
| 9 | 9 |
| 10 #include "SkBitmapDevice.h" | 10 #include "SkBitmapDevice.h" |
| 11 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
| 12 #include "SkDevice.h" | 12 #include "SkDevice.h" |
| 13 #include "SkForceLinking.h" | 13 #include "SkForceLinking.h" |
| 14 #include "SkGraphics.h" | 14 #include "SkGraphics.h" |
| 15 #include "SkImageDecoder.h" | 15 #include "SkImageDecoder.h" |
| 16 #include "SkImageEncoder.h" | 16 #include "SkImageEncoder.h" |
| 17 #include "SkOSFile.h" | 17 #include "SkOSFile.h" |
| 18 #include "SkPicture.h" | 18 #include "SkPicture.h" |
| 19 #include "SkPdfFont.h" | 19 #include "SkPdfFont.h" |
| 20 #include "SkPdfGraphicsState.h" | 20 #include "SkPdfGraphicsState.h" |
| 21 #include "SkPdfHeaders_autogen.h" | 21 #include "SkPdfHeaders_autogen.h" |
| 22 #include "SkPdfMapper_autogen.h" | 22 #include "SkPdfMapper_autogen.h" |
| 23 #include "SkPdfNativeTokenizer.h" | 23 #include "SkPdfNativeTokenizer.h" |
| 24 #include "SkPdfRenderer.h" | 24 #include "SkPdfRenderer.h" |
| 25 #include "SkPdfReporter.h" | 25 #include "SkPdfReporter.h" |
| 26 #include "SkPdfTokenLooper.h" |
| 26 #include "SkPdfUtils.h" | 27 #include "SkPdfUtils.h" |
| 27 #include "SkStream.h" | 28 #include "SkStream.h" |
| 28 #include "SkTypeface.h" | 29 #include "SkTypeface.h" |
| 29 #include "SkTArray.h" | 30 #include "SkTArray.h" |
| 30 #include "SkTDict.h" | 31 #include "SkTDict.h" |
| 31 | 32 |
| 32 // TODO(edisonn): #ifdef these ones, as they are used only for debugging. | 33 // TODO(edisonn): #ifdef these ones, as they are used only for debugging. |
| 33 extern "C" SkPdfContext* gPdfContext; | 34 extern "C" SkPdfContext* gPdfContext; |
| 34 extern "C" SkBitmap* gDumpBitmap; | 35 extern "C" SkBitmap* gDumpBitmap; |
| 35 extern "C" SkCanvas* gDumpCanvas; | 36 extern "C" SkCanvas* gDumpCanvas; |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 StringsInit() { | 201 StringsInit() { |
| 201 NotOwnedString::init(&strings_DeviceRGB, "DeviceRGB"); | 202 NotOwnedString::init(&strings_DeviceRGB, "DeviceRGB"); |
| 202 NotOwnedString::init(&strings_DeviceCMYK, "DeviceCMYK"); | 203 NotOwnedString::init(&strings_DeviceCMYK, "DeviceCMYK"); |
| 203 } | 204 } |
| 204 }; | 205 }; |
| 205 | 206 |
| 206 // TODO(edisonn): this will not work in chrome! Find another solution! | 207 // TODO(edisonn): this will not work in chrome! Find another solution! |
| 207 StringsInit gStringsInit; | 208 StringsInit gStringsInit; |
| 208 | 209 |
| 209 // TODO(edisonn): Document PdfTokenLooper and subclasses. | 210 // TODO(edisonn): Document PdfTokenLooper and subclasses. |
| 210 class PdfTokenLooper { | |
| 211 protected: | |
| 212 PdfTokenLooper* fParent; | |
| 213 SkPdfNativeTokenizer* fTokenizer; | |
| 214 SkPdfContext* fPdfContext; | |
| 215 SkCanvas* fCanvas; | |
| 216 | |
| 217 public: | |
| 218 PdfTokenLooper(PdfTokenLooper* parent, | |
| 219 SkPdfNativeTokenizer* tokenizer, | |
| 220 SkPdfContext* pdfContext, | |
| 221 SkCanvas* canvas) | |
| 222 : fParent(parent), fTokenizer(tokenizer), fPdfContext(pdfContext), fCanv
as(canvas) {} | |
| 223 | |
| 224 virtual ~PdfTokenLooper() {} | |
| 225 | |
| 226 virtual SkPdfResult consumeToken(PdfToken& token) = 0; | |
| 227 virtual void loop() = 0; | |
| 228 | |
| 229 void setUp(PdfTokenLooper* parent) { | |
| 230 fParent = parent; | |
| 231 fTokenizer = parent->fTokenizer; | |
| 232 fPdfContext = parent->fPdfContext; | |
| 233 fCanvas = parent->fCanvas; | |
| 234 } | |
| 235 | |
| 236 SkPdfNativeTokenizer* tokenizer() { return fTokenizer; } | |
| 237 }; | |
| 238 | |
| 239 class PdfMainLooper : public PdfTokenLooper { | 211 class PdfMainLooper : public PdfTokenLooper { |
| 240 public: | 212 public: |
| 241 PdfMainLooper(PdfTokenLooper* parent, | 213 PdfMainLooper(PdfTokenLooper* parent, |
| 242 SkPdfNativeTokenizer* tokenizer, | 214 SkPdfNativeTokenizer* tokenizer, |
| 243 SkPdfContext* pdfContext, | 215 SkPdfContext* pdfContext, |
| 244 SkCanvas* canvas) | 216 SkCanvas* canvas) |
| 245 : PdfTokenLooper(parent, tokenizer, pdfContext, canvas) {} | 217 : PdfTokenLooper(parent, tokenizer, pdfContext, canvas) {} |
| 246 | 218 |
| 247 virtual SkPdfResult consumeToken(PdfToken& token); | 219 virtual SkPdfResult consumeToken(PdfToken& token); |
| 248 virtual void loop(); | 220 virtual void loop(); |
| (...skipping 2912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3161 | 3133 |
| 3162 rect = SkRect::MakeWH(width, height); | 3134 rect = SkRect::MakeWH(width, height); |
| 3163 | 3135 |
| 3164 setup_bitmap(output, SkScalarCeilToInt(width), SkScalarCeilToInt(height)); | 3136 setup_bitmap(output, SkScalarCeilToInt(width), SkScalarCeilToInt(height)); |
| 3165 | 3137 |
| 3166 SkAutoTUnref<SkBaseDevice> device(SkNEW_ARGS(SkBitmapDevice, (*output))); | 3138 SkAutoTUnref<SkBaseDevice> device(SkNEW_ARGS(SkBitmapDevice, (*output))); |
| 3167 SkCanvas canvas(device); | 3139 SkCanvas canvas(device); |
| 3168 | 3140 |
| 3169 return renderer->renderPage(page, &canvas, rect); | 3141 return renderer->renderPage(page, &canvas, rect); |
| 3170 } | 3142 } |
| OLD | NEW |