| 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; | 97 FontRenderParamsQuery query(false); |
| 98 std::vector<std::string> family_names; | |
| 99 base::SplitString(pango_font_description_get_family(native_font), ',', | 98 base::SplitString(pango_font_description_get_family(native_font), ',', |
| 100 &family_names); | 99 &query.families); |
| 101 | 100 |
| 102 const int pango_size = | 101 const int pango_size = |
| 103 pango_font_description_get_size(native_font) / PANGO_SCALE; | 102 pango_font_description_get_size(native_font) / PANGO_SCALE; |
| 104 const bool pango_using_pixels = | 103 if (pango_font_description_get_size_is_absolute(native_font)) |
| 105 pango_font_description_get_size_is_absolute(native_font); | 104 query.pixel_size = pango_size; |
| 105 else |
| 106 query.point_size = pango_size; |
| 106 | 107 |
| 107 int style = 0; | 108 query.style = gfx::Font::NORMAL; |
| 108 // TODO(davemoore) What should we do about other weights? We currently only | 109 // TODO(davemoore): Support weights other than bold? |
| 109 // support BOLD. | |
| 110 if (pango_font_description_get_weight(native_font) == PANGO_WEIGHT_BOLD) | 110 if (pango_font_description_get_weight(native_font) == PANGO_WEIGHT_BOLD) |
| 111 style |= gfx::Font::BOLD; | 111 query.style |= gfx::Font::BOLD; |
| 112 // TODO(davemoore) What about PANGO_STYLE_OBLIQUE? | 112 // TODO(davemoore): What about PANGO_STYLE_OBLIQUE? |
| 113 if (pango_font_description_get_style(native_font) == PANGO_STYLE_ITALIC) | 113 if (pango_font_description_get_style(native_font) == PANGO_STYLE_ITALIC) |
| 114 style |= gfx::Font::ITALIC; | 114 query.style |= gfx::Font::ITALIC; |
| 115 | 115 |
| 116 const FontRenderParams params = GetCustomFontRenderParams( | 116 std::string font_family; |
| 117 false, &family_names, | 117 const FontRenderParams params = gfx::GetFontRenderParams(query, &font_family); |
| 118 pango_using_pixels ? &pango_size : NULL /* pixel_size */, | |
| 119 !pango_using_pixels ? &pango_size : NULL /* point_size */, | |
| 120 &style, &font_family); | |
| 121 | |
| 122 InitFromDetails(skia::RefPtr<SkTypeface>(), font_family, | 118 InitFromDetails(skia::RefPtr<SkTypeface>(), font_family, |
| 123 gfx::GetPangoFontSizeInPixels(native_font), style, params); | 119 gfx::GetPangoFontSizeInPixels(native_font), |
| 120 query.style, params); |
| 124 } | 121 } |
| 125 | 122 |
| 126 PlatformFontPango::PlatformFontPango(const std::string& font_name, | 123 PlatformFontPango::PlatformFontPango(const std::string& font_name, |
| 127 int font_size_pixels) { | 124 int font_size_pixels) { |
| 128 const std::vector<std::string> font_list(1, font_name); | 125 FontRenderParamsQuery query(false); |
| 129 const int style = Font::NORMAL; | 126 query.families.push_back(font_name); |
| 130 const FontRenderParams params = GetCustomFontRenderParams( | 127 query.pixel_size = font_size_pixels; |
| 131 false, &font_list, &font_size_pixels, NULL, &style, NULL); | 128 query.style = gfx::Font::NORMAL; |
| 132 InitFromDetails(skia::RefPtr<SkTypeface>(), font_name, font_size_pixels, | 129 InitFromDetails(skia::RefPtr<SkTypeface>(), font_name, font_size_pixels, |
| 133 style, params); | 130 query.style, gfx::GetFontRenderParams(query, NULL)); |
| 134 } | 131 } |
| 135 | 132 |
| 136 double PlatformFontPango::underline_position() const { | 133 double PlatformFontPango::underline_position() const { |
| 137 const_cast<PlatformFontPango*>(this)->InitPangoMetrics(); | 134 const_cast<PlatformFontPango*>(this)->InitPangoMetrics(); |
| 138 return underline_position_pixels_; | 135 return underline_position_pixels_; |
| 139 } | 136 } |
| 140 | 137 |
| 141 double PlatformFontPango::underline_thickness() const { | 138 double PlatformFontPango::underline_thickness() const { |
| 142 const_cast<PlatformFontPango*>(this)->InitPangoMetrics(); | 139 const_cast<PlatformFontPango*>(this)->InitPangoMetrics(); |
| 143 return underline_thickness_pixels_; | 140 return underline_thickness_pixels_; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 164 | 161 |
| 165 Font PlatformFontPango::DeriveFont(int size_delta, int style) const { | 162 Font PlatformFontPango::DeriveFont(int size_delta, int style) const { |
| 166 const int new_size = font_size_pixels_ + size_delta; | 163 const int new_size = font_size_pixels_ + size_delta; |
| 167 DCHECK_GT(new_size, 0); | 164 DCHECK_GT(new_size, 0); |
| 168 | 165 |
| 169 // If the style changed, we may need to load a new face. | 166 // If the style changed, we may need to load a new face. |
| 170 std::string new_family = font_family_; | 167 std::string new_family = font_family_; |
| 171 skia::RefPtr<SkTypeface> typeface = | 168 skia::RefPtr<SkTypeface> typeface = |
| 172 (style == style_) ? typeface_ : CreateSkTypeface(style, &new_family); | 169 (style == style_) ? typeface_ : CreateSkTypeface(style, &new_family); |
| 173 | 170 |
| 174 const std::vector<std::string> family_list(1, new_family); | 171 FontRenderParamsQuery query(false); |
| 175 const FontRenderParams render_params = GetCustomFontRenderParams( | 172 query.families.push_back(new_family); |
| 176 false, &family_list, &new_size, NULL, &style, NULL); | 173 query.pixel_size = new_size; |
| 174 query.style = style; |
| 177 | 175 |
| 178 return Font(new PlatformFontPango(typeface, | 176 return Font(new PlatformFontPango(typeface, new_family, new_size, style, |
| 179 new_family, | 177 gfx::GetFontRenderParams(query, NULL))); |
| 180 new_size, | |
| 181 style, | |
| 182 render_params)); | |
| 183 } | 178 } |
| 184 | 179 |
| 185 int PlatformFontPango::GetHeight() const { | 180 int PlatformFontPango::GetHeight() const { |
| 186 return height_pixels_; | 181 return height_pixels_; |
| 187 } | 182 } |
| 188 | 183 |
| 189 int PlatformFontPango::GetBaseline() const { | 184 int PlatformFontPango::GetBaseline() const { |
| 190 return ascent_pixels_; | 185 return ascent_pixels_; |
| 191 } | 186 } |
| 192 | 187 |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 return new PlatformFontPango(native_font); | 365 return new PlatformFontPango(native_font); |
| 371 } | 366 } |
| 372 | 367 |
| 373 // static | 368 // static |
| 374 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, | 369 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, |
| 375 int font_size) { | 370 int font_size) { |
| 376 return new PlatformFontPango(font_name, font_size); | 371 return new PlatformFontPango(font_name, font_size); |
| 377 } | 372 } |
| 378 | 373 |
| 379 } // namespace gfx | 374 } // namespace gfx |
| OLD | NEW |