Commit e22312d2 authored by derat's avatar derat Committed by Commit bot

linux: Make RenderTextPango avoid clipping underlines.

Adjust underline positions so the lines won't get clipped. I
think that the inaccuracy may be occurring due to our
conversion from PangoFontDescriptions (usually containing a
point-based size) to a rounded pixel-based size and then
back to a PangoFontDescription. Luckily, RenderTextPango
will be replaced by RenderTextHarfBuzz soon.

Also delete some dead code in PlatformFontPango for
computing underline metrics.

BUG=393117
TEST=manual: checked that the "Import bookmarks now..."
     underline is visible after setting my UI font to
     "Ubuntu 11"

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

Cr-Commit-Position: refs/heads/master@{#292537}
parent 18f529b8
......@@ -130,16 +130,6 @@ PlatformFontPango::PlatformFontPango(const std::string& font_name,
query.style, gfx::GetFontRenderParams(query, NULL));
}
double PlatformFontPango::underline_position() const {
const_cast<PlatformFontPango*>(this)->InitPangoMetrics();
return underline_position_pixels_;
}
double PlatformFontPango::underline_thickness() const {
const_cast<PlatformFontPango*>(this)->InitPangoMetrics();
return underline_thickness_pixels_;
}
////////////////////////////////////////////////////////////////////////////////
// PlatformFontPango, PlatformFont implementation:
......@@ -283,8 +273,6 @@ void PlatformFontPango::InitFromDetails(
pango_metrics_inited_ = false;
average_width_pixels_ = 0.0f;
underline_position_pixels_ = 0.0f;
underline_thickness_pixels_ = 0.0f;
}
void PlatformFontPango::InitFromPlatformFont(const PlatformFontPango* other) {
......@@ -298,8 +286,6 @@ void PlatformFontPango::InitFromPlatformFont(const PlatformFontPango* other) {
cap_height_pixels_ = other->cap_height_pixels_;
pango_metrics_inited_ = other->pango_metrics_inited_;
average_width_pixels_ = other->average_width_pixels_;
underline_position_pixels_ = other->underline_position_pixels_;
underline_thickness_pixels_ = other->underline_thickness_pixels_;
}
void PlatformFontPango::PaintSetup(SkPaint* paint) const {
......@@ -318,19 +304,6 @@ void PlatformFontPango::InitPangoMetrics() {
ScopedPangoFontDescription pango_desc(GetNativeFont());
PangoFontMetrics* pango_metrics = GetPangoFontMetrics(pango_desc.get());
underline_position_pixels_ =
pango_font_metrics_get_underline_position(pango_metrics) /
PANGO_SCALE;
// TODO(davemoore): Come up with a better solution.
// This is a hack, but without doing this the underlines
// we get end up fuzzy. So we align to the midpoint of a pixel.
underline_position_pixels_ /= 2;
underline_thickness_pixels_ =
pango_font_metrics_get_underline_thickness(pango_metrics) /
PANGO_SCALE;
// First get the Pango-based width (converting from Pango units to pixels).
const double pango_width_pixels =
pango_font_metrics_get_approximate_char_width(pango_metrics) /
......
......@@ -40,13 +40,6 @@ class GFX_EXPORT PlatformFontPango : public PlatformFont {
static void SetDefaultFontDescription(const std::string& font_description);
#endif
// Position as an offset from the height of the drawn text, used to draw
// an underline. This is a negative number, so the underline would be
// drawn at y + height + underline_position.
double underline_position() const;
// The thickness to draw the underline.
double underline_thickness() const;
// Overridden from PlatformFont:
virtual Font DeriveFont(int size_delta, int style) const OVERRIDE;
virtual int GetHeight() const OVERRIDE;
......@@ -82,7 +75,7 @@ class GFX_EXPORT PlatformFontPango : public PlatformFont {
// Initializes this object as a copy of another PlatformFontPango.
void InitFromPlatformFont(const PlatformFontPango* other);
// Potentially slow call to get pango metrics (average width, underline info).
// Potentially slow call to get pango metrics (average width).
void InitPangoMetrics();
// Setup a Skia context to use the current typeface.
......@@ -114,8 +107,6 @@ class GFX_EXPORT PlatformFontPango : public PlatformFont {
// to compute them.
bool pango_metrics_inited_;
double average_width_pixels_;
double underline_position_pixels_;
double underline_thickness_pixels_;
// The default font, used for the default constructor.
static Font* default_font_;
......
......@@ -55,11 +55,20 @@ void SetPangoUnderlineMetrics(PangoFontDescription *desc,
// Pango returns the position "above the baseline". Change its sign to convert
// it to a vertical offset from the baseline.
int position = -pango_font_metrics_get_underline_position(metrics);
pango_quantize_line_geometry(&thickness, &position);
// Note: pango_quantize_line_geometry() guarantees pixel boundaries, so
// PANGO_PIXELS() is safe to use.
renderer->SetUnderlineMetrics(PANGO_PIXELS(thickness),
PANGO_PIXELS(position));
pango_quantize_line_geometry(&thickness, &position);
int thickness_pixels = PANGO_PIXELS(thickness);
int position_pixels = PANGO_PIXELS(position);
// Ugly hack: make sure that underlines don't get clipped. See
// http://crbug.com/393117.
int descent_pixels = PANGO_PIXELS(pango_font_metrics_get_descent(metrics));
position_pixels = std::min(position_pixels,
descent_pixels - thickness_pixels);
renderer->SetUnderlineMetrics(thickness_pixels, position_pixels);
}
} // namespace
......
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