| 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> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/strings/string_piece.h" | 14 #include "base/strings/string_piece.h" |
| 15 #include "base/strings/string_split.h" | 15 #include "base/strings/string_split.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "third_party/skia/include/core/SkPaint.h" | 17 #include "third_party/skia/include/core/SkPaint.h" |
| 18 #include "third_party/skia/include/core/SkTypeface.h" | 18 #include "third_party/skia/include/core/SkTypeface.h" |
| 19 #include "ui/gfx/canvas.h" | 19 #include "ui/gfx/canvas.h" |
| 20 #include "ui/gfx/font.h" | 20 #include "ui/gfx/font.h" |
| 21 #include "ui/gfx/font_list.h" |
| 21 #include "ui/gfx/pango_util.h" | 22 #include "ui/gfx/pango_util.h" |
| 22 | 23 |
| 23 #if defined(TOOLKIT_GTK) | 24 #if defined(TOOLKIT_GTK) |
| 24 #include <gdk/gdk.h> | 25 #include <gdk/gdk.h> |
| 25 #include <gtk/gtk.h> | 26 #include <gtk/gtk.h> |
| 26 #endif | 27 #endif |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| 30 // The font family name which is used when a user's application font for | 31 // The font family name which is used when a user's application font for |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 int PlatformFontPango::GetAverageCharacterWidth() const { | 196 int PlatformFontPango::GetAverageCharacterWidth() const { |
| 196 const_cast<PlatformFontPango*>(this)->InitPangoMetrics(); | 197 const_cast<PlatformFontPango*>(this)->InitPangoMetrics(); |
| 197 return SkScalarRound(average_width_pixels_); | 198 return SkScalarRound(average_width_pixels_); |
| 198 } | 199 } |
| 199 | 200 |
| 200 int PlatformFontPango::GetStringWidth(const base::string16& text) const { | 201 int PlatformFontPango::GetStringWidth(const base::string16& text) const { |
| 201 return Canvas::GetStringWidth(text, | 202 return Canvas::GetStringWidth(text, |
| 202 Font(const_cast<PlatformFontPango*>(this))); | 203 Font(const_cast<PlatformFontPango*>(this))); |
| 203 } | 204 } |
| 204 | 205 |
| 206 float PlatformFontPango::GetStringWidthF(const base::string16& text) const { |
| 207 return Canvas::GetStringWidthF( |
| 208 text, FontList(Font(const_cast<PlatformFontPango*>(this)))); |
| 209 } |
| 210 |
| 205 int PlatformFontPango::GetExpectedTextWidth(int length) const { | 211 int PlatformFontPango::GetExpectedTextWidth(int length) const { |
| 206 double char_width = const_cast<PlatformFontPango*>(this)->GetAverageWidth(); | 212 double char_width = const_cast<PlatformFontPango*>(this)->GetAverageWidth(); |
| 207 return round(static_cast<float>(length) * char_width); | 213 return round(static_cast<float>(length) * char_width); |
| 208 } | 214 } |
| 209 | 215 |
| 210 int PlatformFontPango::GetStyle() const { | 216 int PlatformFontPango::GetStyle() const { |
| 211 return style_; | 217 return style_; |
| 212 } | 218 } |
| 213 | 219 |
| 214 std::string PlatformFontPango::GetFontName() const { | 220 std::string PlatformFontPango::GetFontName() const { |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 return new PlatformFontPango(native_font); | 415 return new PlatformFontPango(native_font); |
| 410 } | 416 } |
| 411 | 417 |
| 412 // static | 418 // static |
| 413 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, | 419 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, |
| 414 int font_size) { | 420 int font_size) { |
| 415 return new PlatformFontPango(font_name, font_size); | 421 return new PlatformFontPango(font_name, font_size); |
| 416 } | 422 } |
| 417 | 423 |
| 418 } // namespace gfx | 424 } // namespace gfx |
| OLD | NEW |