| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/gfx/platform_font_pango.h" | 5 #include "ui/gfx/platform_font_pango.h" |
| 6 | 6 |
| 7 #include <fontconfig/fontconfig.h> | 7 #include <fontconfig/fontconfig.h> |
| 8 #include <pango/pango.h> | 8 #include <pango/pango.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 int PlatformFontPango::GetBaseline() const { | 183 int PlatformFontPango::GetBaseline() const { |
| 184 return ascent_pixels_; | 184 return ascent_pixels_; |
| 185 } | 185 } |
| 186 | 186 |
| 187 int PlatformFontPango::GetCapHeight() const { | 187 int PlatformFontPango::GetCapHeight() const { |
| 188 return cap_height_pixels_; | 188 return cap_height_pixels_; |
| 189 } | 189 } |
| 190 | 190 |
| 191 int PlatformFontPango::GetAverageCharacterWidth() const { | 191 int PlatformFontPango::GetAverageCharacterWidth() const { |
| 192 const_cast<PlatformFontPango*>(this)->InitPangoMetrics(); | 192 const_cast<PlatformFontPango*>(this)->InitPangoMetrics(); |
| 193 return SkScalarRound(average_width_pixels_); | 193 return SkScalarRoundToInt(average_width_pixels_); |
| 194 } | 194 } |
| 195 | 195 |
| 196 int PlatformFontPango::GetStringWidth(const base::string16& text) const { | 196 int PlatformFontPango::GetStringWidth(const base::string16& text) const { |
| 197 return Canvas::GetStringWidth(text, | 197 return Canvas::GetStringWidth(text, |
| 198 Font(const_cast<PlatformFontPango*>(this))); | 198 Font(const_cast<PlatformFontPango*>(this))); |
| 199 } | 199 } |
| 200 | 200 |
| 201 int PlatformFontPango::GetExpectedTextWidth(int length) const { | 201 int PlatformFontPango::GetExpectedTextWidth(int length) const { |
| 202 double char_width = const_cast<PlatformFontPango*>(this)->GetAverageWidth(); | 202 double char_width = const_cast<PlatformFontPango*>(this)->GetAverageWidth(); |
| 203 return round(static_cast<float>(length) * char_width); | 203 return round(static_cast<float>(length) * char_width); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 pango_metrics_inited_ = false; | 330 pango_metrics_inited_ = false; |
| 331 average_width_pixels_ = 0.0f; | 331 average_width_pixels_ = 0.0f; |
| 332 underline_position_pixels_ = 0.0f; | 332 underline_position_pixels_ = 0.0f; |
| 333 underline_thickness_pixels_ = 0.0f; | 333 underline_thickness_pixels_ = 0.0f; |
| 334 | 334 |
| 335 SkPaint paint; | 335 SkPaint paint; |
| 336 SkPaint::FontMetrics metrics; | 336 SkPaint::FontMetrics metrics; |
| 337 PaintSetup(&paint); | 337 PaintSetup(&paint); |
| 338 paint.getFontMetrics(&metrics); | 338 paint.getFontMetrics(&metrics); |
| 339 | 339 |
| 340 ascent_pixels_ = SkScalarCeil(-metrics.fAscent); | 340 ascent_pixels_ = SkScalarCeilToInt(-metrics.fAscent); |
| 341 height_pixels_ = ascent_pixels_ + SkScalarCeil(metrics.fDescent); | 341 height_pixels_ = ascent_pixels_ + SkScalarCeilToInt(metrics.fDescent); |
| 342 cap_height_pixels_ = SkScalarCeil(metrics.fCapHeight); | 342 cap_height_pixels_ = SkScalarCeilToInt(metrics.fCapHeight); |
| 343 } | 343 } |
| 344 | 344 |
| 345 void PlatformFontPango::InitFromPlatformFont(const PlatformFontPango* other) { | 345 void PlatformFontPango::InitFromPlatformFont(const PlatformFontPango* other) { |
| 346 typeface_ = other->typeface_; | 346 typeface_ = other->typeface_; |
| 347 font_family_ = other->font_family_; | 347 font_family_ = other->font_family_; |
| 348 font_size_pixels_ = other->font_size_pixels_; | 348 font_size_pixels_ = other->font_size_pixels_; |
| 349 style_ = other->style_; | 349 style_ = other->style_; |
| 350 height_pixels_ = other->height_pixels_; | 350 height_pixels_ = other->height_pixels_; |
| 351 ascent_pixels_ = other->ascent_pixels_; | 351 ascent_pixels_ = other->ascent_pixels_; |
| 352 cap_height_pixels_ = other->cap_height_pixels_; | 352 cap_height_pixels_ = other->cap_height_pixels_; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 return new PlatformFontPango(native_font); | 417 return new PlatformFontPango(native_font); |
| 418 } | 418 } |
| 419 | 419 |
| 420 // static | 420 // static |
| 421 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, | 421 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, |
| 422 int font_size) { | 422 int font_size) { |
| 423 return new PlatformFontPango(font_name, font_size); | 423 return new PlatformFontPango(font_name, font_size); |
| 424 } | 424 } |
| 425 | 425 |
| 426 } // namespace gfx | 426 } // namespace gfx |
| OLD | NEW |