| OLD | NEW |
| 1 #include "SkPdfFont.h" | 1 #include "SkPdfFont.h" |
| 2 #include "SkPdfParser.h" | 2 #include "SkPdfParser.h" |
| 3 | 3 |
| 4 #include "SkStream.h" | 4 #include "SkStream.h" |
| 5 #include "SkTypeface.h" | 5 #include "SkTypeface.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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 fontName, | 141 fontName, |
| 142 SkTypeface::kNormal); | 142 SkTypeface::kNormal); |
| 143 } | 143 } |
| 144 | 144 |
| 145 if (typeface) { | 145 if (typeface) { |
| 146 typeface->ref(); | 146 typeface->ref(); |
| 147 } | 147 } |
| 148 return typeface; | 148 return typeface; |
| 149 } | 149 } |
| 150 | 150 |
| 151 static SkPdfFont* fontFromFontDescriptor(SkPdfFontDescriptorDictionary* fd) { | 151 SkPdfFont* SkPdfFont::fontFromFontDescriptor(SkPdfFontDescriptorDictionary* fd,
bool loadFromName) { |
| 152 // TODO(edisonn): partial implementation |
| 152 // Only one, at most be available | 153 // Only one, at most be available |
| 154 SkPdfStream* pdfStream = NULL; |
| 153 if (fd->has_FontFile()) { | 155 if (fd->has_FontFile()) { |
| 154 | 156 pdfStream = fd->FontFile(); |
| 155 } else if (fd->has_FontFile2()) { | 157 } else if (fd->has_FontFile2()) { |
| 156 SkPdfStream* pdfStream = fd->FontFile2(); | 158 pdfStream = fd->FontFile2(); |
| 157 | 159 } if (fd->has_FontFile3()) { |
| 158 if (!pdfStream->podofo()->GetStream()) { | 160 pdfStream = fd->FontFile3(); |
| 159 // TODO(edisonn): report warning to be used in testing. | 161 } else { |
| 160 return NULL; | 162 if (loadFromName) { |
| 163 return fontFromName(fd, fd->FontName().c_str()); |
| 161 } | 164 } |
| 162 | |
| 163 char* uncompressedStream = NULL; | |
| 164 pdf_long uncompressedStreamLength = 0; | |
| 165 | |
| 166 // TODO(edisonn): get rid of try/catch exceptions! We should not throw o
n user data! | |
| 167 try { | |
| 168 pdfStream->podofo()->GetStream()->GetFilteredCopy(&uncompressedStrea
m, &uncompressedStreamLength); | |
| 169 } catch (PdfError& e) { | |
| 170 // TODO(edisonn): report warning to be used in testing. | |
| 171 return NULL; | |
| 172 } | |
| 173 SkMemoryStream* skStream = new SkMemoryStream(uncompressedStream, uncomp
ressedStreamLength); | |
| 174 SkTypeface* face = SkTypeface::CreateFromStream(skStream); | |
| 175 | |
| 176 if (face == NULL) { | |
| 177 // TODO(edisonn): report warning to be used in testing. | |
| 178 return NULL; | |
| 179 } | |
| 180 | |
| 181 face->ref(); | |
| 182 | |
| 183 return new SkPdfStandardFont(face); | |
| 184 } if (fd->has_FontFile3()) { | |
| 185 | |
| 186 } else { | |
| 187 | |
| 188 } | 165 } |
| 189 | 166 |
| 190 return NULL; | 167 if (!pdfStream || !pdfStream->podofo()->GetStream()) { |
| 168 // TODO(edisonn): report warning to be used in testing. |
| 169 return NULL; |
| 170 } |
| 171 |
| 172 char* uncompressedStream = NULL; |
| 173 pdf_long uncompressedStreamLength = 0; |
| 174 |
| 175 // TODO(edisonn): get rid of try/catch exceptions! We should not throw on us
er data! |
| 176 try { |
| 177 pdfStream->podofo()->GetStream()->GetFilteredCopy(&uncompressedStream, &
uncompressedStreamLength); |
| 178 } catch (PdfError& e) { |
| 179 // TODO(edisonn): report warning to be used in testing. |
| 180 return NULL; |
| 181 } |
| 182 SkMemoryStream* skStream = new SkMemoryStream(uncompressedStream, uncompress
edStreamLength); |
| 183 SkTypeface* face = SkTypeface::CreateFromStream(skStream); |
| 184 |
| 185 if (face == NULL) { |
| 186 // TODO(edisonn): report warning to be used in testing. |
| 187 return NULL; |
| 188 } |
| 189 |
| 190 face->ref(); |
| 191 |
| 192 return new SkPdfStandardFont(face); |
| 191 } | 193 } |
| 192 | 194 |
| 193 SkPdfFont* SkPdfFontFromName(SkPdfObject* obj, const char* fontName) { | 195 SkPdfFont* fontFromName(SkPdfObject* obj, const char* fontName) { |
| 194 SkTypeface* typeface = SkTypefaceFromPdfStandardFont(fontName, false, false)
; | 196 SkTypeface* typeface = SkTypefaceFromPdfStandardFont(fontName, false, false)
; |
| 195 if (typeface != NULL) { | 197 if (typeface != NULL) { |
| 196 return new SkPdfStandardFont(typeface); | 198 return new SkPdfStandardFont(typeface); |
| 197 } | 199 } |
| 198 | 200 |
| 199 // TODO(edisonn): perf - make a map | 201 // TODO(edisonn): perf - make a map |
| 200 for (int i = 0 ; i < obj->doc()->GetObjects().GetSize(); i++) { | 202 for (int i = 0 ; i < obj->doc()->GetObjects().GetSize(); i++) { |
| 201 PdfVecObjects& objects = (PdfVecObjects&)obj->doc()->GetObjects(); | 203 PdfVecObjects& objects = (PdfVecObjects&)obj->doc()->GetObjects(); |
| 202 const PdfObject* podofoFont = objects[i]; | 204 const PdfObject* podofoFont = objects[i]; |
| 203 SkPdfFontDescriptorDictionary* fd = NULL; | 205 SkPdfFontDescriptorDictionary* fd = NULL; |
| 204 if (mapFontDescriptorDictionary(*obj->doc(), *podofoFont, &fd)) { | 206 if (mapFontDescriptorDictionary(*obj->doc(), *podofoFont, &fd)) { |
| 205 if (fd->has_FontName() && fd->FontName() == fontName) { | 207 if (fd->has_FontName() && fd->FontName() == fontName) { |
| 206 SkPdfFont* font = fontFromFontDescriptor(fd); | 208 SkPdfFont* font = SkPdfFont::fontFromFontDescriptor(fd, false); |
| 207 if (font) { | 209 if (font) { |
| 208 return font; | 210 return font; |
| 209 } else { | 211 } else { |
| 210 // failed to load font descriptor | 212 // failed to load font descriptor |
| 211 break; | 213 break; |
| 212 } | 214 } |
| 213 } | 215 } |
| 214 } | 216 } |
| 215 } | 217 } |
| 216 | 218 |
| 217 // TODO(edisonn): warning/report issue | 219 // TODO(edisonn): warning/report issue |
| 218 return SkPdfFont::Default(); | 220 return SkPdfFont::Default(); |
| 219 } | 221 } |
| 220 | 222 |
| 221 SkPdfFont* SkPdfFont::fontFromPdfDictionary(SkPdfFontDictionary* dict) { | 223 SkPdfFont* SkPdfFont::fontFromPdfDictionary(SkPdfFontDictionary* dict) { |
| 222 if (dict == NULL) { | 224 if (dict == NULL) { |
| 223 return NULL; // TODO(edisonn): report default one? | 225 return NULL; // TODO(edisonn): report default one? |
| 224 } | 226 } |
| 225 | 227 |
| 226 switch (dict->getType()) { | 228 switch (dict->getType()) { |
| 227 case kType0FontDictionary_SkPdfObjectType: | 229 case kType0FontDictionary_SkPdfObjectType: |
| 228 return fontFromType0FontDictionary(dict->asType0FontDictionary()); | 230 return fontFromType0FontDictionary(dict->asType0FontDictionary()); |
| 229 | 231 |
| 230 case kTrueTypeFontDictionary_SkPdfObjectType: | 232 case kTrueTypeFontDictionary_SkPdfObjectType: |
| 231 return fontFromTrueTypeFontDictionary(dict->asTrueTypeFontDictionary
()); | 233 return fontFromTrueTypeFontDictionary(dict->asTrueTypeFontDictionary
()); |
| 232 | 234 |
| 233 case kType1FontDictionary_SkPdfObjectType: | 235 case kType1FontDictionary_SkPdfObjectType: |
| 234 return fontFromType1FontDictionary(dict->asType1FontDictionary()); | 236 return fontFromType1FontDictionary(dict->asType1FontDictionary()); |
| 235 | 237 |
| 236 case kCIDFontDictionary_SkPdfObjectType: | |
| 237 return fontFromCIDFontDictionary(dict->asCIDFontDictionary()); | |
| 238 | |
| 239 case kMultiMasterFontDictionary_SkPdfObjectType: | 238 case kMultiMasterFontDictionary_SkPdfObjectType: |
| 240 return fontFromMultiMasterFontDictionary(dict->asMultiMasterFontDict
ionary()); | 239 return fontFromMultiMasterFontDictionary(dict->asMultiMasterFontDict
ionary()); |
| 241 | 240 |
| 242 case kType3FontDictionary_SkPdfObjectType: | 241 case kType3FontDictionary_SkPdfObjectType: |
| 243 return fontFromType3FontDictionary(dict->asType3FontDictionary()); | 242 return fontFromType3FontDictionary(dict->asType3FontDictionary()); |
| 244 } | 243 } |
| 245 return NULL; // TODO(edisonn): report error? | 244 return NULL; // TODO(edisonn): report error? |
| 246 } | 245 } |
| 247 | 246 |
| 248 SkPdfType0Font* SkPdfFont::fontFromType0FontDictionary(SkPdfType0FontDictionary*
dict) { | 247 SkPdfType0Font* SkPdfFont::fontFromType0FontDictionary(SkPdfType0FontDictionary*
dict) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 272 } | 271 } |
| 273 | 272 |
| 274 SkPdfTrueTypeFont* SkPdfFont::fontFromTrueTypeFontDictionary(SkPdfTrueTypeFontDi
ctionary* dict) { | 273 SkPdfTrueTypeFont* SkPdfFont::fontFromTrueTypeFontDictionary(SkPdfTrueTypeFontDi
ctionary* dict) { |
| 275 if (dict == NULL) { | 274 if (dict == NULL) { |
| 276 return NULL; // default one? | 275 return NULL; // default one? |
| 277 } | 276 } |
| 278 | 277 |
| 279 return new SkPdfTrueTypeFont(dict); | 278 return new SkPdfTrueTypeFont(dict); |
| 280 } | 279 } |
| 281 | 280 |
| 282 SkPdfCIDFont* SkPdfFont::fontFromCIDFontDictionary(SkPdfCIDFontDictionary* dict)
{ | |
| 283 if (dict == NULL) { | |
| 284 return NULL; // default one? | |
| 285 } | |
| 286 | |
| 287 return new SkPdfCIDFont(dict); | |
| 288 } | |
| 289 | |
| 290 SkPdfMultiMasterFont* SkPdfFont::fontFromMultiMasterFontDictionary(SkPdfMultiMas
terFontDictionary* dict) { | 281 SkPdfMultiMasterFont* SkPdfFont::fontFromMultiMasterFontDictionary(SkPdfMultiMas
terFontDictionary* dict) { |
| 291 if (dict == NULL) { | 282 if (dict == NULL) { |
| 292 return NULL; // default one? | 283 return NULL; // default one? |
| 293 } | 284 } |
| 294 | 285 |
| 295 return new SkPdfMultiMasterFont(dict); | 286 return new SkPdfMultiMasterFont(dict); |
| 296 } | 287 } |
| 297 | 288 |
| 298 static int skstoi(const SkPdfString* str) { | 289 static int skstoi(const SkPdfString* str) { |
| 299 int ret = 0; | 290 int ret = 0; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 //fCMapEncodingFlag[from] = 1; | 380 //fCMapEncodingFlag[from] = 1; |
| 390 //fCMapEncoding[from] = to; | 381 //fCMapEncoding[from] = to; |
| 391 } | 382 } |
| 392 } | 383 } |
| 393 } | 384 } |
| 394 } | 385 } |
| 395 } | 386 } |
| 396 | 387 |
| 397 | 388 |
| 398 SkPdfType0Font::SkPdfType0Font(SkPdfType0FontDictionary* dict) { | 389 SkPdfType0Font::SkPdfType0Font(SkPdfType0FontDictionary* dict) { |
| 399 fBaseFont = SkPdfFontFromName(dict, dict->BaseFont().c_str()); | 390 fBaseFont = fontFromName(dict, dict->BaseFont().c_str()); |
| 400 fEncoding = NULL; | 391 fEncoding = NULL; |
| 401 | 392 |
| 402 if (dict->has_Encoding()) { | 393 if (dict->has_Encoding()) { |
| 403 if (dict->isEncodingAName()) { | 394 if (dict->isEncodingAName()) { |
| 404 fEncoding = SkPdfEncoding::fromName(dict->getEncodingAsName().c_str(
)); | 395 fEncoding = SkPdfEncoding::fromName(dict->getEncodingAsName().c_str(
)); |
| 405 } else if (dict->isEncodingAStream()) { | 396 } else if (dict->isEncodingAStream()) { |
| 406 //fEncoding = loadEncodingFromStream(dict->getEncodingAsStream()); | 397 //fEncoding = loadEncodingFromStream(dict->getEncodingAsStream()); |
| 407 } else { | 398 } else { |
| 408 // TODO(edisonn): error ... warning .. assert? | 399 // TODO(edisonn): error ... warning .. assert? |
| 409 } | 400 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 427 SkPdfEncoding* SkPdfEncoding::fromName(const char* name) { | 418 SkPdfEncoding* SkPdfEncoding::fromName(const char* name) { |
| 428 SkPdfEncoding* encoding = getStandardEncodings()[name]; | 419 SkPdfEncoding* encoding = getStandardEncodings()[name]; |
| 429 | 420 |
| 430 #ifdef PDF_TRACE | 421 #ifdef PDF_TRACE |
| 431 if (encoding == NULL) { | 422 if (encoding == NULL) { |
| 432 printf("Encoding not found: %s\n", name); | 423 printf("Encoding not found: %s\n", name); |
| 433 } | 424 } |
| 434 #endif | 425 #endif |
| 435 return encoding; | 426 return encoding; |
| 436 } | 427 } |
| OLD | NEW |