diff options
-rw-r--r-- | ui/gfx/platform_font_pango.cc | 59 | ||||
-rw-r--r-- | ui/gfx/platform_font_pango.h | 16 |
2 files changed, 12 insertions, 63 deletions
diff --git a/ui/gfx/platform_font_pango.cc b/ui/gfx/platform_font_pango.cc index 96c601a..67c1b2d 100644 --- a/ui/gfx/platform_font_pango.cc +++ b/ui/gfx/platform_font_pango.cc @@ -179,8 +179,7 @@ int PlatformFontPango::GetCapHeight() const { } int PlatformFontPango::GetExpectedTextWidth(int length) const { - double char_width = const_cast<PlatformFontPango*>(this)->GetAverageWidth(); - return round(static_cast<float>(length) * char_width); + return round(static_cast<float>(length) * average_width_pixels_); } int PlatformFontPango::GetStyle() const { @@ -278,15 +277,19 @@ void PlatformFontPango::InitFromDetails( font_render_params_ = render_params; SkPaint paint; + paint.setAntiAlias(false); + paint.setSubpixelText(false); + paint.setTextSize(font_size_pixels_); + paint.setTypeface(typeface_.get()); + paint.setFakeBoldText((gfx::Font::BOLD & style_) && !typeface_->isBold()); + paint.setTextSkewX((gfx::Font::ITALIC & style_) && !typeface_->isItalic() ? + -SK_Scalar1/4 : 0); SkPaint::FontMetrics metrics; - PaintSetup(&paint); paint.getFontMetrics(&metrics); ascent_pixels_ = SkScalarCeilToInt(-metrics.fAscent); height_pixels_ = ascent_pixels_ + SkScalarCeilToInt(metrics.fDescent); cap_height_pixels_ = SkScalarCeilToInt(metrics.fCapHeight); - - pango_metrics_inited_ = false; - average_width_pixels_ = 0.0f; + average_width_pixels_ = SkScalarToDouble(metrics.fAvgCharWidth); } void PlatformFontPango::InitFromPlatformFont(const PlatformFontPango* other) { @@ -294,52 +297,14 @@ void PlatformFontPango::InitFromPlatformFont(const PlatformFontPango* other) { font_family_ = other->font_family_; font_size_pixels_ = other->font_size_pixels_; style_ = other->style_; +#if defined(OS_CHROMEOS) + device_scale_factor_ = other->device_scale_factor_; +#endif font_render_params_ = other->font_render_params_; ascent_pixels_ = other->ascent_pixels_; height_pixels_ = other->height_pixels_; cap_height_pixels_ = other->cap_height_pixels_; - pango_metrics_inited_ = other->pango_metrics_inited_; average_width_pixels_ = other->average_width_pixels_; -#if defined(OS_CHROMEOS) - device_scale_factor_ = other->device_scale_factor_; -#endif -} - -void PlatformFontPango::PaintSetup(SkPaint* paint) const { - paint->setAntiAlias(false); - paint->setSubpixelText(false); - paint->setTextSize(font_size_pixels_); - paint->setTypeface(typeface_.get()); - paint->setFakeBoldText((gfx::Font::BOLD & style_) && !typeface_->isBold()); - paint->setTextSkewX((gfx::Font::ITALIC & style_) && !typeface_->isItalic() ? - -SK_Scalar1/4 : 0); -} - -void PlatformFontPango::InitPangoMetrics() { - if (!pango_metrics_inited_) { - pango_metrics_inited_ = true; - ScopedPangoFontDescription pango_desc(GetNativeFont()); - PangoFontMetrics* pango_metrics = GetPangoFontMetrics(pango_desc.get()); - - // 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) / - PANGO_SCALE; - - // Yes, this is how Microsoft recommends calculating the dialog unit - // conversions. - const int text_width_pixels = GetStringWidth( - base::ASCIIToUTF16( - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"), - FontList(Font(this))); - const double dialog_units_pixels = (text_width_pixels / 26 + 1) / 2; - average_width_pixels_ = std::min(pango_width_pixels, dialog_units_pixels); - } -} - -double PlatformFontPango::GetAverageWidth() const { - const_cast<PlatformFontPango*>(this)->InitPangoMetrics(); - return average_width_pixels_; } //////////////////////////////////////////////////////////////////////////////// diff --git a/ui/gfx/platform_font_pango.h b/ui/gfx/platform_font_pango.h index f9783d3..47f402e 100644 --- a/ui/gfx/platform_font_pango.h +++ b/ui/gfx/platform_font_pango.h @@ -75,18 +75,6 @@ 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). - void InitPangoMetrics(); - - // Setup a Skia context to use the current typeface. - void PaintSetup(SkPaint* paint) const; - - // Make |this| a copy of |other|. - void CopyFont(const Font& other); - - // The average width of a character, initialized and cached if needed. - double GetAverageWidth() const; - skia::RefPtr<SkTypeface> typeface_; // Additional information about the face. @@ -105,10 +93,6 @@ class GFX_EXPORT PlatformFontPango : public PlatformFont { int ascent_pixels_; int height_pixels_; int cap_height_pixels_; - - // The pango metrics are much more expensive so we wait until we need them - // to compute them. - bool pango_metrics_inited_; double average_width_pixels_; // The default font, used for the default constructor. |