Commit dd065649 authored by derat@chromium.org's avatar derat@chromium.org

linux: Round font sizes when going from points to pixels.

Round point-based Pango font sizes to the nearest pixel.
Otherwise, we can end up with smaller UI fonts than GTK+ 2.0
apps in some cases.

This seems to be in line with what get_scaled_size() does in
Pango's pango/pangofc-fontmap.c, and gives me identically
sized text in Gimp 2.6.12 and Chrome when I set the
Gtk/FontName XSETTINGS property to "Arial 10".

Note that Chrome doesn't currently honor additional
fine-grained configuration performed via FontConfig, like
disabling antialiasing for fonts of a certain size. That'll
happen in a separate change.

BUG=375824

Review URL: https://codereview.chromium.org/377413002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282204 0039d316-1c4b-4281-b951-d872f2087c98
parent a3b1faa0
...@@ -230,17 +230,15 @@ void SetUpPangoLayout( ...@@ -230,17 +230,15 @@ void SetUpPangoLayout(
pango_layout_set_font_description(layout, desc.get()); pango_layout_set_font_description(layout, desc.get());
} }
size_t GetPangoFontSizeInPixels(PangoFontDescription* pango_font) { int GetPangoFontSizeInPixels(PangoFontDescription* pango_font) {
size_t size_in_pixels = pango_font_description_get_size(pango_font); // If the size is absolute, then it's in Pango units rather than points. There
if (pango_font_description_get_size_is_absolute(pango_font)) { // are PANGO_SCALE Pango units in a device unit (pixel).
// If the size is absolute, then it's in Pango units rather than points. if (pango_font_description_get_size_is_absolute(pango_font))
// There are PANGO_SCALE Pango units in a device unit (pixel). return pango_font_description_get_size(pango_font) / PANGO_SCALE;
size_in_pixels /= PANGO_SCALE;
} else { // Otherwise, we need to convert from points.
// Otherwise, we need to convert from points. return static_cast<int>(GetPixelsInPoint() *
size_in_pixels = size_in_pixels * GetPixelsInPoint() / PANGO_SCALE; pango_font_description_get_size(pango_font) / PANGO_SCALE + 0.5);
}
return size_in_pixels;
} }
PangoFontMetrics* GetPangoFontMetrics(PangoFontDescription* desc) { PangoFontMetrics* GetPangoFontMetrics(PangoFontDescription* desc) {
......
...@@ -52,7 +52,7 @@ void SetUpPangoLayout( ...@@ -52,7 +52,7 @@ void SetUpPangoLayout(
int flags); int flags);
// Returns the size in pixels for the specified |pango_font|. // Returns the size in pixels for the specified |pango_font|.
size_t GetPangoFontSizeInPixels(PangoFontDescription* pango_font); int GetPangoFontSizeInPixels(PangoFontDescription* pango_font);
// Retrieves the Pango metrics for a Pango font description. Caches the metrics // Retrieves the Pango metrics for a Pango font description. Caches the metrics
// and never frees them. The metrics objects are relatively small and very // and never frees them. The metrics objects are relatively small and very
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment