[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
This commit is contained in:
vandebo@chromium.org 2011-05-29 05:55:42 +00:00
Родитель d7beab4252
Коммит f0ec2666d9
6 изменённых файлов: 37 добавлений и 17 удалений

Просмотреть файл

@ -127,6 +127,10 @@ public:
*/
void getResources(SkTDArray<SkPDFObject*>* resourceList) const;
/** Get the fonts used on this device.
*/
const SkTDArray<SkPDFFont*>& getFontResources() const;
/** Returns the media box for this device.
*/
SkRefPtr<SkPDFArray> getMediaBox() const;

Просмотреть файл

@ -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<SkTypeface> fTypeface;
SkAdvancedTypefaceMetrics::FontType fType;
#ifdef SK_DEBUG
bool fDescendant;
#endif

Просмотреть файл

@ -86,6 +86,10 @@ public:
SkTDArray<SkPDFDict*>* pageTree,
SkPDFDict** rootNode);
/** Get the fonts used on this page.
*/
const SkTDArray<SkPDFFont*>& getFontResources() const;
private:
// Multiple pages may reference the content.
SkRefPtr<SkPDFDevice> fDevice;

Просмотреть файл

@ -1051,6 +1051,10 @@ void SkPDFDevice::getResources(SkTDArray<SkPDFObject*>* resourceList) const {
}
}
const SkTDArray<SkPDFFont*>& SkPDFDevice::getFontResources() const {
return fFontResources;
}
SkRefPtr<SkPDFArray> SkPDFDevice::getMediaBox() const {
SkRefPtr<SkPDFInt> zero = new SkPDFInt(0);
zero->unref(); // SkRefPtr and new both took a reference.

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -136,3 +136,7 @@ void SkPDFPage::generatePageTree(const SkTDArray<SkPDFPage*>& pages,
if (rootNode)
*rootNode = curNodes[0];
}
const SkTDArray<SkPDFFont*>& SkPDFPage::getFontResources() const {
return fDevice->getFontResources();
}