OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 | 8 |
9 #ifndef SkAdvancedTypefaceMetrics_DEFINED | 9 #ifndef SkAdvancedTypefaceMetrics_DEFINED |
10 #define SkAdvancedTypefaceMetrics_DEFINED | 10 #define SkAdvancedTypefaceMetrics_DEFINED |
(...skipping 21 matching lines...) Expand all Loading... |
32 , fLastGlyphID(0) | 32 , fLastGlyphID(0) |
33 , fEmSize(0) | 33 , fEmSize(0) |
34 , fStyle(0) | 34 , fStyle(0) |
35 , fItalicAngle(0) | 35 , fItalicAngle(0) |
36 , fAscent(0) | 36 , fAscent(0) |
37 , fDescent(0) | 37 , fDescent(0) |
38 , fStemV(0) | 38 , fStemV(0) |
39 , fCapHeight(0) | 39 , fCapHeight(0) |
40 , fBBox(SkIRect::MakeEmpty()) {} | 40 , fBBox(SkIRect::MakeEmpty()) {} |
41 | 41 |
42 ~SkAdvancedTypefaceMetrics(); | 42 ~SkAdvancedTypefaceMetrics() {} |
43 | |
44 /** Retrieve advance data for glyphs. Used by the PDF backend. It | |
45 calls underlying platform dependent API getAdvance to acquire | |
46 the data. | |
47 @param num_glyphs Total number of glyphs in the given font. | |
48 @param glyphIDs For per-glyph info, specify subset of the | |
49 font by giving glyph ids. Each integer | |
50 represents a glyph id. Passing nullptr | |
51 means all glyphs in the font. | |
52 @param glyphIDsCount Number of elements in subsetGlyphIds. | |
53 Ignored if glyphIDs is nullptr. | |
54 @param getAdvance A function that takes a glyph id and | |
55 passes back advance data from the | |
56 typeface. Returns false on failure. | |
57 */ | |
58 typedef std::function<bool(int glyphId, int16_t* advanceData)> GetAdvance; | |
59 void setGlyphWidths(int num_glyphs, | |
60 const uint32_t* subsetGlyphIDs, | |
61 uint32_t subsetGlyphIDsLength, | |
62 GetAdvance getAdvance); | |
63 | 43 |
64 SkString fFontName; | 44 SkString fFontName; |
65 | 45 |
66 enum FontType { | 46 enum FontType { |
67 kType1_Font, | 47 kType1_Font, |
68 kType1CID_Font, | 48 kType1CID_Font, |
69 kCFF_Font, | 49 kCFF_Font, |
70 kTrueType_Font, | 50 kTrueType_Font, |
71 kOther_Font, | 51 kOther_Font, |
72 }; | 52 }; |
(...skipping 28 matching lines...) Expand all Loading... |
101 int16_t fItalicAngle; // Counterclockwise degrees from vertical of the | 81 int16_t fItalicAngle; // Counterclockwise degrees from vertical of the |
102 // dominant vertical stroke for an Italic face. | 82 // dominant vertical stroke for an Italic face. |
103 // The following fields are all in font units. | 83 // The following fields are all in font units. |
104 int16_t fAscent; // Max height above baseline, not including accents. | 84 int16_t fAscent; // Max height above baseline, not including accents. |
105 int16_t fDescent; // Max depth below baseline (negative). | 85 int16_t fDescent; // Max depth below baseline (negative). |
106 int16_t fStemV; // Thickness of dominant vertical stem. | 86 int16_t fStemV; // Thickness of dominant vertical stem. |
107 int16_t fCapHeight; // Height (from baseline) of top of flat capitals. | 87 int16_t fCapHeight; // Height (from baseline) of top of flat capitals. |
108 | 88 |
109 SkIRect fBBox; // The bounding box of all glyphs (in font units). | 89 SkIRect fBBox; // The bounding box of all glyphs (in font units). |
110 | 90 |
111 template <typename Data> | |
112 struct AdvanceMetric { | |
113 enum MetricType { | |
114 kDefault, // Default advance: fAdvance.count = 1 | |
115 kRange, // Advances for a range: fAdvance.count = fEndID-fStartID | |
116 kRun // fStartID-fEndID have same advance: fAdvance.count = 1 | |
117 }; | |
118 MetricType fType; | |
119 uint16_t fStartId; | |
120 uint16_t fEndId; | |
121 SkTDArray<Data> fAdvance; | |
122 AdvanceMetric(uint16_t startId) : fStartId(startId) {} | |
123 AdvanceMetric(AdvanceMetric&& other) = default; | |
124 AdvanceMetric& operator=(AdvanceMetric&& other) = default; | |
125 AdvanceMetric(const AdvanceMetric&) = delete; | |
126 AdvanceMetric& operator=(const AdvanceMetric&) = delete; | |
127 }; | |
128 | |
129 struct VerticalMetric { | |
130 int16_t fVerticalAdvance; | |
131 int16_t fOriginXDisp; // Horiz. displacement of the secondary origin. | |
132 int16_t fOriginYDisp; // Vert. displacement of the secondary origin. | |
133 }; | |
134 typedef AdvanceMetric<int16_t> WidthRange; | |
135 typedef AdvanceMetric<VerticalMetric> VerticalAdvanceRange; | |
136 | |
137 // This is indexed by glyph id. | |
138 SkSinglyLinkedList<WidthRange> fGlyphWidths; | |
139 // Only used for Vertical CID fonts. | |
140 SkSinglyLinkedList<VerticalAdvanceRange> fVerticalMetrics; | |
141 | |
142 // The names of each glyph, only populated for postscript fonts. | 91 // The names of each glyph, only populated for postscript fonts. |
143 SkAutoTDelete<SkAutoTArray<SkString> > fGlyphNames; | 92 SkTArray<SkString> fGlyphNames; |
144 | 93 |
145 // The mapping from glyph to Unicode, only populated if | 94 // The mapping from glyph to Unicode, only populated if |
146 // kToUnicode_PerGlyphInfo is passed to GetAdvancedTypefaceMetrics. | 95 // kToUnicode_PerGlyphInfo is passed to GetAdvancedTypefaceMetrics. |
147 SkTDArray<SkUnichar> fGlyphToUnicode; | 96 SkTDArray<SkUnichar> fGlyphToUnicode; |
148 | 97 |
149 static void FinishRange(WidthRange* range, | |
150 int endId, | |
151 WidthRange::MetricType type); | |
152 | |
153 private: | 98 private: |
154 typedef SkRefCnt INHERITED; | 99 typedef SkRefCnt INHERITED; |
155 }; | 100 }; |
156 | 101 |
157 | 102 |
158 #endif | 103 #endif |
OLD | NEW |