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

Side by Side Diff: src/fonts/SkFontMgr_fontconfig.cpp

Issue 134643028: Make SkFontMgr interface const. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: dw fixes Created 6 years, 10 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/core/SkFontHost.cpp ('k') | src/ports/SkFontHost_linux.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 2013 Google Inc. 2 * Copyright 2013 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 #include "SkFontMgr.h" 8 #include "SkFontMgr.h"
9 #include "SkFontStyle.h" 9 #include "SkFontStyle.h"
10 #include "SkFontConfigInterface.h" 10 #include "SkFontConfigInterface.h"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 } 177 }
178 178
179 SkTypeface* SkFontStyleSet_FC::matchStyle(const SkFontStyle& pattern) { 179 SkTypeface* SkFontStyleSet_FC::matchStyle(const SkFontStyle& pattern) {
180 return NULL; 180 return NULL;
181 } 181 }
182 182
183 class SkFontMgr_fontconfig : public SkFontMgr { 183 class SkFontMgr_fontconfig : public SkFontMgr {
184 SkAutoTUnref<SkFontConfigInterface> fFCI; 184 SkAutoTUnref<SkFontConfigInterface> fFCI;
185 SkDataTable* fFamilyNames; 185 SkDataTable* fFamilyNames;
186 186
187 void init() {
188 if (!fFamilyNames) {
189 fFamilyNames = fFCI->getFamilyNames();
190 }
191 }
192 187
193 public: 188 public:
194 SkFontMgr_fontconfig(SkFontConfigInterface* fci) 189 SkFontMgr_fontconfig(SkFontConfigInterface* fci)
195 : fFCI(fci) 190 : fFCI(fci)
196 , fFamilyNames(NULL) {} 191 , fFamilyNames(fFCI->getFamilyNames()) {}
197 192
198 virtual ~SkFontMgr_fontconfig() { 193 virtual ~SkFontMgr_fontconfig() {
199 SkSafeUnref(fFamilyNames); 194 SkSafeUnref(fFamilyNames);
200 } 195 }
201 196
202 protected: 197 protected:
203 virtual int onCountFamilies() { 198 virtual int onCountFamilies() const SK_OVERRIDE {
204 this->init();
205 return fFamilyNames->count(); 199 return fFamilyNames->count();
206 } 200 }
207 201
208 virtual void onGetFamilyName(int index, SkString* familyName) { 202 virtual void onGetFamilyName(int index, SkString* familyName) const SK_OVERR IDE {
209 this->init();
210 familyName->set(fFamilyNames->atStr(index)); 203 familyName->set(fFamilyNames->atStr(index));
211 } 204 }
212 205
213 virtual SkFontStyleSet* onCreateStyleSet(int index) { 206 virtual SkFontStyleSet* onCreateStyleSet(int index) const SK_OVERRIDE {
214 this->init();
215 return this->onMatchFamily(fFamilyNames->atStr(index)); 207 return this->onMatchFamily(fFamilyNames->atStr(index));
216 } 208 }
217 209
218 virtual SkFontStyleSet* onMatchFamily(const char familyName[]) { 210 virtual SkFontStyleSet* onMatchFamily(const char familyName[]) const SK_OVER RIDE {
219 this->init();
220
221 FcPattern* pattern = FcPatternCreate(); 211 FcPattern* pattern = FcPatternCreate();
222 212
223 FcPatternAddString(pattern, FC_FAMILY, (FcChar8*)familyName); 213 FcPatternAddString(pattern, FC_FAMILY, (FcChar8*)familyName);
224 #if 0 214 #if 0
225 FcPatternAddBool(pattern, FC_SCALABLE, FcTrue); 215 FcPatternAddBool(pattern, FC_SCALABLE, FcTrue);
226 #endif 216 #endif
227 FcConfigSubstitute(NULL, pattern, FcMatchPattern); 217 FcConfigSubstitute(NULL, pattern, FcMatchPattern);
228 FcDefaultSubstitute(pattern); 218 FcDefaultSubstitute(pattern);
229 219
230 const char* post_config_family = get_name(pattern, FC_FAMILY); 220 const char* post_config_family = get_name(pattern, FC_FAMILY);
(...skipping 23 matching lines...) Expand all
254 } 244 }
255 } 245 }
256 246
257 SkFontStyleSet_FC* sset = SkNEW_ARGS(SkFontStyleSet_FC, 247 SkFontStyleSet_FC* sset = SkNEW_ARGS(SkFontStyleSet_FC,
258 (trimmedMatches.begin(), 248 (trimmedMatches.begin(),
259 trimmedMatches.count())); 249 trimmedMatches.count()));
260 return sset; 250 return sset;
261 } 251 }
262 252
263 virtual SkTypeface* onMatchFamilyStyle(const char familyName[], 253 virtual SkTypeface* onMatchFamilyStyle(const char familyName[],
264 const SkFontStyle&) { return NULL; } 254 const SkFontStyle&) const SK_OVERRIDE { return NULL; }
265 virtual SkTypeface* onMatchFaceStyle(const SkTypeface*, 255 virtual SkTypeface* onMatchFaceStyle(const SkTypeface*,
266 const SkFontStyle&) { return NULL; } 256 const SkFontStyle&) const SK_OVERRIDE { return NULL; }
267 257
268 virtual SkTypeface* onCreateFromData(SkData*, int ttcIndex) { return NULL; } 258 virtual SkTypeface* onCreateFromData(SkData*, int ttcIndex) const SK_OVERRID E { return NULL; }
269 259
270 virtual SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) { 260 virtual SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) const SK_OVERRIDE {
271 const size_t length = stream->getLength(); 261 const size_t length = stream->getLength();
272 if (!length) { 262 if (!length) {
273 return NULL; 263 return NULL;
274 } 264 }
275 if (length >= 1024 * 1024 * 1024) { 265 if (length >= 1024 * 1024 * 1024) {
276 return NULL; // don't accept too large fonts (>= 1GB) for safety. 266 return NULL; // don't accept too large fonts (>= 1GB) for safety.
277 } 267 }
278 268
279 // TODO should the caller give us the style or should we get it from fre etype? 269 // TODO should the caller give us the style or should we get it from fre etype?
280 SkTypeface::Style style = SkTypeface::kNormal; 270 SkTypeface::Style style = SkTypeface::kNormal;
281 bool isFixedWidth = false; 271 bool isFixedWidth = false;
282 if (!find_name_and_attributes(stream, NULL, &style, &isFixedWidth)) { 272 if (!find_name_and_attributes(stream, NULL, &style, &isFixedWidth)) {
283 return NULL; 273 return NULL;
284 } 274 }
285 275
286 SkTypeface* face = SkNEW_ARGS(FontConfigTypeface, (style, isFixedWidth, stream)); 276 SkTypeface* face = SkNEW_ARGS(FontConfigTypeface, (style, isFixedWidth, stream));
287 return face; 277 return face;
288 } 278 }
289 279
290 virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) { 280 virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const SK_OVERRIDE {
291 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); 281 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path));
292 return stream.get() ? this->createFromStream(stream, ttcIndex) : NULL; 282 return stream.get() ? this->createFromStream(stream, ttcIndex) : NULL;
293 } 283 }
294 284
295 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], 285 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[],
296 unsigned styleBits) SK_OVERRIDE { 286 unsigned styleBits) const SK_OVER RIDE {
297 return FontConfigTypeface::LegacyCreateTypeface(NULL, familyName, 287 return FontConfigTypeface::LegacyCreateTypeface(NULL, familyName,
298 (SkTypeface::Style)styleBits); 288 (SkTypeface::Style)styleBits);
299 } 289 }
300 }; 290 };
301 291
302 SkFontMgr* SkFontMgr::Factory() { 292 SkFontMgr* SkFontMgr::Factory() {
303 SkFontConfigInterface* fci = RefFCI(); 293 SkFontConfigInterface* fci = RefFCI();
304 return fci ? SkNEW_ARGS(SkFontMgr_fontconfig, (fci)) : NULL; 294 return fci ? SkNEW_ARGS(SkFontMgr_fontconfig, (fci)) : NULL;
305 } 295 }
OLDNEW
« no previous file with comments | « src/core/SkFontHost.cpp ('k') | src/ports/SkFontHost_linux.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698