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 // TODO(edisonn): this file not commented much on purpose. | 8 // TODO(edisonn): this file not commented much on purpose. |
9 // It will probably need heavy refactoring soon anyway to support all encodings,
fonts and | 9 // It will probably need heavy refactoring soon anyway to support all encodings,
fonts and |
10 // proper text sizing and spacing | 10 // proper text sizing and spacing |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 uint16_t* text; | 70 uint16_t* text; |
71 int len; | 71 int len; |
72 | 72 |
73 public: | 73 public: |
74 unsigned int operator[](int i) const { return text[i]; } | 74 unsigned int operator[](int i) const { return text[i]; } |
75 int size() const { return len; } | 75 int size() const { return len; } |
76 }; | 76 }; |
77 | 77 |
78 class SkPdfEncoding { | 78 class SkPdfEncoding { |
79 public: | 79 public: |
| 80 virtual ~SkPdfEncoding() {} |
80 virtual bool decodeText(const SkUnencodedText& textIn, SkDecodedText* textOu
t) const = 0; | 81 virtual bool decodeText(const SkUnencodedText& textIn, SkDecodedText* textOu
t) const = 0; |
81 static SkPdfEncoding* fromName(const char* name); | 82 static SkPdfEncoding* fromName(const char* name); |
82 }; | 83 }; |
83 | 84 |
84 SkTDict<SkPdfEncoding*>& getStandardEncodings(); | 85 SkTDict<SkPdfEncoding*>& getStandardEncodings(); |
85 | 86 |
86 class SkPdfToUnicode { | 87 class SkPdfToUnicode { |
87 SkPdfNativeDoc* fParsed; | 88 SkPdfNativeDoc* fParsed; |
88 // TODO(edisonn): hide public members | 89 // TODO(edisonn): hide public members |
89 public: | 90 public: |
90 unsigned short* fCMapEncoding; | 91 unsigned short* fCMapEncoding; |
91 unsigned char* fCMapEncodingFlag; | 92 unsigned char* fCMapEncodingFlag; |
92 | 93 |
93 SkPdfToUnicode(SkPdfNativeDoc* parsed, SkPdfStream* stream); | 94 SkPdfToUnicode(SkPdfNativeDoc* parsed, SkPdfStream* stream); |
94 }; | 95 }; |
95 | 96 |
96 | 97 |
97 class SkPdfIdentityHEncoding : public SkPdfEncoding { | 98 class SkPdfIdentityHEncoding : public SkPdfEncoding { |
98 public: | 99 public: |
| 100 virtual ~SkPdfIdentityHEncoding() {} |
99 virtual bool decodeText(const SkUnencodedText& textIn, SkDecodedText* textOu
t) const { | 101 virtual bool decodeText(const SkUnencodedText& textIn, SkDecodedText* textOu
t) const { |
100 // TODO(edisonn): SkASSERT(textIn.len % 2 == 0); or report error? | 102 // TODO(edisonn): SkASSERT(textIn.len % 2 == 0); or report error? |
101 | 103 |
102 uint16_t* text = (uint16_t*)textIn.text; | 104 uint16_t* text = (uint16_t*)textIn.text; |
103 textOut->text = new uint16_t[textIn.len / 2]; | 105 textOut->text = new uint16_t[textIn.len / 2]; |
104 textOut->len = textIn.len / 2; | 106 textOut->len = textIn.len / 2; |
105 | 107 |
106 for (int i = 0; i < textOut->len; i++) { | 108 for (int i = 0; i < textOut->len; i++) { |
107 textOut->text[i] = ((text[i] << 8) & 0xff00) | ((text[i] >> 8) & 0x0
0ff); | 109 textOut->text[i] = ((text[i] << 8) & 0xff00) | ((text[i] >> 8) & 0x0
0ff); |
108 } | 110 } |
109 | 111 |
110 return true; | 112 return true; |
111 } | 113 } |
112 | 114 |
113 static SkPdfIdentityHEncoding* instance() { | 115 static SkPdfIdentityHEncoding* instance() { |
114 static SkPdfIdentityHEncoding* inst = new SkPdfIdentityHEncoding(); | 116 static SkPdfIdentityHEncoding* inst = new SkPdfIdentityHEncoding(); |
115 return inst; | 117 return inst; |
116 } | 118 } |
117 }; | 119 }; |
118 | 120 |
119 // TODO(edisonn): using this one when no encoding is specified | 121 // TODO(edisonn): using this one when no encoding is specified |
120 class SkPdfDefaultEncoding : public SkPdfEncoding { | 122 class SkPdfDefaultEncoding : public SkPdfEncoding { |
121 public: | 123 public: |
| 124 virtual ~SkPdfDefaultEncoding() {} |
122 virtual bool decodeText(const SkUnencodedText& textIn, SkDecodedText* textOu
t) const { | 125 virtual bool decodeText(const SkUnencodedText& textIn, SkDecodedText* textOu
t) const { |
123 // TODO(edisonn): SkASSERT(textIn.len % 2 == 0); or report error? | 126 // TODO(edisonn): SkASSERT(textIn.len % 2 == 0); or report error? |
124 | 127 |
125 unsigned char* text = (unsigned char*)textIn.text; | 128 unsigned char* text = (unsigned char*)textIn.text; |
126 textOut->text = new uint16_t[textIn.len]; | 129 textOut->text = new uint16_t[textIn.len]; |
127 textOut->len = textIn.len; | 130 textOut->len = textIn.len; |
128 | 131 |
129 for (int i = 0; i < textOut->len; i++) { | 132 for (int i = 0; i < textOut->len; i++) { |
130 textOut->text[i] = text[i]; | 133 textOut->text[i] = text[i]; |
131 } | 134 } |
132 | 135 |
133 return true; | 136 return true; |
134 } | 137 } |
135 | 138 |
136 static SkPdfDefaultEncoding* instance() { | 139 static SkPdfDefaultEncoding* instance() { |
137 static SkPdfDefaultEncoding* inst = new SkPdfDefaultEncoding(); | 140 static SkPdfDefaultEncoding* inst = new SkPdfDefaultEncoding(); |
138 return inst; | 141 return inst; |
139 } | 142 } |
140 }; | 143 }; |
141 | 144 |
142 class SkPdfCIDToGIDMapIdentityEncoding : public SkPdfEncoding { | 145 class SkPdfCIDToGIDMapIdentityEncoding : public SkPdfEncoding { |
143 public: | 146 public: |
| 147 virtual ~SkPdfCIDToGIDMapIdentityEncoding() {} |
144 virtual bool decodeText(const SkUnencodedText& textIn, SkDecodedText* textOu
t) const { | 148 virtual bool decodeText(const SkUnencodedText& textIn, SkDecodedText* textOu
t) const { |
145 // TODO(edisonn): SkASSERT(textIn.len % 2 == 0); or report error? | 149 // TODO(edisonn): SkASSERT(textIn.len % 2 == 0); or report error? |
146 | 150 |
147 uint16_t* text = (uint16_t*)textIn.text; | 151 uint16_t* text = (uint16_t*)textIn.text; |
148 textOut->text = new uint16_t[textIn.len / 2]; | 152 textOut->text = new uint16_t[textIn.len / 2]; |
149 textOut->len = textIn.len / 2; | 153 textOut->len = textIn.len / 2; |
150 | 154 |
151 for (int i = 0; i < textOut->len; i++) { | 155 for (int i = 0; i < textOut->len; i++) { |
152 textOut->text[i] = ((text[i] << 8) & 0xff00) | ((text[i] >> 8) & 0x0
0ff); | 156 textOut->text[i] = ((text[i] << 8) & 0xff00) | ((text[i] >> 8) & 0x0
0ff); |
153 } | 157 } |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 SkDoubleToScalar(pdfContext->fGraphicsState.fCurFontSize * | 471 SkDoubleToScalar(pdfContext->fGraphicsState.fCurFontSize * |
468 fChars[ch - fFirstChar].fWidth), | 472 fChars[ch - fFirstChar].fWidth), |
469 SkDoubleToScalar(0.0)); | 473 SkDoubleToScalar(0.0)); |
470 return fChars[ch - fFirstChar].fWidth; | 474 return fChars[ch - fFirstChar].fWidth; |
471 } | 475 } |
472 | 476 |
473 virtual void afterWord(SkPaint* paint, SkMatrix* matrix) {} | 477 virtual void afterWord(SkPaint* paint, SkMatrix* matrix) {} |
474 }; | 478 }; |
475 | 479 |
476 #endif // SkPdfFont_DEFINED | 480 #endif // SkPdfFont_DEFINED |
OLD | NEW |