| 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 #ifndef SkPdfTokenLooper_DEFINED | 8 #ifndef SkPdfTokenLooper_DEFINED |
| 9 #define SkPdfTokenLooper_DEFINED | 9 #define SkPdfTokenLooper_DEFINED |
| 10 | 10 |
| 11 #include "SkPdfNativeTokenizer.h" | 11 #include "SkPdfNativeTokenizer.h" |
| 12 // For SkPdfResult | 12 // For SkPdfResult |
| 13 #include "SkPdfUtils.h" | 13 #include "SkPdfUtils.h" |
| 14 | 14 |
| 15 class SkCanvas; | 15 class SkCanvas; |
| 16 class SkPdfContext; | 16 class SkPdfContext; |
| 17 | 17 |
| 18 /** |
| 19 * An object which reads tokens from a tokenizer and draws it to an SkCanvas. |
| 20 * FIXME (scroggo): Can this be an interface? See http://goo.gl/AXQtkH |
| 21 */ |
| 18 class SkPdfTokenLooper { | 22 class SkPdfTokenLooper { |
| 19 protected: | 23 public: |
| 20 SkPdfTokenLooper* fParent; | 24 /** |
| 21 SkPdfNativeTokenizer* fTokenizer; | 25 * Create a looper with no parent. |
| 22 SkPdfContext* fPdfContext; | 26 * @param tokenizer SkPdfNativeTokenizer for reading tokens. |
| 23 SkCanvas* fCanvas; | 27 * @param pdfContext Context for drawing state. |
| 28 * @param canvas Target SkCanvas for drawing. |
| 29 */ |
| 30 SkPdfTokenLooper(SkPdfNativeTokenizer* tokenizer, |
| 31 SkPdfContext* pdfContext, |
| 32 SkCanvas* canvas) |
| 33 : fParent(NULL) |
| 34 , fTokenizer(tokenizer) |
| 35 , fPdfContext(pdfContext) |
| 36 , fCanvas(canvas) {} |
| 24 | 37 |
| 25 public: | 38 /** |
| 26 SkPdfTokenLooper(SkPdfTokenLooper* parent, | 39 * Create a looper as a child of parent. It will share the |
| 27 SkPdfNativeTokenizer* tokenizer, | 40 * SkPdfContext, SkPdfTokenizer, and SkCanvas with its parent. |
| 28 SkPdfContext* pdfContext, | 41 */ |
| 29 SkCanvas* canvas) | 42 explicit SkPdfTokenLooper(SkPdfTokenLooper* parent) |
| 30 : fParent(parent), fTokenizer(tokenizer), fPdfContext(pdfContext), fCanv
as(canvas) {} | 43 : fParent(parent) |
| 44 , fTokenizer(parent->fTokenizer) |
| 45 , fPdfContext(parent->fPdfContext) |
| 46 , fCanvas(parent->fCanvas) {} |
| 31 | 47 |
| 32 virtual ~SkPdfTokenLooper() {} | 48 virtual ~SkPdfTokenLooper() {} |
| 33 | 49 |
| 50 /** |
| 51 * Consume a token, and draw to fCanvas as directed. |
| 52 */ |
| 34 virtual SkPdfResult consumeToken(PdfToken& token) = 0; | 53 virtual SkPdfResult consumeToken(PdfToken& token) = 0; |
| 54 |
| 55 /** |
| 56 * Consume all the tokens this looper can handle. |
| 57 */ |
| 35 virtual void loop() = 0; | 58 virtual void loop() = 0; |
| 36 | 59 |
| 37 void setUp(SkPdfTokenLooper* parent) { | 60 protected: |
| 38 fParent = parent; | 61 // All are unowned pointers. |
| 39 fTokenizer = parent->fTokenizer; | 62 SkPdfTokenLooper* fParent; |
| 40 fPdfContext = parent->fPdfContext; | 63 SkPdfNativeTokenizer* fTokenizer; |
| 41 fCanvas = parent->fCanvas; | 64 SkPdfContext* fPdfContext; |
| 42 } | 65 SkCanvas* fCanvas; |
| 43 }; | 66 }; |
| 44 | 67 |
| 45 #endif // SkPdfTokenLooper_DEFINED | 68 #endif // SkPdfTokenLooper_DEFINED |
| OLD | NEW |