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

Side by Side Diff: skia/ext/SkFontHost_fontconfig_direct.cpp

Issue 147005: Linux: fix fake italics for font's without italic variants. (Closed)
Patch Set: ... Created 11 years, 6 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 | « skia/ext/SkFontHost_fontconfig_direct.h ('k') | skia/ext/SkFontHost_fontconfig_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* libs/graphics/ports/SkFontHost_fontconfig_direct.cpp 1 /* libs/graphics/ports/SkFontHost_fontconfig_direct.cpp
2 ** 2 **
3 ** Copyright 2009, Google Inc. 3 ** Copyright 2009, Google Inc.
4 ** 4 **
5 ** Licensed under the Apache License, Version 2.0 (the "License"); 5 ** Licensed under the Apache License, Version 2.0 (the "License");
6 ** you may not use this file except in compliance with the License. 6 ** you may not use this file except in compliance with the License.
7 ** You may obtain a copy of the License at 7 ** You may obtain a copy of the License at
8 ** 8 **
9 ** http://www.apache.org/licenses/LICENSE-2.0 9 ** http://www.apache.org/licenses/LICENSE-2.0
10 ** 10 **
(...skipping 25 matching lines...) Expand all
36 static bool IsFallbackFontAllowed(const std::string& family) 36 static bool IsFallbackFontAllowed(const std::string& family)
37 { 37 {
38 return family == "Sans" || 38 return family == "Sans" ||
39 family == "Serif" || 39 family == "Serif" ||
40 family == "Monospace"; 40 family == "Monospace";
41 } 41 }
42 42
43 bool FontConfigDirect::Match(std::string* result_family, 43 bool FontConfigDirect::Match(std::string* result_family,
44 unsigned* result_fileid, 44 unsigned* result_fileid,
45 bool fileid_valid, unsigned fileid, 45 bool fileid_valid, unsigned fileid,
46 const std::string& family, int is_bold, 46 const std::string& family, bool* is_bold,
47 int is_italic) { 47 bool* is_italic) {
48 SkAutoMutexAcquire ac(mutex_); 48 SkAutoMutexAcquire ac(mutex_);
49 FcPattern* pattern = FcPatternCreate(); 49 FcPattern* pattern = FcPatternCreate();
50 50
51 FcValue fcvalue; 51 FcValue fcvalue;
52 if (fileid_valid) { 52 if (fileid_valid) {
53 const std::map<unsigned, std::string>::const_iterator 53 const std::map<unsigned, std::string>::const_iterator
54 i = fileid_to_filename_.find(fileid); 54 i = fileid_to_filename_.find(fileid);
55 if (i == fileid_to_filename_.end()) { 55 if (i == fileid_to_filename_.end()) {
56 FcPatternDestroy(pattern); 56 FcPatternDestroy(pattern);
57 return false; 57 return false;
58 } 58 }
59 59
60 fcvalue.type = FcTypeString; 60 fcvalue.type = FcTypeString;
61 fcvalue.u.s = (FcChar8*) i->second.c_str(); 61 fcvalue.u.s = (FcChar8*) i->second.c_str();
62 FcPatternAdd(pattern, FC_FILE, fcvalue, 0); 62 FcPatternAdd(pattern, FC_FILE, fcvalue, 0);
63 } 63 }
64 if (!family.empty()) { 64 if (!family.empty()) {
65 fcvalue.type = FcTypeString; 65 fcvalue.type = FcTypeString;
66 fcvalue.u.s = (FcChar8*) family.c_str(); 66 fcvalue.u.s = (FcChar8*) family.c_str();
67 FcPatternAdd(pattern, FC_FAMILY, fcvalue, 0); 67 FcPatternAdd(pattern, FC_FAMILY, fcvalue, 0);
68 } 68 }
69 if (is_bold > 0) { 69
70 fcvalue.type = FcTypeInteger; 70 fcvalue.type = FcTypeInteger;
71 fcvalue.u.i = is_bold ? FC_WEIGHT_BOLD : FC_WEIGHT_NORMAL; 71 fcvalue.u.i = is_bold && *is_bold ? FC_WEIGHT_BOLD : FC_WEIGHT_NORMAL;
72 FcPatternAdd(pattern, FC_WEIGHT, fcvalue, 0); 72 FcPatternAdd(pattern, FC_WEIGHT, fcvalue, 0);
73 } 73
74 if (is_italic > 0) { 74 fcvalue.type = FcTypeInteger;
75 fcvalue.type = FcTypeInteger; 75 fcvalue.u.i = is_italic && *is_italic ? FC_SLANT_ITALIC : FC_SLANT_ROMAN;
76 fcvalue.u.i = is_italic ? FC_SLANT_ITALIC : FC_SLANT_ROMAN; 76 FcPatternAdd(pattern, FC_SLANT, fcvalue, 0);
77 FcPatternAdd(pattern, FC_SLANT, fcvalue, 0);
78 }
79 77
80 FcConfigSubstitute(0, pattern, FcMatchPattern); 78 FcConfigSubstitute(0, pattern, FcMatchPattern);
81 FcDefaultSubstitute(pattern); 79 FcDefaultSubstitute(pattern);
82 80
83 // Font matching: 81 // Font matching:
84 // CSS often specifies a fallback list of families: 82 // CSS often specifies a fallback list of families:
85 // font-family: a, b, c, serif; 83 // font-family: a, b, c, serif;
86 // However, fontconfig will always do its best to find *a* font when asked 84 // However, fontconfig will always do its best to find *a* font when asked
87 // for something so we need a way to tell if the match which it has found is 85 // for something so we need a way to tell if the match which it has found is
88 // "good enough" for us. Otherwise, we can return NULL which gets piped up 86 // "good enough" for us. Otherwise, we can return NULL which gets piped up
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 164
167 if (result_fileid) 165 if (result_fileid)
168 *result_fileid = out_fileid; 166 *result_fileid = out_fileid;
169 167
170 FcChar8* c_family; 168 FcChar8* c_family;
171 if (FcPatternGetString(match, FC_FAMILY, 0, &c_family)) { 169 if (FcPatternGetString(match, FC_FAMILY, 0, &c_family)) {
172 FcPatternDestroy(match); 170 FcPatternDestroy(match);
173 return NULL; 171 return NULL;
174 } 172 }
175 173
174 int resulting_bold;
175 if (FcPatternGetInteger(match, FC_WEIGHT, 0, &resulting_bold))
176 resulting_bold = FC_WEIGHT_NORMAL;
177
178 int resulting_italic;
179 if (FcPatternGetInteger(match, FC_SLANT, 0, &resulting_italic))
180 resulting_italic = FC_SLANT_ROMAN;
181
182 if (is_bold)
183 *is_bold = resulting_bold >= FC_WEIGHT_BOLD;
184 if (is_italic)
185 *is_italic = resulting_italic == FC_SLANT_ITALIC;
186
176 if (result_family) 187 if (result_family)
177 *result_family = (char *) c_family; 188 *result_family = (char *) c_family;
178 189
179 FcPatternDestroy(match); 190 FcPatternDestroy(match);
180 191
181 return true; 192 return true;
182 } 193 }
183 194
184 int FontConfigDirect::Open(unsigned fileid) { 195 int FontConfigDirect::Open(unsigned fileid) {
185 SkAutoMutexAcquire ac(mutex_); 196 SkAutoMutexAcquire ac(mutex_);
186 const std::map<unsigned, std::string>::const_iterator 197 const std::map<unsigned, std::string>::const_iterator
187 i = fileid_to_filename_.find(fileid); 198 i = fileid_to_filename_.find(fileid);
188 if (i == fileid_to_filename_.end()) 199 if (i == fileid_to_filename_.end())
189 return -1; 200 return -1;
190 201
191 return open(i->second.c_str(), O_RDONLY); 202 return open(i->second.c_str(), O_RDONLY);
192 } 203 }
OLDNEW
« no previous file with comments | « skia/ext/SkFontHost_fontconfig_direct.h ('k') | skia/ext/SkFontHost_fontconfig_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698