Index: ui/gfx/font_render_params_linux.cc |
diff --git a/ui/gfx/font_render_params_linux.cc b/ui/gfx/font_render_params_linux.cc |
index 4a06c59f13a957098855de933fc620776c6e4f7c..0d9d66c56ece215adec1d28315af599d3ffa83d5 100644 |
--- a/ui/gfx/font_render_params_linux.cc |
+++ b/ui/gfx/font_render_params_linux.cc |
@@ -18,67 +18,111 @@ namespace gfx { |
namespace { |
-bool SubpixelPositioningRequested(bool renderer) { |
+bool SubpixelPositioningRequested(bool for_web_contents) { |
return CommandLine::ForCurrentProcess()->HasSwitch( |
- renderer ? switches::kEnableWebkitTextSubpixelPositioning |
- : switches::kEnableBrowserTextSubpixelPositioning); |
+ for_web_contents ? switches::kEnableWebkitTextSubpixelPositioning |
+ : switches::kEnableBrowserTextSubpixelPositioning); |
} |
-// Initializes |params| with the system's default settings. |renderer| is true |
-// when setting WebKit renderer defaults. |
-void LoadDefaults(FontRenderParams* params, bool renderer) { |
- // For non-GTK builds (read: Aura), just use reasonable hardcoded values. |
- params->antialiasing = true; |
- params->autohinter = true; |
- params->use_bitmaps = true; |
- params->hinting = FontRenderParams::HINTING_SLIGHT; |
+// Converts a Fontconfig FC_HINT_STYLE value to a FontRenderParams::Hinting |
msw
2014/07/12 02:26:41
optional nit: omit "a" and "value" x2 for a one-li
Daniel Erat
2014/07/12 02:44:38
Done.
|
+// value. |
+FontRenderParams::Hinting FontconfigHintStyleToFontRenderParamsHinting( |
msw
2014/07/12 02:26:41
optional nit: consider a shorter name?
Daniel Erat
2014/07/12 02:44:38
i just changed these to "ConvertFontconfig____"; t
msw
2014/07/12 17:57:11
Nice.
|
+ int hint_style) { |
+ switch (hint_style) { |
msw
2014/07/12 02:26:41
This needs a return statement after the switch.
Daniel Erat
2014/07/12 02:44:38
do we use compilers that don't understand the defa
msw
2014/07/12 17:57:11
I don't make the clang rules, I just fix the clang
Daniel Erat
2014/07/14 14:59:15
cool (seems to build locally with clang)
|
+ case FC_HINT_SLIGHT: return FontRenderParams::HINTING_SLIGHT; |
+ case FC_HINT_MEDIUM: return FontRenderParams::HINTING_MEDIUM; |
+ case FC_HINT_FULL: return FontRenderParams::HINTING_FULL; |
+ default: return FontRenderParams::HINTING_NONE; |
+ } |
+} |
+ |
+// Converts a Fontconfig FC_RGBA value to a FontRenderParams::SubpixelRendering |
msw
2014/07/12 02:26:41
optional nit: omit "a" and "value" x2 for a one-li
Daniel Erat
2014/07/12 02:44:38
Done.
|
+// value. |
+FontRenderParams::SubpixelRendering |
+FontconfigRgbaToFontRenderParamsSubpixelRendering(int rgba) { |
msw
2014/07/12 02:26:41
optional nit: consider a shorter name?
Daniel Erat
2014/07/12 02:44:38
Done.
|
+ switch (rgba) { |
msw
2014/07/12 02:26:41
This needs a return statement after the switch.
Daniel Erat
2014/07/12 02:44:38
same here
|
+ case FC_RGBA_RGB: return FontRenderParams::SUBPIXEL_RENDERING_RGB; |
+ case FC_RGBA_BGR: return FontRenderParams::SUBPIXEL_RENDERING_BGR; |
+ case FC_RGBA_VRGB: return FontRenderParams::SUBPIXEL_RENDERING_VRGB; |
+ case FC_RGBA_VBGR: return FontRenderParams::SUBPIXEL_RENDERING_VBGR; |
+ default: return FontRenderParams::SUBPIXEL_RENDERING_NONE; |
+ } |
+} |
- // Fetch default subpixel rendering settings from FontConfig. |
+// Queries Fontconfig for rendering settings and updates |params_out| and |
+// |family_out| (if non-NULL). Returns false on failure. See |
+// GetCustomFontRenderParams() for descriptions of arguments. |
+bool QueryFontconfig(const std::vector<std::string>* family_list, |
+ const int* pixel_size, |
+ const int* point_size |
msw
2014/07/12 02:26:41
nit: missing comma
Daniel Erat
2014/07/12 02:44:38
ugh, broke this in post-compile reindenting
|
+ FontRenderParams* params_out, |
+ std::string* family_out) { |
FcPattern* pattern = FcPatternCreate(); |
+ CHECK(pattern); |
+ |
+ if (family_list) { |
+ for (std::vector<std::string>::const_iterator it = family_list->begin(); |
+ it != family_list->end(); ++it) { |
+ FcPatternAddString( |
+ pattern, FC_FAMILY, reinterpret_cast<const FcChar8*>(it->c_str())); |
+ } |
+ } |
+ if (pixel_size) |
+ FcPatternAddDouble(pattern, FC_PIXEL_SIZE, *pixel_size); |
+ if (point_size) |
+ FcPatternAddInteger(pattern, FC_SIZE, *point_size); |
+ |
FcConfigSubstitute(NULL, pattern, FcMatchPattern); |
FcDefaultSubstitute(pattern); |
FcResult result; |
- FcPattern* match = FcFontMatch(0, pattern, &result); |
- DCHECK(match); |
- int fc_rgba = FC_RGBA_RGB; |
- FcPatternGetInteger(match, FC_RGBA, 0, &fc_rgba); |
- FcPatternDestroy(pattern); |
- FcPatternDestroy(match); |
- |
- switch (fc_rgba) { |
- case FC_RGBA_RGB: |
- params->subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_RGB; |
- break; |
- case FC_RGBA_BGR: |
- params->subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_BGR; |
- break; |
- case FC_RGBA_VRGB: |
- params->subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_VRGB; |
- break; |
- case FC_RGBA_VBGR: |
- params->subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_VBGR; |
- break; |
- default: |
- params->subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_NONE; |
+ FcPattern* match = FcFontMatch(NULL, pattern, &result); |
+ if (!match) |
+ return false; |
+ |
+ if (family_out) { |
+ FcChar8* family = NULL; |
+ if (FcPatternGetString(match, FC_FAMILY, 0, &family) == FcResultMatch) |
+ family_out->assign(reinterpret_cast<const char*>(family)); |
} |
-#if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
- // TODO(derat): Get the autohinter setting from FontConfig. Until then, |
- // maintain backward compatibility with what we were doing previously. |
- params->autohinter = renderer; |
- const LinuxFontDelegate* delegate = LinuxFontDelegate::instance(); |
- if (delegate) { |
- params->antialiasing = delegate->UseAntialiasing(); |
- params->hinting = delegate->GetHintingStyle(); |
- params->subpixel_rendering = delegate->GetSubpixelRenderingStyle(); |
+ if (params_out) { |
+ FcBool fc_antialias = 0; |
+ if (FcPatternGetBool(match, FC_ANTIALIAS, 0, &fc_antialias) == |
+ FcResultMatch) |
+ params_out->antialiasing = fc_antialias; |
+ |
+ FcBool fc_autohint = 0; |
+ if (FcPatternGetBool(match, FC_AUTOHINT, 0, &fc_autohint) == FcResultMatch) |
+ params_out->autohinter = fc_autohint; |
+ |
+ FcBool fc_hinting = 0; |
+ int fc_hint_style = FC_HINT_NONE; |
+ if (FcPatternGetBool(match, FC_HINTING, 0, &fc_hinting) == FcResultMatch && |
+ fc_hinting && |
+ FcPatternGetInteger(match, FC_HINT_STYLE, 0, &fc_hint_style) == |
+ FcResultMatch) { |
+ params_out->hinting = FontconfigHintStyleToFontRenderParamsHinting( |
+ fc_hint_style); |
+ } else { |
+ params_out->hinting = FontRenderParams::HINTING_NONE; |
+ } |
+ |
+ int fc_rgba = FC_RGBA_UNKNOWN; |
+ if (FcPatternGetInteger(match, FC_RGBA, 0, &fc_rgba) == FcResultMatch) { |
+ params_out->subpixel_rendering = |
+ FontconfigRgbaToFontRenderParamsSubpixelRendering(fc_rgba); |
+ } else { |
+ params_out->subpixel_rendering = |
+ FontRenderParams::SUBPIXEL_RENDERING_NONE; |
+ } |
} |
-#endif |
- params->subpixel_positioning = SubpixelPositioningRequested(renderer); |
+ return true; |
+} |
- // To enable subpixel positioning, we need to disable hinting. |
- if (params->subpixel_positioning) |
- params->hinting = FontRenderParams::HINTING_NONE; |
+// Initializes |params| with the system's default settings. |
+void LoadDefaults(FontRenderParams* params, bool for_web_contents) { |
+ *params = GetCustomFontRenderParams(for_web_contents, NULL, NULL, NULL, NULL); |
} |
} // namespace |
@@ -87,7 +131,7 @@ const FontRenderParams& GetDefaultFontRenderParams() { |
static bool loaded_defaults = false; |
static FontRenderParams default_params; |
if (!loaded_defaults) |
- LoadDefaults(&default_params, /* renderer */ false); |
+ LoadDefaults(&default_params, /* for_web_contents */ false); |
loaded_defaults = true; |
return default_params; |
} |
@@ -96,13 +140,57 @@ const FontRenderParams& GetDefaultWebKitFontRenderParams() { |
static bool loaded_defaults = false; |
static FontRenderParams default_params; |
if (!loaded_defaults) |
- LoadDefaults(&default_params, /* renderer */ true); |
+ LoadDefaults(&default_params, /* for_web_contents */ true); |
loaded_defaults = true; |
return default_params; |
} |
-bool GetDefaultWebkitSubpixelPositioning() { |
- return SubpixelPositioningRequested(true); |
+FontRenderParams GetCustomFontRenderParams( |
+ bool for_web_contents, |
+ const std::vector<std::string>* family_list, |
+ const int* pixel_size, |
+ const int* point_size, |
+ std::string* family_out) { |
+ FontRenderParams params; |
+ if (family_out) |
+ family_out->clear(); |
+ |
+#if defined(OS_CHROMEOS) |
+ // Use reasonable defaults. |
+ params.antialiasing = true; |
+ params.autohinter = true; |
+ params.use_bitmaps = true; |
+ params.hinting = FontRenderParams::HINTING_SLIGHT; |
+ |
+ // Query Fontconfig to get the family name and subpixel rendering setting. |
+ FontRenderParams fc_params; |
+ QueryFontconfig(family_list, pixel_size, point_size, &fc_params, family_out); |
+ params.subpixel_rendering = fc_params.subpixel_rendering; |
+#else |
+ // Start with the delegate's settings, but let Fontconfig have the final say. |
+ // TODO(derat): Figure out if we need to query the delegate at all. Does |
+ // GtkSettings always get overridden by Fontconfig in GTK apps? |
+ const LinuxFontDelegate* delegate = LinuxFontDelegate::instance(); |
+ if (delegate) { |
+ params.antialiasing = delegate->UseAntialiasing(); |
+ params.hinting = delegate->GetHintingStyle(); |
+ params.subpixel_rendering = delegate->GetSubpixelRenderingStyle(); |
+ } |
+ QueryFontconfig(family_list, pixel_size, point_size, ¶ms, family_out); |
+#endif |
+ |
+ params.subpixel_positioning = SubpixelPositioningRequested(for_web_contents); |
+ |
+ // To enable subpixel positioning, we need to disable hinting. |
+ if (params.subpixel_positioning) |
+ params.hinting = FontRenderParams::HINTING_NONE; |
+ |
+ // Use the first family from the list if Fontconfig didn't suggest a family. |
+ if (family_out && family_out->empty() && |
+ family_list && !family_list->empty()) |
+ *family_out = (*family_list)[0]; |
+ |
+ return params; |
} |
} // namespace gfx |