OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/gfx/font_fallback.h" |
| 6 |
| 7 #include <fontconfig/fontconfig.h> |
| 8 |
| 9 namespace gfx { |
| 10 |
| 11 std::vector<std::string> GetFallbackFontFamilies(std::string font_family) { |
| 12 std::vector<std::string> fallback_fonts; |
| 13 |
| 14 FcPattern* pattern = FcPatternCreate(); |
| 15 FcValue family; |
| 16 family.type = FcTypeString; |
| 17 family.u.s = reinterpret_cast<const FcChar8*>(font_family.c_str()); |
| 18 FcPatternAdd(pattern, FC_FAMILY, family, FcFalse); |
| 19 if (FcConfigSubstitute(NULL, pattern, FcMatchPattern) == FcTrue) { |
| 20 FcDefaultSubstitute(pattern); |
| 21 FcResult result; |
| 22 FcFontSet* fonts = FcFontSort(NULL, pattern, FcTrue, NULL, &result); |
| 23 if (fonts) { |
| 24 for (int i = 0; i < fonts->nfont; ++i) { |
| 25 char* name = NULL; |
| 26 FcPatternGetString(fonts->fonts[i], FC_FAMILY, 0, |
| 27 reinterpret_cast<FcChar8**>(&name)); |
| 28 if (fallback_fonts.empty() || fallback_fonts.back() != name) |
| 29 fallback_fonts.push_back(std::string(name)); |
| 30 } |
| 31 FcFontSetDestroy(fonts); |
| 32 } |
| 33 } |
| 34 FcPatternDestroy(pattern); |
| 35 |
| 36 if (fallback_fonts.empty()) |
| 37 fallback_fonts.push_back(font_family); |
| 38 |
| 39 return fallback_fonts; |
| 40 } |
| 41 |
| 42 } // namespace gfx |
OLD | NEW |