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) What should we do about other weights? We currently only |
msw
2014/07/23 22:16:35
nit: one-liner "TODO(davemoore) Support weights ot
Daniel Erat
2014/07/23 22:47:18
Done.
| |
109 // support BOLD. | 110 // support BOLD. |
110 if (pango_font_description_get_weight(native_font) == PANGO_WEIGHT_BOLD) | 111 if (pango_font_description_get_weight(native_font) == PANGO_WEIGHT_BOLD) |
111 style |= gfx::Font::BOLD; | 112 query.style |= gfx::Font::BOLD; |
112 // TODO(davemoore) What about PANGO_STYLE_OBLIQUE? | 113 // TODO(davemoore) What about PANGO_STYLE_OBLIQUE? |
113 if (pango_font_description_get_style(native_font) == PANGO_STYLE_ITALIC) | 114 if (pango_font_description_get_style(native_font) == PANGO_STYLE_ITALIC) |
114 style |= gfx::Font::ITALIC; | 115 query.style |= gfx::Font::ITALIC; |
115 | 116 |
116 const FontRenderParams params = GetCustomFontRenderParams( | 117 std::string font_family; |
117 false, &family_names, | 118 const FontRenderParams params = gfx::GetFontRenderParams(query, &font_family); |
msw
2014/07/23 22:16:35
nit: maybe inline this below?
Daniel Erat
2014/07/23 22:47:18
seems scary since it updates |font_family|, which
msw
2014/07/23 22:54:31
Acknowledged.
| |
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, | 119 InitFromDetails(skia::RefPtr<SkTypeface>(), font_family, |
123 gfx::GetPangoFontSizeInPixels(native_font), style, params); | 120 gfx::GetPangoFontSizeInPixels(native_font), |
121 query.style, params); | |
124 } | 122 } |
125 | 123 |
126 PlatformFontPango::PlatformFontPango(const std::string& font_name, | 124 PlatformFontPango::PlatformFontPango(const std::string& font_name, |
127 int font_size_pixels) { | 125 int font_size_pixels) { |
128 const std::vector<std::string> font_list(1, font_name); | 126 FontRenderParamsQuery query(false); |
129 const int style = Font::NORMAL; | 127 query.families.push_back(font_name); |
130 const FontRenderParams params = GetCustomFontRenderParams( | 128 query.pixel_size = font_size_pixels; |
131 false, &font_list, &font_size_pixels, NULL, &style, NULL); | 129 query.style = gfx::Font::NORMAL; |
msw
2014/07/23 22:16:35
Should this omit the style from the query if it's
Daniel Erat
2014/07/23 22:47:18
i think that requesting normal here is the right t
msw
2014/07/23 22:54:31
Acknowledged.
| |
130 const FontRenderParams params = gfx::GetFontRenderParams(query, NULL); | |
msw
2014/07/23 22:16:35
nit: maybe inline this below?
Daniel Erat
2014/07/23 22:47:18
Done.
| |
132 InitFromDetails(skia::RefPtr<SkTypeface>(), font_name, font_size_pixels, | 131 InitFromDetails(skia::RefPtr<SkTypeface>(), font_name, font_size_pixels, |
133 style, params); | 132 query.style, params); |
134 } | 133 } |
135 | 134 |
136 double PlatformFontPango::underline_position() const { | 135 double PlatformFontPango::underline_position() const { |
137 const_cast<PlatformFontPango*>(this)->InitPangoMetrics(); | 136 const_cast<PlatformFontPango*>(this)->InitPangoMetrics(); |
138 return underline_position_pixels_; | 137 return underline_position_pixels_; |
139 } | 138 } |
140 | 139 |
141 double PlatformFontPango::underline_thickness() const { | 140 double PlatformFontPango::underline_thickness() const { |
142 const_cast<PlatformFontPango*>(this)->InitPangoMetrics(); | 141 const_cast<PlatformFontPango*>(this)->InitPangoMetrics(); |
143 return underline_thickness_pixels_; | 142 return underline_thickness_pixels_; |
(...skipping 20 matching lines...) Expand all Loading... | |
164 | 163 |
165 Font PlatformFontPango::DeriveFont(int size_delta, int style) const { | 164 Font PlatformFontPango::DeriveFont(int size_delta, int style) const { |
166 const int new_size = font_size_pixels_ + size_delta; | 165 const int new_size = font_size_pixels_ + size_delta; |
167 DCHECK_GT(new_size, 0); | 166 DCHECK_GT(new_size, 0); |
168 | 167 |
169 // If the style changed, we may need to load a new face. | 168 // If the style changed, we may need to load a new face. |
170 std::string new_family = font_family_; | 169 std::string new_family = font_family_; |
171 skia::RefPtr<SkTypeface> typeface = | 170 skia::RefPtr<SkTypeface> typeface = |
172 (style == style_) ? typeface_ : CreateSkTypeface(style, &new_family); | 171 (style == style_) ? typeface_ : CreateSkTypeface(style, &new_family); |
173 | 172 |
174 const std::vector<std::string> family_list(1, new_family); | 173 FontRenderParamsQuery query(false); |
175 const FontRenderParams render_params = GetCustomFontRenderParams( | 174 query.families.push_back(new_family); |
176 false, &family_list, &new_size, NULL, &style, NULL); | 175 query.pixel_size = new_size; |
176 query.style = style; | |
177 const FontRenderParams render_params = gfx::GetFontRenderParams(query, NULL); | |
msw
2014/07/23 22:16:35
nit: maybe inline this below?
Daniel Erat
2014/07/23 22:47:18
Done.
| |
177 | 178 |
178 return Font(new PlatformFontPango(typeface, | 179 return Font(new PlatformFontPango(typeface, |
179 new_family, | 180 new_family, |
180 new_size, | 181 new_size, |
181 style, | 182 style, |
182 render_params)); | 183 render_params)); |
183 } | 184 } |
184 | 185 |
185 int PlatformFontPango::GetHeight() const { | 186 int PlatformFontPango::GetHeight() const { |
186 return height_pixels_; | 187 return height_pixels_; |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
370 return new PlatformFontPango(native_font); | 371 return new PlatformFontPango(native_font); |
371 } | 372 } |
372 | 373 |
373 // static | 374 // static |
374 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, | 375 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, |
375 int font_size) { | 376 int font_size) { |
376 return new PlatformFontPango(font_name, font_size); | 377 return new PlatformFontPango(font_name, font_size); |
377 } | 378 } |
378 | 379 |
379 } // namespace gfx | 380 } // namespace gfx |
OLD | NEW |