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 <pango/pango.h> | 7 #include <pango/pango.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <string> | 10 #include <string> |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 SkString family_name; | 195 SkString family_name; |
196 typeface_->getFamilyName(&family_name); | 196 typeface_->getFamilyName(&family_name); |
197 return family_name.c_str(); | 197 return family_name.c_str(); |
198 } | 198 } |
199 | 199 |
200 int PlatformFontPango::GetFontSize() const { | 200 int PlatformFontPango::GetFontSize() const { |
201 return font_size_pixels_; | 201 return font_size_pixels_; |
202 } | 202 } |
203 | 203 |
204 const FontRenderParams& PlatformFontPango::GetFontRenderParams() const { | 204 const FontRenderParams& PlatformFontPango::GetFontRenderParams() const { |
| 205 #if defined(OS_CHROMEOS) |
| 206 float current_scale_factor = gfx::GetFontRenderParamsDeviceScaleFactor(); |
| 207 if (current_scale_factor != device_scale_factor_) { |
| 208 FontRenderParamsQuery query(false); |
| 209 query.families.push_back(font_family_); |
| 210 query.pixel_size = font_size_pixels_; |
| 211 query.style = style_; |
| 212 query.device_scale_factor = current_scale_factor; |
| 213 font_render_params_ = gfx::GetFontRenderParams(query, nullptr); |
| 214 device_scale_factor_ = current_scale_factor; |
| 215 } |
| 216 #endif |
205 return font_render_params_; | 217 return font_render_params_; |
206 } | 218 } |
207 | 219 |
208 NativeFont PlatformFontPango::GetNativeFont() const { | 220 NativeFont PlatformFontPango::GetNativeFont() const { |
209 PangoFontDescription* pfd = pango_font_description_new(); | 221 PangoFontDescription* pfd = pango_font_description_new(); |
210 pango_font_description_set_family(pfd, GetFontName().c_str()); | 222 pango_font_description_set_family(pfd, GetFontName().c_str()); |
211 // Set the absolute size to avoid overflowing UI elements. | 223 // Set the absolute size to avoid overflowing UI elements. |
212 // pango_font_description_set_absolute_size() takes a size in Pango units. | 224 // pango_font_description_set_absolute_size() takes a size in Pango units. |
213 // There are PANGO_SCALE Pango units in one device unit. Screen output | 225 // There are PANGO_SCALE Pango units in one device unit. Screen output |
214 // devices use pixels as their device units. | 226 // devices use pixels as their device units. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 int font_size_pixels, | 265 int font_size_pixels, |
254 int style, | 266 int style, |
255 const FontRenderParams& render_params) { | 267 const FontRenderParams& render_params) { |
256 DCHECK_GT(font_size_pixels, 0); | 268 DCHECK_GT(font_size_pixels, 0); |
257 | 269 |
258 font_family_ = font_family; | 270 font_family_ = font_family; |
259 typeface_ = typeface ? typeface : CreateSkTypeface(style, &font_family_); | 271 typeface_ = typeface ? typeface : CreateSkTypeface(style, &font_family_); |
260 | 272 |
261 font_size_pixels_ = font_size_pixels; | 273 font_size_pixels_ = font_size_pixels; |
262 style_ = style; | 274 style_ = style; |
| 275 #if defined(OS_CHROMEOS) |
| 276 device_scale_factor_ = gfx::GetFontRenderParamsDeviceScaleFactor(); |
| 277 #endif |
263 font_render_params_ = render_params; | 278 font_render_params_ = render_params; |
264 | 279 |
265 SkPaint paint; | 280 SkPaint paint; |
266 SkPaint::FontMetrics metrics; | 281 SkPaint::FontMetrics metrics; |
267 PaintSetup(&paint); | 282 PaintSetup(&paint); |
268 paint.getFontMetrics(&metrics); | 283 paint.getFontMetrics(&metrics); |
269 ascent_pixels_ = SkScalarCeilToInt(-metrics.fAscent); | 284 ascent_pixels_ = SkScalarCeilToInt(-metrics.fAscent); |
270 height_pixels_ = ascent_pixels_ + SkScalarCeilToInt(metrics.fDescent); | 285 height_pixels_ = ascent_pixels_ + SkScalarCeilToInt(metrics.fDescent); |
271 cap_height_pixels_ = SkScalarCeilToInt(metrics.fCapHeight); | 286 cap_height_pixels_ = SkScalarCeilToInt(metrics.fCapHeight); |
272 | 287 |
273 pango_metrics_inited_ = false; | 288 pango_metrics_inited_ = false; |
274 average_width_pixels_ = 0.0f; | 289 average_width_pixels_ = 0.0f; |
275 } | 290 } |
276 | 291 |
277 void PlatformFontPango::InitFromPlatformFont(const PlatformFontPango* other) { | 292 void PlatformFontPango::InitFromPlatformFont(const PlatformFontPango* other) { |
278 typeface_ = other->typeface_; | 293 typeface_ = other->typeface_; |
279 font_family_ = other->font_family_; | 294 font_family_ = other->font_family_; |
280 font_size_pixels_ = other->font_size_pixels_; | 295 font_size_pixels_ = other->font_size_pixels_; |
281 style_ = other->style_; | 296 style_ = other->style_; |
282 font_render_params_ = other->font_render_params_; | 297 font_render_params_ = other->font_render_params_; |
283 ascent_pixels_ = other->ascent_pixels_; | 298 ascent_pixels_ = other->ascent_pixels_; |
284 height_pixels_ = other->height_pixels_; | 299 height_pixels_ = other->height_pixels_; |
285 cap_height_pixels_ = other->cap_height_pixels_; | 300 cap_height_pixels_ = other->cap_height_pixels_; |
286 pango_metrics_inited_ = other->pango_metrics_inited_; | 301 pango_metrics_inited_ = other->pango_metrics_inited_; |
287 average_width_pixels_ = other->average_width_pixels_; | 302 average_width_pixels_ = other->average_width_pixels_; |
| 303 #if defined(OS_CHROMEOS) |
| 304 device_scale_factor_ = other->device_scale_factor_; |
| 305 #endif |
288 } | 306 } |
289 | 307 |
290 void PlatformFontPango::PaintSetup(SkPaint* paint) const { | 308 void PlatformFontPango::PaintSetup(SkPaint* paint) const { |
291 paint->setAntiAlias(false); | 309 paint->setAntiAlias(false); |
292 paint->setSubpixelText(false); | 310 paint->setSubpixelText(false); |
293 paint->setTextSize(font_size_pixels_); | 311 paint->setTextSize(font_size_pixels_); |
294 paint->setTypeface(typeface_.get()); | 312 paint->setTypeface(typeface_.get()); |
295 paint->setFakeBoldText((gfx::Font::BOLD & style_) && !typeface_->isBold()); | 313 paint->setFakeBoldText((gfx::Font::BOLD & style_) && !typeface_->isBold()); |
296 paint->setTextSkewX((gfx::Font::ITALIC & style_) && !typeface_->isItalic() ? | 314 paint->setTextSkewX((gfx::Font::ITALIC & style_) && !typeface_->isItalic() ? |
297 -SK_Scalar1/4 : 0); | 315 -SK_Scalar1/4 : 0); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 return new PlatformFontPango(native_font); | 355 return new PlatformFontPango(native_font); |
338 } | 356 } |
339 | 357 |
340 // static | 358 // static |
341 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, | 359 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, |
342 int font_size) { | 360 int font_size) { |
343 return new PlatformFontPango(font_name, font_size); | 361 return new PlatformFontPango(font_name, font_size); |
344 } | 362 } |
345 | 363 |
346 } // namespace gfx | 364 } // namespace gfx |
OLD | NEW |