reed@google.com | b1c65b6 | 2013-02-26 15:50:51 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2009 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | /* migrated from chrome/src/skia/ext/SkFontHost_fontconfig_direct.cpp */ |
| 9 | |
reed@google.com | b1c65b6 | 2013-02-26 15:50:51 +0000 | [diff] [blame] | 10 | #include <string> |
| 11 | #include <unistd.h> |
| 12 | #include <fcntl.h> |
| 13 | |
| 14 | #include <fontconfig/fontconfig.h> |
| 15 | |
| 16 | #include "SkFontConfigInterface.h" |
reed@google.com | b1c65b6 | 2013-02-26 15:50:51 +0000 | [diff] [blame] | 17 | #include "SkStream.h" |
| 18 | |
| 19 | class SkFontConfigInterfaceDirect : public SkFontConfigInterface { |
| 20 | public: |
| 21 | SkFontConfigInterfaceDirect(); |
| 22 | virtual ~SkFontConfigInterfaceDirect(); |
| 23 | |
reed@google.com | f71a233 | 2013-02-27 19:06:30 +0000 | [diff] [blame] | 24 | virtual bool matchFamilyName(const char familyName[], |
| 25 | SkTypeface::Style requested, |
| 26 | FontIdentity* outFontIdentifier, |
| 27 | SkString* outFamilyName, |
| 28 | SkTypeface::Style* outStyle) SK_OVERRIDE; |
| 29 | virtual SkStream* openStream(const FontIdentity&) SK_OVERRIDE; |
reed@google.com | b1c65b6 | 2013-02-26 15:50:51 +0000 | [diff] [blame] | 30 | |
| 31 | private: |
| 32 | SkMutex mutex_; |
reed@google.com | b1c65b6 | 2013-02-26 15:50:51 +0000 | [diff] [blame] | 33 | }; |
| 34 | |
reed@google.com | d66045e | 2013-03-04 19:07:02 +0000 | [diff] [blame] | 35 | SkFontConfigInterface* SkFontConfigInterface::GetSingletonDirectInterface() { |
| 36 | static SkFontConfigInterface* gDirect; |
| 37 | if (NULL == gDirect) { |
| 38 | gDirect = new SkFontConfigInterfaceDirect; |
| 39 | } |
| 40 | return gDirect; |
reed@google.com | b1c65b6 | 2013-02-26 15:50:51 +0000 | [diff] [blame] | 41 | } |
| 42 | |
robertphillips@google.com | 21db1db | 2013-04-09 23:56:51 +0000 | [diff] [blame^] | 43 | #if 0 |
reed@google.com | 54c6914 | 2013-04-09 15:54:52 +0000 | [diff] [blame] | 44 | int SkFontConfigInterface::countFamilies() { return 0; } |
| 45 | |
| 46 | int SkFontConfigInterface::getFamilySet(int index, SkString* outFamilyName, |
| 47 | FontIdentity outIdentities[], |
| 48 | int maxCount) { |
| 49 | return 0; |
| 50 | } |
| 51 | |
| 52 | int SkFontConfigInterface::matchFamilySet(const char familyName[], |
| 53 | SkString* outFamilyName, |
| 54 | FontIdentity outIdentities[], |
| 55 | int maxCount) { |
| 56 | return 0; |
| 57 | } |
robertphillips@google.com | 21db1db | 2013-04-09 23:56:51 +0000 | [diff] [blame^] | 58 | #endif |
reed@google.com | 54c6914 | 2013-04-09 15:54:52 +0000 | [diff] [blame] | 59 | |
| 60 | /////////////////////////////////////////////////////////////////////////////// |
| 61 | |
reed@google.com | b1c65b6 | 2013-02-26 15:50:51 +0000 | [diff] [blame] | 62 | namespace { |
| 63 | |
| 64 | // Equivalence classes, used to match the Liberation and other fonts |
| 65 | // with their metric-compatible replacements. See the discussion in |
| 66 | // GetFontEquivClass(). |
| 67 | enum FontEquivClass |
| 68 | { |
| 69 | OTHER, |
| 70 | SANS, |
| 71 | SERIF, |
| 72 | MONO, |
| 73 | SYMBOL, |
| 74 | PGOTHIC, |
| 75 | GOTHIC, |
| 76 | PMINCHO, |
| 77 | MINCHO, |
| 78 | SIMSUN, |
| 79 | NSIMSUN, |
| 80 | SIMHEI, |
| 81 | PMINGLIU, |
| 82 | MINGLIU, |
| 83 | PMINGLIUHK, |
| 84 | MINGLIUHK, |
commit-bot@chromium.org | c4de776 | 2013-03-20 13:33:33 +0000 | [diff] [blame] | 85 | CAMBRIA, |
reed@google.com | b1c65b6 | 2013-02-26 15:50:51 +0000 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | // Match the font name against a whilelist of fonts, returning the equivalence |
| 89 | // class. |
| 90 | FontEquivClass GetFontEquivClass(const char* fontname) |
| 91 | { |
| 92 | // It would be nice for fontconfig to tell us whether a given suggested |
| 93 | // replacement is a "strong" match (that is, an equivalent font) or |
| 94 | // a "weak" match (that is, fontconfig's next-best attempt at finding a |
| 95 | // substitute). However, I played around with the fontconfig API for |
| 96 | // a good few hours and could not make it reveal this information. |
| 97 | // |
| 98 | // So instead, we hardcode. Initially this function emulated |
| 99 | // /etc/fonts/conf.d/30-metric-aliases.conf |
| 100 | // from my Ubuntu system, but we're better off being very conservative. |
| 101 | |
| 102 | // Arimo, Tinos and Cousine are a set of fonts metric-compatible with |
| 103 | // Arial, Times New Roman and Courier New with a character repertoire |
| 104 | // much larger than Liberation. Note that Cousine is metrically |
| 105 | // compatible with Courier New, but the former is sans-serif while |
| 106 | // the latter is serif. |
| 107 | |
| 108 | |
| 109 | struct FontEquivMap { |
| 110 | FontEquivClass clazz; |
| 111 | const char name[40]; |
| 112 | }; |
| 113 | |
| 114 | static const FontEquivMap kFontEquivMap[] = { |
| 115 | { SANS, "Arial" }, |
| 116 | { SANS, "Arimo" }, |
| 117 | { SANS, "Liberation Sans" }, |
| 118 | |
| 119 | { SERIF, "Times New Roman" }, |
| 120 | { SERIF, "Tinos" }, |
| 121 | { SERIF, "Liberation Serif" }, |
| 122 | |
| 123 | { MONO, "Courier New" }, |
| 124 | { MONO, "Cousine" }, |
| 125 | { MONO, "Liberation Mono" }, |
| 126 | |
| 127 | { SYMBOL, "Symbol" }, |
| 128 | { SYMBOL, "Symbol Neu" }, |
| 129 | |
| 130 | // MS Pゴシック |
| 131 | { PGOTHIC, "MS PGothic" }, |
| 132 | { PGOTHIC, "\xef\xbc\xad\xef\xbc\xb3 \xef\xbc\xb0" |
| 133 | "\xe3\x82\xb4\xe3\x82\xb7\xe3\x83\x83\xe3\x82\xaf" }, |
| 134 | { PGOTHIC, "IPAPGothic" }, |
| 135 | { PGOTHIC, "MotoyaG04Gothic" }, |
| 136 | |
| 137 | // MS ゴシック |
| 138 | { GOTHIC, "MS Gothic" }, |
| 139 | { GOTHIC, "\xef\xbc\xad\xef\xbc\xb3 " |
| 140 | "\xe3\x82\xb4\xe3\x82\xb7\xe3\x83\x83\xe3\x82\xaf" }, |
| 141 | { GOTHIC, "IPAGothic" }, |
| 142 | { GOTHIC, "MotoyaG04GothicMono" }, |
| 143 | |
| 144 | // MS P明朝 |
| 145 | { PMINCHO, "MS PMincho" }, |
| 146 | { PMINCHO, "\xef\xbc\xad\xef\xbc\xb3 \xef\xbc\xb0" |
| 147 | "\xe6\x98\x8e\xe6\x9c\x9d"}, |
| 148 | { PMINCHO, "IPAPMincho" }, |
| 149 | { PMINCHO, "MotoyaG04Mincho" }, |
| 150 | |
| 151 | // MS 明朝 |
| 152 | { MINCHO, "MS Mincho" }, |
| 153 | { MINCHO, "\xef\xbc\xad\xef\xbc\xb3 \xe6\x98\x8e\xe6\x9c\x9d" }, |
| 154 | { MINCHO, "IPAMincho" }, |
| 155 | { MINCHO, "MotoyaG04MinchoMono" }, |
| 156 | |
| 157 | // 宋体 |
| 158 | { SIMSUN, "Simsun" }, |
| 159 | { SIMSUN, "\xe5\xae\x8b\xe4\xbd\x93" }, |
| 160 | { SIMSUN, "MSung GB18030" }, |
| 161 | { SIMSUN, "Song ASC" }, |
| 162 | |
| 163 | // 新宋体 |
| 164 | { NSIMSUN, "NSimsun" }, |
| 165 | { NSIMSUN, "\xe6\x96\xb0\xe5\xae\x8b\xe4\xbd\x93" }, |
| 166 | { NSIMSUN, "MSung GB18030" }, |
| 167 | { NSIMSUN, "N Song ASC" }, |
| 168 | |
| 169 | // 黑体 |
| 170 | { SIMHEI, "Simhei" }, |
| 171 | { SIMHEI, "\xe9\xbb\x91\xe4\xbd\x93" }, |
| 172 | { SIMHEI, "MYingHeiGB18030" }, |
| 173 | { SIMHEI, "MYingHeiB5HK" }, |
| 174 | |
commit-bot@chromium.org | c4de776 | 2013-03-20 13:33:33 +0000 | [diff] [blame] | 175 | // 新細明體 |
| 176 | { PMINGLIU, "PMingLiU"}, |
| 177 | { PMINGLIU, "\xe6\x96\xb0\xe7\xb4\xb0\xe6\x98\x8e\xe9\xab\x94" }, |
| 178 | { PMINGLIU, "MSung B5HK"}, |
reed@google.com | b1c65b6 | 2013-02-26 15:50:51 +0000 | [diff] [blame] | 179 | |
commit-bot@chromium.org | c4de776 | 2013-03-20 13:33:33 +0000 | [diff] [blame] | 180 | // 細明體 |
| 181 | { MINGLIU, "MingLiU"}, |
| 182 | { MINGLIU, "\xe7\xb4\xb0\xe6\x98\x8e\xe9\xab\x94" }, |
| 183 | { MINGLIU, "MSung B5HK"}, |
reed@google.com | b1c65b6 | 2013-02-26 15:50:51 +0000 | [diff] [blame] | 184 | |
commit-bot@chromium.org | c4de776 | 2013-03-20 13:33:33 +0000 | [diff] [blame] | 185 | // 新細明體 |
| 186 | { PMINGLIUHK, "PMingLiU_HKSCS"}, |
| 187 | { PMINGLIUHK, "\xe6\x96\xb0\xe7\xb4\xb0\xe6\x98\x8e\xe9\xab\x94_HKSCS" }, |
| 188 | { PMINGLIUHK, "MSung B5HK"}, |
reed@google.com | b1c65b6 | 2013-02-26 15:50:51 +0000 | [diff] [blame] | 189 | |
commit-bot@chromium.org | c4de776 | 2013-03-20 13:33:33 +0000 | [diff] [blame] | 190 | // 細明體 |
| 191 | { MINGLIUHK, "MingLiU_HKSCS"}, |
| 192 | { MINGLIUHK, "\xe7\xb4\xb0\xe6\x98\x8e\xe9\xab\x94_HKSCS" }, |
| 193 | { MINGLIUHK, "MSung B5HK"}, |
| 194 | |
| 195 | // Cambria |
| 196 | { CAMBRIA, "Cambria" }, |
| 197 | { CAMBRIA, "Caladea" }, |
reed@google.com | b1c65b6 | 2013-02-26 15:50:51 +0000 | [diff] [blame] | 198 | }; |
| 199 | |
| 200 | static const size_t kFontCount = |
| 201 | sizeof(kFontEquivMap)/sizeof(kFontEquivMap[0]); |
| 202 | |
| 203 | // TODO(jungshik): If this loop turns out to be hot, turn |
| 204 | // the array to a static (hash)map to speed it up. |
| 205 | for (size_t i = 0; i < kFontCount; ++i) { |
| 206 | if (strcasecmp(kFontEquivMap[i].name, fontname) == 0) |
| 207 | return kFontEquivMap[i].clazz; |
| 208 | } |
| 209 | return OTHER; |
| 210 | } |
| 211 | |
| 212 | |
| 213 | // Return true if |font_a| and |font_b| are visually and at the metrics |
| 214 | // level interchangeable. |
| 215 | bool IsMetricCompatibleReplacement(const char* font_a, const char* font_b) |
| 216 | { |
| 217 | FontEquivClass class_a = GetFontEquivClass(font_a); |
| 218 | FontEquivClass class_b = GetFontEquivClass(font_b); |
| 219 | |
| 220 | return class_a != OTHER && class_a == class_b; |
| 221 | } |
| 222 | |
reed@google.com | b1c65b6 | 2013-02-26 15:50:51 +0000 | [diff] [blame] | 223 | // Normally we only return exactly the font asked for. In last-resort |
| 224 | // cases, the request either doesn't specify a font or is one of the |
| 225 | // basic font names like "Sans", "Serif" or "Monospace". This function |
| 226 | // tells you whether a given request is for such a fallback. |
| 227 | bool IsFallbackFontAllowed(const std::string& family) { |
| 228 | const char* family_cstr = family.c_str(); |
| 229 | return family.empty() || |
| 230 | strcasecmp(family_cstr, "sans") == 0 || |
| 231 | strcasecmp(family_cstr, "serif") == 0 || |
| 232 | strcasecmp(family_cstr, "monospace") == 0; |
| 233 | } |
| 234 | |
| 235 | // Find matching font from |font_set| for the given font family. |
| 236 | FcPattern* MatchFont(FcFontSet* font_set, |
| 237 | FcChar8* post_config_family, |
| 238 | const std::string& family) { |
| 239 | // Older versions of fontconfig have a bug where they cannot select |
| 240 | // only scalable fonts so we have to manually filter the results. |
| 241 | FcPattern* match = NULL; |
| 242 | for (int i = 0; i < font_set->nfont; ++i) { |
| 243 | FcPattern* current = font_set->fonts[i]; |
| 244 | FcBool is_scalable; |
| 245 | |
| 246 | if (FcPatternGetBool(current, FC_SCALABLE, 0, |
| 247 | &is_scalable) != FcResultMatch || |
| 248 | !is_scalable) { |
| 249 | continue; |
| 250 | } |
| 251 | |
| 252 | // fontconfig can also return fonts which are unreadable |
| 253 | FcChar8* c_filename; |
| 254 | if (FcPatternGetString(current, FC_FILE, 0, &c_filename) != FcResultMatch) |
| 255 | continue; |
| 256 | |
| 257 | if (access(reinterpret_cast<char*>(c_filename), R_OK) != 0) |
| 258 | continue; |
| 259 | |
| 260 | match = current; |
| 261 | break; |
| 262 | } |
| 263 | |
| 264 | if (match && !IsFallbackFontAllowed(family)) { |
| 265 | bool acceptable_substitute = false; |
| 266 | for (int id = 0; id < 255; ++id) { |
| 267 | FcChar8* post_match_family; |
| 268 | if (FcPatternGetString(match, FC_FAMILY, id, &post_match_family) != |
| 269 | FcResultMatch) |
| 270 | break; |
| 271 | acceptable_substitute = |
| 272 | (strcasecmp(reinterpret_cast<char*>(post_config_family), |
| 273 | reinterpret_cast<char*>(post_match_family)) == 0 || |
| 274 | // Workaround for Issue 12530: |
| 275 | // requested family: "Bitstream Vera Sans" |
| 276 | // post_config_family: "Arial" |
| 277 | // post_match_family: "Bitstream Vera Sans" |
| 278 | // -> We should treat this case as a good match. |
| 279 | strcasecmp(family.c_str(), |
| 280 | reinterpret_cast<char*>(post_match_family)) == 0) || |
| 281 | IsMetricCompatibleReplacement(family.c_str(), |
| 282 | reinterpret_cast<char*>(post_match_family)); |
| 283 | if (acceptable_substitute) |
| 284 | break; |
| 285 | } |
| 286 | if (!acceptable_substitute) |
| 287 | return NULL; |
| 288 | } |
| 289 | |
| 290 | return match; |
| 291 | } |
| 292 | |
| 293 | // Retrieves |is_bold|, |is_italic| and |font_family| properties from |font|. |
reed@google.com | f71a233 | 2013-02-27 19:06:30 +0000 | [diff] [blame] | 294 | SkTypeface::Style GetFontStyle(FcPattern* font) { |
reed@google.com | b1c65b6 | 2013-02-26 15:50:51 +0000 | [diff] [blame] | 295 | int resulting_bold; |
| 296 | if (FcPatternGetInteger(font, FC_WEIGHT, 0, &resulting_bold)) |
| 297 | resulting_bold = FC_WEIGHT_NORMAL; |
| 298 | |
| 299 | int resulting_italic; |
| 300 | if (FcPatternGetInteger(font, FC_SLANT, 0, &resulting_italic)) |
| 301 | resulting_italic = FC_SLANT_ROMAN; |
| 302 | |
| 303 | // If we ask for an italic font, fontconfig might take a roman font and set |
| 304 | // the undocumented property FC_MATRIX to a skew matrix. It'll then say |
| 305 | // that the font is italic or oblique. So, if we see a matrix, we don't |
| 306 | // believe that it's italic. |
| 307 | FcValue matrix; |
| 308 | const bool have_matrix = FcPatternGet(font, FC_MATRIX, 0, &matrix) == 0; |
| 309 | |
| 310 | // If we ask for an italic font, fontconfig might take a roman font and set |
| 311 | // FC_EMBOLDEN. |
| 312 | FcValue embolden; |
| 313 | const bool have_embolden = FcPatternGet(font, FC_EMBOLDEN, 0, &embolden) == 0; |
| 314 | |
| 315 | int styleBits = 0; |
| 316 | if (resulting_bold > FC_WEIGHT_MEDIUM && !have_embolden) { |
| 317 | styleBits |= SkTypeface::kBold; |
| 318 | } |
| 319 | if (resulting_italic > FC_SLANT_ROMAN && !have_matrix) { |
| 320 | styleBits |= SkTypeface::kItalic; |
| 321 | } |
| 322 | |
reed@google.com | f71a233 | 2013-02-27 19:06:30 +0000 | [diff] [blame] | 323 | return (SkTypeface::Style)styleBits; |
reed@google.com | b1c65b6 | 2013-02-26 15:50:51 +0000 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | } // anonymous namespace |
| 327 | |
| 328 | /////////////////////////////////////////////////////////////////////////////// |
| 329 | |
reed@google.com | f71a233 | 2013-02-27 19:06:30 +0000 | [diff] [blame] | 330 | #define kMaxFontFamilyLength 2048 |
reed@google.com | b1c65b6 | 2013-02-26 15:50:51 +0000 | [diff] [blame] | 331 | |
reed@google.com | f71a233 | 2013-02-27 19:06:30 +0000 | [diff] [blame] | 332 | SkFontConfigInterfaceDirect::SkFontConfigInterfaceDirect() { |
reed@google.com | b1c65b6 | 2013-02-26 15:50:51 +0000 | [diff] [blame] | 333 | FcInit(); |
| 334 | } |
| 335 | |
| 336 | SkFontConfigInterfaceDirect::~SkFontConfigInterfaceDirect() { |
| 337 | } |
| 338 | |
reed@google.com | f71a233 | 2013-02-27 19:06:30 +0000 | [diff] [blame] | 339 | bool SkFontConfigInterfaceDirect::matchFamilyName(const char familyName[], |
| 340 | SkTypeface::Style style, |
| 341 | FontIdentity* outIdentity, |
| 342 | SkString* outFamilyName, |
| 343 | SkTypeface::Style* outStyle) { |
reed@google.com | ee619a0 | 2013-02-26 22:58:09 +0000 | [diff] [blame] | 344 | std::string familyStr(familyName ? familyName : ""); |
| 345 | if (familyStr.length() > kMaxFontFamilyLength) { |
reed@google.com | b1c65b6 | 2013-02-26 15:50:51 +0000 | [diff] [blame] | 346 | return false; |
| 347 | } |
| 348 | |
| 349 | SkAutoMutexAcquire ac(mutex_); |
| 350 | |
reed@google.com | b1c65b6 | 2013-02-26 15:50:51 +0000 | [diff] [blame] | 351 | FcPattern* pattern = FcPatternCreate(); |
| 352 | |
reed@google.com | ee619a0 | 2013-02-26 22:58:09 +0000 | [diff] [blame] | 353 | if (familyName) { |
| 354 | FcPatternAddString(pattern, FC_FAMILY, (FcChar8*)familyName); |
| 355 | } |
reed@google.com | b1c65b6 | 2013-02-26 15:50:51 +0000 | [diff] [blame] | 356 | FcPatternAddInteger(pattern, FC_WEIGHT, |
| 357 | (style & SkTypeface::kBold) ? FC_WEIGHT_BOLD |
| 358 | : FC_WEIGHT_NORMAL); |
| 359 | FcPatternAddInteger(pattern, FC_SLANT, |
| 360 | (style & SkTypeface::kItalic) ? FC_SLANT_ITALIC |
| 361 | : FC_SLANT_ROMAN); |
| 362 | FcPatternAddBool(pattern, FC_SCALABLE, FcTrue); |
| 363 | |
| 364 | FcConfigSubstitute(NULL, pattern, FcMatchPattern); |
| 365 | FcDefaultSubstitute(pattern); |
| 366 | |
| 367 | // Font matching: |
| 368 | // CSS often specifies a fallback list of families: |
| 369 | // font-family: a, b, c, serif; |
| 370 | // However, fontconfig will always do its best to find *a* font when asked |
| 371 | // for something so we need a way to tell if the match which it has found is |
| 372 | // "good enough" for us. Otherwise, we can return NULL which gets piped up |
| 373 | // and lets WebKit know to try the next CSS family name. However, fontconfig |
| 374 | // configs allow substitutions (mapping "Arial -> Helvetica" etc) and we |
| 375 | // wish to support that. |
| 376 | // |
| 377 | // Thus, if a specific family is requested we set @family_requested. Then we |
| 378 | // record two strings: the family name after config processing and the |
| 379 | // family name after resolving. If the two are equal, it's a good match. |
| 380 | // |
| 381 | // So consider the case where a user has mapped Arial to Helvetica in their |
| 382 | // config. |
| 383 | // requested family: "Arial" |
| 384 | // post_config_family: "Helvetica" |
| 385 | // post_match_family: "Helvetica" |
| 386 | // -> good match |
| 387 | // |
| 388 | // and for a missing font: |
| 389 | // requested family: "Monaco" |
| 390 | // post_config_family: "Monaco" |
| 391 | // post_match_family: "Times New Roman" |
| 392 | // -> BAD match |
| 393 | // |
| 394 | // However, we special-case fallback fonts; see IsFallbackFontAllowed(). |
| 395 | FcChar8* post_config_family; |
| 396 | FcPatternGetString(pattern, FC_FAMILY, 0, &post_config_family); |
| 397 | |
| 398 | FcResult result; |
| 399 | FcFontSet* font_set = FcFontSort(0, pattern, 0, 0, &result); |
| 400 | if (!font_set) { |
| 401 | FcPatternDestroy(pattern); |
| 402 | return false; |
| 403 | } |
| 404 | |
reed@google.com | ee619a0 | 2013-02-26 22:58:09 +0000 | [diff] [blame] | 405 | FcPattern* match = MatchFont(font_set, post_config_family, familyStr); |
reed@google.com | b1c65b6 | 2013-02-26 15:50:51 +0000 | [diff] [blame] | 406 | if (!match) { |
| 407 | FcPatternDestroy(pattern); |
| 408 | FcFontSetDestroy(font_set); |
| 409 | return false; |
| 410 | } |
| 411 | |
| 412 | FcPatternDestroy(pattern); |
| 413 | |
reed@google.com | f71a233 | 2013-02-27 19:06:30 +0000 | [diff] [blame] | 414 | // From here out we just extract our results from 'match' |
| 415 | |
| 416 | if (FcPatternGetString(match, FC_FAMILY, 0, &post_config_family) != FcResultMatch) { |
| 417 | FcFontSetDestroy(font_set); |
| 418 | return false; |
| 419 | } |
| 420 | |
reed@google.com | b1c65b6 | 2013-02-26 15:50:51 +0000 | [diff] [blame] | 421 | FcChar8* c_filename; |
| 422 | if (FcPatternGetString(match, FC_FILE, 0, &c_filename) != FcResultMatch) { |
| 423 | FcFontSetDestroy(font_set); |
| 424 | return false; |
| 425 | } |
reed@google.com | f71a233 | 2013-02-27 19:06:30 +0000 | [diff] [blame] | 426 | |
reed@google.com | b1c65b6 | 2013-02-26 15:50:51 +0000 | [diff] [blame] | 427 | int face_index; |
| 428 | if (FcPatternGetInteger(match, FC_INDEX, 0, &face_index) != FcResultMatch) { |
| 429 | FcFontSetDestroy(font_set); |
| 430 | return false; |
| 431 | } |
| 432 | |
reed@google.com | b1c65b6 | 2013-02-26 15:50:51 +0000 | [diff] [blame] | 433 | FcFontSetDestroy(font_set); |
| 434 | |
reed@google.com | f71a233 | 2013-02-27 19:06:30 +0000 | [diff] [blame] | 435 | if (outIdentity) { |
reed@google.com | 8c9737e | 2013-03-06 13:06:03 +0000 | [diff] [blame] | 436 | outIdentity->fTTCIndex = face_index; |
reed@google.com | f71a233 | 2013-02-27 19:06:30 +0000 | [diff] [blame] | 437 | outIdentity->fString.set((const char*)c_filename); |
reed@google.com | b1c65b6 | 2013-02-26 15:50:51 +0000 | [diff] [blame] | 438 | } |
reed@google.com | f71a233 | 2013-02-27 19:06:30 +0000 | [diff] [blame] | 439 | if (outFamilyName) { |
| 440 | outFamilyName->set((const char*)post_config_family); |
reed@google.com | b1c65b6 | 2013-02-26 15:50:51 +0000 | [diff] [blame] | 441 | } |
reed@google.com | f71a233 | 2013-02-27 19:06:30 +0000 | [diff] [blame] | 442 | if (outStyle) { |
| 443 | *outStyle = GetFontStyle(match); |
reed@google.com | b1c65b6 | 2013-02-26 15:50:51 +0000 | [diff] [blame] | 444 | } |
reed@google.com | ee619a0 | 2013-02-26 22:58:09 +0000 | [diff] [blame] | 445 | return true; |
reed@google.com | b1c65b6 | 2013-02-26 15:50:51 +0000 | [diff] [blame] | 446 | } |
| 447 | |
reed@google.com | f71a233 | 2013-02-27 19:06:30 +0000 | [diff] [blame] | 448 | SkStream* SkFontConfigInterfaceDirect::openStream(const FontIdentity& identity) { |
reed@google.com | 8c3f84d | 2013-03-19 13:34:55 +0000 | [diff] [blame] | 449 | return SkStream::NewFromFile(identity.fString.c_str()); |
reed@google.com | b1c65b6 | 2013-02-26 15:50:51 +0000 | [diff] [blame] | 450 | } |