OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #ifndef SkAdvancedTypefaceMetrics_DEFINED | 10 #ifndef SkAdvancedTypefaceMetrics_DEFINED |
11 #define SkAdvancedTypefaceMetrics_DEFINED | 11 #define SkAdvancedTypefaceMetrics_DEFINED |
12 | 12 |
13 #include "SkRect.h" | 13 #include "SkRect.h" |
14 #include "SkRefCnt.h" | 14 #include "SkRefCnt.h" |
15 #include "SkString.h" | 15 #include "SkString.h" |
16 #include "SkTDArray.h" | 16 #include "SkTDArray.h" |
17 #include "SkTemplates.h" | 17 #include "SkTemplates.h" |
18 #include "SkTScopedPtr.h" | |
19 | 18 |
20 /** \class SkAdvancedTypefaceMetrics | 19 /** \class SkAdvancedTypefaceMetrics |
21 | 20 |
22 The SkAdvancedTypefaceMetrics class is used by the PDF backend to correctly | 21 The SkAdvancedTypefaceMetrics class is used by the PDF backend to correctly |
23 embed typefaces. This class is filled in with information about a given | 22 embed typefaces. This class is filled in with information about a given |
24 typeface by the SkFontHost class. | 23 typeface by the SkFontHost class. |
25 */ | 24 */ |
26 | 25 |
27 class SkAdvancedTypefaceMetrics : public SkRefCnt { | 26 class SkAdvancedTypefaceMetrics : public SkRefCnt { |
28 public: | 27 public: |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 struct AdvanceMetric { | 82 struct AdvanceMetric { |
84 enum MetricType { | 83 enum MetricType { |
85 kDefault, // Default advance: fAdvance.count = 1 | 84 kDefault, // Default advance: fAdvance.count = 1 |
86 kRange, // Advances for a range: fAdvance.count = fEndID-fStartID | 85 kRange, // Advances for a range: fAdvance.count = fEndID-fStartID |
87 kRun // fStartID-fEndID have same advance: fAdvance.count = 1 | 86 kRun // fStartID-fEndID have same advance: fAdvance.count = 1 |
88 }; | 87 }; |
89 MetricType fType; | 88 MetricType fType; |
90 uint16_t fStartId; | 89 uint16_t fStartId; |
91 uint16_t fEndId; | 90 uint16_t fEndId; |
92 SkTDArray<Data> fAdvance; | 91 SkTDArray<Data> fAdvance; |
93 SkTScopedPtr<AdvanceMetric<Data> > fNext; | 92 SkAutoTDelete<AdvanceMetric<Data> > fNext; |
94 }; | 93 }; |
95 | 94 |
96 struct VerticalMetric { | 95 struct VerticalMetric { |
97 int16_t fVerticalAdvance; | 96 int16_t fVerticalAdvance; |
98 int16_t fOriginXDisp; // Horiz. displacement of the secondary origin. | 97 int16_t fOriginXDisp; // Horiz. displacement of the secondary origin. |
99 int16_t fOriginYDisp; // Vert. displacement of the secondary origin. | 98 int16_t fOriginYDisp; // Vert. displacement of the secondary origin. |
100 }; | 99 }; |
101 typedef AdvanceMetric<int16_t> WidthRange; | 100 typedef AdvanceMetric<int16_t> WidthRange; |
102 typedef AdvanceMetric<VerticalMetric> VerticalAdvanceRange; | 101 typedef AdvanceMetric<VerticalMetric> VerticalAdvanceRange; |
103 | 102 |
104 // This is indexed by glyph id. | 103 // This is indexed by glyph id. |
105 SkTScopedPtr<WidthRange> fGlyphWidths; | 104 SkAutoTDelete<WidthRange> fGlyphWidths; |
106 // Only used for Vertical CID fonts. | 105 // Only used for Vertical CID fonts. |
107 SkTScopedPtr<VerticalAdvanceRange> fVerticalMetrics; | 106 SkAutoTDelete<VerticalAdvanceRange> fVerticalMetrics; |
108 | 107 |
109 // The names of each glyph, only populated for postscript fonts. | 108 // The names of each glyph, only populated for postscript fonts. |
110 SkTScopedPtr<SkAutoTArray<SkString> > fGlyphNames; | 109 SkAutoTDelete<SkAutoTArray<SkString> > fGlyphNames; |
111 | 110 |
112 // The mapping from glyph to Unicode, only populated if | 111 // The mapping from glyph to Unicode, only populated if |
113 // kToUnicode_PerGlyphInfo is passed to GetAdvancedTypefaceMetrics. | 112 // kToUnicode_PerGlyphInfo is passed to GetAdvancedTypefaceMetrics. |
114 SkTDArray<SkUnichar> fGlyphToUnicode; | 113 SkTDArray<SkUnichar> fGlyphToUnicode; |
115 | 114 |
116 private: | 115 private: |
117 typedef SkRefCnt INHERITED; | 116 typedef SkRefCnt INHERITED; |
118 }; | 117 }; |
119 | 118 |
120 namespace skia_advanced_typeface_metrics_utils { | 119 namespace skia_advanced_typeface_metrics_utils { |
121 | 120 |
122 template <typename Data> | 121 template <typename Data> |
123 void resetRange(SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* range, | 122 void resetRange(SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* range, |
124 int startId); | 123 int startId); |
125 | 124 |
126 template <typename Data> | 125 template <typename Data> |
127 SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* appendRange( | 126 SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* appendRange( |
128 SkTScopedPtr<SkAdvancedTypefaceMetrics::AdvanceMetric<Data> >* nextSlot, | 127 SkAutoTDelete<SkAdvancedTypefaceMetrics::AdvanceMetric<Data> >* nextSlot
, |
129 int startId); | 128 int startId); |
130 | 129 |
131 template <typename Data> | 130 template <typename Data> |
132 void finishRange( | 131 void finishRange( |
133 SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* range, | 132 SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* range, |
134 int endId, | 133 int endId, |
135 typename SkAdvancedTypefaceMetrics::AdvanceMetric<Data>::MetricType | 134 typename SkAdvancedTypefaceMetrics::AdvanceMetric<Data>::MetricType |
136 type); | 135 type); |
137 | 136 |
138 /** Retrieve advance data for glyphs. Used by the PDF backend. It calls | 137 /** Retrieve advance data for glyphs. Used by the PDF backend. It calls |
139 underlying platform dependent API getAdvance to acquire the data. | 138 underlying platform dependent API getAdvance to acquire the data. |
140 @param num_glyphs Total number of glyphs in the given font. | 139 @param num_glyphs Total number of glyphs in the given font. |
141 @param glyphIDs For per-glyph info, specify subset of the font by | 140 @param glyphIDs For per-glyph info, specify subset of the font by |
142 giving glyph ids. Each integer represents a glyph | 141 giving glyph ids. Each integer represents a glyph |
143 id. Passing NULL means all glyphs in the font. | 142 id. Passing NULL means all glyphs in the font. |
144 @param glyphIDsCount Number of elements in subsetGlyphIds. Ignored if | 143 @param glyphIDsCount Number of elements in subsetGlyphIds. Ignored if |
145 glyphIDs is NULL. | 144 glyphIDs is NULL. |
146 */ | 145 */ |
147 template <typename Data, typename FontHandle> | 146 template <typename Data, typename FontHandle> |
148 SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* getAdvanceData( | 147 SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* getAdvanceData( |
149 FontHandle fontHandle, | 148 FontHandle fontHandle, |
150 int num_glyphs, | 149 int num_glyphs, |
151 const uint32_t* glyphIDs, | 150 const uint32_t* glyphIDs, |
152 uint32_t glyphIDsCount, | 151 uint32_t glyphIDsCount, |
153 bool (*getAdvance)(FontHandle fontHandle, int gId, Data* data)); | 152 bool (*getAdvance)(FontHandle fontHandle, int gId, Data* data)); |
154 | 153 |
155 } // namespace skia_advanced_typeface_metrics_utils | 154 } // namespace skia_advanced_typeface_metrics_utils |
156 | 155 |
157 #endif | 156 #endif |
OLD | NEW |