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 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 } | 279 } |
280 | 280 |
281 void PlatformFontLinux::ComputeMetricsIfNecessary() { | 281 void PlatformFontLinux::ComputeMetricsIfNecessary() { |
282 if (metrics_need_computation_) { | 282 if (metrics_need_computation_) { |
283 metrics_need_computation_ = false; | 283 metrics_need_computation_ = false; |
284 | 284 |
285 SkPaint paint; | 285 SkPaint paint; |
286 paint.setAntiAlias(false); | 286 paint.setAntiAlias(false); |
287 paint.setSubpixelText(false); | 287 paint.setSubpixelText(false); |
288 paint.setTextSize(font_size_pixels_); | 288 paint.setTextSize(font_size_pixels_); |
289 paint.setTypeface(typeface_.get()); | 289 paint.setTypeface(typeface_); |
290 paint.setFakeBoldText(weight_ >= Font::Weight::BOLD && | 290 paint.setFakeBoldText(weight_ >= Font::Weight::BOLD && |
291 !typeface_->isBold()); | 291 !typeface_->isBold()); |
292 paint.setTextSkewX((Font::ITALIC & style_) && !typeface_->isItalic() ? | 292 paint.setTextSkewX((Font::ITALIC & style_) && !typeface_->isItalic() ? |
293 -SK_Scalar1/4 : 0); | 293 -SK_Scalar1/4 : 0); |
294 SkPaint::FontMetrics metrics; | 294 SkPaint::FontMetrics metrics; |
295 paint.getFontMetrics(&metrics); | 295 paint.getFontMetrics(&metrics); |
296 ascent_pixels_ = SkScalarCeilToInt(-metrics.fAscent); | 296 ascent_pixels_ = SkScalarCeilToInt(-metrics.fAscent); |
297 height_pixels_ = ascent_pixels_ + SkScalarCeilToInt(metrics.fDescent); | 297 height_pixels_ = ascent_pixels_ + SkScalarCeilToInt(metrics.fDescent); |
298 cap_height_pixels_ = SkScalarCeilToInt(metrics.fCapHeight); | 298 cap_height_pixels_ = SkScalarCeilToInt(metrics.fCapHeight); |
299 average_width_pixels_ = SkScalarToDouble(metrics.fAvgCharWidth); | 299 average_width_pixels_ = SkScalarToDouble(metrics.fAvgCharWidth); |
300 } | 300 } |
301 } | 301 } |
302 | 302 |
303 //////////////////////////////////////////////////////////////////////////////// | 303 //////////////////////////////////////////////////////////////////////////////// |
304 // PlatformFont, public: | 304 // PlatformFont, public: |
305 | 305 |
306 // static | 306 // static |
307 PlatformFont* PlatformFont::CreateDefault() { | 307 PlatformFont* PlatformFont::CreateDefault() { |
308 return new PlatformFontLinux; | 308 return new PlatformFontLinux; |
309 } | 309 } |
310 | 310 |
311 // static | 311 // static |
312 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, | 312 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, |
313 int font_size) { | 313 int font_size) { |
314 return new PlatformFontLinux(font_name, font_size); | 314 return new PlatformFontLinux(font_name, font_size); |
315 } | 315 } |
316 | 316 |
317 } // namespace gfx | 317 } // namespace gfx |
OLD | NEW |