more work on pdf fonts, more to come

Review URL: https://codereview.chromium.org/18117005

git-svn-id: http://skia.googlecode.com/svn/trunk@9796 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/experimental/PdfViewer/SkPdfFont.cpp b/experimental/PdfViewer/SkPdfFont.cpp
index 42c8056..8170453 100644
--- a/experimental/PdfViewer/SkPdfFont.cpp
+++ b/experimental/PdfViewer/SkPdfFont.cpp
@@ -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;
-        }
-
-        char* uncompressedStream = NULL;
-        pdf_long uncompressedStreamLength = 0;
-
-        // 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);
-
-        if (face == NULL) {
-            // TODO(edisonn): report warning to be used in testing.
-            return NULL;
-        }
-
-        face->ref();
-
-        return new SkPdfStandardFont(face);
+        pdfStream = fd->FontFile2();
     } if (fd->has_FontFile3()) {
-
+        pdfStream = fd->FontFile3();
     } else {
-
+        if (loadFromName) {
+            return fontFromName(fd, fd->FontName().c_str());
+        }
     }
 
-    return NULL;
+    if (!pdfStream || !pdfStream->podofo()->GetStream()) {
+        // TODO(edisonn): report warning to be used in testing.
+        return NULL;
+    }
+
+    char* uncompressedStream = NULL;
+    pdf_long uncompressedStreamLength = 0;
+
+    // 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);
+
+    if (face == NULL) {
+        // TODO(edisonn): report warning to be used in testing.
+        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()) {