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..a39bf01159bb907b06cd32670c7b63d7070dc5dc 100644 |
--- a/ui/gfx/font_render_params_linux.cc |
+++ b/ui/gfx/font_render_params_linux.cc |
@@ -24,61 +24,120 @@ bool SubpixelPositioningRequested(bool renderer) { |
: 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; |
- |
- // 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( |
Daniel Erat
2014/07/11 17:15:29
this essentially just combines the code from LoadD
msw
2014/07/12 00:27:32
Acknowledged.
|
+ const std::vector<std::string>* family_list, |
+ const int* pixel_size, |
+ const int* point_size, |
+ 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) { |
+ FcValue value; |
+ value.type = FcTypeString; |
+ value.u.s = reinterpret_cast<const FcChar8*>(it->c_str()); |
+ FcPatternAdd(pattern, FC_FAMILY, value, FcTrue /* append */); |
msw
2014/07/12 00:27:33
nit: FcPatternAddString might be simpler.
Daniel Erat
2014/07/12 01:55:32
nice! i'd missed these
|
+ } |
+ } |
+ if (pixel_size) { |
+ FcValue value; |
+ value.type = FcTypeDouble; |
+ value.u.d = *pixel_size; |
+ FcPatternAdd(pattern, FC_PIXEL_SIZE, value, FcTrue /* append */); |
msw
2014/07/12 00:27:33
nit: FcPatternAddDouble might be simpler
Daniel Erat
2014/07/12 01:55:33
Done.
|
+ } |
+ if (point_size) { |
+ FcValue value; |
+ value.type = FcTypeInteger; |
+ value.u.i = *point_size; |
+ FcPatternAdd(pattern, FC_SIZE, value, FcTrue /* append */); |
msw
2014/07/12 00:27:32
nit: FcPatternAddInteger might be simpler.
Daniel Erat
2014/07/12 01:55:33
Done.
|
+ } |
+ |
FcConfigSubstitute(NULL, pattern, FcMatchPattern); |
FcDefaultSubstitute(pattern); |
FcResult result; |
FcPattern* match = FcFontMatch(0, pattern, &result); |
msw
2014/07/12 00:27:32
nit: s/0/NULL/
Daniel Erat
2014/07/12 01:55:32
Done.
|
- 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; |
+ if (!match) |
msw
2014/07/12 00:27:33
Should we DCHECK this or is it okay to not actuall
Daniel Erat
2014/07/12 01:55:32
the documentation is silent, of course, but the im
msw
2014/07/12 02:26:40
Acknowledged.
|
+ 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 && |
+ FcPatternGetInteger(match, FC_HINT_STYLE, 0, &fc_hint_style) == |
msw
2014/07/12 00:27:32
Does it make sense to offer a default hinting sett
Daniel Erat
2014/07/12 01:55:33
(to make it possible for users to choose self-cont
msw
2014/07/12 02:26:40
Acknowledged.
|
+ FcResultMatch) { |
+ params_out->hinting = FontRenderParams::HINTING_NONE; |
+ if (fc_hinting) { |
+ switch (fc_hint_style) { |
msw
2014/07/12 00:27:33
optional nit: add a conversion helper.
Daniel Erat
2014/07/12 01:55:33
Done.
|
+ case FC_HINT_SLIGHT: |
+ params_out->hinting = FontRenderParams::HINTING_SLIGHT; |
+ break; |
+ case FC_HINT_MEDIUM: |
+ params_out->hinting = FontRenderParams::HINTING_MEDIUM; |
+ break; |
+ case FC_HINT_FULL: |
+ params_out->hinting = FontRenderParams::HINTING_FULL; |
+ break; |
+ default: |
+ // Leave hinting disabled otherwise. |
+ break; |
+ } |
+ } |
+ } |
+ |
+ int fc_rgba = FC_RGBA_UNKNOWN; |
+ if (FcPatternGetInteger(match, FC_RGBA, 0, &fc_rgba) == FcResultMatch) { |
+ switch (fc_rgba) { |
msw
2014/07/12 00:27:32
optional nit: add a conversion helper.
Daniel Erat
2014/07/12 01:55:32
Done.
|
+ case FC_RGBA_RGB: |
+ params_out->subpixel_rendering = |
+ FontRenderParams::SUBPIXEL_RENDERING_RGB; |
+ break; |
+ case FC_RGBA_BGR: |
+ params_out->subpixel_rendering = |
+ FontRenderParams::SUBPIXEL_RENDERING_BGR; |
+ break; |
+ case FC_RGBA_VRGB: |
+ params_out->subpixel_rendering = |
+ FontRenderParams::SUBPIXEL_RENDERING_VRGB; |
+ break; |
+ case FC_RGBA_VBGR: |
+ params_out->subpixel_rendering = |
+ FontRenderParams::SUBPIXEL_RENDERING_VBGR; |
+ break; |
+ default: |
+ 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. |renderer| is true |
+// when setting WebKit renderer defaults. |
+void LoadDefaults(FontRenderParams* params, bool renderer) { |
+ *params = GetCustomFontRenderParams(renderer, NULL, NULL, NULL, NULL); |
} |
} // namespace |
@@ -101,6 +160,52 @@ const FontRenderParams& GetDefaultWebKitFontRenderParams() { |
return default_params; |
} |
+FontRenderParams GetCustomFontRenderParams( |
+ bool renderer, |
+ 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; |
msw
2014/07/12 00:27:32
These reasonable defaults previously applied to De
Daniel Erat
2014/07/12 01:55:32
no, i don't think so. i just meant "reasonable for
msw
2014/07/12 02:26:40
Ah, ok. Should we remove these explicit assignment
Daniel Erat
2014/07/12 02:44:38
i'd rather continue to be explicit for chrome os,
|
+ params.autohinter = true; |
+ params.use_bitmaps = true; |
+ params.hinting = FontRenderParams::HINTING_SLIGHT; |
+ |
+ // Query Fontconfig to get the family name and subpixel rendering setting. |
msw
2014/07/12 00:27:33
Why don't we respect the other FontConfig settings
Daniel Erat
2014/07/12 01:55:32
i'd actually like for us to get away from using fo
msw
2014/07/12 02:26:40
Can you add a comment here? The reasons for limite
Daniel Erat
2014/07/12 02:44:38
done. also added a TODO, since i'm still not wholl
|
+ 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. |
+ const LinuxFontDelegate* delegate = LinuxFontDelegate::instance(); |
msw
2014/07/12 00:27:33
Can we remove LinuxFontDelegate (or most if it) no
Daniel Erat
2014/07/12 01:55:32
i'll add a TODO about this since i honestly wasn't
msw
2014/07/12 02:26:40
Acknowledged.
|
+ 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(renderer); |
+ |
+ // 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]; |
Daniel Erat
2014/07/11 17:15:29
i didn't bother adding fallback code like this for
msw
2014/07/12 00:27:33
Acknowledged.
|
+ |
+ return params; |
+} |
+ |
bool GetDefaultWebkitSubpixelPositioning() { |
return SubpixelPositioningRequested(true); |
} |