Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/ports/SkFontHost_linux.cpp

Issue 1037793002: C++11 override should now be supported by all of {bots,Chrome,Android,Mozilla} (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: git cl web Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/ports/SkFontHost_FreeType_common.h ('k') | src/ports/SkFontHost_mac.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
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 #include "SkFontHost_FreeType_common.h" 8 #include "SkFontHost_FreeType_common.h"
9 #include "SkFontDescriptor.h" 9 #include "SkFontDescriptor.h"
10 #include "SkFontMgr.h" 10 #include "SkFontMgr.h"
(...skipping 23 matching lines...) Expand all
34 bool sysFont, const SkString familyName, int index) 34 bool sysFont, const SkString familyName, int index)
35 : INHERITED(style, SkTypefaceCache::NewFontID(), isFixedPitch) 35 : INHERITED(style, SkTypefaceCache::NewFontID(), isFixedPitch)
36 , fIsSysFont(sysFont), fFamilyName(familyName), fIndex(index) 36 , fIsSysFont(sysFont), fFamilyName(familyName), fIndex(index)
37 { } 37 { }
38 38
39 bool isSysFont() const { return fIsSysFont; } 39 bool isSysFont() const { return fIsSysFont; }
40 40
41 virtual const char* getUniqueString() const = 0; 41 virtual const char* getUniqueString() const = 0;
42 42
43 protected: 43 protected:
44 void onGetFamilyName(SkString* familyName) const SK_OVERRIDE { 44 void onGetFamilyName(SkString* familyName) const override {
45 *familyName = fFamilyName; 45 *familyName = fFamilyName;
46 } 46 }
47 47
48 void onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocal) const SK_OVE RRIDE { 48 void onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocal) const overri de {
49 desc->setFamilyName(fFamilyName.c_str()); 49 desc->setFamilyName(fFamilyName.c_str());
50 desc->setFontFileName(this->getUniqueString()); 50 desc->setFontFileName(this->getUniqueString());
51 desc->setFontIndex(fIndex); 51 desc->setFontIndex(fIndex);
52 *isLocal = !this->isSysFont(); 52 *isLocal = !this->isSysFont();
53 } 53 }
54 54
55 int getIndex() const { return fIndex; } 55 int getIndex() const { return fIndex; }
56 56
57 private: 57 private:
58 const bool fIsSysFont; 58 const bool fIsSysFont;
59 const SkString fFamilyName; 59 const SkString fFamilyName;
60 const int fIndex; 60 const int fIndex;
61 61
62 typedef SkTypeface_FreeType INHERITED; 62 typedef SkTypeface_FreeType INHERITED;
63 }; 63 };
64 64
65 /** The empty SkTypeface implementation for the custom font manager. 65 /** The empty SkTypeface implementation for the custom font manager.
66 * Used as the last resort fallback typeface. 66 * Used as the last resort fallback typeface.
67 */ 67 */
68 class SkTypeface_Empty : public SkTypeface_Custom { 68 class SkTypeface_Empty : public SkTypeface_Custom {
69 public: 69 public:
70 SkTypeface_Empty() : INHERITED(SkFontStyle(), false, true, SkString(), 0) {} 70 SkTypeface_Empty() : INHERITED(SkFontStyle(), false, true, SkString(), 0) {}
71 71
72 const char* getUniqueString() const SK_OVERRIDE { return NULL; } 72 const char* getUniqueString() const override { return NULL; }
73 73
74 protected: 74 protected:
75 SkStreamAsset* onOpenStream(int*) const SK_OVERRIDE { return NULL; } 75 SkStreamAsset* onOpenStream(int*) const override { return NULL; }
76 76
77 private: 77 private:
78 typedef SkTypeface_Custom INHERITED; 78 typedef SkTypeface_Custom INHERITED;
79 }; 79 };
80 80
81 /** The stream SkTypeface implementation for the custom font manager. */ 81 /** The stream SkTypeface implementation for the custom font manager. */
82 class SkTypeface_Stream : public SkTypeface_Custom { 82 class SkTypeface_Stream : public SkTypeface_Custom {
83 public: 83 public:
84 SkTypeface_Stream(const SkFontStyle& style, bool isFixedPitch, bool sysFont, 84 SkTypeface_Stream(const SkFontStyle& style, bool isFixedPitch, bool sysFont,
85 const SkString familyName, SkStreamAsset* stream, int inde x) 85 const SkString familyName, SkStreamAsset* stream, int inde x)
86 : INHERITED(style, isFixedPitch, sysFont, familyName, index) 86 : INHERITED(style, isFixedPitch, sysFont, familyName, index)
87 , fStream(stream) 87 , fStream(stream)
88 { } 88 { }
89 89
90 const char* getUniqueString() const SK_OVERRIDE { return NULL; } 90 const char* getUniqueString() const override { return NULL; }
91 91
92 protected: 92 protected:
93 SkStreamAsset* onOpenStream(int* ttcIndex) const SK_OVERRIDE { 93 SkStreamAsset* onOpenStream(int* ttcIndex) const override {
94 *ttcIndex = this->getIndex(); 94 *ttcIndex = this->getIndex();
95 return fStream->duplicate(); 95 return fStream->duplicate();
96 } 96 }
97 97
98 private: 98 private:
99 const SkAutoTDelete<const SkStreamAsset> fStream; 99 const SkAutoTDelete<const SkStreamAsset> fStream;
100 100
101 typedef SkTypeface_Custom INHERITED; 101 typedef SkTypeface_Custom INHERITED;
102 }; 102 };
103 103
104 // This configuration option is useful if we need to open and hold handles to 104 // This configuration option is useful if we need to open and hold handles to
105 // all found system font data (e.g., for skfiddle, where the application can't 105 // all found system font data (e.g., for skfiddle, where the application can't
106 // access the filesystem to read fonts on demand) 106 // access the filesystem to read fonts on demand)
107 107
108 SK_CONF_DECLARE(bool, c_CustomTypefaceRetain, "fonts.customFont.retainAllData", false, 108 SK_CONF_DECLARE(bool, c_CustomTypefaceRetain, "fonts.customFont.retainAllData", false,
109 "Retain the open stream for each found font on the system."); 109 "Retain the open stream for each found font on the system.");
110 110
111 /** The file SkTypeface implementation for the custom font manager. */ 111 /** The file SkTypeface implementation for the custom font manager. */
112 class SkTypeface_File : public SkTypeface_Custom { 112 class SkTypeface_File : public SkTypeface_Custom {
113 public: 113 public:
114 SkTypeface_File(const SkFontStyle& style, bool isFixedPitch, bool sysFont, 114 SkTypeface_File(const SkFontStyle& style, bool isFixedPitch, bool sysFont,
115 const SkString familyName, const char path[], int index) 115 const SkString familyName, const char path[], int index)
116 : INHERITED(style, isFixedPitch, sysFont, familyName, index) 116 : INHERITED(style, isFixedPitch, sysFont, familyName, index)
117 , fPath(path) 117 , fPath(path)
118 , fStream(c_CustomTypefaceRetain ? SkStream::NewFromFile(fPath.c_str()) : NULL) 118 , fStream(c_CustomTypefaceRetain ? SkStream::NewFromFile(fPath.c_str()) : NULL)
119 { } 119 { }
120 120
121 const char* getUniqueString() const SK_OVERRIDE { 121 const char* getUniqueString() const override {
122 const char* str = strrchr(fPath.c_str(), '/'); 122 const char* str = strrchr(fPath.c_str(), '/');
123 if (str) { 123 if (str) {
124 str += 1; // skip the '/' 124 str += 1; // skip the '/'
125 } 125 }
126 return str; 126 return str;
127 } 127 }
128 128
129 protected: 129 protected:
130 SkStreamAsset* onOpenStream(int* ttcIndex) const SK_OVERRIDE { 130 SkStreamAsset* onOpenStream(int* ttcIndex) const override {
131 *ttcIndex = this->getIndex(); 131 *ttcIndex = this->getIndex();
132 if (fStream.get()) { 132 if (fStream.get()) {
133 return fStream->duplicate(); 133 return fStream->duplicate();
134 } else { 134 } else {
135 return SkStream::NewFromFile(fPath.c_str()); 135 return SkStream::NewFromFile(fPath.c_str());
136 } 136 }
137 } 137 }
138 138
139 private: 139 private:
140 SkString fPath; 140 SkString fPath;
141 const SkAutoTDelete<SkStreamAsset> fStream; 141 const SkAutoTDelete<SkStreamAsset> fStream;
142 142
143 typedef SkTypeface_Custom INHERITED; 143 typedef SkTypeface_Custom INHERITED;
144 }; 144 };
145 145
146 /////////////////////////////////////////////////////////////////////////////// 146 ///////////////////////////////////////////////////////////////////////////////
147 147
148 /** 148 /**
149 * SkFontStyleSet_Custom 149 * SkFontStyleSet_Custom
150 * 150 *
151 * This class is used by SkFontMgr_Custom to hold SkTypeface_Custom families. 151 * This class is used by SkFontMgr_Custom to hold SkTypeface_Custom families.
152 */ 152 */
153 class SkFontStyleSet_Custom : public SkFontStyleSet { 153 class SkFontStyleSet_Custom : public SkFontStyleSet {
154 public: 154 public:
155 explicit SkFontStyleSet_Custom(const SkString familyName) : fFamilyName(fami lyName) { } 155 explicit SkFontStyleSet_Custom(const SkString familyName) : fFamilyName(fami lyName) { }
156 156
157 int count() SK_OVERRIDE { 157 int count() override {
158 return fStyles.count(); 158 return fStyles.count();
159 } 159 }
160 160
161 void getStyle(int index, SkFontStyle* style, SkString* name) SK_OVERRIDE { 161 void getStyle(int index, SkFontStyle* style, SkString* name) override {
162 SkASSERT(index < fStyles.count()); 162 SkASSERT(index < fStyles.count());
163 bool bold = fStyles[index]->isBold(); 163 bool bold = fStyles[index]->isBold();
164 bool italic = fStyles[index]->isItalic(); 164 bool italic = fStyles[index]->isItalic();
165 *style = SkFontStyle(bold ? SkFontStyle::kBold_Weight : SkFontStyle::kNo rmal_Weight, 165 *style = SkFontStyle(bold ? SkFontStyle::kBold_Weight : SkFontStyle::kNo rmal_Weight,
166 SkFontStyle::kNormal_Width, 166 SkFontStyle::kNormal_Width,
167 italic ? SkFontStyle::kItalic_Slant : SkFontStyle:: kUpright_Slant); 167 italic ? SkFontStyle::kItalic_Slant : SkFontStyle:: kUpright_Slant);
168 name->reset(); 168 name->reset();
169 } 169 }
170 170
171 SkTypeface* createTypeface(int index) SK_OVERRIDE { 171 SkTypeface* createTypeface(int index) override {
172 SkASSERT(index < fStyles.count()); 172 SkASSERT(index < fStyles.count());
173 return SkRef(fStyles[index].get()); 173 return SkRef(fStyles[index].get());
174 } 174 }
175 175
176 static int match_score(const SkFontStyle& pattern, const SkFontStyle& candid ate) { 176 static int match_score(const SkFontStyle& pattern, const SkFontStyle& candid ate) {
177 int score = 0; 177 int score = 0;
178 score += (pattern.width() - candidate.width()) * 100; 178 score += (pattern.width() - candidate.width()) * 100;
179 score += (pattern.isItalic() == candidate.isItalic()) ? 0 : 1000; 179 score += (pattern.isItalic() == candidate.isItalic()) ? 0 : 1000;
180 score += pattern.weight() - candidate.weight(); 180 score += pattern.weight() - candidate.weight();
181 return score; 181 return score;
182 } 182 }
183 183
184 SkTypeface* matchStyle(const SkFontStyle& pattern) SK_OVERRIDE { 184 SkTypeface* matchStyle(const SkFontStyle& pattern) override {
185 if (0 == fStyles.count()) { 185 if (0 == fStyles.count()) {
186 return NULL; 186 return NULL;
187 } 187 }
188 188
189 SkTypeface_Custom* closest = fStyles[0]; 189 SkTypeface_Custom* closest = fStyles[0];
190 int minScore = std::numeric_limits<int>::max(); 190 int minScore = std::numeric_limits<int>::max();
191 for (int i = 0; i < fStyles.count(); ++i) { 191 for (int i = 0; i < fStyles.count(); ++i) {
192 bool bold = fStyles[i]->isBold(); 192 bool bold = fStyles[i]->isBold();
193 bool italic = fStyles[i]->isItalic(); 193 bool italic = fStyles[i]->isItalic();
194 SkFontStyle style = SkFontStyle(bold ? SkFontStyle::kBold_Weight 194 SkFontStyle style = SkFontStyle(bold ? SkFontStyle::kBold_Weight
(...skipping 29 matching lines...) Expand all
224 * one SkFontStyleSet_Custom for each family. This class may be modified 224 * one SkFontStyleSet_Custom for each family. This class may be modified
225 * to load fonts from any source by changing the initialization. 225 * to load fonts from any source by changing the initialization.
226 */ 226 */
227 class SkFontMgr_Custom : public SkFontMgr { 227 class SkFontMgr_Custom : public SkFontMgr {
228 public: 228 public:
229 explicit SkFontMgr_Custom(const char* dir) { 229 explicit SkFontMgr_Custom(const char* dir) {
230 this->load_system_fonts(dir); 230 this->load_system_fonts(dir);
231 } 231 }
232 232
233 protected: 233 protected:
234 int onCountFamilies() const SK_OVERRIDE { 234 int onCountFamilies() const override {
235 return fFamilies.count(); 235 return fFamilies.count();
236 } 236 }
237 237
238 void onGetFamilyName(int index, SkString* familyName) const SK_OVERRIDE { 238 void onGetFamilyName(int index, SkString* familyName) const override {
239 SkASSERT(index < fFamilies.count()); 239 SkASSERT(index < fFamilies.count());
240 familyName->set(fFamilies[index]->fFamilyName); 240 familyName->set(fFamilies[index]->fFamilyName);
241 } 241 }
242 242
243 SkFontStyleSet_Custom* onCreateStyleSet(int index) const SK_OVERRIDE { 243 SkFontStyleSet_Custom* onCreateStyleSet(int index) const override {
244 SkASSERT(index < fFamilies.count()); 244 SkASSERT(index < fFamilies.count());
245 return SkRef(fFamilies[index].get()); 245 return SkRef(fFamilies[index].get());
246 } 246 }
247 247
248 SkFontStyleSet_Custom* onMatchFamily(const char familyName[]) const SK_OVERR IDE { 248 SkFontStyleSet_Custom* onMatchFamily(const char familyName[]) const override {
249 for (int i = 0; i < fFamilies.count(); ++i) { 249 for (int i = 0; i < fFamilies.count(); ++i) {
250 if (fFamilies[i]->fFamilyName.equals(familyName)) { 250 if (fFamilies[i]->fFamilyName.equals(familyName)) {
251 return SkRef(fFamilies[i].get()); 251 return SkRef(fFamilies[i].get());
252 } 252 }
253 } 253 }
254 return NULL; 254 return NULL;
255 } 255 }
256 256
257 virtual SkTypeface* onMatchFamilyStyle(const char familyName[], 257 virtual SkTypeface* onMatchFamilyStyle(const char familyName[],
258 const SkFontStyle& fontStyle) const S K_OVERRIDE 258 const SkFontStyle& fontStyle) const o verride
259 { 259 {
260 SkAutoTUnref<SkFontStyleSet> sset(this->matchFamily(familyName)); 260 SkAutoTUnref<SkFontStyleSet> sset(this->matchFamily(familyName));
261 return sset->matchStyle(fontStyle); 261 return sset->matchStyle(fontStyle);
262 } 262 }
263 263
264 virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], con st SkFontStyle&, 264 virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], con st SkFontStyle&,
265 const char* bcp47[], int bcp 47Count, 265 const char* bcp47[], int bcp 47Count,
266 SkUnichar character) const S K_OVERRIDE 266 SkUnichar character) const o verride
267 { 267 {
268 return NULL; 268 return NULL;
269 } 269 }
270 270
271 virtual SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember, 271 virtual SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember,
272 const SkFontStyle& fontStyle) const SK_ OVERRIDE 272 const SkFontStyle& fontStyle) const ove rride
273 { 273 {
274 for (int i = 0; i < fFamilies.count(); ++i) { 274 for (int i = 0; i < fFamilies.count(); ++i) {
275 for (int j = 0; j < fFamilies[i]->fStyles.count(); ++j) { 275 for (int j = 0; j < fFamilies[i]->fStyles.count(); ++j) {
276 if (fFamilies[i]->fStyles[j] == familyMember) { 276 if (fFamilies[i]->fStyles[j] == familyMember) {
277 return fFamilies[i]->matchStyle(fontStyle); 277 return fFamilies[i]->matchStyle(fontStyle);
278 } 278 }
279 } 279 }
280 } 280 }
281 return NULL; 281 return NULL;
282 } 282 }
283 283
284 SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const SK_OVERRIDE { 284 SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override {
285 return this->createFromStream(new SkMemoryStream(data), ttcIndex); 285 return this->createFromStream(new SkMemoryStream(data), ttcIndex);
286 } 286 }
287 287
288 SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) cons t SK_OVERRIDE { 288 SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) cons t override {
289 SkAutoTDelete<SkStreamAsset> stream(bareStream); 289 SkAutoTDelete<SkStreamAsset> stream(bareStream);
290 if (NULL == stream || stream->getLength() <= 0) { 290 if (NULL == stream || stream->getLength() <= 0) {
291 return NULL; 291 return NULL;
292 } 292 }
293 293
294 bool isFixedPitch; 294 bool isFixedPitch;
295 SkFontStyle style; 295 SkFontStyle style;
296 SkString name; 296 SkString name;
297 if (fScanner.scanFont(stream, ttcIndex, &name, &style, &isFixedPitch)) { 297 if (fScanner.scanFont(stream, ttcIndex, &name, &style, &isFixedPitch)) {
298 return SkNEW_ARGS(SkTypeface_Stream, (style, isFixedPitch, false, na me, 298 return SkNEW_ARGS(SkTypeface_Stream, (style, isFixedPitch, false, na me,
299 stream.detach(), ttcIndex)); 299 stream.detach(), ttcIndex));
300 } else { 300 } else {
301 return NULL; 301 return NULL;
302 } 302 }
303 } 303 }
304 304
305 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const SK_OVERR IDE { 305 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override {
306 SkAutoTDelete<SkStreamAsset> stream(SkStream::NewFromFile(path)); 306 SkAutoTDelete<SkStreamAsset> stream(SkStream::NewFromFile(path));
307 return stream.get() ? this->createFromStream(stream.detach(), ttcIndex) : NULL; 307 return stream.get() ? this->createFromStream(stream.detach(), ttcIndex) : NULL;
308 } 308 }
309 309
310 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], 310 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[],
311 unsigned styleBits) const SK_OVER RIDE 311 unsigned styleBits) const overrid e
312 { 312 {
313 SkTypeface::Style oldStyle = (SkTypeface::Style)styleBits; 313 SkTypeface::Style oldStyle = (SkTypeface::Style)styleBits;
314 SkFontStyle style = SkFontStyle(oldStyle & SkTypeface::kBold 314 SkFontStyle style = SkFontStyle(oldStyle & SkTypeface::kBold
315 ? SkFontStyle::kBold_Weight 315 ? SkFontStyle::kBold_Weight
316 : SkFontStyle::kNormal_Weight, 316 : SkFontStyle::kNormal_Weight,
317 SkFontStyle::kNormal_Width, 317 SkFontStyle::kNormal_Width,
318 oldStyle & SkTypeface::kItalic 318 oldStyle & SkTypeface::kItalic
319 ? SkFontStyle::kItalic_Slant 319 ? SkFontStyle::kItalic_Slant
320 : SkFontStyle::kUpright_Slant); 320 : SkFontStyle::kUpright_Slant);
321 SkTypeface* tf = NULL; 321 SkTypeface* tf = NULL;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 429
430 SkTArray<SkAutoTUnref<SkFontStyleSet_Custom>, true> fFamilies; 430 SkTArray<SkAutoTUnref<SkFontStyleSet_Custom>, true> fFamilies;
431 SkFontStyleSet_Custom* gDefaultFamily; 431 SkFontStyleSet_Custom* gDefaultFamily;
432 SkTypeface* gDefaultNormal; 432 SkTypeface* gDefaultNormal;
433 SkTypeface_FreeType::Scanner fScanner; 433 SkTypeface_FreeType::Scanner fScanner;
434 }; 434 };
435 435
436 SkFontMgr* SkFontMgr::Factory() { 436 SkFontMgr* SkFontMgr::Factory() {
437 return new SkFontMgr_Custom(SK_FONT_FILE_PREFIX); 437 return new SkFontMgr_Custom(SK_FONT_FILE_PREFIX);
438 } 438 }
OLDNEW
« no previous file with comments | « src/ports/SkFontHost_FreeType_common.h ('k') | src/ports/SkFontHost_mac.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698