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/SkString.h" |
18 #include "third_party/skia/include/core/SkTypeface.h" | 19 #include "third_party/skia/include/core/SkTypeface.h" |
19 #include "ui/gfx/canvas.h" | 20 #include "ui/gfx/canvas.h" |
20 #include "ui/gfx/font.h" | 21 #include "ui/gfx/font.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 |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 } | 209 } |
209 | 210 |
210 int PlatformFontPango::GetStyle() const { | 211 int PlatformFontPango::GetStyle() const { |
211 return style_; | 212 return style_; |
212 } | 213 } |
213 | 214 |
214 std::string PlatformFontPango::GetFontName() const { | 215 std::string PlatformFontPango::GetFontName() const { |
215 return font_family_; | 216 return font_family_; |
216 } | 217 } |
217 | 218 |
| 219 std::string PlatformFontPango::GetActualFontNameForTesting() const { |
| 220 SkString family_name; |
| 221 typeface_->getFamilyName(&family_name); |
| 222 return family_name.c_str(); |
| 223 } |
| 224 |
218 int PlatformFontPango::GetFontSize() const { | 225 int PlatformFontPango::GetFontSize() const { |
219 return font_size_pixels_; | 226 return font_size_pixels_; |
220 } | 227 } |
221 | 228 |
222 NativeFont PlatformFontPango::GetNativeFont() const { | 229 NativeFont PlatformFontPango::GetNativeFont() const { |
223 PangoFontDescription* pfd = pango_font_description_new(); | 230 PangoFontDescription* pfd = pango_font_description_new(); |
224 pango_font_description_set_family(pfd, GetFontName().c_str()); | 231 pango_font_description_set_family(pfd, GetFontName().c_str()); |
225 // Set the absolute size to avoid overflowing UI elements. | 232 // Set the absolute size to avoid overflowing UI elements. |
226 // pango_font_description_set_absolute_size() takes a size in Pango units. | 233 // pango_font_description_set_absolute_size() takes a size in Pango units. |
227 // There are PANGO_SCALE Pango units in one device unit. Screen output | 234 // There are PANGO_SCALE Pango units in one device unit. Screen output |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 #endif // !defined(TOOLKIT_GTK) | 293 #endif // !defined(TOOLKIT_GTK) |
287 } | 294 } |
288 | 295 |
289 | 296 |
290 void PlatformFontPango::InitWithNameAndSize(const std::string& font_name, | 297 void PlatformFontPango::InitWithNameAndSize(const std::string& font_name, |
291 int font_size) { | 298 int font_size) { |
292 DCHECK_GT(font_size, 0); | 299 DCHECK_GT(font_size, 0); |
293 std::string fallback; | 300 std::string fallback; |
294 | 301 |
295 skia::RefPtr<SkTypeface> typeface = skia::AdoptRef( | 302 skia::RefPtr<SkTypeface> typeface = skia::AdoptRef( |
296 SkTypeface::CreateFromName(font_name.c_str(), SkTypeface::kNormal)); | 303 SkTypeface::CreateFromName(font_name.c_str(), SkTypeface::kNormal)); |
297 if (!typeface) { | 304 if (!typeface) { |
298 // A non-scalable font such as .pcf is specified. Falls back to a default | 305 // A non-scalable font such as .pcf is specified. Falls back to a default |
299 // scalable font. | 306 // scalable font. |
300 typeface = skia::AdoptRef( | 307 typeface = skia::AdoptRef( |
301 SkTypeface::CreateFromName( | 308 SkTypeface::CreateFromName( |
302 kFallbackFontFamilyName, SkTypeface::kNormal)); | 309 kFallbackFontFamilyName, SkTypeface::kNormal)); |
303 CHECK(typeface) << "Could not find any font: " | 310 CHECK(typeface) << "Could not find any font: " |
304 << font_name | 311 << font_name |
305 << ", " << kFallbackFontFamilyName; | 312 << ", " << kFallbackFontFamilyName; |
306 fallback = kFallbackFontFamilyName; | 313 fallback = kFallbackFontFamilyName; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 return new PlatformFontPango(native_font); | 416 return new PlatformFontPango(native_font); |
410 } | 417 } |
411 | 418 |
412 // static | 419 // static |
413 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, | 420 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, |
414 int font_size) { | 421 int font_size) { |
415 return new PlatformFontPango(font_name, font_size); | 422 return new PlatformFontPango(font_name, font_size); |
416 } | 423 } |
417 | 424 |
418 } // namespace gfx | 425 } // namespace gfx |
OLD | NEW |