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

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

Issue 149482: Linux: workaround a fontconfig bug. (Closed)
Patch Set: ... Created 11 years, 5 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 | webkit/api/src/gtk/WebFontInfo.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 /* 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 // requested family: "Monaco" 108 // requested family: "Monaco"
109 // post_config_family: "Monaco" 109 // post_config_family: "Monaco"
110 // post_match_family: "Times New Roman" 110 // post_match_family: "Times New Roman"
111 // -> BAD match 111 // -> BAD match
112 // 112 //
113 // However, we special-case fallback fonts; see IsFallbackFontAllowed(). 113 // However, we special-case fallback fonts; see IsFallbackFontAllowed().
114 FcChar8* post_config_family; 114 FcChar8* post_config_family;
115 FcPatternGetString(pattern, FC_FAMILY, 0, &post_config_family); 115 FcPatternGetString(pattern, FC_FAMILY, 0, &post_config_family);
116 116
117 FcResult result; 117 FcResult result;
118 FcPattern* match = FcFontMatch(0, pattern, &result); 118 FcFontSet* font_set = FcFontSort(0, pattern, 0, 0, &result);
119 if (!match) { 119 if (!font_set) {
120 FcPatternDestroy(pattern); 120 FcPatternDestroy(pattern);
121 return false; 121 return false;
122 } 122 }
123 123
124 // Older versions of fontconfig have a bug where they cannot select
125 // only scalable fonts so we have to manually filter the results.
126 FcPattern* match = NULL;
127 for (int i = 0; i < font_set->nfont; ++i) {
128 FcPattern* current = font_set->fonts[i];
129 FcBool is_scalable;
130
131 if (FcPatternGetBool(current, FC_SCALABLE, 0,
132 &is_scalable) != FcResultMatch ||
133 !is_scalable) {
134 continue;
135 }
136
137 match = current;
138 break;
139 }
140
141 if (!match) {
142 FcPatternDestroy(pattern);
143 FcFontSetDestroy(font_set);
144 return false;
145 }
146
124 FcChar8* post_match_family; 147 FcChar8* post_match_family;
125 FcPatternGetString(match, FC_FAMILY, 0, &post_match_family); 148 FcPatternGetString(match, FC_FAMILY, 0, &post_match_family);
126 const bool family_names_match = 149 const bool family_names_match =
127 family.empty() ? 150 family.empty() ?
128 true : 151 true :
129 strcasecmp((char *)post_config_family, (char *)post_match_family) == 0; 152 strcasecmp((char *)post_config_family, (char *)post_match_family) == 0;
130 153
131 FcPatternDestroy(pattern); 154 FcPatternDestroy(pattern);
132 155
133 if (!family_names_match && !IsFallbackFontAllowed(family)) { 156 if (!family_names_match && !IsFallbackFontAllowed(family)) {
134 FcPatternDestroy(match); 157 FcFontSetDestroy(font_set);
135 return false; 158 return false;
136 } 159 }
137 160
138 FcChar8* c_filename; 161 FcChar8* c_filename;
139 if (FcPatternGetString(match, FC_FILE, 0, &c_filename) != FcResultMatch) { 162 if (FcPatternGetString(match, FC_FILE, 0, &c_filename) != FcResultMatch) {
140 FcPatternDestroy(match); 163 FcFontSetDestroy(font_set);
141 return NULL; 164 return false;
142 } 165 }
143 const std::string filename((char *) c_filename); 166 const std::string filename((char *) c_filename);
144 167
145 unsigned out_fileid; 168 unsigned out_fileid;
146 if (fileid_valid) { 169 if (fileid_valid) {
147 out_fileid = fileid; 170 out_fileid = fileid;
148 } else { 171 } else {
149 const std::map<std::string, unsigned>::const_iterator 172 const std::map<std::string, unsigned>::const_iterator
150 i = filename_to_fileid_.find(filename); 173 i = filename_to_fileid_.find(filename);
151 if (i == filename_to_fileid_.end()) { 174 if (i == filename_to_fileid_.end()) {
152 out_fileid = next_file_id_++; 175 out_fileid = next_file_id_++;
153 filename_to_fileid_[filename] = out_fileid; 176 filename_to_fileid_[filename] = out_fileid;
154 fileid_to_filename_[out_fileid] = filename; 177 fileid_to_filename_[out_fileid] = filename;
155 } else { 178 } else {
156 out_fileid = i->second; 179 out_fileid = i->second;
157 } 180 }
158 } 181 }
159 182
160 if (result_fileid) 183 if (result_fileid)
161 *result_fileid = out_fileid; 184 *result_fileid = out_fileid;
162 185
163 FcChar8* c_family; 186 FcChar8* c_family;
164 if (FcPatternGetString(match, FC_FAMILY, 0, &c_family)) { 187 if (FcPatternGetString(match, FC_FAMILY, 0, &c_family)) {
165 FcPatternDestroy(match); 188 FcFontSetDestroy(font_set);
166 return NULL; 189 return false;
167 } 190 }
168 191
169 int resulting_bold; 192 int resulting_bold;
170 if (FcPatternGetInteger(match, FC_WEIGHT, 0, &resulting_bold)) 193 if (FcPatternGetInteger(match, FC_WEIGHT, 0, &resulting_bold))
171 resulting_bold = FC_WEIGHT_NORMAL; 194 resulting_bold = FC_WEIGHT_NORMAL;
172 195
173 int resulting_italic; 196 int resulting_italic;
174 if (FcPatternGetInteger(match, FC_SLANT, 0, &resulting_italic)) 197 if (FcPatternGetInteger(match, FC_SLANT, 0, &resulting_italic))
175 resulting_italic = FC_SLANT_ROMAN; 198 resulting_italic = FC_SLANT_ROMAN;
176 199
(...skipping 11 matching lines...) Expand all
188 FcPatternGet(match, FC_EMBOLDEN, 0, &embolden) == 0; 211 FcPatternGet(match, FC_EMBOLDEN, 0, &embolden) == 0;
189 212
190 if (is_bold) 213 if (is_bold)
191 *is_bold = resulting_bold >= FC_WEIGHT_BOLD && !have_embolden; 214 *is_bold = resulting_bold >= FC_WEIGHT_BOLD && !have_embolden;
192 if (is_italic) 215 if (is_italic)
193 *is_italic = resulting_italic > FC_SLANT_ROMAN && !have_matrix; 216 *is_italic = resulting_italic > FC_SLANT_ROMAN && !have_matrix;
194 217
195 if (result_family) 218 if (result_family)
196 *result_family = (char *) c_family; 219 *result_family = (char *) c_family;
197 220
198 FcPatternDestroy(match); 221 FcFontSetDestroy(font_set);
199 222
200 return true; 223 return true;
201 } 224 }
202 225
203 int FontConfigDirect::Open(unsigned fileid) { 226 int FontConfigDirect::Open(unsigned fileid) {
204 SkAutoMutexAcquire ac(mutex_); 227 SkAutoMutexAcquire ac(mutex_);
205 const std::map<unsigned, std::string>::const_iterator 228 const std::map<unsigned, std::string>::const_iterator
206 i = fileid_to_filename_.find(fileid); 229 i = fileid_to_filename_.find(fileid);
207 if (i == fileid_to_filename_.end()) 230 if (i == fileid_to_filename_.end())
208 return -1; 231 return -1;
209 232
210 return open(i->second.c_str(), O_RDONLY); 233 return open(i->second.c_str(), O_RDONLY);
211 } 234 }
OLDNEW
« no previous file with comments | « no previous file | webkit/api/src/gtk/WebFontInfo.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698