Chromium Code Reviews| 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 FcPattern* pattern = FcPatternCreate(); | |
| 14 FcValue family; | |
| 15 family.type = FcTypeString; | |
| 16 family.u.s = reinterpret_cast<const unsigned char*>(font_family.c_str()); | |
|
msw
2014/06/30 17:35:53
Maybe use FcChar8* to match the FC types like plat
ckocagil
2014/07/04 15:30:15
Done.
| |
| 17 FcPatternAdd(pattern, FC_FAMILY, family, FcFalse); | |
| 18 | |
| 19 FcConfigSubstitute(NULL, pattern, FcMatchPattern); | |
|
msw
2014/06/30 17:35:53
Check the return value here? (I guess font_render_
ckocagil
2014/07/04 15:30:15
Let's do it here anyway, done.
| |
| 20 FcDefaultSubstitute(pattern); | |
| 21 FcResult result; | |
| 22 FcFontSet* fonts = FcFontSort(NULL, pattern, FcTrue, NULL, &result); | |
| 23 | |
| 24 if (fonts) { | |
| 25 for (int i = 0; i < fonts->nfont; ++i) { | |
| 26 char* name = NULL; | |
| 27 FcPatternGetString(fonts->fonts[i], FC_FAMILY, 0, | |
| 28 reinterpret_cast<unsigned char**>(&name)); | |
| 29 if (fallback_fonts.empty() || fallback_fonts.back() != name) | |
|
msw
2014/06/30 17:35:53
Do we expect there to be adjacent duplicate entrie
ckocagil
2014/07/04 15:30:15
Yes. Currently we only take the family name into a
msw
2014/07/07 22:52:45
That seems worth explaining in a short comment her
ckocagil
2014/07/12 11:47:54
Done.
| |
| 30 fallback_fonts.push_back(std::string(name)); | |
| 31 } | |
| 32 | |
| 33 FcFontSetDestroy(fonts); | |
| 34 } | |
| 35 | |
| 36 FcPatternDestroy(pattern); | |
| 37 | |
| 38 if (fallback_fonts.empty()) | |
| 39 fallback_fonts.push_back(font_family); | |
| 40 | |
| 41 return fallback_fonts; | |
| 42 } | |
| 43 | |
| 44 } // namespace gfx | |
| OLD | NEW |