OLD | NEW |
1 #ifndef __DEFINED__SkPdfFont | 1 #ifndef __DEFINED__SkPdfFont |
2 #define __DEFINED__SkPdfFont | 2 #define __DEFINED__SkPdfFont |
3 | 3 |
4 #include "SkPdfHeaders_autogen.h" | 4 #include "SkPdfHeaders_autogen.h" |
5 #include "SkPdfPodofoMapper_autogen.h" | 5 #include "SkPdfPodofoMapper_autogen.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "SkUtils.h" | 10 #include "SkUtils.h" |
| 11 #include "SkPdfBasics.h" |
| 12 #include "SkPdfUtils.h" |
| 13 |
11 | 14 |
12 class SkPdfType0Font; | 15 class SkPdfType0Font; |
13 class SkPdfType1Font; | 16 class SkPdfType1Font; |
14 class SkPdfType3Font; | 17 class SkPdfType3Font; |
15 class SkPdfTrueTypeFont; | 18 class SkPdfTrueTypeFont; |
16 class SkPdfCIDFont; | 19 class SkPdfCIDFont; |
17 class SkPdfMultiMasterFont; | 20 class SkPdfMultiMasterFont; |
18 class SkPdfFont; | 21 class SkPdfFont; |
19 | 22 |
20 | 23 |
(...skipping 14 matching lines...) Expand all Loading... |
35 public: | 38 public: |
36 SkUnencodedText(const SkPdfObject* obj) { | 39 SkUnencodedText(const SkPdfObject* obj) { |
37 text = (void*)obj->podofo()->GetString().GetString(); | 40 text = (void*)obj->podofo()->GetString().GetString(); |
38 len = obj->podofo()->GetString().GetLength(); | 41 len = obj->podofo()->GetString().GetLength(); |
39 } | 42 } |
40 }; | 43 }; |
41 | 44 |
42 struct SkDecodedText { | 45 struct SkDecodedText { |
43 uint16_t* text; | 46 uint16_t* text; |
44 int len; | 47 int len; |
| 48 public: |
| 49 unsigned int operator[](int i) const { return text[i]; } |
| 50 int size() const { return len; } |
45 }; | 51 }; |
46 | 52 |
47 struct SkUnicodeText { | 53 struct SkUnicodeText { |
48 uint16_t* text; | 54 uint16_t* text; |
49 int len; | 55 int len; |
50 | 56 |
51 public: | 57 public: |
52 unsigned int operator[](int i) const { return text[i]; } | 58 unsigned int operator[](int i) const { return text[i]; } |
53 int size() const { return len; } | 59 int size() const { return len; } |
54 }; | 60 }; |
55 | 61 |
56 class SkPdfEncoding { | 62 class SkPdfEncoding { |
57 public: | 63 public: |
58 virtual bool decodeText(const SkUnencodedText& textIn, SkDecodedText* textOu
t) const = 0; | 64 virtual bool decodeText(const SkUnencodedText& textIn, SkDecodedText* textOu
t) const = 0; |
| 65 static SkPdfEncoding* fromName(const char* name); |
59 }; | 66 }; |
60 | 67 |
| 68 std::map<std::string, SkPdfEncoding*>& getStandardEncodings(); |
| 69 |
| 70 class SkPdfToUnicode { |
| 71 // TODO(edisonn): hide public members |
| 72 public: |
| 73 unsigned short* fCMapEncoding; |
| 74 unsigned char* fCMapEncodingFlag; |
| 75 |
| 76 SkPdfToUnicode(const SkPdfStream* stream); |
| 77 }; |
| 78 |
| 79 |
61 class SkPdfIdentityHEncoding : public SkPdfEncoding { | 80 class SkPdfIdentityHEncoding : public SkPdfEncoding { |
62 public: | 81 public: |
63 virtual bool decodeText(const SkUnencodedText& textIn, SkDecodedText* textOu
t) const { | 82 virtual bool decodeText(const SkUnencodedText& textIn, SkDecodedText* textOu
t) const { |
64 // TODO(edisonn): SkASSERT(textIn.len % 2 == 0); or report error? | 83 // TODO(edisonn): SkASSERT(textIn.len % 2 == 0); or report error? |
65 | 84 |
66 uint16_t* text = (uint16_t*)textIn.text; | 85 uint16_t* text = (uint16_t*)textIn.text; |
67 textOut->text = new uint16_t[textIn.len / 2]; | 86 textOut->text = new uint16_t[textIn.len / 2]; |
68 textOut->len = textIn.len / 2; | 87 textOut->len = textIn.len / 2; |
69 | 88 |
70 for (int i = 0; i < textOut->len; i++) { | 89 for (int i = 0; i < textOut->len; i++) { |
71 textOut->text[i] = ((text[i] << 8) & 0xff00) | ((text[i] >> 8) & 0x0
0ff); | 90 textOut->text[i] = ((text[i] << 8) & 0xff00) | ((text[i] >> 8) & 0x0
0ff); |
72 } | 91 } |
73 | 92 |
74 return true; | 93 return true; |
75 } | 94 } |
76 | 95 |
77 static SkPdfIdentityHEncoding* instance() { | 96 static SkPdfIdentityHEncoding* instance() { |
78 static SkPdfIdentityHEncoding* inst = new SkPdfIdentityHEncoding(); | 97 static SkPdfIdentityHEncoding* inst = new SkPdfIdentityHEncoding(); |
79 return inst; | 98 return inst; |
80 } | 99 } |
81 }; | 100 }; |
82 | 101 |
| 102 |
| 103 class SkPdfCIDToGIDMapIdentityEncoding : public SkPdfEncoding { |
| 104 public: |
| 105 virtual bool decodeText(const SkUnencodedText& textIn, SkDecodedText* textOu
t) const { |
| 106 // TODO(edisonn): SkASSERT(textIn.len % 2 == 0); or report error? |
| 107 |
| 108 unsigned char* text = (unsigned char*)textIn.text; |
| 109 textOut->text = new uint16_t[textIn.len]; |
| 110 textOut->len = textIn.len; |
| 111 |
| 112 for (int i = 0; i < textOut->len; i++) { |
| 113 textOut->text[i] = text[i]; |
| 114 } |
| 115 |
| 116 return true; |
| 117 } |
| 118 |
| 119 static SkPdfCIDToGIDMapIdentityEncoding* instance() { |
| 120 static SkPdfCIDToGIDMapIdentityEncoding* inst = new SkPdfCIDToGIDMapIden
tityEncoding(); |
| 121 return inst; |
| 122 } |
| 123 }; |
| 124 |
83 class SkPdfFont { | 125 class SkPdfFont { |
84 public: | 126 public: |
85 SkPdfFont* fBaseFont; | 127 SkPdfFont* fBaseFont; |
86 SkPdfEncoding* fEncoding; | 128 SkPdfEncoding* fEncoding; |
| 129 SkPdfToUnicode* fToUnicode; |
| 130 |
87 | 131 |
88 public: | 132 public: |
89 SkPdfFont() : fBaseFont(NULL), fEncoding(SkPdfIdentityHEncoding::instance())
{} | 133 SkPdfFont() : fBaseFont(NULL), fEncoding(NULL), fToUnicode(NULL) {} |
90 | 134 |
91 const SkPdfEncoding* encoding() const {return fEncoding;} | 135 const SkPdfEncoding* encoding() const {return fEncoding;} |
92 | 136 |
93 void drawText(const SkUnicodeText& text, SkPaint* paint, SkCanvas* canvas, S
kMatrix* matrix) { | 137 void drawText(const SkDecodedText& text, SkPaint* paint, PdfContext* pdfCont
ext, SkCanvas* canvas, SkMatrix* matrix) { |
94 for (int i = 0 ; i < text.size(); i++) { | 138 for (int i = 0 ; i < text.size(); i++) { |
95 drawOneChar(text[i], paint, canvas, matrix); | 139 drawOneChar(text[i], paint, pdfContext, canvas, matrix); |
96 } | 140 } |
97 } | 141 } |
98 | 142 |
99 virtual void ToUnicode(const SkDecodedText& textIn, SkUnicodeText* textOut)
const { | 143 void ToUnicode(const SkDecodedText& textIn, SkUnicodeText* textOut) const { |
100 textOut->text = textIn.text; | 144 if (fToUnicode) { |
101 textOut->len = textIn.len; | 145 textOut->text = new uint16_t[textIn.len]; |
| 146 textOut->len = textIn.len; |
| 147 for (int i = 0; i < textIn.len; i++) { |
| 148 textOut->text[i] = fToUnicode->fCMapEncoding[textIn.text[i]]; |
| 149 } |
| 150 } else { |
| 151 textOut->text = textIn.text; |
| 152 textOut->len = textIn.len; |
| 153 } |
| 154 }; |
| 155 |
| 156 inline unsigned int ToUnicode(unsigned int ch) const { |
| 157 if (fToUnicode) { |
| 158 return fToUnicode->fCMapEncoding[ch]; |
| 159 } else { |
| 160 return ch; |
| 161 } |
102 }; | 162 }; |
103 | 163 |
104 static SkPdfFont* fontFromPdfDictionary(SkPdfFontDictionary* dict); | 164 static SkPdfFont* fontFromPdfDictionary(SkPdfFontDictionary* dict); |
105 static SkPdfFont* Default() {return SkPdfFontFromName(NULL, "TimesNewRoman")
;} | 165 static SkPdfFont* Default() {return SkPdfFontFromName(NULL, "TimesNewRoman")
;} |
106 | 166 |
107 static SkPdfType0Font* fontFromType0FontDictionary(SkPdfType0FontDictionary*
dict); | 167 static SkPdfType0Font* fontFromType0FontDictionary(SkPdfType0FontDictionary*
dict); |
108 static SkPdfType1Font* fontFromType1FontDictionary(SkPdfType1FontDictionary*
dict); | 168 static SkPdfType1Font* fontFromType1FontDictionary(SkPdfType1FontDictionary*
dict); |
109 static SkPdfType3Font* fontFromType3FontDictionary(SkPdfType3FontDictionary*
dict); | 169 static SkPdfType3Font* fontFromType3FontDictionary(SkPdfType3FontDictionary*
dict); |
110 static SkPdfTrueTypeFont* fontFromTrueTypeFontDictionary(SkPdfTrueTypeFontDi
ctionary* dict); | 170 static SkPdfTrueTypeFont* fontFromTrueTypeFontDictionary(SkPdfTrueTypeFontDi
ctionary* dict); |
111 static SkPdfCIDFont* fontFromCIDFontDictionary(SkPdfCIDFontDictionary* dict)
; | 171 static SkPdfCIDFont* fontFromCIDFontDictionary(SkPdfCIDFontDictionary* dict)
; |
112 static SkPdfMultiMasterFont* fontFromMultiMasterFontDictionary(SkPdfMultiMas
terFontDictionary* dict); | 172 static SkPdfMultiMasterFont* fontFromMultiMasterFontDictionary(SkPdfMultiMas
terFontDictionary* dict); |
113 | 173 |
114 public: | 174 public: |
115 virtual void drawOneChar(unsigned int ch, SkPaint* paint, SkCanvas* canvas,
SkMatrix* matrix) = 0; | 175 virtual void drawOneChar(unsigned int ch, SkPaint* paint, PdfContext* pdfCon
text, SkCanvas* canvas, SkMatrix* matrix) = 0; |
116 virtual void afterChar(SkPaint* paint, SkMatrix* matrix) = 0; | 176 virtual void afterChar(SkPaint* paint, SkMatrix* matrix) = 0; |
117 virtual void afterWord(SkPaint* paint, SkMatrix* matrix) = 0; | 177 virtual void afterWord(SkPaint* paint, SkMatrix* matrix) = 0; |
118 }; | 178 }; |
119 | 179 |
120 class SkPdfStandardFont : public SkPdfFont { | 180 class SkPdfStandardFont : public SkPdfFont { |
121 SkTypeface* fTypeface; | 181 SkTypeface* fTypeface; |
122 | 182 |
123 public: | 183 public: |
124 SkPdfStandardFont(SkTypeface* typeface) : fTypeface(typeface) {} | 184 SkPdfStandardFont(SkTypeface* typeface) : fTypeface(typeface) {} |
125 | 185 |
126 public: | 186 public: |
127 virtual void drawOneChar(unsigned int ch, SkPaint* paint, SkCanvas* canvas,
SkMatrix* matrix) { | 187 virtual void drawOneChar(unsigned int ch, SkPaint* paint, PdfContext* pdfCon
text, SkCanvas* canvas, SkMatrix* matrix) { |
128 paint->setTypeface(fTypeface); | 188 paint->setTypeface(fTypeface); |
129 paint->setTextEncoding(SkPaint::kUTF8_TextEncoding); | 189 paint->setTextEncoding(SkPaint::kUTF8_TextEncoding); |
130 | 190 |
131 unsigned long ch4 = ch; | 191 unsigned long ch4 = ch; |
132 char utf8[10]; | 192 char utf8[10]; |
133 int len = SkUTF8_FromUnichar(ch4, utf8); | 193 int len = SkUTF8_FromUnichar(ch4, utf8); |
134 | 194 |
135 canvas->drawText(utf8, len, SkDoubleToScalar(0), SkDoubleToScalar(0), *p
aint); | 195 canvas->drawText(utf8, len, SkDoubleToScalar(0), SkDoubleToScalar(0), *p
aint); |
136 | 196 |
137 SkScalar textWidth = paint->measureText(utf8, len); | 197 SkScalar textWidth = paint->measureText(utf8, len); |
138 matrix->preTranslate(textWidth, SkDoubleToScalar(0.0)); | 198 matrix->preTranslate(textWidth, SkDoubleToScalar(0.0)); |
139 } | 199 } |
140 | 200 |
141 virtual void afterChar(SkPaint* paint, SkMatrix* matrix) {} | 201 virtual void afterChar(SkPaint* paint, SkMatrix* matrix) {} |
142 virtual void afterWord(SkPaint* paint, SkMatrix* matrix) {} | 202 virtual void afterWord(SkPaint* paint, SkMatrix* matrix) {} |
143 }; | 203 }; |
144 | 204 |
145 | |
146 class SkPdfType0Font : public SkPdfFont { | 205 class SkPdfType0Font : public SkPdfFont { |
147 unsigned short* fCMapEncoding; | |
148 unsigned char* fCMapEncodingFlag; | |
149 public: | 206 public: |
150 SkPdfType0Font(SkPdfType0FontDictionary* dict); | 207 SkPdfType0Font(SkPdfType0FontDictionary* dict); |
151 | 208 |
152 public: | 209 public: |
153 virtual void ToUnicode(const SkDecodedText& textIn, SkUnicodeText* textOut)
const { | |
154 textOut->text = new uint16_t[textIn.len]; | |
155 textOut->len = textIn.len; | |
156 for (int i = 0; i < textIn.len; i++) { | |
157 textOut->text[i] = fCMapEncoding[textIn.text[i]]; | |
158 } | |
159 }; | |
160 | 210 |
161 virtual void drawOneChar(unsigned int ch, SkPaint* paint, SkCanvas* canvas,
SkMatrix* matrix) { | 211 virtual void drawOneChar(unsigned int ch, SkPaint* paint, PdfContext* pdfCon
text, SkCanvas* canvas, SkMatrix* matrix) { |
162 fBaseFont->drawOneChar(ch, paint, canvas, matrix); | 212 fBaseFont->drawOneChar(ToUnicode(ch), paint, pdfContext, canvas, matrix)
; |
163 } | 213 } |
164 | 214 |
165 virtual void afterChar(SkPaint* paint, SkMatrix* matrix) { | 215 virtual void afterChar(SkPaint* paint, SkMatrix* matrix) { |
166 | 216 |
167 } | 217 } |
168 | 218 |
169 virtual void afterWord(SkPaint* paint, SkMatrix* matrix) { | 219 virtual void afterWord(SkPaint* paint, SkMatrix* matrix) { |
170 | |
171 } | 220 } |
172 }; | 221 }; |
173 | 222 |
174 class SkPdfTrueTypeFont : public SkPdfFont { | 223 class SkPdfTrueTypeFont : public SkPdfFont { |
175 public: | 224 public: |
176 SkPdfTrueTypeFont(SkPdfTrueTypeFontDictionary* dict) { | 225 SkPdfTrueTypeFont(SkPdfTrueTypeFontDictionary* dict) { |
177 fBaseFont = SkPdfFontFromName(dict, dict->BaseFont().c_str()); | 226 fBaseFont = SkPdfFontFromName(dict, dict->BaseFont().c_str()); |
178 } | 227 } |
179 | 228 |
180 public: | 229 public: |
181 virtual void drawOneChar(unsigned int ch, SkPaint* paint, SkCanvas* canvas,
SkMatrix* matrix) { | 230 virtual void drawOneChar(unsigned int ch, SkPaint* paint, PdfContext* pdfCon
text, SkCanvas* canvas, SkMatrix* matrix) { |
182 | 231 |
183 } | 232 } |
184 | 233 |
185 virtual void afterChar(SkPaint* paint, SkMatrix* matrix) { | 234 virtual void afterChar(SkPaint* paint, SkMatrix* matrix) { |
186 | 235 |
187 } | 236 } |
188 | 237 |
189 virtual void afterWord(SkPaint* paint, SkMatrix* matrix) { | 238 virtual void afterWord(SkPaint* paint, SkMatrix* matrix) { |
190 | 239 |
191 } | 240 } |
192 }; | 241 }; |
193 | 242 |
194 | 243 |
195 class SkPdfType1Font : public SkPdfFont { | 244 class SkPdfType1Font : public SkPdfFont { |
196 public: | 245 public: |
197 SkPdfType1Font(SkPdfType1FontDictionary* dict) { | 246 SkPdfType1Font(SkPdfType1FontDictionary* dict) { |
198 fBaseFont = SkPdfFontFromName(dict, dict->BaseFont().c_str()); | 247 fBaseFont = SkPdfFontFromName(dict, dict->BaseFont().c_str()); |
199 } | 248 } |
200 | 249 |
201 | 250 |
202 public: | 251 public: |
203 virtual void drawOneChar(unsigned int ch, SkPaint* paint, SkCanvas* canvas
, SkMatrix* matrix) { | 252 virtual void drawOneChar(unsigned int ch, SkPaint* paint, PdfContext* pdfC
ontext, SkCanvas* canvas, SkMatrix* matrix) { |
204 | 253 |
205 } | 254 } |
206 | 255 |
207 virtual void afterChar(SkPaint* paint, SkMatrix* matrix) { | 256 virtual void afterChar(SkPaint* paint, SkMatrix* matrix) { |
208 | 257 |
209 } | 258 } |
210 | 259 |
211 virtual void afterWord(SkPaint* paint, SkMatrix* matrix) { | 260 virtual void afterWord(SkPaint* paint, SkMatrix* matrix) { |
212 | 261 |
213 } | 262 } |
214 }; | 263 }; |
215 | 264 |
216 | 265 |
217 class SkPdfCIDFont : public SkPdfFont { | 266 class SkPdfCIDFont : public SkPdfFont { |
218 public: | 267 public: |
219 SkPdfCIDFont(SkPdfCIDFontDictionary* dict) { | 268 SkPdfCIDFont(SkPdfCIDFontDictionary* dict) { |
220 fBaseFont = SkPdfFontFromName(dict, dict->BaseFont().c_str()); | 269 fBaseFont = SkPdfFontFromName(dict, dict->BaseFont().c_str()); |
221 } | 270 } |
222 | 271 |
223 public: | 272 public: |
224 virtual void drawOneChar(unsigned int ch, SkPaint* paint, SkCanvas* canvas,
SkMatrix* matrix) { | 273 virtual void drawOneChar(unsigned int ch, SkPaint* paint, PdfContext* pdfCon
text, SkCanvas* canvas, SkMatrix* matrix) { |
225 | 274 |
226 } | 275 } |
227 | 276 |
228 virtual void afterChar(SkPaint* paint, SkMatrix* matrix) { | 277 virtual void afterChar(SkPaint* paint, SkMatrix* matrix) { |
229 | 278 |
230 } | 279 } |
231 | 280 |
232 virtual void afterWord(SkPaint* paint, SkMatrix* matrix) { | 281 virtual void afterWord(SkPaint* paint, SkMatrix* matrix) { |
233 | 282 |
234 } | 283 } |
235 }; | 284 }; |
236 | 285 |
237 class SkPdfMultiMasterFont : public SkPdfFont { | 286 class SkPdfMultiMasterFont : public SkPdfFont { |
238 public: | 287 public: |
239 SkPdfMultiMasterFont(SkPdfMultiMasterFontDictionary* dict) { | 288 SkPdfMultiMasterFont(SkPdfMultiMasterFontDictionary* dict) { |
240 fBaseFont = SkPdfFontFromName(dict, dict->BaseFont().c_str()); | 289 fBaseFont = SkPdfFontFromName(dict, dict->BaseFont().c_str()); |
241 } | 290 } |
242 | 291 |
243 public: | 292 public: |
244 virtual void drawOneChar(unsigned int ch, SkPaint* paint, SkCanvas* canvas,
SkMatrix* matrix) { | 293 virtual void drawOneChar(unsigned int ch, SkPaint* paint, PdfContext* pdfCon
text, SkCanvas* canvas, SkMatrix* matrix) { |
245 | 294 |
246 } | 295 } |
247 | 296 |
248 virtual void afterChar(SkPaint* paint, SkMatrix* matrix) { | 297 virtual void afterChar(SkPaint* paint, SkMatrix* matrix) { |
249 | 298 |
250 } | 299 } |
251 | 300 |
252 virtual void afterWord(SkPaint* paint, SkMatrix* matrix) { | 301 virtual void afterWord(SkPaint* paint, SkMatrix* matrix) { |
253 | 302 |
254 } | 303 } |
255 }; | 304 }; |
| 305 /* |
| 306 class CIDToGIDMap { |
| 307 virtual unsigned int map(unsigned int cid) = 0; |
| 308 static CIDToGIDMap* fromName(const char* name); |
| 309 }; |
| 310 |
| 311 class CIDToGIDMap_Identity { |
| 312 virtual unsigned int map(unsigned int cid) { return cid; } |
| 313 |
| 314 static CIDToGIDMap_Identity* instance() { |
| 315 static CIDToGIDMap_Identity* inst = new CIDToGIDMap_Identity(); |
| 316 return inst; |
| 317 } |
| 318 }; |
| 319 |
| 320 CIDToGIDMap* CIDToGIDMap::fromName(const char* name) { |
| 321 // The only one supported right now is Identity |
| 322 if (strcmp(name, "Identity") == 0) { |
| 323 return CIDToGIDMap_Identity::instance(); |
| 324 } |
| 325 |
| 326 #ifdef PDF_TRACE |
| 327 // TODO(edisonn): warning/report |
| 328 printf("Unknown CIDToGIDMap: %s\n", name); |
| 329 #endif |
| 330 return NULL; |
| 331 } |
| 332 CIDToGIDMap* fCidToGid; |
| 333 */ |
256 | 334 |
257 class SkPdfType3Font : public SkPdfFont { | 335 class SkPdfType3Font : public SkPdfFont { |
| 336 struct Type3FontChar { |
| 337 SkPdfObject* fObj; |
| 338 double fWidth; |
| 339 }; |
| 340 |
| 341 SkPdfDictionary* fCharProcs; |
| 342 SkPdfEncodingDictionary* fEncodingDict; |
| 343 unsigned int fFirstChar; |
| 344 unsigned int fLastChar; |
| 345 |
| 346 SkRect fFontBBox; |
| 347 SkMatrix fFonMatrix; |
| 348 |
| 349 Type3FontChar* fChars; |
| 350 |
258 public: | 351 public: |
259 SkPdfType3Font(SkPdfType3FontDictionary* dict) { | 352 SkPdfType3Font(SkPdfType3FontDictionary* dict) { |
260 fBaseFont = SkPdfFontFromName(dict, dict->BaseFont().c_str()); | 353 fBaseFont = SkPdfFontFromName(dict, dict->BaseFont().c_str()); |
| 354 |
| 355 if (dict->has_Encoding()) { |
| 356 if (dict->isEncodingAName()) { |
| 357 fEncoding = SkPdfEncoding::fromName(dict->getEncodingAsName().c
_str()); |
| 358 } else if (dict->isEncodingAEncodingdictionary()) { |
| 359 // technically, there is no encoding. |
| 360 fEncoding = SkPdfCIDToGIDMapIdentityEncoding::instance(); |
| 361 fEncodingDict = dict->getEncodingAsEncodingdictionary(); |
| 362 } |
| 363 } |
| 364 |
| 365 // null? |
| 366 fCharProcs = dict->CharProcs(); |
| 367 |
| 368 fToUnicode = NULL; |
| 369 if (dict->has_ToUnicode()) { |
| 370 fToUnicode = new SkPdfToUnicode(dict->ToUnicode()); |
| 371 } |
| 372 |
| 373 fFirstChar = dict->FirstChar(); |
| 374 fLastChar = dict->LastChar(); |
| 375 fFonMatrix = dict->has_FontMatrix() ? *dict->FontMatrix() : SkMatrix::I(
); |
| 376 |
| 377 if (dict->FontBBox()) { |
| 378 fFontBBox = *dict->FontBBox(); |
| 379 } |
| 380 |
| 381 fChars = new Type3FontChar[fLastChar - fFirstChar + 1]; |
| 382 |
| 383 memset(fChars, 0, sizeof(fChars[0]) * (fLastChar - fFirstChar + 1)); |
| 384 |
| 385 |
| 386 SkPdfArray* widths = dict->Widths(); |
| 387 for (int i = 0 ; i < widths->size(); i++) { |
| 388 if ((fFirstChar + i) < fFirstChar || (fFirstChar + i) > fLastChar) { |
| 389 printf("break; error 1\n"); |
| 390 } |
| 391 fChars[i].fWidth = (*widths)[i]->asNumber()->value(); |
| 392 } |
| 393 |
| 394 SkPdfArray* diffs = fEncodingDict->Differences(); |
| 395 int j = fFirstChar; |
| 396 for (int i = 0 ; i < diffs->size(); i++) { |
| 397 if ((*diffs)[i]->asInteger()) { |
| 398 j = (*diffs)[i]->asInteger()->value(); |
| 399 } else if ((*diffs)[i]->asName()) { |
| 400 if (j < fFirstChar || j > fLastChar) { |
| 401 printf("break; error 2\n"); |
| 402 } |
| 403 fChars[j - fFirstChar].fObj = fCharProcs->get((*diffs)[i]->asNam
e()->value().c_str()); |
| 404 j++; |
| 405 } else { |
| 406 // err |
| 407 } |
| 408 } |
261 } | 409 } |
262 | 410 |
263 public: | 411 public: |
264 virtual void drawOneChar(unsigned int ch, SkPaint* paint, SkCanvas* canvas,
SkMatrix* matrix) { | 412 virtual void drawOneChar(unsigned int ch, SkPaint* paint, PdfContext* pdfCon
text, SkCanvas* canvas, SkMatrix* matrix) { |
| 413 if (ch < fFirstChar || ch > fLastChar || !fChars[ch - fFirstChar].fObj)
{ |
| 414 fBaseFont->drawOneChar(ToUnicode(ch), paint, pdfContext, canvas, mat
rix); |
| 415 return; |
| 416 } |
265 | 417 |
| 418 #ifdef PDF_TRACE |
| 419 printf("Type 3 char to unicode: %c\n", ToUnicode(ch)); |
| 420 if (ToUnicode(ch) == 'A') { |
| 421 printf("break;\n"); |
| 422 } |
| 423 #endif |
| 424 |
| 425 doType3Char(pdfContext, canvas, fChars[ch - fFirstChar].fObj, fFontBBox,
fFonMatrix, pdfContext->fGraphicsState.fCurFontSize); |
266 } | 426 } |
267 | 427 |
268 virtual void afterChar(SkPaint* paint, SkMatrix* matrix) { | 428 virtual void afterChar(SkPaint* paint, SkMatrix* matrix) { |
269 | |
270 } | 429 } |
271 | 430 |
272 virtual void afterWord(SkPaint* paint, SkMatrix* matrix) { | 431 virtual void afterWord(SkPaint* paint, SkMatrix* matrix) { |
273 | 432 |
274 } | 433 } |
275 }; | 434 }; |
276 | 435 |
277 #endif // __DEFINED__SkPdfFont | 436 #endif // __DEFINED__SkPdfFont |
OLD | NEW |