Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Unified Diff: experimental/PdfViewer/SkPdfFont.cpp

Issue 18117005: more work on pdf fonts, more to come (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « experimental/PdfViewer/SkPdfFont.h ('k') | experimental/PdfViewer/SkPdfParser.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: experimental/PdfViewer/SkPdfFont.cpp
===================================================================
--- experimental/PdfViewer/SkPdfFont.cpp (revision 9788)
+++ experimental/PdfViewer/SkPdfFont.cpp (working copy)
@@ -148,49 +148,51 @@
return typeface;
}
-static SkPdfFont* fontFromFontDescriptor(SkPdfFontDescriptorDictionary* fd) {
+SkPdfFont* SkPdfFont::fontFromFontDescriptor(SkPdfFontDescriptorDictionary* fd, bool loadFromName) {
+ // TODO(edisonn): partial implementation
// Only one, at most be available
+ SkPdfStream* pdfStream = NULL;
if (fd->has_FontFile()) {
-
+ pdfStream = fd->FontFile();
} else if (fd->has_FontFile2()) {
- SkPdfStream* pdfStream = fd->FontFile2();
-
- if (!pdfStream->podofo()->GetStream()) {
- // TODO(edisonn): report warning to be used in testing.
- return NULL;
+ pdfStream = fd->FontFile2();
+ } if (fd->has_FontFile3()) {
+ pdfStream = fd->FontFile3();
+ } else {
+ if (loadFromName) {
+ return fontFromName(fd, fd->FontName().c_str());
}
+ }
- char* uncompressedStream = NULL;
- pdf_long uncompressedStreamLength = 0;
+ if (!pdfStream || !pdfStream->podofo()->GetStream()) {
+ // TODO(edisonn): report warning to be used in testing.
+ return NULL;
+ }
- // TODO(edisonn): get rid of try/catch exceptions! We should not throw on user data!
- try {
- pdfStream->podofo()->GetStream()->GetFilteredCopy(&uncompressedStream, &uncompressedStreamLength);
- } catch (PdfError& e) {
- // TODO(edisonn): report warning to be used in testing.
- return NULL;
- }
- SkMemoryStream* skStream = new SkMemoryStream(uncompressedStream, uncompressedStreamLength);
- SkTypeface* face = SkTypeface::CreateFromStream(skStream);
+ char* uncompressedStream = NULL;
+ pdf_long uncompressedStreamLength = 0;
- if (face == NULL) {
- // TODO(edisonn): report warning to be used in testing.
- return NULL;
- }
+ // TODO(edisonn): get rid of try/catch exceptions! We should not throw on user data!
+ try {
+ pdfStream->podofo()->GetStream()->GetFilteredCopy(&uncompressedStream, &uncompressedStreamLength);
+ } catch (PdfError& e) {
+ // TODO(edisonn): report warning to be used in testing.
+ return NULL;
+ }
+ SkMemoryStream* skStream = new SkMemoryStream(uncompressedStream, uncompressedStreamLength);
+ SkTypeface* face = SkTypeface::CreateFromStream(skStream);
- face->ref();
-
- return new SkPdfStandardFont(face);
- } if (fd->has_FontFile3()) {
-
- } else {
-
+ if (face == NULL) {
+ // TODO(edisonn): report warning to be used in testing.
+ return NULL;
}
- return NULL;
+ face->ref();
+
+ return new SkPdfStandardFont(face);
}
-SkPdfFont* SkPdfFontFromName(SkPdfObject* obj, const char* fontName) {
+SkPdfFont* fontFromName(SkPdfObject* obj, const char* fontName) {
SkTypeface* typeface = SkTypefaceFromPdfStandardFont(fontName, false, false);
if (typeface != NULL) {
return new SkPdfStandardFont(typeface);
@@ -203,7 +205,7 @@
SkPdfFontDescriptorDictionary* fd = NULL;
if (mapFontDescriptorDictionary(*obj->doc(), *podofoFont, &fd)) {
if (fd->has_FontName() && fd->FontName() == fontName) {
- SkPdfFont* font = fontFromFontDescriptor(fd);
+ SkPdfFont* font = SkPdfFont::fontFromFontDescriptor(fd, false);
if (font) {
return font;
} else {
@@ -233,9 +235,6 @@
case kType1FontDictionary_SkPdfObjectType:
return fontFromType1FontDictionary(dict->asType1FontDictionary());
- case kCIDFontDictionary_SkPdfObjectType:
- return fontFromCIDFontDictionary(dict->asCIDFontDictionary());
-
case kMultiMasterFontDictionary_SkPdfObjectType:
return fontFromMultiMasterFontDictionary(dict->asMultiMasterFontDictionary());
@@ -279,14 +278,6 @@
return new SkPdfTrueTypeFont(dict);
}
-SkPdfCIDFont* SkPdfFont::fontFromCIDFontDictionary(SkPdfCIDFontDictionary* dict) {
- if (dict == NULL) {
- return NULL; // default one?
- }
-
- return new SkPdfCIDFont(dict);
-}
-
SkPdfMultiMasterFont* SkPdfFont::fontFromMultiMasterFontDictionary(SkPdfMultiMasterFontDictionary* dict) {
if (dict == NULL) {
return NULL; // default one?
@@ -396,7 +387,7 @@
SkPdfType0Font::SkPdfType0Font(SkPdfType0FontDictionary* dict) {
- fBaseFont = SkPdfFontFromName(dict, dict->BaseFont().c_str());
+ fBaseFont = fontFromName(dict, dict->BaseFont().c_str());
fEncoding = NULL;
if (dict->has_Encoding()) {
« no previous file with comments | « experimental/PdfViewer/SkPdfFont.h ('k') | experimental/PdfViewer/SkPdfParser.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698