OLD | NEW |
1 #include "SkPdfFont.h" | 1 #include "SkPdfFont.h" |
2 | 2 |
3 #include "SkStream.h" | 3 #include "SkStream.h" |
4 #include "SkTypeface.h" | 4 #include "SkTypeface.h" |
5 #include "SkPdfNativeTokenizer.h" | 5 #include "SkPdfNativeTokenizer.h" |
6 | 6 |
7 std::map<std::string, SkPdfStandardFontEntry>& getStandardFonts() { | 7 std::map<std::string, SkPdfStandardFontEntry>& getStandardFonts() { |
8 static std::map<std::string, SkPdfStandardFontEntry> gPdfStandardFonts; | 8 static std::map<std::string, SkPdfStandardFontEntry> gPdfStandardFonts; |
9 | 9 |
10 // TODO (edisonn): , vs - ? what does it mean? | 10 // TODO (edisonn): , vs - ? what does it mean? |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 } else if (fd->has_FontFile2()) { | 157 } else if (fd->has_FontFile2()) { |
158 pdfStream = fd->FontFile2(doc); | 158 pdfStream = fd->FontFile2(doc); |
159 } if (fd->has_FontFile3()) { | 159 } if (fd->has_FontFile3()) { |
160 pdfStream = fd->FontFile3(doc); | 160 pdfStream = fd->FontFile3(doc); |
161 } else { | 161 } else { |
162 if (loadFromName) { | 162 if (loadFromName) { |
163 return fontFromName(doc, fd, fd->FontName(doc).c_str()); | 163 return fontFromName(doc, fd, fd->FontName(doc).c_str()); |
164 } | 164 } |
165 } | 165 } |
166 | 166 |
167 unsigned char* uncompressedStream = NULL; | 167 const unsigned char* uncompressedStream = NULL; |
168 size_t uncompressedStreamLength = 0; | 168 size_t uncompressedStreamLength = 0; |
169 | 169 |
170 // TODO(edisonn): report warning to be used in testing. | 170 // TODO(edisonn): report warning to be used in testing. |
171 if (!pdfStream || | 171 if (!pdfStream || |
172 !pdfStream->GetFilteredStreamRef(&uncompressedStream, &uncompressedS
treamLength, doc->allocator()) || | 172 !pdfStream->GetFilteredStreamRef(&uncompressedStream, &uncompressedS
treamLength) || |
173 !uncompressedStream || | 173 !uncompressedStream || |
174 !uncompressedStreamLength) { | 174 !uncompressedStreamLength) { |
175 return NULL; | 175 return NULL; |
176 } | 176 } |
177 | 177 |
178 SkMemoryStream* skStream = new SkMemoryStream(uncompressedStream, uncompress
edStreamLength); | 178 SkMemoryStream* skStream = new SkMemoryStream(uncompressedStream, uncompress
edStreamLength); |
179 SkTypeface* face = SkTypeface::CreateFromStream(skStream); | 179 SkTypeface* face = SkTypeface::CreateFromStream(skStream); |
180 | 180 |
181 if (face == NULL) { | 181 if (face == NULL) { |
182 // TODO(edisonn): report warning to be used in testing. | 182 // TODO(edisonn): report warning to be used in testing. |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 return ret; | 314 return ret; |
315 } | 315 } |
316 | 316 |
317 #define tokenIsKeyword(token,keyword) (token.fType == kKeyword_TokenType && toke
n.fKeywordLength==sizeof(keyword)-1 && strncmp(token.fKeyword, keyword, sizeof(k
eyword)-1) == 0) | 317 #define tokenIsKeyword(token,keyword) (token.fType == kKeyword_TokenType && toke
n.fKeywordLength==sizeof(keyword)-1 && strncmp(token.fKeyword, keyword, sizeof(k
eyword)-1) == 0) |
318 | 318 |
319 SkPdfToUnicode::SkPdfToUnicode(SkNativeParsedPDF* parsed, SkPdfStream* stream) :
fParsed(parsed) { | 319 SkPdfToUnicode::SkPdfToUnicode(SkNativeParsedPDF* parsed, SkPdfStream* stream) :
fParsed(parsed) { |
320 fCMapEncoding = NULL; | 320 fCMapEncoding = NULL; |
321 fCMapEncodingFlag = NULL; | 321 fCMapEncodingFlag = NULL; |
322 | 322 |
323 if (stream) { | 323 if (stream) { |
324 SkPdfNativeTokenizer* tokenizer = fParsed->tokenizerOfStream(stream); | 324 // Since font will be cached, the font has to sit in the per doc allocat
or, not to be |
| 325 // freed after the page is done drawing. |
| 326 SkPdfNativeTokenizer* tokenizer = fParsed->tokenizerOfStream(stream, par
sed->allocator()); |
325 PdfToken token; | 327 PdfToken token; |
326 | 328 |
327 fCMapEncoding = new unsigned short[256 * 256]; | 329 fCMapEncoding = new unsigned short[256 * 256]; |
328 fCMapEncodingFlag = new unsigned char[256 * 256]; | 330 fCMapEncodingFlag = new unsigned char[256 * 256]; |
329 for (int i = 0 ; i < 256 * 256; i++) { | 331 for (int i = 0 ; i < 256 * 256; i++) { |
330 fCMapEncoding[i] = i; | 332 fCMapEncoding[i] = i; |
331 fCMapEncodingFlag[i] = 0; | 333 fCMapEncodingFlag[i] = 0; |
332 } | 334 } |
333 | 335 |
334 // TODO(edisonn): deal with multibyte character, or longer strings. | 336 // TODO(edisonn): deal with multibyte character, or longer strings. |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 SkPdfEncoding* SkPdfEncoding::fromName(const char* name) { | 444 SkPdfEncoding* SkPdfEncoding::fromName(const char* name) { |
443 SkPdfEncoding* encoding = getStandardEncodings()[name]; | 445 SkPdfEncoding* encoding = getStandardEncodings()[name]; |
444 | 446 |
445 #ifdef PDF_TRACE | 447 #ifdef PDF_TRACE |
446 if (encoding == NULL) { | 448 if (encoding == NULL) { |
447 printf("Encoding not found: %s\n", name); | 449 printf("Encoding not found: %s\n", name); |
448 } | 450 } |
449 #endif | 451 #endif |
450 return encoding; | 452 return encoding; |
451 } | 453 } |
OLD | NEW |