aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/pdf/SkPDFFont.h
diff options
context:
space:
mode:
authorGravatar halcanary <halcanary@google.com>2016-08-17 14:21:42 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-08-17 14:21:42 -0700
commit0a61270f4ba85d10659fb63a86817b435ec04c94 (patch)
treedcdc5d23af09dcdb2a85da2c49598c6412e26959 /src/pdf/SkPDFFont.h
parent69c166d2ce3f4d2099f35f8e88f1aa56ceeaf960 (diff)
SkPDF: cache metrics once.
Motivation: drawText can look up unicode mapping at draw time to see if ActualText should be used after crrev.com/2084533004 lands. For each SkTypeface, only call getAdvancedTypefaceMetrics() once per document. Cache the result in the SkPDFCanon, indexed by SkFontID. Also cache PDF FontDescriptors in the canon, also indexed by SkFontID (Type1 fonts only). Simplify PDF font lookup, map SkFontID+SkGlyphID into a uint64_t. Map that uint64_t to SkPDFFonts. Remove SkPDFCanon::findFont(), SkPDFCanon::addFont(), SkPDFFont::IsMatch(), and enum SkPDFFont::Match. SkPDFFont no longer holds on to ref of SkAdvancedTypefaceMetrics. Instead, SkPDFFont::GetFontResource() and SkPDFFont::getFontSubset() get metrics from canon. SkPDFFont multybite bool is now a function of type. GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2253993002 Review-Url: https://codereview.chromium.org/2253993002
Diffstat (limited to 'src/pdf/SkPDFFont.h')
-rw-r--r--src/pdf/SkPDFFont.h74
1 files changed, 20 insertions, 54 deletions
diff --git a/src/pdf/SkPDFFont.h b/src/pdf/SkPDFFont.h
index 36b93ecc35..f2f1df4c24 100644
--- a/src/pdf/SkPDFFont.h
+++ b/src/pdf/SkPDFFont.h
@@ -60,7 +60,6 @@ private:
SkTArray<FontGlyphSetPair> fMap;
};
-
/** \class SkPDFFont
A PDF Object class representing a font. The font may have resources
attached to it in order to embed the font. SkPDFFonts are canonicalized
@@ -76,28 +75,27 @@ public:
/** Returns the typeface represented by this class. Returns nullptr for the
* default typeface.
*/
- SkTypeface* typeface() { return fTypeface.get(); }
+ SkTypeface* typeface() const { return fTypeface.get(); }
/** Returns the font type represented in this font. For Type0 fonts,
* returns the type of the decendant font.
*/
- SkAdvancedTypefaceMetrics::FontType getType() { return fFontType; }
-
- /** Returns true if this font encoding supports glyph IDs above 255.
- */
- bool multiByteGlyphs() const { return fMultiByteGlyphs; }
+ SkAdvancedTypefaceMetrics::FontType getType() const { return fFontType; }
- /** Returns true if the machine readable licensing bits allow embedding.
- */
- bool canEmbed() const;
+ static bool IsMultiByte(SkAdvancedTypefaceMetrics::FontType type) {
+ return type == SkAdvancedTypefaceMetrics::kType1CID_Font ||
+ type == SkAdvancedTypefaceMetrics::kTrueType_Font;
+ }
- /** Returns true if the machine readable licensing bits allow subsetting.
+ /** Returns true if this font encoding supports glyph IDs above 255.
*/
- bool canSubset() const;
+ bool multiByteGlyphs() const { return SkPDFFont::IsMultiByte(this->getType()); }
/** Return true if this font has an encoding for the passed glyph id.
*/
- bool hasGlyph(uint16_t glyphID);
+ bool hasGlyph(SkGlyphID gid) {
+ return (gid >= fFirstGlyphID && gid <= fLastGlyphID) || gid == 0;
+ }
/** Convert (in place) the input glyph IDs into the font encoding. If the
* font has more glyphs than can be encoded (like a type 1 font with more
@@ -124,10 +122,11 @@ public:
*/
static SkPDFFont* GetFontResource(SkPDFCanon* canon,
SkTypeface* typeface,
- uint16_t glyphID);
+ SkGlyphID glyphID);
- static sk_sp<const SkAdvancedTypefaceMetrics> GetFontMetricsWithToUnicode(
- SkTypeface*, uint32_t* glyphs, uint32_t glyphsCount);
+ // Uses (kGlyphNames_PerGlyphInfo | kToUnicode_PerGlyphInfo).
+ static const SkAdvancedTypefaceMetrics* GetMetrics(SkTypeface* typeface,
+ SkPDFCanon* canon);
/** Subset the font based on usage set. Returns a SkPDFFont instance with
* subset.
@@ -135,18 +134,8 @@ public:
* @return nullptr if font does not support subsetting, a new instance
* of SkPDFFont otherwise.
*/
- virtual sk_sp<SkPDFObject> getFontSubset(const SkPDFGlyphSet* usage);
-
- enum Match {
- kExact_Match,
- kRelated_Match,
- kNot_Match,
- };
- static Match IsMatch(SkPDFFont* existingFont,
- uint32_t existingFontID,
- uint16_t existingGlyphID,
- uint32_t searchFontID,
- uint16_t searchGlyphID);
+ virtual sk_sp<SkPDFObject> getFontSubset(SkPDFCanon* canon,
+ const SkPDFGlyphSet* usage);
/**
* Return false iff the typeface has its NotEmbeddable flag set.
@@ -156,52 +145,29 @@ public:
protected:
// Common constructor to handle common members.
- SkPDFFont(sk_sp<const SkAdvancedTypefaceMetrics> fontInfo,
- sk_sp<SkTypeface> typeface,
- sk_sp<SkPDFDict> relatedFontDescriptor,
- SkAdvancedTypefaceMetrics::FontType fontType,
- bool multiByteGlyphs);
-
- // Accessors for subclass.
- const SkAdvancedTypefaceMetrics* getFontInfo() const { return fFontInfo.get(); }
- sk_sp<const SkAdvancedTypefaceMetrics> refFontInfo() const { return fFontInfo; }
+ SkPDFFont(sk_sp<SkTypeface> typeface,
+ SkAdvancedTypefaceMetrics::FontType fontType);
- void setFontInfo(sk_sp<const SkAdvancedTypefaceMetrics> info);
SkGlyphID firstGlyphID() const { return fFirstGlyphID; }
SkGlyphID lastGlyphID() const { return fLastGlyphID; }
- void setLastGlyphID(uint16_t glyphID);
-
- // Accessors for FontDescriptor associated with this object.
- SkPDFDict* getFontDescriptor() const { return fDescriptor.get(); }
- sk_sp<SkPDFDict> refFontDescriptor() const { return fDescriptor; }
- void setFontDescriptor(sk_sp<SkPDFDict> descriptor);
sk_sp<SkTypeface> refTypeface() const { return fTypeface; }
/** Set fFirstGlyphID and fLastGlyphID to span at most 255 glyphs,
* including the passed glyphID.
*/
- void adjustGlyphRangeForSingleByteEncoding(uint16_t glyphID);
-
- // Generate ToUnicode table according to glyph usage subset.
- // If subset is nullptr, all available glyph ids will be used.
- void populateToUnicodeTable(const SkPDFGlyphSet* subset);
-
- static bool Find(uint32_t fontID, uint16_t glyphID, int* index);
+ void adjustGlyphRangeForSingleByteEncoding(SkGlyphID glyphID);
void drop() override;
private:
sk_sp<SkTypeface> fTypeface;
- sk_sp<const SkAdvancedTypefaceMetrics> fFontInfo;
- sk_sp<SkPDFDict> fDescriptor;
// The glyph IDs accessible with this font. For Type1 (non CID) fonts,
// this will be a subset if the font has more than 255 glyphs.
SkGlyphID fFirstGlyphID;
SkGlyphID fLastGlyphID;
SkAdvancedTypefaceMetrics::FontType fFontType;
- bool fMultiByteGlyphs;
typedef SkPDFDict INHERITED;
};