Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: app/gfx/font_skia.cc

Issue 207009: Workaround for Issue 15949: cannot use the "WenQuanYi Bitmap Song" (chinese F... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "app/gfx/font.h" 5 #include "app/gfx/font.h"
6 6
7 #include "app/gfx/canvas.h" 7 #include "app/gfx/canvas.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/string_piece.h"
9 #include "base/sys_string_conversions.h" 10 #include "base/sys_string_conversions.h"
10 #include "third_party/skia/include/core/SkTypeface.h" 11 #include "third_party/skia/include/core/SkTypeface.h"
11 #include "third_party/skia/include/core/SkPaint.h" 12 #include "third_party/skia/include/core/SkPaint.h"
12 13
14 namespace {
15
16 // The font family name which is used when a user's application font for
17 // GNOME/KDE is a non-scalable one. The name should be listed in the
18 // IsFallbackFontAllowed function in skia/ext/SkFontHost_fontconfig_direct.cpp.
19 const char* kFallbackFontFamilyName = "sans";
20
21 } // namespace
22
13 namespace gfx { 23 namespace gfx {
14 24
15 Font::Font(const Font& other) { 25 Font::Font(const Font& other) {
16 CopyFont(other); 26 CopyFont(other);
17 } 27 }
18 28
19 Font& Font::operator=(const Font& other) { 29 Font& Font::operator=(const Font& other) {
20 CopyFont(other); 30 CopyFont(other);
21 return *this; 31 return *this;
22 } 32 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 int Font::baseline() const { 92 int Font::baseline() const {
83 return ascent_; 93 return ascent_;
84 } 94 }
85 95
86 int Font::ave_char_width() const { 96 int Font::ave_char_width() const {
87 return avg_width_; 97 return avg_width_;
88 } 98 }
89 99
90 Font Font::CreateFont(const std::wstring& font_family, int font_size) { 100 Font Font::CreateFont(const std::wstring& font_family, int font_size) {
91 DCHECK_GT(font_size, 0); 101 DCHECK_GT(font_size, 0);
102 std::wstring fallback;
92 103
93 SkTypeface* tf = SkTypeface::CreateFromName( 104 SkTypeface* tf = SkTypeface::CreateFromName(
94 base::SysWideToUTF8(font_family).c_str(), SkTypeface::kNormal); 105 base::SysWideToUTF8(font_family).c_str(), SkTypeface::kNormal);
95 // Temporary CHECK for tracking down 106 if (!tf) {
96 // http://code.google.com/p/chromium/issues/detail?id=12530 107 // A non-scalable font such as .pcf is specified. Falls back to a default
97 CHECK(tf) << "Could not find font: " << base::SysWideToUTF8(font_family); 108 // scalable font.
109 tf = SkTypeface::CreateFromName(
110 kFallbackFontFamilyName, SkTypeface::kNormal);
111 CHECK(tf) << "Could not find any font: "
112 << base::SysWideToUTF8(font_family)
113 << ", " << kFallbackFontFamilyName;
114 fallback = base::SysUTF8ToWide(kFallbackFontFamilyName);
115 }
98 SkAutoUnref tf_helper(tf); 116 SkAutoUnref tf_helper(tf);
99 117
100 return Font(tf, font_family, font_size, NORMAL); 118 return Font(
119 tf, fallback.empty() ? font_family : fallback, font_size, NORMAL);
101 } 120 }
102 121
103 Font Font::DeriveFont(int size_delta, int style) const { 122 Font Font::DeriveFont(int size_delta, int style) const {
104 // If the delta is negative, if must not push the size below 1 123 // If the delta is negative, if must not push the size below 1
105 if (size_delta < 0) { 124 if (size_delta < 0) {
106 DCHECK_LT(-size_delta, font_size_); 125 DCHECK_LT(-size_delta, font_size_);
107 } 126 }
108 127
109 if (style == style_) { 128 if (style == style_) {
110 // Fast path, we just use the same typeface at a different size 129 // Fast path, we just use the same typeface at a different size
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 177
159 int Font::FontSize() { 178 int Font::FontSize() {
160 return font_size_; 179 return font_size_;
161 } 180 }
162 181
163 NativeFont Font::nativeFont() const { 182 NativeFont Font::nativeFont() const {
164 return typeface_; 183 return typeface_;
165 } 184 }
166 185
167 } // namespace gfx 186 } // namespace gfx
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698