diff options
-rw-r--r-- | ui/base/ui_base_switches.cc | 18 | ||||
-rw-r--r-- | ui/base/ui_base_switches.h | 1 | ||||
-rw-r--r-- | ui/gfx/pango_util.cc | 19 | ||||
-rw-r--r-- | ui/gfx/render_text_linux.cc | 11 |
4 files changed, 37 insertions, 12 deletions
diff --git a/ui/base/ui_base_switches.cc b/ui/base/ui_base_switches.cc index 67ef448..773c441 100644 --- a/ui/base/ui_base_switches.cc +++ b/ui/base/ui_base_switches.cc @@ -8,28 +8,32 @@ namespace switches { // The default device scale factor to apply to the browser UI and // the contents in the absence of a viewport meta tag. -const char kDefaultDeviceScaleFactor[] = "default-device-scale-factor"; +const char kDefaultDeviceScaleFactor[] = "default-device-scale-factor"; // Enable touch screen calibration. -const char kDisableTouchCalibration[] = "disable-touch-calibration"; +const char kDisableTouchCalibration[] = "disable-touch-calibration"; + +// Let text glyphs have X-positions that aren't snapped to the pixel grid. +const char kEnableTextSubpixelPositioning[] = + "enable-text-subpixel-positioning"; // Enable support for touch events. -const char kEnableTouchEvents[] = "enable-touch-events"; +const char kEnableTouchEvents[] = "enable-touch-events"; // The language file that we want to try to open. Of the form // language[-country] where language is the 2 letter code from ISO-639. -const char kLang[] = "lang"; +const char kLang[] = "lang"; // Load the locale resources from the given path. When running on Mac/Unix the // path should point to a locale.pak file. -const char kLocalePak[] = "locale_pak"; +const char kLocalePak[] = "locale_pak"; // Disable ui::MessageBox. This is useful when running as part of scripts that // do not have a user interface. -const char kNoMessageBox[] = "no-message-box"; +const char kNoMessageBox[] = "no-message-box"; // Enables UI changes that make it easier to use with a touchscreen. -const char kTouchOptimizedUI[] = "touch-optimized-ui"; +const char kTouchOptimizedUI[] = "touch-optimized-ui"; #if defined(OS_MACOSX) diff --git a/ui/base/ui_base_switches.h b/ui/base/ui_base_switches.h index 14b4fc7..61f978f 100644 --- a/ui/base/ui_base_switches.h +++ b/ui/base/ui_base_switches.h @@ -15,6 +15,7 @@ namespace switches { UI_EXPORT extern const char kDefaultDeviceScaleFactor[]; UI_EXPORT extern const char kDisableTouchCalibration[]; +UI_EXPORT extern const char kEnableTextSubpixelPositioning[]; UI_EXPORT extern const char kEnableTouchEvents[]; UI_EXPORT extern const char kLang[]; UI_EXPORT extern const char kLocalePak[]; diff --git a/ui/gfx/pango_util.cc b/ui/gfx/pango_util.cc index e835602..6a981fa 100644 --- a/ui/gfx/pango_util.cc +++ b/ui/gfx/pango_util.cc @@ -24,6 +24,9 @@ #include <gdk/gdk.h> #include <gtk/gtk.h> #include "ui/gfx/gtk_util.h" +#else +#include "base/command_line.h" +#include "ui/base/ui_base_switches.h" #endif #include "ui/gfx/skia_util.h" @@ -146,8 +149,20 @@ cairo_font_options_t* GetCairoFontOptions() { cairo_font_options_set_antialias(cairo_font_options, cairo_antialias); cairo_font_options_set_subpixel_order(cairo_font_options, cairo_subpixel_order); - cairo_font_options_set_hint_style(cairo_font_options, - CAIRO_HINT_STYLE_SLIGHT); + + if (CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableTextSubpixelPositioning)) { + // To enable subpixel positioning, we need to disable hinting. + cairo_font_options_set_hint_metrics(cairo_font_options, + CAIRO_HINT_METRICS_OFF); + cairo_font_options_set_hint_style(cairo_font_options, + CAIRO_HINT_STYLE_NONE); + } else { + cairo_font_options_set_hint_metrics(cairo_font_options, + CAIRO_HINT_METRICS_ON); + cairo_font_options_set_hint_style(cairo_font_options, + CAIRO_HINT_STYLE_SLIGHT); + } #endif return cairo_font_options; diff --git a/ui/gfx/render_text_linux.cc b/ui/gfx/render_text_linux.cc index 6333bba..69fb4bf 100644 --- a/ui/gfx/render_text_linux.cc +++ b/ui/gfx/render_text_linux.cc @@ -242,6 +242,7 @@ void RenderTextLinux::GetGlyphBounds(size_t index, int* height) { PangoRectangle pos; pango_layout_index_to_pos(layout_, TextIndexToLayoutIndex(index), &pos); + // TODO(derat): Support fractional ranges for subpixel positioning? *xspan = ui::Range(PANGO_PIXELS(pos.x), PANGO_PIXELS(pos.x + pos.width)); *height = PANGO_PIXELS(pos.height); } @@ -430,9 +431,12 @@ void RenderTextLinux::DrawVisualText(Canvas* canvas) { for (int i = 0; i < glyph_count; ++i) { const PangoGlyphInfo& glyph = run->glyphs->glyphs[i]; glyphs[i] = static_cast<uint16>(glyph.glyph); - pos[i].set(glyph_x + PANGO_PIXELS(glyph.geometry.x_offset), - y + PANGO_PIXELS(glyph.geometry.y_offset)); - glyph_x += PANGO_PIXELS(glyph.geometry.width); + // Use pango_units_to_double() rather than PANGO_PIXELS() here so that + // units won't get rounded to the pixel grid if we're using subpixel + // positioning. + pos[i].set(glyph_x + pango_units_to_double(glyph.geometry.x_offset), + y + pango_units_to_double(glyph.geometry.y_offset)); + glyph_x += pango_units_to_double(glyph.geometry.width); // If this glyph is beyond the current style, draw the glyphs so far and // advance to the next style. @@ -532,6 +536,7 @@ std::vector<Rect> RenderTextLinux::CalculateSubstringBounds(ui::Range range) { std::vector<Rect> bounds; for (int i = 0; i < n_ranges; ++i) { + // TODO(derat): Support fractional bounds for subpixel positioning? int x = PANGO_PIXELS(ranges[2 * i]); int width = PANGO_PIXELS(ranges[2 * i + 1]) - x; Rect rect(x, y, width, height); |