OLD | NEW |
1 #include "SkPdfFont.h" | 1 #include "SkPdfFont.h" |
2 #include "SkPdfParser.h" | 2 #include "SkPdfParser.h" |
3 | 3 |
| 4 #include "SkStream.h" |
| 5 #include "SkTypeface.h" |
| 6 |
4 std::map<std::string, SkPdfStandardFontEntry>& getStandardFonts() { | 7 std::map<std::string, SkPdfStandardFontEntry>& getStandardFonts() { |
5 static std::map<std::string, SkPdfStandardFontEntry> gPdfStandardFonts; | 8 static std::map<std::string, SkPdfStandardFontEntry> gPdfStandardFonts; |
6 | 9 |
7 // TODO (edisonn): , vs - ? what does it mean? | 10 // TODO (edisonn): , vs - ? what does it mean? |
8 // TODO (edisonn): MT, PS, Oblique=italic?, ... what does it mean? | 11 // TODO (edisonn): MT, PS, Oblique=italic?, ... what does it mean? |
9 if (gPdfStandardFonts.empty()) { | 12 if (gPdfStandardFonts.empty()) { |
10 gPdfStandardFonts["Arial"] = {"Arial", false, false}; | 13 gPdfStandardFonts["Arial"] = {"Arial", false, false}; |
11 gPdfStandardFonts["Arial,Bold"] = {"Arial", true, false}; | 14 gPdfStandardFonts["Arial,Bold"] = {"Arial", true, false}; |
12 gPdfStandardFonts["Arial,BoldItalic"] = {"Arial", true, true}; | 15 gPdfStandardFonts["Arial,BoldItalic"] = {"Arial", true, true}; |
13 gPdfStandardFonts["Arial,Italic"] = {"Arial", false, true}; | 16 gPdfStandardFonts["Arial,Italic"] = {"Arial", false, true}; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 fontName, | 141 fontName, |
139 SkTypeface::kNormal); | 142 SkTypeface::kNormal); |
140 } | 143 } |
141 | 144 |
142 if (typeface) { | 145 if (typeface) { |
143 typeface->ref(); | 146 typeface->ref(); |
144 } | 147 } |
145 return typeface; | 148 return typeface; |
146 } | 149 } |
147 | 150 |
| 151 static SkPdfFont* fontFromFontDescriptor(SkPdfFontDescriptorDictionary* fd) { |
| 152 // Only one, at most be available |
| 153 if (fd->has_FontFile()) { |
| 154 |
| 155 } else if (fd->has_FontFile2()) { |
| 156 SkPdfStream* pdfStream = fd->FontFile2(); |
| 157 |
| 158 if (!pdfStream->podofo()->GetStream()) { |
| 159 // TODO(edisonn): report warning to be used in testing. |
| 160 return NULL; |
| 161 } |
| 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 } |
| 189 |
| 190 return NULL; |
| 191 } |
| 192 |
148 SkPdfFont* SkPdfFontFromName(SkPdfObject* obj, const char* fontName) { | 193 SkPdfFont* SkPdfFontFromName(SkPdfObject* obj, const char* fontName) { |
149 SkTypeface* typeface = SkTypefaceFromPdfStandardFont(fontName, false, false)
; | 194 SkTypeface* typeface = SkTypefaceFromPdfStandardFont(fontName, false, false)
; |
150 if (typeface != NULL) { | 195 if (typeface != NULL) { |
151 return new SkPdfStandardFont(typeface); | 196 return new SkPdfStandardFont(typeface); |
152 } | 197 } |
153 // SkPdfObject* font = obtainFont(pdfContext, fontName); | 198 |
154 // if (!font->asFontDictionary()) { | 199 // TODO(edisonn): perf - make a map |
155 // return NULL; | 200 for (int i = 0 ; i < obj->doc()->GetObjects().GetSize(); i++) { |
156 // } | 201 PdfVecObjects& objects = (PdfVecObjects&)obj->doc()->GetObjects(); |
157 // SkPdfFont::fontFromPdfDictionary(font->asDictionary()); | 202 const PdfObject* podofoFont = objects[i]; |
158 // } | 203 SkPdfFontDescriptorDictionary* fd = NULL; |
159 // TODO(edisonn): deal with inherited fonts, load from parent objects | 204 if (mapFontDescriptorDictionary(*obj->doc(), *podofoFont, &fd)) { |
| 205 if (fd->has_FontName() && fd->FontName() == fontName) { |
| 206 SkPdfFont* font = fontFromFontDescriptor(fd); |
| 207 if (font) { |
| 208 return font; |
| 209 } else { |
| 210 // failed to load font descriptor |
| 211 break; |
| 212 } |
| 213 } |
| 214 } |
| 215 } |
| 216 |
| 217 // TODO(edisonn): warning/report issue |
160 return SkPdfFont::Default(); | 218 return SkPdfFont::Default(); |
161 } | 219 } |
162 | 220 |
163 SkPdfFont* SkPdfFont::fontFromPdfDictionary(SkPdfFontDictionary* dict) { | 221 SkPdfFont* SkPdfFont::fontFromPdfDictionary(SkPdfFontDictionary* dict) { |
164 if (dict == NULL) { | 222 if (dict == NULL) { |
165 return NULL; // TODO(edisonn): report default one? | 223 return NULL; // TODO(edisonn): report default one? |
166 } | 224 } |
167 | 225 |
168 switch (dict->getType()) { | 226 switch (dict->getType()) { |
169 case kType0FontDictionary_SkPdfObjectType: | 227 case kType0FontDictionary_SkPdfObjectType: |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 SkPdfEncoding* SkPdfEncoding::fromName(const char* name) { | 427 SkPdfEncoding* SkPdfEncoding::fromName(const char* name) { |
370 SkPdfEncoding* encoding = getStandardEncodings()[name]; | 428 SkPdfEncoding* encoding = getStandardEncodings()[name]; |
371 | 429 |
372 #ifdef PDF_TRACE | 430 #ifdef PDF_TRACE |
373 if (encoding == NULL) { | 431 if (encoding == NULL) { |
374 printf("Encoding not found: %s\n", name); | 432 printf("Encoding not found: %s\n", name); |
375 } | 433 } |
376 #endif | 434 #endif |
377 return encoding; | 435 return encoding; |
378 } | 436 } |
OLD | NEW |