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

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

Issue 437253003: Remove dependency on std::string (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 4 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 | « no previous file | no next file » | 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 2009 Google Inc. 2 * Copyright 2009 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 /* migrated from chrome/src/skia/ext/SkFontHost_fontconfig_direct.cpp */ 8 /* migrated from chrome/src/skia/ext/SkFontHost_fontconfig_direct.cpp */
9 9
10 #include <string>
11 #include <unistd.h> 10 #include <unistd.h>
12 #include <fcntl.h> 11 #include <fcntl.h>
13 12
14 #include <fontconfig/fontconfig.h> 13 #include <fontconfig/fontconfig.h>
15 14
16 #include "SkBuffer.h" 15 #include "SkBuffer.h"
17 #include "SkFontConfigInterface.h" 16 #include "SkFontConfigInterface.h"
18 #include "SkLazyPtr.h" 17 #include "SkLazyPtr.h"
19 #include "SkStream.h" 18 #include "SkStream.h"
19 #include "SkString.h"
20 20
21 size_t SkFontConfigInterface::FontIdentity::writeToMemory(void* addr) const { 21 size_t SkFontConfigInterface::FontIdentity::writeToMemory(void* addr) const {
22 size_t size = sizeof(fID) + sizeof(fTTCIndex); 22 size_t size = sizeof(fID) + sizeof(fTTCIndex);
23 size += sizeof(int32_t) + sizeof(int32_t) + sizeof(uint8_t); // weight, widt h, italic 23 size += sizeof(int32_t) + sizeof(int32_t) + sizeof(uint8_t); // weight, widt h, italic
24 size += sizeof(int32_t) + fString.size(); // store length+data 24 size += sizeof(int32_t) + fString.size(); // store length+data
25 if (addr) { 25 if (addr) {
26 SkWBuffer buffer(addr, size); 26 SkWBuffer buffer(addr, size);
27 27
28 buffer.write32(fID); 28 buffer.write32(fID);
29 buffer.write32(fTTCIndex); 29 buffer.write32(fTTCIndex);
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 FontEquivClass class_a = GetFontEquivClass(font_a); 311 FontEquivClass class_a = GetFontEquivClass(font_a);
312 FontEquivClass class_b = GetFontEquivClass(font_b); 312 FontEquivClass class_b = GetFontEquivClass(font_b);
313 313
314 return class_a != OTHER && class_a == class_b; 314 return class_a != OTHER && class_a == class_b;
315 } 315 }
316 316
317 // Normally we only return exactly the font asked for. In last-resort 317 // Normally we only return exactly the font asked for. In last-resort
318 // cases, the request either doesn't specify a font or is one of the 318 // cases, the request either doesn't specify a font or is one of the
319 // basic font names like "Sans", "Serif" or "Monospace". This function 319 // basic font names like "Sans", "Serif" or "Monospace". This function
320 // tells you whether a given request is for such a fallback. 320 // tells you whether a given request is for such a fallback.
321 bool IsFallbackFontAllowed(const std::string& family) { 321 bool IsFallbackFontAllowed(const SkString& family) {
322 const char* family_cstr = family.c_str(); 322 const char* family_cstr = family.c_str();
323 return family.empty() || 323 return family.isEmpty() ||
324 strcasecmp(family_cstr, "sans") == 0 || 324 strcasecmp(family_cstr, "sans") == 0 ||
325 strcasecmp(family_cstr, "serif") == 0 || 325 strcasecmp(family_cstr, "serif") == 0 ||
326 strcasecmp(family_cstr, "monospace") == 0; 326 strcasecmp(family_cstr, "monospace") == 0;
327 } 327 }
328 328
329 static bool valid_pattern(FcPattern* pattern) { 329 static bool valid_pattern(FcPattern* pattern) {
330 #ifdef SK_FONT_CONFIG_ONLY_ALLOW_SCALABLE_FONTS 330 #ifdef SK_FONT_CONFIG_ONLY_ALLOW_SCALABLE_FONTS
331 FcBool is_scalable; 331 FcBool is_scalable;
332 if (FcPatternGetBool(pattern, FC_SCALABLE, 0, &is_scalable) != FcResultMatch 332 if (FcPatternGetBool(pattern, FC_SCALABLE, 0, &is_scalable) != FcResultMatch
333 || !is_scalable) { 333 || !is_scalable) {
334 return false; 334 return false;
335 } 335 }
336 #endif 336 #endif
337 337
338 // fontconfig can also return fonts which are unreadable 338 // fontconfig can also return fonts which are unreadable
339 const char* c_filename = get_name(pattern, FC_FILE); 339 const char* c_filename = get_name(pattern, FC_FILE);
340 if (!c_filename) { 340 if (!c_filename) {
341 return false; 341 return false;
342 } 342 }
343 if (access(c_filename, R_OK) != 0) { 343 if (access(c_filename, R_OK) != 0) {
344 return false; 344 return false;
345 } 345 }
346 return true; 346 return true;
347 } 347 }
348 348
349 // Find matching font from |font_set| for the given font family. 349 // Find matching font from |font_set| for the given font family.
350 FcPattern* MatchFont(FcFontSet* font_set, 350 FcPattern* MatchFont(FcFontSet* font_set,
351 const char* post_config_family, 351 const char* post_config_family,
352 const std::string& family) { 352 const SkString& family) {
353 // Older versions of fontconfig have a bug where they cannot select 353 // Older versions of fontconfig have a bug where they cannot select
354 // only scalable fonts so we have to manually filter the results. 354 // only scalable fonts so we have to manually filter the results.
355 FcPattern* match = NULL; 355 FcPattern* match = NULL;
356 for (int i = 0; i < font_set->nfont; ++i) { 356 for (int i = 0; i < font_set->nfont; ++i) {
357 FcPattern* current = font_set->fonts[i]; 357 FcPattern* current = font_set->fonts[i];
358 if (valid_pattern(current)) { 358 if (valid_pattern(current)) {
359 match = current; 359 match = current;
360 break; 360 break;
361 } 361 }
362 } 362 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 } 434 }
435 435
436 SkFontConfigInterfaceDirect::~SkFontConfigInterfaceDirect() { 436 SkFontConfigInterfaceDirect::~SkFontConfigInterfaceDirect() {
437 } 437 }
438 438
439 bool SkFontConfigInterfaceDirect::matchFamilyName(const char familyName[], 439 bool SkFontConfigInterfaceDirect::matchFamilyName(const char familyName[],
440 SkTypeface::Style style, 440 SkTypeface::Style style,
441 FontIdentity* outIdentity, 441 FontIdentity* outIdentity,
442 SkString* outFamilyName, 442 SkString* outFamilyName,
443 SkTypeface::Style* outStyle) { 443 SkTypeface::Style* outStyle) {
444 std::string familyStr(familyName ? familyName : ""); 444 SkString familyStr(familyName ? familyName : "");
445 if (familyStr.length() > kMaxFontFamilyLength) { 445 if (familyStr.size() > kMaxFontFamilyLength) {
446 return false; 446 return false;
447 } 447 }
448 448
449 SkAutoMutexAcquire ac(mutex_); 449 SkAutoMutexAcquire ac(mutex_);
450 450
451 FcPattern* pattern = FcPatternCreate(); 451 FcPattern* pattern = FcPatternCreate();
452 452
453 if (familyName) { 453 if (familyName) {
454 FcPatternAddString(pattern, FC_FAMILY, (FcChar8*)familyName); 454 FcPatternAddString(pattern, FC_FAMILY, (FcChar8*)familyName);
455 } 455 }
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 return SkDataTable::NewCopyArrays((const void*const*)names.begin(), 601 return SkDataTable::NewCopyArrays((const void*const*)names.begin(),
602 sizes.begin(), names.count()); 602 sizes.begin(), names.count());
603 } 603 }
604 604
605 bool SkFontConfigInterfaceDirect::matchFamilySet(const char inFamilyName[], 605 bool SkFontConfigInterfaceDirect::matchFamilySet(const char inFamilyName[],
606 SkString* outFamilyName, 606 SkString* outFamilyName,
607 SkTArray<FontIdentity>* ids) { 607 SkTArray<FontIdentity>* ids) {
608 SkAutoMutexAcquire ac(mutex_); 608 SkAutoMutexAcquire ac(mutex_);
609 609
610 #if 0 610 #if 0
611 std::string familyStr(familyName ? familyName : ""); 611 SkString familyStr(familyName ? familyName : "");
612 if (familyStr.length() > kMaxFontFamilyLength) { 612 if (familyStr.size() > kMaxFontFamilyLength) {
613 return false; 613 return false;
614 } 614 }
615 615
616 SkAutoMutexAcquire ac(mutex_); 616 SkAutoMutexAcquire ac(mutex_);
617 617
618 FcPattern* pattern = FcPatternCreate(); 618 FcPattern* pattern = FcPatternCreate();
619 619
620 if (familyName) { 620 if (familyName) {
621 FcPatternAddString(pattern, FC_FAMILY, (FcChar8*)familyName); 621 FcPatternAddString(pattern, FC_FAMILY, (FcChar8*)familyName);
622 } 622 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 *trimmedMatches.append() = match[i]; 724 *trimmedMatches.append() = match[i];
725 } 725 }
726 } 726 }
727 727
728 SkFontStyleSet_FC* sset = SkNEW_ARGS(SkFontStyleSet_FC, 728 SkFontStyleSet_FC* sset = SkNEW_ARGS(SkFontStyleSet_FC,
729 (trimmedMatches.begin(), 729 (trimmedMatches.begin(),
730 trimmedMatches.count())); 730 trimmedMatches.count()));
731 #endif 731 #endif
732 return false; 732 return false;
733 } 733 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698