Revert "[PDF] Fix font embedding restrictions."

This reverts r12600 and r12601, likely causing crash on Mac.

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

git-svn-id: http://skia.googlecode.com/svn/trunk@12604 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/pdf/SkPDFDocument.cpp b/src/pdf/SkPDFDocument.cpp
index 79699a0..0633d30 100644
--- a/src/pdf/SkPDFDocument.cpp
+++ b/src/pdf/SkPDFDocument.cpp
@@ -258,13 +258,11 @@
     return true;
 }
 
-// Deprecated.
 void SkPDFDocument::getCountOfFontTypes(
-        int counts[SkAdvancedTypefaceMetrics::kOther_Font + 2]) const {
+        int counts[SkAdvancedTypefaceMetrics::kNotEmbeddable_Font + 1]) const {
     sk_bzero(counts, sizeof(int) *
-                     (SkAdvancedTypefaceMetrics::kOther_Font + 2));
+                     (SkAdvancedTypefaceMetrics::kNotEmbeddable_Font + 1));
     SkTDArray<SkFontID> seenFonts;
-    int notEmbeddable = 0;
 
     for (int pageNumber = 0; pageNumber < fPages.count(); pageNumber++) {
         const SkTDArray<SkPDFFont*>& fontResources =
@@ -274,49 +272,9 @@
             if (seenFonts.find(fontID) == -1) {
                 counts[fontResources[font]->getType()]++;
                 seenFonts.push(fontID);
-                if (!fontResources[font]->canEmbed()) {
-                    notEmbeddable++;
-                }
             }
         }
     }
-    counts[SkAdvancedTypefaceMetrics::kOther_Font + 1] = notEmbeddable;
-}
-
-void SkPDFDocument::getCountOfFontTypes(
-        int counts[SkAdvancedTypefaceMetrics::kOther_Font + 1],
-        int* notSubsettableCount,
-        int* notEmbeddableCount) const {
-    sk_bzero(counts, sizeof(int) *
-                     (SkAdvancedTypefaceMetrics::kOther_Font + 1));
-    SkTDArray<SkFontID> seenFonts;
-    int notSubsettable = 0;
-    int notEmbeddable = 0;
-
-    for (int pageNumber = 0; pageNumber < fPages.count(); pageNumber++) {
-        const SkTDArray<SkPDFFont*>& fontResources =
-                fPages[pageNumber]->getFontResources();
-        for (int font = 0; font < fontResources.count(); font++) {
-            SkFontID fontID = fontResources[font]->typeface()->uniqueID();
-            if (seenFonts.find(fontID) == -1) {
-                counts[fontResources[font]->getType()]++;
-                seenFonts.push(fontID);
-                if (!fontResources[font]->canSubset()) {
-                    notSubsettable++;
-                }
-                if (!fontResources[font]->canEmbed()) {
-                    notEmbeddable++;
-                }
-            }
-        }
-    }
-    if (notSubsettableCount) {
-        *notSubsettableCount = notSubsettable;
-
-    }
-    if (notEmbeddableCount) {
-        *notEmbeddableCount = notEmbeddable;
-    }
 }
 
 void SkPDFDocument::emitHeader(SkWStream* stream) {
diff --git a/src/pdf/SkPDFFont.cpp b/src/pdf/SkPDFFont.cpp
index 30c11d9..1641a89 100644
--- a/src/pdf/SkPDFFont.cpp
+++ b/src/pdf/SkPDFFont.cpp
@@ -749,24 +749,6 @@
     return fFontType;
 }
 
-bool SkPDFFont::canEmbed() const {
-    if (!fFontInfo.get()) {
-        SkASSERT(fFontType == SkAdvancedTypefaceMetrics::kOther_Font);
-        return true;
-    }
-    return (fFontInfo->fFlags &
-            SkAdvancedTypefaceMetrics::kNotEmbeddable_FontFlag) == 0;
-}
-
-bool SkPDFFont::canSubset() const {
-    if (!fFontInfo.get()) {
-        SkASSERT(fFontType == SkAdvancedTypefaceMetrics::kOther_Font);
-        return true;
-    }
-    return (fFontInfo->fFlags &
-            SkAdvancedTypefaceMetrics::kNotSubsettable_FontFlag) == 0;
-}
-
 bool SkPDFFont::hasGlyph(uint16_t id) {
     return (id >= fFirstGlyphID && id <= fLastGlyphID) || id == 0;
 }
