| 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_linux.h" | 5 #include "ui/gfx/platform_font_linux.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 SkFontStyle sk_style( | 53 SkFontStyle sk_style( |
| 54 font_weight, SkFontStyle::kNormal_Width, | 54 font_weight, SkFontStyle::kNormal_Width, |
| 55 italic ? SkFontStyle::kItalic_Slant : SkFontStyle::kUpright_Slant); | 55 italic ? SkFontStyle::kItalic_Slant : SkFontStyle::kUpright_Slant); |
| 56 sk_sp<SkTypeface> typeface = | 56 sk_sp<SkTypeface> typeface = |
| 57 SkTypeface::MakeFromName(family->c_str(), sk_style); | 57 SkTypeface::MakeFromName(family->c_str(), sk_style); |
| 58 if (!typeface) { | 58 if (!typeface) { |
| 59 // A non-scalable font such as .pcf is specified. Fall back to a default | 59 // A non-scalable font such as .pcf is specified. Fall back to a default |
| 60 // scalable font. | 60 // scalable font. |
| 61 typeface = sk_sp<SkTypeface>(SkTypeface::MakeFromName( | 61 typeface = sk_sp<SkTypeface>(SkTypeface::MakeFromName( |
| 62 kFallbackFontFamilyName, sk_style)); | 62 kFallbackFontFamilyName, sk_style)); |
| 63 CHECK(typeface) << "Could not find any font: " << *family << ", " | 63 // Could not find any font. |
| 64 << kFallbackFontFamilyName; | 64 CHECK(typeface); |
| 65 *family = kFallbackFontFamilyName; | 65 *family = kFallbackFontFamilyName; |
| 66 } | 66 } |
| 67 return typeface; | 67 return typeface; |
| 68 } | 68 } |
| 69 | 69 |
| 70 } // namespace | 70 } // namespace |
| 71 | 71 |
| 72 #if defined(OS_CHROMEOS) | 72 #if defined(OS_CHROMEOS) |
| 73 std::string* PlatformFontLinux::default_font_description_ = NULL; | 73 std::string* PlatformFontLinux::default_font_description_ = NULL; |
| 74 #endif | 74 #endif |
| 75 | 75 |
| 76 //////////////////////////////////////////////////////////////////////////////// | 76 //////////////////////////////////////////////////////////////////////////////// |
| 77 // PlatformFontLinux, public: | 77 // PlatformFontLinux, public: |
| 78 | 78 |
| 79 PlatformFontLinux::PlatformFontLinux() { | 79 PlatformFontLinux::PlatformFontLinux() { |
| 80 if (!g_default_font.Get()) { | 80 if (!g_default_font.Get()) { |
| 81 std::string family = kFallbackFontFamilyName; | 81 std::string family = kFallbackFontFamilyName; |
| 82 int size_pixels = 12; | 82 int size_pixels = 12; |
| 83 int style = Font::NORMAL; | 83 int style = Font::NORMAL; |
| 84 Font::Weight weight = Font::Weight::NORMAL; | 84 Font::Weight weight = Font::Weight::NORMAL; |
| 85 FontRenderParams params; | 85 FontRenderParams params; |
| 86 | 86 |
| 87 #if defined(OS_CHROMEOS) | 87 #if defined(OS_CHROMEOS) |
| 88 // On Chrome OS, a FontList font description string is stored as a | 88 // On Chrome OS, a FontList font description string is stored as a |
| 89 // translatable resource and passed in via SetDefaultFontDescription(). | 89 // translatable resource and passed in via SetDefaultFontDescription(). |
| 90 if (default_font_description_) { | 90 if (default_font_description_) { |
| 91 FontRenderParamsQuery query; | 91 FontRenderParamsQuery query; |
| 92 CHECK(FontList::ParseDescription(*default_font_description_, | 92 CHECK(FontList::ParseDescription(*default_font_description_, |
| 93 &query.families, &query.style, | 93 &query.families, &query.style, |
| 94 &query.pixel_size, &query.weight)) | 94 &query.pixel_size, &query.weight)); |
| 95 << "Failed to parse font description " << *default_font_description_; | |
| 96 params = gfx::GetFontRenderParams(query, &family); | 95 params = gfx::GetFontRenderParams(query, &family); |
| 97 size_pixels = query.pixel_size; | 96 size_pixels = query.pixel_size; |
| 98 style = query.style; | 97 style = query.style; |
| 99 weight = query.weight; | 98 weight = query.weight; |
| 100 } | 99 } |
| 101 #else | 100 #else |
| 102 // On Linux, LinuxFontDelegate is used to query the native toolkit (e.g. | 101 // On Linux, LinuxFontDelegate is used to query the native toolkit (e.g. |
| 103 // GTK+) for the default UI font. | 102 // GTK+) for the default UI font. |
| 104 const LinuxFontDelegate* delegate = LinuxFontDelegate::instance(); | 103 const LinuxFontDelegate* delegate = LinuxFontDelegate::instance(); |
| 105 if (delegate) { | 104 if (delegate) { |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 return new PlatformFontLinux; | 307 return new PlatformFontLinux; |
| 309 } | 308 } |
| 310 | 309 |
| 311 // static | 310 // static |
| 312 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, | 311 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, |
| 313 int font_size) { | 312 int font_size) { |
| 314 return new PlatformFontLinux(font_name, font_size); | 313 return new PlatformFontLinux(font_name, font_size); |
| 315 } | 314 } |
| 316 | 315 |
| 317 } // namespace gfx | 316 } // namespace gfx |
| OLD | NEW |