Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkPDFFont.h
Go to the documentation of this file.
1/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7#ifndef SkPDFFont_DEFINED
8#define SkPDFFont_DEFINED
9
16#include "src/pdf/SkPDFTypes.h"
17
18#include <vector>
19
20class SkPDFDocument;
21class SkString;
22
23/** \class SkPDFFont
24 A PDF Object class representing a font. The font may have resources
25 attached to it in order to embed the font. SkPDFFonts are canonicalized
26 so that resource deduplication will only include one copy of a font.
27 This class uses the same pattern as SkPDFGraphicState, a static weak
28 reference to each instantiated class.
29*/
30class SkPDFFont {
31public:
35
36 /** Returns the typeface represented by this class. Returns nullptr for the
37 * default typeface.
38 */
39 SkTypeface* typeface() const { return fTypeface.get(); }
40
41 /** Returns the font type represented in this font. For Type0 fonts,
42 * returns the type of the descendant font.
43 */
44 SkAdvancedTypefaceMetrics::FontType getType() const { return fFontType; }
45
48 static void GetType1GlyphNames(const SkTypeface&, SkString*);
49
55
56 /** Returns true if this font encoding supports glyph IDs above 255.
57 */
58 bool multiByteGlyphs() const { return SkPDFFont::IsMultiByte(this->getType()); }
59
60 /** Return true if this font has an encoding for the passed glyph id.
61 */
62 bool hasGlyph(SkGlyphID gid) {
63 return (gid >= this->firstGlyphID() && gid <= this->lastGlyphID()) || gid == 0;
64 }
65
66 /** Convert the input glyph ID into the font encoding. */
68 if (this->multiByteGlyphs() || gid == 0) {
69 return gid;
70 }
71 SkASSERT(gid >= this->firstGlyphID() && gid <= this->lastGlyphID());
72 SkASSERT(this->firstGlyphID() > 0);
73 return gid - this->firstGlyphID() + 1;
74 }
75
77 SkASSERT(this->hasGlyph(glyph));
78 fGlyphUsage.set(glyph);
79 }
80
81 SkPDFIndirectReference indirectReference() const { return fIndirectReference; }
82
83 /** Get the font resource for the passed typeface and glyphID. The
84 * reference count of the object is incremented and it is the caller's
85 * responsibility to unreference it when done. This is needed to
86 * accommodate the weak reference pattern used when the returned object
87 * is new and has no other references.
88 * @param typeface The typeface to find, not nullptr.
89 * @param glyphID Specify which section of a large font is of interest.
90 */
92 const SkGlyph* glyphs,
94
95 /** Gets SkAdvancedTypefaceMetrics, and caches the result.
96 * @param typeface can not be nullptr.
97 * @return nullptr only when typeface is bad.
98 */
100 SkPDFDocument* canon);
101
102 static const std::vector<SkUnichar>& GetUnicodeMap(const SkTypeface* typeface,
103 SkPDFDocument* canon);
104
105 static void PopulateCommonFontDescriptor(SkPDFDict* descriptor,
107 uint16_t emSize,
108 int16_t defaultWidth);
109
110 void emitSubset(SkPDFDocument*) const;
111
112 /**
113 * Return false iff the typeface has its NotEmbeddable flag set.
114 * typeface is not nullptr
115 */
117
118 SkGlyphID firstGlyphID() const { return fGlyphUsage.firstNonZero(); }
119 SkGlyphID lastGlyphID() const { return fGlyphUsage.lastGlyph(); }
120 const SkPDFGlyphUse& glyphUsage() const { return fGlyphUsage; }
121 sk_sp<SkTypeface> refTypeface() const { return fTypeface; }
122
123private:
124 sk_sp<SkTypeface> fTypeface;
125 SkPDFGlyphUse fGlyphUsage;
126 SkPDFIndirectReference fIndirectReference;
128
134 // The glyph IDs accessible with this font. For Type1 (non CID) fonts,
135 // this will be a subset if the font has more than 255 glyphs.
136
137 SkPDFFont() = delete;
138 SkPDFFont(const SkPDFFont&) = delete;
139 SkPDFFont& operator=(const SkPDFFont&) = delete;
140};
141
142#endif
uint16_t glyphs[5]
#define SkASSERT(cond)
Definition SkAssert.h:116
uint16_t SkGlyphID
Definition SkTypes.h:179
SkAdvancedTypefaceMetrics::FontType getType() const
Definition SkPDFFont.h:44
void noteGlyphUsage(SkGlyphID glyph)
Definition SkPDFFont.h:76
bool hasGlyph(SkGlyphID gid)
Definition SkPDFFont.h:62
bool multiByteGlyphs() const
Definition SkPDFFont.h:58
static const SkAdvancedTypefaceMetrics * GetMetrics(const SkTypeface *typeface, SkPDFDocument *canon)
static void PopulateCommonFontDescriptor(SkPDFDict *descriptor, const SkAdvancedTypefaceMetrics &, uint16_t emSize, int16_t defaultWidth)
static SkPDFFont * GetFontResource(SkPDFDocument *doc, const SkGlyph *glyphs, SkTypeface *typeface)
SkPDFIndirectReference indirectReference() const
Definition SkPDFFont.h:81
static SkAdvancedTypefaceMetrics::FontType FontType(const SkTypeface &, const SkAdvancedTypefaceMetrics &)
static bool IsMultiByte(SkAdvancedTypefaceMetrics::FontType type)
Definition SkPDFFont.h:50
static const std::vector< SkUnichar > & GetUnicodeMap(const SkTypeface *typeface, SkPDFDocument *canon)
SkPDFFont & operator=(SkPDFFont &&)
SkGlyphID lastGlyphID() const
Definition SkPDFFont.h:119
SkGlyphID firstGlyphID() const
Definition SkPDFFont.h:118
SkPDFFont(SkPDFFont &&)
void emitSubset(SkPDFDocument *) const
const SkPDFGlyphUse & glyphUsage() const
Definition SkPDFFont.h:120
static void GetType1GlyphNames(const SkTypeface &, SkString *)
Definition SkPDFFont.cpp:53
sk_sp< SkTypeface > refTypeface() const
Definition SkPDFFont.h:121
SkGlyphID glyphToPDFFontEncoding(SkGlyphID gid) const
Definition SkPDFFont.h:67
SkTypeface * typeface() const
Definition SkPDFFont.h:39
static bool CanEmbedTypeface(SkTypeface *, SkPDFDocument *)
void set(SkGlyphID gid)
SkGlyphID lastGlyph() const
SkGlyphID firstNonZero() const
T * get() const
Definition SkRefCnt.h:303