edisonn@google.com | cf2cfa1 | 2013-08-21 16:31:37 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef SkPdfUtils_DEFINED |
| 9 | #define SkPdfUtils_DEFINED |
edisonn@google.com | b857a0c | 2013-06-25 20:45:40 +0000 | [diff] [blame] | 10 | |
edisonn@google.com | 3aa3555 | 2013-08-14 18:26:20 +0000 | [diff] [blame] | 11 | #include "SkMatrix.h" |
| 12 | #include "SkRect.h" |
edisonn@google.com | 33f11b6 | 2013-08-14 21:35:27 +0000 | [diff] [blame] | 13 | #include "SkPdfConfig.h" |
edisonn@google.com | 063d707 | 2013-08-16 15:05:08 +0000 | [diff] [blame] | 14 | #include "SkString.h" |
edisonn@google.com | b857a0c | 2013-06-25 20:45:40 +0000 | [diff] [blame] | 15 | |
edisonn@google.com | b857a0c | 2013-06-25 20:45:40 +0000 | [diff] [blame] | 16 | class SkPdfArray; |
edisonn@google.com | 3aa3555 | 2013-08-14 18:26:20 +0000 | [diff] [blame] | 17 | class SkPdfContext; |
| 18 | class SkCanvas; |
| 19 | class SkPdfNativeObject; |
| 20 | |
| 21 | // TODO(edisonn): temporary code, to report how much of the PDF we actually think we rendered. |
| 22 | enum SkPdfResult { |
| 23 | kOK_SkPdfResult, |
| 24 | kPartial_SkPdfResult, |
| 25 | kNYI_SkPdfResult, |
| 26 | kIgnoreError_SkPdfResult, |
| 27 | kError_SkPdfResult, |
| 28 | kUnsupported_SkPdfResult, |
| 29 | |
| 30 | kCount_SkPdfResult |
| 31 | }; |
| 32 | |
| 33 | struct NotOwnedString { |
| 34 | const unsigned char* fBuffer; |
edisonn@google.com | c8fda9d | 2013-10-09 20:23:12 +0000 | [diff] [blame^] | 35 | // TODO(edisonn): clean up, the last two bytes are used to signal if compression is used |
edisonn@google.com | 3aa3555 | 2013-08-14 18:26:20 +0000 | [diff] [blame] | 36 | size_t fBytes; |
| 37 | |
| 38 | static void init(NotOwnedString* str) { |
| 39 | str->fBuffer = NULL; |
| 40 | str->fBytes = 0; |
| 41 | } |
| 42 | |
| 43 | static void init(NotOwnedString* str, const char* sz) { |
| 44 | str->fBuffer = (const unsigned char*)sz; |
| 45 | str->fBytes = strlen(sz); |
| 46 | } |
| 47 | |
| 48 | bool equals(const char* sz) { |
| 49 | return strncmp((const char*)fBuffer, sz, fBytes) == 0 && fBytes == strlen(sz); |
| 50 | |
| 51 | } |
| 52 | }; |
edisonn@google.com | b857a0c | 2013-06-25 20:45:40 +0000 | [diff] [blame] | 53 | |
edisonn@google.com | c8fda9d | 2013-10-09 20:23:12 +0000 | [diff] [blame^] | 54 | SkMatrix SkMatrixFromPdfMatrix(double array[6]); |
| 55 | |
edisonn@google.com | 063d707 | 2013-08-16 15:05:08 +0000 | [diff] [blame] | 56 | // TODO(edisonn): hack to make code generation simpler. Alternatively we can update the |
| 57 | // generate_code.py not to rely on != operator |
| 58 | bool operator !=(const SkString& first, const char* second); |
| 59 | |
edisonn@google.com | b857a0c | 2013-06-25 20:45:40 +0000 | [diff] [blame] | 60 | SkMatrix SkMatrixFromPdfArray(SkPdfArray* pdfArray); |
| 61 | |
edisonn@google.com | 3aa3555 | 2013-08-14 18:26:20 +0000 | [diff] [blame] | 62 | SkPdfResult doType3Char(SkPdfContext* pdfContext, SkCanvas* canvas, const SkPdfNativeObject* skobj, SkRect bBox, SkMatrix matrix, double textSize); |
| 63 | |
| 64 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 65 | // |
| 66 | // TRACE functions |
| 67 | // |
| 68 | #ifdef PDF_TRACE |
| 69 | void SkTraceMatrix(const SkMatrix& matrix, const char* sz); |
| 70 | void SkTraceRect(const SkRect& rect, const char* sz); |
| 71 | #else |
| 72 | #define SkTraceMatrix(a,b) |
| 73 | #define SkTraceRect(a,b) |
| 74 | #endif |
edisonn@google.com | b857a0c | 2013-06-25 20:45:40 +0000 | [diff] [blame] | 75 | |
edisonn@google.com | c8fda9d | 2013-10-09 20:23:12 +0000 | [diff] [blame^] | 76 | #ifdef PDF_TRACE_TOKENIZER |
| 77 | |
| 78 | static void TRACE_COMMENT(char ch) { |
| 79 | printf("%c", ch); |
| 80 | } |
| 81 | |
| 82 | static void TRACE_TK(char ch) { |
| 83 | printf("%c", ch); |
| 84 | } |
| 85 | |
| 86 | static void TRACE_NAME(const unsigned char* start, const unsigned char* end) { |
| 87 | while (start < end) { |
| 88 | printf("%c", *start); |
| 89 | start++; |
| 90 | } |
| 91 | printf("\n"); |
| 92 | } |
| 93 | |
| 94 | static void TRACE_STRING(const unsigned char* start, const unsigned char* end) { |
| 95 | while (start < end) { |
| 96 | printf("%c", *start); |
| 97 | start++; |
| 98 | } |
| 99 | printf("\n"); |
| 100 | } |
| 101 | |
| 102 | static void TRACE_HEXSTRING(const unsigned char* start, const unsigned char* end) { |
| 103 | while (start < end) { |
| 104 | printf("%c", *start); |
| 105 | start++; |
| 106 | } |
| 107 | printf("\n"); |
| 108 | } |
| 109 | |
| 110 | #else |
| 111 | #define TRACE_COMMENT(ch) |
| 112 | #define TRACE_TK(ch) |
| 113 | #define TRACE_NAME(start,end) |
| 114 | #define TRACE_STRING(start,end) |
| 115 | #define TRACE_HEXSTRING(start,end) |
| 116 | #endif |
| 117 | |
edisonn@google.com | cf2cfa1 | 2013-08-21 16:31:37 +0000 | [diff] [blame] | 118 | #endif // SkPdfUtils_DEFINED |