| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 #if defined(OS_CHROMEOS) | 67 #if defined(OS_CHROMEOS) |
| 68 // static | 68 // static |
| 69 std::string* PlatformFontPango::default_font_description_ = NULL; | 69 std::string* PlatformFontPango::default_font_description_ = NULL; |
| 70 #endif | 70 #endif |
| 71 | 71 |
| 72 //////////////////////////////////////////////////////////////////////////////// | 72 //////////////////////////////////////////////////////////////////////////////// |
| 73 // PlatformFontPango, public: | 73 // PlatformFontPango, public: |
| 74 | 74 |
| 75 PlatformFontPango::PlatformFontPango() { | 75 PlatformFontPango::PlatformFontPango() { |
| 76 if (!default_font_) { | 76 if (!default_font_) { |
| 77 std::string desc_string; | 77 scoped_ptr<ScopedPangoFontDescription> description; |
| 78 #if defined(OS_CHROMEOS) | 78 #if defined(OS_CHROMEOS) |
| 79 // Font name must have been provided by way of SetDefaultFontDescription(). | |
| 80 CHECK(default_font_description_); | 79 CHECK(default_font_description_); |
| 81 desc_string = *default_font_description_; | 80 description.reset( |
| 81 new ScopedPangoFontDescription(*default_font_description_)); |
| 82 #else | 82 #else |
| 83 const gfx::LinuxFontDelegate* delegate = gfx::LinuxFontDelegate::instance(); | 83 const gfx::LinuxFontDelegate* delegate = gfx::LinuxFontDelegate::instance(); |
| 84 desc_string = delegate ? delegate->GetDefaultFontDescription() : "sans 10"; | 84 if (delegate) |
| 85 description = delegate->GetDefaultPangoFontDescription(); |
| 85 #endif | 86 #endif |
| 86 | 87 if (!description || !description->get()) |
| 87 ScopedPangoFontDescription desc( | 88 description.reset(new ScopedPangoFontDescription("sans 10")); |
| 88 pango_font_description_from_string(desc_string.c_str())); | 89 default_font_ = new Font(description->get()); |
| 89 default_font_ = new Font(desc.get()); | |
| 90 } | 90 } |
| 91 | 91 |
| 92 InitFromPlatformFont( | 92 InitFromPlatformFont( |
| 93 static_cast<PlatformFontPango*>(default_font_->platform_font())); | 93 static_cast<PlatformFontPango*>(default_font_->platform_font())); |
| 94 } | 94 } |
| 95 | 95 |
| 96 PlatformFontPango::PlatformFontPango(NativeFont native_font) { | 96 PlatformFontPango::PlatformFontPango(NativeFont native_font) { |
| 97 const int pango_size = | 97 const int pango_size = |
| 98 pango_font_description_get_size(native_font) / PANGO_SCALE; | 98 pango_font_description_get_size(native_font) / PANGO_SCALE; |
| 99 const bool pango_using_pixels = | 99 const bool pango_using_pixels = |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 return new PlatformFontPango(native_font); | 372 return new PlatformFontPango(native_font); |
| 373 } | 373 } |
| 374 | 374 |
| 375 // static | 375 // static |
| 376 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, | 376 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, |
| 377 int font_size) { | 377 int font_size) { |
| 378 return new PlatformFontPango(font_name, font_size); | 378 return new PlatformFontPango(font_name, font_size); |
| 379 } | 379 } |
| 380 | 380 |
| 381 } // namespace gfx | 381 } // namespace gfx |
| OLD | NEW |