summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorderat <derat@chromium.org>2014-08-28 18:27:09 -0700
committerCommit bot <commit-bot@chromium.org>2014-08-29 01:29:21 +0000
commite22312d2327d29a092171a6ab13de12654a36b25 (patch)
tree44d07b0926d2474e6464a0881c291757d4101470
parent18f529b83ec0988b5ff490fa76733f8f43bfc552 (diff)
downloadchromium_src-e22312d2327d29a092171a6ab13de12654a36b25.zip
chromium_src-e22312d2327d29a092171a6ab13de12654a36b25.tar.gz
chromium_src-e22312d2327d29a092171a6ab13de12654a36b25.tar.bz2
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}
-rw-r--r--ui/gfx/platform_font_pango.cc27
-rw-r--r--ui/gfx/platform_font_pango.h11
-rw-r--r--ui/gfx/render_text_pango.cc15
3 files changed, 13 insertions, 40 deletions
diff --git a/ui/gfx/platform_font_pango.cc b/ui/gfx/platform_font_pango.cc
index 403b836..c408740 100644
--- a/ui/gfx/platform_font_pango.cc
+++ b/ui/gfx/platform_font_pango.cc
@@ -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) /
diff --git a/ui/gfx/platform_font_pango.h b/ui/gfx/platform_font_pango.h
index 3a49438..a636db2 100644
--- a/ui/gfx/platform_font_pango.h
+++ b/ui/gfx/platform_font_pango.h
@@ -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_;
diff --git a/ui/gfx/render_text_pango.cc b/ui/gfx/render_text_pango.cc
index 86a5242..07cbfb9 100644
--- a/ui/gfx/render_text_pango.cc
+++ b/ui/gfx/render_text_pango.cc
@@ -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