From f0ec2666d9a3f0f1662f0d63b5147628c49648aa Mon Sep 17 00:00:00 2001 From: "vandebo@chromium.org" Date: Sun, 29 May 2011 05:55:42 +0000 Subject: [PATCH] [PDF] Add plumbing and accessors so that Chrome can record the font types used in a PDF. - Add a font type accessor to SkPDFFont. - Plumb font resource retrivial up to SkPDFPage. Review URL: http://codereview.appspot.com/4547069 git-svn-id: http://skia.googlecode.com/svn/trunk@1444 2bbb7eff-a529-9590-31e7-b0007b416f81 --- include/pdf/SkPDFDevice.h | 4 ++++ include/pdf/SkPDFFont.h | 6 ++++++ include/pdf/SkPDFPage.h | 4 ++++ src/pdf/SkPDFDevice.cpp | 4 ++++ src/pdf/SkPDFFont.cpp | 32 +++++++++++++++----------------- src/pdf/SkPDFPage.cpp | 4 ++++ 6 files changed, 37 insertions(+), 17 deletions(-) diff --git a/include/pdf/SkPDFDevice.h b/include/pdf/SkPDFDevice.h index 2a9aba5..5e05021 100644 --- a/include/pdf/SkPDFDevice.h +++ b/include/pdf/SkPDFDevice.h @@ -127,6 +127,10 @@ public: */ void getResources(SkTDArray* resourceList) const; + /** Get the fonts used on this device. + */ + const SkTDArray& getFontResources() const; + /** Returns the media box for this device. */ SkRefPtr getMediaBox() const; diff --git a/include/pdf/SkPDFFont.h b/include/pdf/SkPDFFont.h index 45e4195..9ba32e3 100644 --- a/include/pdf/SkPDFFont.h +++ b/include/pdf/SkPDFFont.h @@ -42,6 +42,11 @@ public: */ SkTypeface* typeface(); + /** Returns the font type represented in this font. For Type0 fonts, + * returns the type of the decendant font. + */ + SkAdvancedTypefaceMetrics::FontType getType(); + /** Return true if this font has an encoding for the passed glyph id. */ bool hasGlyph(uint16_t glyphID); @@ -72,6 +77,7 @@ public: private: SkRefPtr fTypeface; + SkAdvancedTypefaceMetrics::FontType fType; #ifdef SK_DEBUG bool fDescendant; #endif diff --git a/include/pdf/SkPDFPage.h b/include/pdf/SkPDFPage.h index b12be16..d677a29 100644 --- a/include/pdf/SkPDFPage.h +++ b/include/pdf/SkPDFPage.h @@ -86,6 +86,10 @@ public: SkTDArray* pageTree, SkPDFDict** rootNode); + /** Get the fonts used on this page. + */ + const SkTDArray& getFontResources() const; + private: // Multiple pages may reference the content. SkRefPtr fDevice; diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp index 4c0021a..c6ddf39 100644 --- a/src/pdf/SkPDFDevice.cpp +++ b/src/pdf/SkPDFDevice.cpp @@ -1051,6 +1051,10 @@ void SkPDFDevice::getResources(SkTDArray* resourceList) const { } } +const SkTDArray& SkPDFDevice::getFontResources() const { + return fFontResources; +} + SkRefPtr SkPDFDevice::getMediaBox() const { SkRefPtr zero = new SkPDFInt(0); zero->unref(); // SkRefPtr and new both took a reference. diff --git a/src/pdf/SkPDFFont.cpp b/src/pdf/SkPDFFont.cpp index cc249ca..277ed12 100755 --- a/src/pdf/SkPDFFont.cpp +++ b/src/pdf/SkPDFFont.cpp @@ -444,6 +444,10 @@ SkTypeface* SkPDFFont::typeface() { return fTypeface.get(); } +SkAdvancedTypefaceMetrics::FontType SkPDFFont::getType() { + return fType; +} + bool SkPDFFont::hasGlyph(uint16_t id) { return (id >= fFirstGlyphID && id <= fLastGlyphID) || id == 0; } @@ -541,6 +545,8 @@ SkPDFFont::SkPDFFont(class SkAdvancedTypefaceMetrics* fontInfo, SkPDFDict* fontDescriptor) : SkPDFDict("Font"), fTypeface(typeface), + fType(fontInfo ? fontInfo->fType : + SkAdvancedTypefaceMetrics::kNotEmbeddable_Font), #ifdef SK_DEBUG fDescendant(descendantFont), #endif @@ -549,20 +555,12 @@ SkPDFFont::SkPDFFont(class SkAdvancedTypefaceMetrics* fontInfo, fLastGlyphID(fontInfo ? fontInfo->fLastGlyphID : 0), fFontInfo(fontInfo), fDescriptor(fontDescriptor) { - - SkAdvancedTypefaceMetrics::FontType type; - if (fontInfo) { - type = fontInfo->fType; - } else { - type = SkAdvancedTypefaceMetrics::kNotEmbeddable_Font; - } - if (fontInfo && fontInfo->fMultiMaster) { - SkASSERT(false); // Not supported yet. - fontInfo->fType = SkAdvancedTypefaceMetrics::kOther_Font; + NOT_IMPLEMENTED(true, true); + fType = SkAdvancedTypefaceMetrics::kOther_Font; } - if (type == SkAdvancedTypefaceMetrics::kType1CID_Font || - type == SkAdvancedTypefaceMetrics::kTrueType_Font) { + if (fType == SkAdvancedTypefaceMetrics::kType1CID_Font || + fType == SkAdvancedTypefaceMetrics::kTrueType_Font) { if (descendantFont) { populateCIDFont(); } else { @@ -574,15 +572,15 @@ SkPDFFont::SkPDFFont(class SkAdvancedTypefaceMetrics* fontInfo, return; } - if (type == SkAdvancedTypefaceMetrics::kType1_Font && + if (fType == SkAdvancedTypefaceMetrics::kType1_Font && populateType1Font(glyphID)) { return; } - SkASSERT(type == SkAdvancedTypefaceMetrics::kType1_Font || - type == SkAdvancedTypefaceMetrics::kCFF_Font || - type == SkAdvancedTypefaceMetrics::kOther_Font || - type == SkAdvancedTypefaceMetrics::kNotEmbeddable_Font); + SkASSERT(fType == SkAdvancedTypefaceMetrics::kType1_Font || + fType == SkAdvancedTypefaceMetrics::kCFF_Font || + fType == SkAdvancedTypefaceMetrics::kOther_Font || + fType == SkAdvancedTypefaceMetrics::kNotEmbeddable_Font); populateType3Font(glyphID); } diff --git a/src/pdf/SkPDFPage.cpp b/src/pdf/SkPDFPage.cpp index 9aa21c6..2a8183d 100644 --- a/src/pdf/SkPDFPage.cpp +++ b/src/pdf/SkPDFPage.cpp @@ -136,3 +136,7 @@ void SkPDFPage::generatePageTree(const SkTDArray& pages, if (rootNode) *rootNode = curNodes[0]; } + +const SkTDArray& SkPDFPage::getFontResources() const { + return fDevice->getFontResources(); +} -- 2.7.4