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

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

Issue 1316233002: Style Change: NULL->nullptr (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-27 (Thursday) 10:25:06 EDT Created 5 years, 3 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
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 "SkFontConfigInterface.h" 8 #include "SkFontConfigInterface.h"
9 #include "SkFontConfigTypeface.h" 9 #include "SkFontConfigTypeface.h"
10 #include "SkFontMgr.h" 10 #include "SkFontMgr.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 // borrow this global from SkFontHost_fontconfig. eventually that file should 53 // borrow this global from SkFontHost_fontconfig. eventually that file should
54 // go away, and be replaced with this one. 54 // go away, and be replaced with this one.
55 extern SkFontConfigInterface* SkFontHost_fontconfig_ref_global(); 55 extern SkFontConfigInterface* SkFontHost_fontconfig_ref_global();
56 static SkFontConfigInterface* RefFCI() { 56 static SkFontConfigInterface* RefFCI() {
57 return SkFontHost_fontconfig_ref_global(); 57 return SkFontHost_fontconfig_ref_global();
58 } 58 }
59 59
60 // look for the last substring after a '/' and return that, or return null. 60 // look for the last substring after a '/' and return that, or return null.
61 static const char* find_just_name(const char* str) { 61 static const char* find_just_name(const char* str) {
62 const char* last = strrchr(str, '/'); 62 const char* last = strrchr(str, '/');
63 return last ? last + 1 : NULL; 63 return last ? last + 1 : nullptr;
64 } 64 }
65 65
66 static bool is_lower(char c) { 66 static bool is_lower(char c) {
67 return c >= 'a' && c <= 'z'; 67 return c >= 'a' && c <= 'z';
68 } 68 }
69 69
70 static int get_int(FcPattern* pattern, const char field[]) { 70 static int get_int(FcPattern* pattern, const char field[]) {
71 SkASSERT(gFCSafeToUse); 71 SkASSERT(gFCSafeToUse);
72 int value; 72 int value;
73 if (FcPatternGetInteger(pattern, field, 0, &value) != FcResultMatch) { 73 if (FcPatternGetInteger(pattern, field, 0, &value) != FcResultMatch) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 FcPattern** iter = font_set->fonts; 116 FcPattern** iter = font_set->fonts;
117 FcPattern** stop = iter + font_set->nfont; 117 FcPattern** stop = iter + font_set->nfont;
118 // find the first good match 118 // find the first good match
119 for (; iter < stop; ++iter) { 119 for (; iter < stop; ++iter) {
120 if (valid_pattern(*iter)) { 120 if (valid_pattern(*iter)) {
121 break; 121 break;
122 } 122 }
123 } 123 }
124 124
125 if (iter == stop || !match_name(*iter, post_config_family)) { 125 if (iter == stop || !match_name(*iter, post_config_family)) {
126 return NULL; 126 return nullptr;
127 } 127 }
128 128
129 FcPattern** firstIter = iter++; 129 FcPattern** firstIter = iter++;
130 for (; iter < stop; ++iter) { 130 for (; iter < stop; ++iter) {
131 if (!valid_pattern(*iter) || !match_name(*iter, post_config_family)) { 131 if (!valid_pattern(*iter) || !match_name(*iter, post_config_family)) {
132 break; 132 break;
133 } 133 }
134 } 134 }
135 135
136 *count = iter - firstIter; 136 *count = iter - firstIter;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 SkASSERT((unsigned)index < (unsigned)fRecCount); 195 SkASSERT((unsigned)index < (unsigned)fRecCount);
196 if (style) { 196 if (style) {
197 *style = fRecs[index].fStyle; 197 *style = fRecs[index].fStyle;
198 } 198 }
199 if (styleName) { 199 if (styleName) {
200 *styleName = fRecs[index].fStyleName; 200 *styleName = fRecs[index].fStyleName;
201 } 201 }
202 } 202 }
203 203
204 SkTypeface* SkFontStyleSet_FC::createTypeface(int index) { 204 SkTypeface* SkFontStyleSet_FC::createTypeface(int index) {
205 return NULL; 205 return nullptr;
206 } 206 }
207 207
208 SkTypeface* SkFontStyleSet_FC::matchStyle(const SkFontStyle& pattern) { 208 SkTypeface* SkFontStyleSet_FC::matchStyle(const SkFontStyle& pattern) {
209 return NULL; 209 return nullptr;
210 } 210 }
211 211
212 class SkFontMgr_fontconfig : public SkFontMgr { 212 class SkFontMgr_fontconfig : public SkFontMgr {
213 SkAutoTUnref<SkFontConfigInterface> fFCI; 213 SkAutoTUnref<SkFontConfigInterface> fFCI;
214 SkDataTable* fFamilyNames; 214 SkDataTable* fFamilyNames;
215 SkTypeface_FreeType::Scanner fScanner; 215 SkTypeface_FreeType::Scanner fScanner;
216 216
217 public: 217 public:
218 SkFontMgr_fontconfig(SkFontConfigInterface* fci) 218 SkFontMgr_fontconfig(SkFontConfigInterface* fci)
219 : fFCI(fci) 219 : fFCI(fci)
(...skipping 18 matching lines...) Expand all
238 238
239 SkFontStyleSet* onMatchFamily(const char familyName[]) const override { 239 SkFontStyleSet* onMatchFamily(const char familyName[]) const override {
240 FCLocker lock; 240 FCLocker lock;
241 241
242 FcPattern* pattern = FcPatternCreate(); 242 FcPattern* pattern = FcPatternCreate();
243 243
244 FcPatternAddString(pattern, FC_FAMILY, (FcChar8*)familyName); 244 FcPatternAddString(pattern, FC_FAMILY, (FcChar8*)familyName);
245 #if 0 245 #if 0
246 FcPatternAddBool(pattern, FC_SCALABLE, FcTrue); 246 FcPatternAddBool(pattern, FC_SCALABLE, FcTrue);
247 #endif 247 #endif
248 FcConfigSubstitute(NULL, pattern, FcMatchPattern); 248 FcConfigSubstitute(nullptr, pattern, FcMatchPattern);
249 FcDefaultSubstitute(pattern); 249 FcDefaultSubstitute(pattern);
250 250
251 const char* post_config_family = get_name(pattern, FC_FAMILY); 251 const char* post_config_family = get_name(pattern, FC_FAMILY);
252 252
253 FcResult result; 253 FcResult result;
254 FcFontSet* font_set = FcFontSort(0, pattern, 0, 0, &result); 254 FcFontSet* font_set = FcFontSort(0, pattern, 0, 0, &result);
255 if (!font_set) { 255 if (!font_set) {
256 FcPatternDestroy(pattern); 256 FcPatternDestroy(pattern);
257 return NULL; 257 return nullptr;
258 } 258 }
259 259
260 int count; 260 int count;
261 FcPattern** match = MatchFont(font_set, post_config_family, &count); 261 FcPattern** match = MatchFont(font_set, post_config_family, &count);
262 if (!match) { 262 if (!match) {
263 FcPatternDestroy(pattern); 263 FcPatternDestroy(pattern);
264 FcFontSetDestroy(font_set); 264 FcFontSetDestroy(font_set);
265 return NULL; 265 return nullptr;
266 } 266 }
267 267
268 FcPatternDestroy(pattern); 268 FcPatternDestroy(pattern);
269 269
270 SkTDArray<FcPattern*> trimmedMatches; 270 SkTDArray<FcPattern*> trimmedMatches;
271 for (int i = 0; i < count; ++i) { 271 for (int i = 0; i < count; ++i) {
272 const char* justName = find_just_name(get_name(match[i], FC_FILE)); 272 const char* justName = find_just_name(get_name(match[i], FC_FILE));
273 if (!is_lower(*justName)) { 273 if (!is_lower(*justName)) {
274 *trimmedMatches.append() = match[i]; 274 *trimmedMatches.append() = match[i];
275 } 275 }
276 } 276 }
277 277
278 SkFontStyleSet_FC* sset = 278 SkFontStyleSet_FC* sset =
279 new SkFontStyleSet_FC(trimmedMatches.begin(), trimmedMatches.cou nt()); 279 new SkFontStyleSet_FC(trimmedMatches.begin(), trimmedMatches.cou nt());
280 return sset; 280 return sset;
281 } 281 }
282 282
283 SkTypeface* onMatchFamilyStyle(const char familyName[], 283 SkTypeface* onMatchFamilyStyle(const char familyName[],
284 const SkFontStyle&) const override { return N ULL; } 284 const SkFontStyle&) const override { return n ullptr; }
285 SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], const SkFon tStyle&, 285 SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], const SkFon tStyle&,
286 const char* bcp47[], int bcp47Count, 286 const char* bcp47[], int bcp47Count,
287 SkUnichar character) const override { 287 SkUnichar character) const override {
288 return NULL; 288 return nullptr;
289 } 289 }
290 SkTypeface* onMatchFaceStyle(const SkTypeface*, 290 SkTypeface* onMatchFaceStyle(const SkTypeface*,
291 const SkFontStyle&) const override { return NUL L; } 291 const SkFontStyle&) const override { return nul lptr; }
292 292
293 SkTypeface* onCreateFromData(SkData*, int ttcIndex) const override { return NULL; } 293 SkTypeface* onCreateFromData(SkData*, int ttcIndex) const override { return nullptr; }
294 294
295 SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) cons t override { 295 SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) cons t override {
296 SkAutoTDelete<SkStreamAsset> stream(bareStream); 296 SkAutoTDelete<SkStreamAsset> stream(bareStream);
297 const size_t length = stream->getLength(); 297 const size_t length = stream->getLength();
298 if (!length) { 298 if (!length) {
299 return NULL; 299 return nullptr;
300 } 300 }
301 if (length >= 1024 * 1024 * 1024) { 301 if (length >= 1024 * 1024 * 1024) {
302 return NULL; // don't accept too large fonts (>= 1GB) for safety. 302 return nullptr; // don't accept too large fonts (>= 1GB) for safety .
303 } 303 }
304 304
305 // TODO should the caller give us the style or should we get it from fre etype? 305 // TODO should the caller give us the style or should we get it from fre etype?
306 SkFontStyle style; 306 SkFontStyle style;
307 bool isFixedWidth = false; 307 bool isFixedWidth = false;
308 if (!fScanner.scanFont(stream, 0, NULL, &style, &isFixedWidth, NULL)) { 308 if (!fScanner.scanFont(stream, 0, nullptr, &style, &isFixedWidth, nullpt r)) {
309 return NULL; 309 return nullptr;
310 } 310 }
311 311
312 SkTypeface* face = FontConfigTypeface::Create(style, isFixedWidth, strea m.detach()); 312 SkTypeface* face = FontConfigTypeface::Create(style, isFixedWidth, strea m.detach());
313 return face; 313 return face;
314 } 314 }
315 315
316 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override { 316 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override {
317 SkAutoTDelete<SkStreamAsset> stream(SkStream::NewFromFile(path)); 317 SkAutoTDelete<SkStreamAsset> stream(SkStream::NewFromFile(path));
318 return stream.get() ? this->createFromStream(stream.detach(), ttcIndex) : NULL; 318 return stream.get() ? this->createFromStream(stream.detach(), ttcIndex) : nullptr;
319 } 319 }
320 320
321 SkTypeface* onLegacyCreateTypeface(const char familyName[], 321 SkTypeface* onLegacyCreateTypeface(const char familyName[],
322 unsigned styleBits) const override { 322 unsigned styleBits) const override {
323 FCLocker lock; 323 FCLocker lock;
324 return FontConfigTypeface::LegacyCreateTypeface(familyName, (SkTypeface: :Style)styleBits); 324 return FontConfigTypeface::LegacyCreateTypeface(familyName, (SkTypeface: :Style)styleBits);
325 } 325 }
326 }; 326 };
327 327
328 SkFontMgr* SkFontMgr::Factory() { 328 SkFontMgr* SkFontMgr::Factory() {
329 SkFontConfigInterface* fci = RefFCI(); 329 SkFontConfigInterface* fci = RefFCI();
330 return fci ? new SkFontMgr_fontconfig(fci) : NULL; 330 return fci ? new SkFontMgr_fontconfig(fci) : nullptr;
331 } 331 }
OLDNEW
« no previous file with comments | « src/effects/gradients/SkTwoPointConicalGradient_gpu.cpp ('k') | src/fonts/SkFontMgr_indirect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698