@@ -815,7 +797,7 @@
 
         // This only is to catch callers who pass invalid glyph ids.
         // If glyph id is invalid, then we will create duplicate entries
-        // for TrueType fonts.
+        // for True Type fonts.
         SkAdvancedTypefaceMetrics::FontType fontType =
             fontMetrics.get() ? fontMetrics.get()->fType :
                                 SkAdvancedTypefaceMetrics::kOther_Font;
@@ -895,8 +877,9 @@
           fLastGlyphID(info ? info->fLastGlyphID : 0),
           fFontInfo(SkSafeRef(info)),
           fDescriptor(SkSafeRef(relatedFontDescriptor)) {
-    if (info == NULL ||
-            info->fFlags & SkAdvancedTypefaceMetrics::kMultiMaster_FontFlag) {
+    if (info == NULL) {
+        fFontType = SkAdvancedTypefaceMetrics::kNotEmbeddable_Font;
+    } else if (info->fMultiMaster) {
         fFontType = SkAdvancedTypefaceMetrics::kOther_Font;
     } else {
         fFontType = info->fType;
@@ -908,10 +891,9 @@
                              SkTypeface* typeface, uint16_t glyphID,
                              SkPDFDict* relatedFontDescriptor) {
     SkAdvancedTypefaceMetrics::FontType type =
-        info ? info->fType : SkAdvancedTypefaceMetrics::kOther_Font;
+        info ? info->fType : SkAdvancedTypefaceMetrics::kNotEmbeddable_Font;
 
-    if (info &&
-            (info->fFlags & SkAdvancedTypefaceMetrics::kMultiMaster_FontFlag)) {
+    if (info && info->fMultiMaster) {
         NOT_IMPLEMENTED(true, true);
         return new SkPDFType3Font(info,
                                   typeface,
@@ -930,7 +912,8 @@
     }
 
     SkASSERT(type == SkAdvancedTypefaceMetrics::kCFF_Font ||
-             type == SkAdvancedTypefaceMetrics::kOther_Font);
+             type == SkAdvancedTypefaceMetrics::kOther_Font ||
+             type == SkAdvancedTypefaceMetrics::kNotEmbeddable_Font);
 
     return new SkPDFType3Font(info, typeface, glyphID);
 }
@@ -1057,17 +1040,11 @@
                                SkTypeface* typeface)
         : SkPDFFont(info, typeface, NULL) {
     SkDEBUGCODE(fPopulated = false);
-    if (!canSubset()) {
-        populate(NULL);
-    }
 }
 
 SkPDFType0Font::~SkPDFType0Font() {}
 
 SkPDFFont* SkPDFType0Font::getFontSubset(const SkPDFGlyphSet* subset) {
-    if (!canSubset()) {
-        return NULL;
-    }
     SkPDFType0Font* newSubset = new SkPDFType0Font(fontInfo(), typeface());
     newSubset->populate(subset);
     return newSubset;
@@ -1116,34 +1093,19 @@
     SkAutoTUnref<SkPDFDict> descriptor(new SkPDFDict("FontDescriptor"));
     setFontDescriptor(descriptor.get());
     addResource(descriptor.get());
-    insert("FontDescriptor", new SkPDFObjRef(descriptor.get()))->unref();
-    if (!addCommonFontDescriptorEntries(defaultWidth)) {
-        return false;
-    }
-    if (!canEmbed()) {
-        return true;
-    }
 
     switch (getType()) {
         case SkAdvancedTypefaceMetrics::kTrueType_Font: {
-            SkAutoTUnref<SkPDFStream> fontStream;
-            int fontSize = 0;
-            if (canSubset()) {
-                SkPDFStream* rawStream = NULL;
-                fontSize = get_subset_font_stream(fontInfo()->fFontName.c_str(),
+            SkASSERT(subset);
+            // Font subsetting
+            SkPDFStream* rawStream = NULL;
+            int fontSize = get_subset_font_stream(fontInfo()->fFontName.c_str(),
                                                   typeface(),
                                                   *subset,
                                                   &rawStream);
-                fontStream.reset(rawStream);
-            } else {
-                int ttcIndex;
-                SkAutoTUnref<SkStream> fontData(
-                        typeface()->openStream(&ttcIndex));
-                fontStream.reset(new SkPDFStream(fontData.get()));
-                fontSize = fontData->getLength();
-            }
             SkASSERT(fontSize);
-            SkASSERT(fontStream.get());
+            SkASSERT(rawStream);
+            SkAutoTUnref<SkPDFStream> fontStream(rawStream);
             addResource(fontStream.get());
 
             fontStream->insertInt("Length1", fontSize);
@@ -1171,7 +1133,9 @@
         default:
             SkASSERT(false);
     }
-    return true;
+
+    insert("FontDescriptor", new SkPDFObjRef(descriptor.get()))->unref();
+    return addCommonFontDescriptorEntries(defaultWidth);
 }
 
 bool SkPDFCIDFont::populate(const SkPDFGlyphSet* subset) {
@@ -1287,15 +1251,12 @@
     if (fontData == NULL) {
         return false;
     }
-    if (canEmbed()) {
-        SkAutoTUnref<SkPDFStream> fontStream(new SkPDFStream(fontData));
-        addResource(fontStream.get());
-        fontStream->insertInt("Length1", header);
-        fontStream->insertInt("Length2", data);
-        fontStream->insertInt("Length3", trailer);
-        descriptor->insert("FontFile",
-                           new SkPDFObjRef(fontStream.get()))->unref();
-    }
+    SkAutoTUnref<SkPDFStream> fontStream(new SkPDFStream(fontData));
+    addResource(fontStream.get());
+    fontStream->insertInt("Length1", header);
+    fontStream->insertInt("Length2", data);
+    fontStream->insertInt("Length3", trailer);
+    descriptor->insert("FontFile", new SkPDFObjRef(fontStream.get()))->unref();
 
     addResource(descriptor.get());
     insert("FontDescriptor", new SkPDFObjRef(descriptor.get()))->unref();
diff --git a/src/pdf/SkPDFFont.h b/src/pdf/SkPDFFont.h
index 815c73a..694c69a 100644
--- a/src/pdf/SkPDFFont.h
+++ b/src/pdf/SkPDFFont.h
@@ -99,14 +99,6 @@
      */
     virtual bool multiByteGlyphs() const = 0;
 
-    /** Returns true if the machine readable licensing bits allow embedding.
-     */
-    bool canEmbed() const;
-
-    /** Returns true if the machine readable licensing bits allow subsetting.
-     */
-    bool canSubset() const;
-
     /** Return true if this font has an encoding for the passed glyph id.
      */
     bool hasGlyph(uint16_t glyphID);
@@ -129,7 +121,8 @@
      *  @param typeface  The typeface to find.
      *  @param glyphID   Specify which section of a large font is of interest.
      */
-    static SkPDFFont* GetFontResource(SkTypeface* typeface, uint16_t glyphID);
+    static SkPDFFont* GetFontResource(SkTypeface* typeface,
+                                             uint16_t glyphID);
 
     /** Subset the font based on usage set. Returns a SkPDFFont instance with
      *  subset.
@@ -195,6 +188,8 @@
     // this will be a subset if the font has more than 255 glyphs.
     uint16_t fFirstGlyphID;
     uint16_t fLastGlyphID;
+    // The font info is only kept around after construction for large
+    // Type1 (non CID) fonts that need multiple "fonts" to access all glyphs.
     SkAutoTUnref<SkAdvancedTypefaceMetrics> fFontInfo;
     SkTDArray<SkPDFObject*> fResources;
     SkAutoTUnref<SkPDFDict> fDescriptor;