| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 if (!g_default_font.Get()) { | 72 if (!g_default_font.Get()) { |
| 73 std::string family = kFallbackFontFamilyName; | 73 std::string family = kFallbackFontFamilyName; |
| 74 int size_pixels = 12; | 74 int size_pixels = 12; |
| 75 int style = Font::NORMAL; | 75 int style = Font::NORMAL; |
| 76 FontRenderParams params; | 76 FontRenderParams params; |
| 77 | 77 |
| 78 #if defined(OS_CHROMEOS) | 78 #if defined(OS_CHROMEOS) |
| 79 // On Chrome OS, a FontList font description string is stored as a | 79 // On Chrome OS, a FontList font description string is stored as a |
| 80 // translatable resource and passed in via SetDefaultFontDescription(). | 80 // translatable resource and passed in via SetDefaultFontDescription(). |
| 81 if (default_font_description_) { | 81 if (default_font_description_) { |
| 82 FontRenderParamsQuery query(false /* for_web_contents */); | 82 FontRenderParamsQuery query; |
| 83 CHECK(FontList::ParseDescription(*default_font_description_, | 83 CHECK(FontList::ParseDescription(*default_font_description_, |
| 84 &query.families, &query.style, | 84 &query.families, &query.style, |
| 85 &query.pixel_size)) | 85 &query.pixel_size)) |
| 86 << "Failed to parse font description " << *default_font_description_; | 86 << "Failed to parse font description " << *default_font_description_; |
| 87 params = gfx::GetFontRenderParams(query, &family); | 87 params = gfx::GetFontRenderParams(query, &family); |
| 88 size_pixels = query.pixel_size; | 88 size_pixels = query.pixel_size; |
| 89 style = query.style; | 89 style = query.style; |
| 90 } | 90 } |
| 91 #else | 91 #else |
| 92 // On Linux, LinuxFontDelegate is used to query the native toolkit (e.g. | 92 // On Linux, LinuxFontDelegate is used to query the native toolkit (e.g. |
| 93 // GTK+) for the default UI font. | 93 // GTK+) for the default UI font. |
| 94 const LinuxFontDelegate* delegate = LinuxFontDelegate::instance(); | 94 const LinuxFontDelegate* delegate = LinuxFontDelegate::instance(); |
| 95 if (delegate) { | 95 if (delegate) { |
| 96 delegate->GetDefaultFontDescription( | 96 delegate->GetDefaultFontDescription( |
| 97 &family, &size_pixels, &style, ¶ms); | 97 &family, &size_pixels, &style, ¶ms); |
| 98 } | 98 } |
| 99 #endif | 99 #endif |
| 100 | 100 |
| 101 g_default_font.Get() = new PlatformFontLinux( | 101 g_default_font.Get() = new PlatformFontLinux( |
| 102 CreateSkTypeface(style, &family), family, size_pixels, style, params); | 102 CreateSkTypeface(style, &family), family, size_pixels, style, params); |
| 103 } | 103 } |
| 104 | 104 |
| 105 InitFromPlatformFont(g_default_font.Get().get()); | 105 InitFromPlatformFont(g_default_font.Get().get()); |
| 106 } | 106 } |
| 107 | 107 |
| 108 PlatformFontLinux::PlatformFontLinux(const std::string& font_name, | 108 PlatformFontLinux::PlatformFontLinux(const std::string& font_name, |
| 109 int font_size_pixels) { | 109 int font_size_pixels) { |
| 110 FontRenderParamsQuery query(false); | 110 FontRenderParamsQuery query; |
| 111 query.families.push_back(font_name); | 111 query.families.push_back(font_name); |
| 112 query.pixel_size = font_size_pixels; | 112 query.pixel_size = font_size_pixels; |
| 113 query.style = Font::NORMAL; | 113 query.style = Font::NORMAL; |
| 114 InitFromDetails(skia::RefPtr<SkTypeface>(), font_name, font_size_pixels, | 114 InitFromDetails(skia::RefPtr<SkTypeface>(), font_name, font_size_pixels, |
| 115 query.style, gfx::GetFontRenderParams(query, NULL)); | 115 query.style, gfx::GetFontRenderParams(query, NULL)); |
| 116 } | 116 } |
| 117 | 117 |
| 118 //////////////////////////////////////////////////////////////////////////////// | 118 //////////////////////////////////////////////////////////////////////////////// |
| 119 // PlatformFontLinux, PlatformFont implementation: | 119 // PlatformFontLinux, PlatformFont implementation: |
| 120 | 120 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 136 | 136 |
| 137 Font PlatformFontLinux::DeriveFont(int size_delta, int style) const { | 137 Font PlatformFontLinux::DeriveFont(int size_delta, int style) const { |
| 138 const int new_size = font_size_pixels_ + size_delta; | 138 const int new_size = font_size_pixels_ + size_delta; |
| 139 DCHECK_GT(new_size, 0); | 139 DCHECK_GT(new_size, 0); |
| 140 | 140 |
| 141 // If the style changed, we may need to load a new face. | 141 // If the style changed, we may need to load a new face. |
| 142 std::string new_family = font_family_; | 142 std::string new_family = font_family_; |
| 143 skia::RefPtr<SkTypeface> typeface = | 143 skia::RefPtr<SkTypeface> typeface = |
| 144 (style == style_) ? typeface_ : CreateSkTypeface(style, &new_family); | 144 (style == style_) ? typeface_ : CreateSkTypeface(style, &new_family); |
| 145 | 145 |
| 146 FontRenderParamsQuery query(false); | 146 FontRenderParamsQuery query; |
| 147 query.families.push_back(new_family); | 147 query.families.push_back(new_family); |
| 148 query.pixel_size = new_size; | 148 query.pixel_size = new_size; |
| 149 query.style = style; | 149 query.style = style; |
| 150 | 150 |
| 151 return Font(new PlatformFontLinux(typeface, new_family, new_size, style, | 151 return Font(new PlatformFontLinux(typeface, new_family, new_size, style, |
| 152 gfx::GetFontRenderParams(query, NULL))); | 152 gfx::GetFontRenderParams(query, NULL))); |
| 153 } | 153 } |
| 154 | 154 |
| 155 int PlatformFontLinux::GetHeight() const { | 155 int PlatformFontLinux::GetHeight() const { |
| 156 return height_pixels_; | 156 return height_pixels_; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 183 } | 183 } |
| 184 | 184 |
| 185 int PlatformFontLinux::GetFontSize() const { | 185 int PlatformFontLinux::GetFontSize() const { |
| 186 return font_size_pixels_; | 186 return font_size_pixels_; |
| 187 } | 187 } |
| 188 | 188 |
| 189 const FontRenderParams& PlatformFontLinux::GetFontRenderParams() { | 189 const FontRenderParams& PlatformFontLinux::GetFontRenderParams() { |
| 190 #if defined(OS_CHROMEOS) | 190 #if defined(OS_CHROMEOS) |
| 191 float current_scale_factor = GetFontRenderParamsDeviceScaleFactor(); | 191 float current_scale_factor = GetFontRenderParamsDeviceScaleFactor(); |
| 192 if (current_scale_factor != device_scale_factor_) { | 192 if (current_scale_factor != device_scale_factor_) { |
| 193 FontRenderParamsQuery query(false); | 193 FontRenderParamsQuery query; |
| 194 query.families.push_back(font_family_); | 194 query.families.push_back(font_family_); |
| 195 query.pixel_size = font_size_pixels_; | 195 query.pixel_size = font_size_pixels_; |
| 196 query.style = style_; | 196 query.style = style_; |
| 197 query.device_scale_factor = current_scale_factor; | 197 query.device_scale_factor = current_scale_factor; |
| 198 font_render_params_ = gfx::GetFontRenderParams(query, nullptr); | 198 font_render_params_ = gfx::GetFontRenderParams(query, nullptr); |
| 199 device_scale_factor_ = current_scale_factor; | 199 device_scale_factor_ = current_scale_factor; |
| 200 } | 200 } |
| 201 #endif | 201 #endif |
| 202 return font_render_params_; | 202 return font_render_params_; |
| 203 } | 203 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 return new PlatformFontLinux; | 272 return new PlatformFontLinux; |
| 273 } | 273 } |
| 274 | 274 |
| 275 // static | 275 // static |
| 276 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, | 276 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, |
| 277 int font_size) { | 277 int font_size) { |
| 278 return new PlatformFontLinux(font_name, font_size); | 278 return new PlatformFontLinux(font_name, font_size); |
| 279 } | 279 } |
| 280 | 280 |
| 281 } // namespace gfx | 281 } // namespace gfx |
| OLD | NEW |