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

Unified Diff: ui/gfx/font_fallback_linux.cc

Issue 331713003: RenderTextHarfBuzz: Implement font fallback for Win and Linux (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: move uniscribe emf func to font_fallback_win, and use it in harfbuzz Created 6 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 side-by-side diff with in-line comments
Download patch
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..e6b9c7db00b755ca5fe61e228225722d968e994a
--- /dev/null
+++ b/ui/gfx/font_fallback_linux.cc
@@ -0,0 +1,58 @@
+// 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 {
+
+namespace {
+
+typedef std::map<std::string, std::vector<std::string> > FallbackCache;
+base::LazyInstance<FallbackCache>::Leaky g_fallback_cache =
+ LAZY_INSTANCE_INITIALIZER;
+
+} // namespace
+
+std::vector<std::string> GetFallbackFontFamilies(std::string font_family) {
+ std::vector<std::string>* cache_value = &g_fallback_cache.Get()[font_family];
+ if (!cache_value->empty())
+ return *cache_value;
+
+ std::vector<std::string> fallback_fonts;
+
+ FcPattern* pattern = FcPatternCreate();
+ FcValue family;
+ family.type = FcTypeString;
+ family.u.s = reinterpret_cast<const FcChar8*>(font_family.c_str());
+ FcPatternAdd(pattern, FC_FAMILY, family, FcFalse);
+ if (FcConfigSubstitute(NULL, pattern, FcMatchPattern) == FcTrue) {
+ 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<FcChar8**>(&name));
+ // FontConfig returns multiple fonts with the same family name and
+ // different configurations. Check to prevent duplicate family names.
+ if (fallback_fonts.empty() || fallback_fonts.back() != name)
+ fallback_fonts.push_back(std::string(name));
+ }
+ FcFontSetDestroy(fonts);
+ }
+ }
+ FcPatternDestroy(pattern);
+
+ if (fallback_fonts.empty())
+ fallback_fonts.push_back(font_family);
+
+ *cache_value = fallback_fonts;
+
+ return fallback_fonts;
+}
+
+} // namespace gfx
« no previous file with comments | « ui/gfx/font_fallback.h ('k') | ui/gfx/font_fallback_mac.cc » ('j') | ui/gfx/font_fallback_win.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698