Index: ui/gfx/font_fallback_linux.cc |
diff --git a/ui/gfx/font_fallback_linux.cc b/ui/gfx/font_fallback_linux.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8dbae0ba8eafba8db5281dee75a8a097c082399f |
--- /dev/null |
+++ b/ui/gfx/font_fallback_linux.cc |
@@ -0,0 +1,44 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "ui/gfx/font_fallback.h" |
+ |
+#include <fontconfig/fontconfig.h> |
+ |
+namespace gfx { |
+ |
+std::vector<std::string> GetFallbackFontFamilies(std::string font_family) { |
+ std::vector<std::string> fallback_fonts; |
+ FcPattern* pattern = FcPatternCreate(); |
+ FcValue family; |
+ family.type = FcTypeString; |
+ 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.
|
+ FcPatternAdd(pattern, FC_FAMILY, family, FcFalse); |
+ |
+ 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.
|
+ FcDefaultSubstitute(pattern); |
+ FcResult result; |
+ FcFontSet* fonts = FcFontSort(NULL, pattern, FcTrue, NULL, &result); |
+ |
+ if (fonts) { |
+ for (int i = 0; i < fonts->nfont; ++i) { |
+ char* name = NULL; |
+ FcPatternGetString(fonts->fonts[i], FC_FAMILY, 0, |
+ reinterpret_cast<unsigned char**>(&name)); |
+ 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.
|
+ fallback_fonts.push_back(std::string(name)); |
+ } |
+ |
+ FcFontSetDestroy(fonts); |
+ } |
+ |
+ FcPatternDestroy(pattern); |
+ |
+ if (fallback_fonts.empty()) |
+ fallback_fonts.push_back(font_family); |
+ |
+ return fallback_fonts; |
+} |
+ |
+} // namespace gfx |