Chromium Code Reviews| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 if (!description || !description->get()) | 87 if (!description || !description->get()) |
| 88 description.reset(new ScopedPangoFontDescription("sans 10")); | 88 description.reset(new ScopedPangoFontDescription("sans 10")); |
| 89 default_font_ = new Font(description->get()); | 89 default_font_ = new Font(description->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 std::string font_family; | |
| 98 std::vector<std::string> family_names; | |
| 99 base::SplitString(pango_font_description_get_family(native_font), ',', | |
| 100 &family_names); | |
| 101 | |
| 97 const int pango_size = | 102 const int pango_size = |
| 98 pango_font_description_get_size(native_font) / PANGO_SCALE; | 103 pango_font_description_get_size(native_font) / PANGO_SCALE; |
| 99 const bool pango_using_pixels = | 104 const bool pango_using_pixels = |
| 100 pango_font_description_get_size_is_absolute(native_font); | 105 pango_font_description_get_size_is_absolute(native_font); |
| 101 | 106 |
| 102 std::string font_family; | |
| 103 std::vector<std::string> family_names; | |
| 104 base::SplitString(pango_font_description_get_family(native_font), ',', | |
| 105 &family_names); | |
| 106 const FontRenderParams params = GetCustomFontRenderParams( | |
| 107 false, &family_names, | |
| 108 pango_using_pixels ? &pango_size : NULL /* pixel_size */, | |
| 109 !pango_using_pixels ? &pango_size : NULL /* point_size */, | |
| 110 &font_family); | |
| 111 | |
| 112 int style = 0; | 107 int style = 0; |
| 113 // TODO(davemoore) What should we do about other weights? We currently only | 108 // TODO(davemoore) What should we do about other weights? We currently only |
| 114 // support BOLD. | 109 // support BOLD. |
| 115 if (pango_font_description_get_weight(native_font) == PANGO_WEIGHT_BOLD) | 110 if (pango_font_description_get_weight(native_font) == PANGO_WEIGHT_BOLD) |
| 116 style |= gfx::Font::BOLD; | 111 style |= gfx::Font::BOLD; |
| 117 // TODO(davemoore) What about PANGO_STYLE_OBLIQUE? | 112 // TODO(davemoore) What about PANGO_STYLE_OBLIQUE? |
| 118 if (pango_font_description_get_style(native_font) == PANGO_STYLE_ITALIC) | 113 if (pango_font_description_get_style(native_font) == PANGO_STYLE_ITALIC) |
| 119 style |= gfx::Font::ITALIC; | 114 style |= gfx::Font::ITALIC; |
| 120 | 115 |
| 116 const FontRenderParams params = GetCustomFontRenderParams( | |
| 117 false, &family_names, | |
| 118 pango_using_pixels ? &pango_size : NULL /* pixel_size */, | |
| 119 !pango_using_pixels ? &pango_size : NULL /* point_size */, | |
| 120 &style, &font_family); | |
| 121 | |
| 121 InitFromDetails(skia::RefPtr<SkTypeface>(), font_family, | 122 InitFromDetails(skia::RefPtr<SkTypeface>(), font_family, |
| 122 gfx::GetPangoFontSizeInPixels(native_font), style, params); | 123 gfx::GetPangoFontSizeInPixels(native_font), style, params); |
| 123 } | 124 } |
| 124 | 125 |
| 125 PlatformFontPango::PlatformFontPango(const std::string& font_name, | 126 PlatformFontPango::PlatformFontPango(const std::string& font_name, |
| 126 int font_size_pixels) { | 127 int font_size_pixels) { |
| 127 const std::vector<std::string> font_list(1, font_name); | 128 const std::vector<std::string> font_list(1, font_name); |
| 129 const int style = Font::NORMAL; | |
| 128 const FontRenderParams params = GetCustomFontRenderParams( | 130 const FontRenderParams params = GetCustomFontRenderParams( |
| 129 false, &font_list, &font_size_pixels, NULL, NULL); | 131 false, &font_list, &font_size_pixels, NULL, &style, NULL); |
| 130 InitFromDetails(skia::RefPtr<SkTypeface>(), font_name, font_size_pixels, | 132 InitFromDetails(skia::RefPtr<SkTypeface>(), font_name, font_size_pixels, |
| 131 SkTypeface::kNormal, params); | 133 style, params); |
|
Daniel Erat
2014/07/19 01:34:44
this was a bug, but luckily both enums use 0 for "
msw
2014/07/19 03:11:52
Acknowledged; thanks for fixing it.
| |
| 132 } | 134 } |
| 133 | 135 |
| 134 double PlatformFontPango::underline_position() const { | 136 double PlatformFontPango::underline_position() const { |
| 135 const_cast<PlatformFontPango*>(this)->InitPangoMetrics(); | 137 const_cast<PlatformFontPango*>(this)->InitPangoMetrics(); |
| 136 return underline_position_pixels_; | 138 return underline_position_pixels_; |
| 137 } | 139 } |
| 138 | 140 |
| 139 double PlatformFontPango::underline_thickness() const { | 141 double PlatformFontPango::underline_thickness() const { |
| 140 const_cast<PlatformFontPango*>(this)->InitPangoMetrics(); | 142 const_cast<PlatformFontPango*>(this)->InitPangoMetrics(); |
| 141 return underline_thickness_pixels_; | 143 return underline_thickness_pixels_; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 162 | 164 |
| 163 Font PlatformFontPango::DeriveFont(int size_delta, int style) const { | 165 Font PlatformFontPango::DeriveFont(int size_delta, int style) const { |
| 164 const int new_size = font_size_pixels_ + size_delta; | 166 const int new_size = font_size_pixels_ + size_delta; |
| 165 DCHECK_GT(new_size, 0); | 167 DCHECK_GT(new_size, 0); |
| 166 | 168 |
| 167 // If the style changed, we may need to load a new face. | 169 // If the style changed, we may need to load a new face. |
| 168 std::string new_family = font_family_; | 170 std::string new_family = font_family_; |
| 169 skia::RefPtr<SkTypeface> typeface = | 171 skia::RefPtr<SkTypeface> typeface = |
| 170 (style == style_) ? typeface_ : CreateSkTypeface(style, &new_family); | 172 (style == style_) ? typeface_ : CreateSkTypeface(style, &new_family); |
| 171 | 173 |
| 172 // If the size or family changed, get updated rendering settings. | 174 const std::vector<std::string> family_list(1, new_family); |
| 173 FontRenderParams render_params = font_render_params_; | 175 const FontRenderParams render_params = GetCustomFontRenderParams( |
| 174 if (size_delta != 0 || new_family != font_family_) { | 176 false, &family_list, &new_size, NULL, &style, NULL); |
| 175 const std::vector<std::string> family_list(1, new_family); | |
| 176 render_params = GetCustomFontRenderParams( | |
| 177 false, &family_list, &new_size, NULL, NULL); | |
| 178 } | |
| 179 | 177 |
| 180 return Font(new PlatformFontPango(typeface, | 178 return Font(new PlatformFontPango(typeface, |
| 181 new_family, | 179 new_family, |
| 182 new_size, | 180 new_size, |
| 183 style, | 181 style, |
| 184 render_params)); | 182 render_params)); |
| 185 } | 183 } |
| 186 | 184 |
| 187 int PlatformFontPango::GetHeight() const { | 185 int PlatformFontPango::GetHeight() const { |
| 188 return height_pixels_; | 186 return height_pixels_; |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 372 return new PlatformFontPango(native_font); | 370 return new PlatformFontPango(native_font); |
| 373 } | 371 } |
| 374 | 372 |
| 375 // static | 373 // static |
| 376 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, | 374 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, |
| 377 int font_size) { | 375 int font_size) { |
| 378 return new PlatformFontPango(font_name, font_size); | 376 return new PlatformFontPango(font_name, font_size); |
| 379 } | 377 } |
| 380 | 378 |
| 381 } // namespace gfx | 379 } // namespace gfx |
| OLD | NEW |