| 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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 int PlatformFontPango::GetCapHeight() const { | 185 int PlatformFontPango::GetCapHeight() const { |
| 186 // Return the height as an approximation because Pango doesn't support cap | 186 // Return the height as an approximation because Pango doesn't support cap |
| 187 // height. | 187 // height. |
| 188 // TODO(yukishiino): Come up with a better approximation of cap height, or | 188 // TODO(yukishiino): Come up with a better approximation of cap height, or |
| 189 // support cap height metrics. Another option is to have a hard-coded table | 189 // support cap height metrics. Another option is to have a hard-coded table |
| 190 // of cap height for major fonts used in Chromium/Chrome. | 190 // of cap height for major fonts used in Chromium/Chrome. |
| 191 // See http://crbug.com/249507 | 191 // See http://crbug.com/249507 |
| 192 return height_pixels_; | 192 return height_pixels_; |
| 193 } | 193 } |
| 194 | 194 |
| 195 int PlatformFontPango::GetAverageCharacterWidth() const { | 195 float PlatformFontPango::GetAverageCharacterWidth() const { |
| 196 const_cast<PlatformFontPango*>(this)->InitPangoMetrics(); | 196 const_cast<PlatformFontPango*>(this)->InitPangoMetrics(); |
| 197 return SkScalarRound(average_width_pixels_); | 197 return SkScalarRound(average_width_pixels_); |
| 198 } | 198 } |
| 199 | 199 |
| 200 int PlatformFontPango::GetStringWidth(const base::string16& text) const { | 200 float PlatformFontPango::GetStringWidth(const base::string16& text) const { |
| 201 return Canvas::GetStringWidth(text, | 201 return Canvas::GetStringWidth(text, |
| 202 Font(const_cast<PlatformFontPango*>(this))); | 202 Font(const_cast<PlatformFontPango*>(this))); |
| 203 } | 203 } |
| 204 | 204 |
| 205 int PlatformFontPango::GetExpectedTextWidth(int length) const { | 205 float PlatformFontPango::GetExpectedTextWidth(int length) const { |
| 206 double char_width = const_cast<PlatformFontPango*>(this)->GetAverageWidth(); | 206 double char_width = const_cast<PlatformFontPango*>(this)->GetAverageWidth(); |
| 207 return round(static_cast<float>(length) * char_width); | 207 return round(static_cast<float>(length) * char_width); |
| 208 } | 208 } |
| 209 | 209 |
| 210 int PlatformFontPango::GetStyle() const { | 210 int PlatformFontPango::GetStyle() const { |
| 211 return style_; | 211 return style_; |
| 212 } | 212 } |
| 213 | 213 |
| 214 std::string PlatformFontPango::GetFontName() const { | 214 std::string PlatformFontPango::GetFontName() const { |
| 215 return font_family_; | 215 return font_family_; |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 return new PlatformFontPango(native_font); | 409 return new PlatformFontPango(native_font); |
| 410 } | 410 } |
| 411 | 411 |
| 412 // static | 412 // static |
| 413 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, | 413 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, |
| 414 int font_size) { | 414 int font_size) { |
| 415 return new PlatformFontPango(font_name, font_size); | 415 return new PlatformFontPango(font_name, font_size); |
| 416 } | 416 } |
| 417 | 417 |
| 418 } // namespace gfx | 418 } // namespace gfx |
| OLD | NEW |