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

Side by Side Diff: ui/gfx/platform_font_pango.cc

Issue 7977025: aura: Make 'ui' buildable without gtk. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 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 | « ui/gfx/platform_font_pango.h ('k') | ui/gfx/rect.h » ('j') | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_gtk.h" 5 #include "ui/gfx/platform_font_pango.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <fontconfig/fontconfig.h> 8 #include <fontconfig/fontconfig.h>
9 #include <map> 9 #include <map>
10 #include <pango/pango.h> 10 #include <pango/pango.h>
11 #include <string> 11 #include <string>
12 12
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/string_piece.h" 14 #include "base/string_piece.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "third_party/skia/include/core/SkTypeface.h" 16 #include "third_party/skia/include/core/SkTypeface.h"
17 #include "third_party/skia/include/core/SkPaint.h" 17 #include "third_party/skia/include/core/SkPaint.h"
18 #include "ui/gfx/canvas_skia.h" 18 #include "ui/gfx/canvas_skia.h"
19 #include "ui/gfx/font.h" 19 #include "ui/gfx/font.h"
20 #include "ui/gfx/linux_util.h" 20 #include "ui/gfx/linux_util.h"
21 21
22 #if !defined(USE_WAYLAND) 22 #if !defined(USE_WAYLAND) && defined(TOOLKIT_USES_GTK)
23 #include <gdk/gdk.h> 23 #include <gdk/gdk.h>
24 #include <gtk/gtk.h> 24 #include <gtk/gtk.h>
25 #endif 25 #endif
26 26
27 namespace { 27 namespace {
28 28
29 // The font family name which is used when a user's application font for 29 // The font family name which is used when a user's application font for
30 // GNOME/KDE is a non-scalable one. The name should be listed in the 30 // GNOME/KDE is a non-scalable one. The name should be listed in the
31 // IsFallbackFontAllowed function in skia/ext/SkFontHost_fontconfig_direct.cpp. 31 // IsFallbackFontAllowed function in skia/ext/SkFontHost_fontconfig_direct.cpp.
32 const char* kFallbackFontFamilyName = "sans"; 32 const char* kFallbackFontFamilyName = "sans";
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 FcPatternGetString(match, FC_FAMILY, 0, &match_family); 107 FcPatternGetString(match, FC_FAMILY, 0, &match_family);
108 108
109 string16 font_family = UTF8ToUTF16(reinterpret_cast<char*>(match_family)); 109 string16 font_family = UTF8ToUTF16(reinterpret_cast<char*>(match_family));
110 FcPatternDestroy(match); 110 FcPatternDestroy(match);
111 FcPatternDestroy(pattern); 111 FcPatternDestroy(pattern);
112 free(family_name_copy); 112 free(family_name_copy);
113 return font_family; 113 return font_family;
114 } 114 }
115 115
116 std::string GetDefaultFont() { 116 std::string GetDefaultFont() {
117 #if defined(USE_WAYLAND) || defined(USE_AURA) 117 #if defined(USE_WAYLAND) || !defined(TOOLKIT_USES_GTK)
118 return "sans 10"; 118 return "sans 10";
119 #else 119 #else
120 GtkSettings* settings = gtk_settings_get_default(); 120 GtkSettings* settings = gtk_settings_get_default();
121 121
122 gchar* font_name = NULL; 122 gchar* font_name = NULL;
123 g_object_get(settings, "gtk-font-name", &font_name, NULL); 123 g_object_get(settings, "gtk-font-name", &font_name, NULL);
124 124
125 // Temporary CHECK for helping track down 125 // Temporary CHECK for helping track down
126 // http://code.google.com/p/chromium/issues/detail?id=12530 126 // http://code.google.com/p/chromium/issues/detail?id=12530
127 CHECK(font_name) << " Unable to get gtk-font-name for default font."; 127 CHECK(font_name) << " Unable to get gtk-font-name for default font.";
128 128
129 std::string default_font = std::string(font_name); 129 std::string default_font = std::string(font_name);
130 g_free(font_name); 130 g_free(font_name);
131 return default_font; 131 return default_font;
132 #endif 132 #endif
133 } 133 }
134 134
135 } // namespace 135 } // namespace
136 136
137 namespace gfx { 137 namespace gfx {
138 138
139 Font* PlatformFontGtk::default_font_ = NULL; 139 Font* PlatformFontPango::default_font_ = NULL;
140 140
141 //////////////////////////////////////////////////////////////////////////////// 141 ////////////////////////////////////////////////////////////////////////////////
142 // PlatformFontGtk, public: 142 // PlatformFontPango, public:
143 143
144 PlatformFontGtk::PlatformFontGtk() { 144 PlatformFontPango::PlatformFontPango() {
145 if (default_font_ == NULL) { 145 if (default_font_ == NULL) {
146 std::string font_name = GetDefaultFont(); 146 std::string font_name = GetDefaultFont();
147 147
148 PangoFontDescription* desc = 148 PangoFontDescription* desc =
149 pango_font_description_from_string(font_name.c_str()); 149 pango_font_description_from_string(font_name.c_str());
150 default_font_ = new Font(desc); 150 default_font_ = new Font(desc);
151 pango_font_description_free(desc); 151 pango_font_description_free(desc);
152 152
153 DCHECK(default_font_); 153 DCHECK(default_font_);
154 } 154 }
155 155
156 InitFromPlatformFont( 156 InitFromPlatformFont(
157 static_cast<PlatformFontGtk*>(default_font_->platform_font())); 157 static_cast<PlatformFontPango*>(default_font_->platform_font()));
158 } 158 }
159 159
160 PlatformFontGtk::PlatformFontGtk(const Font& other) { 160 PlatformFontPango::PlatformFontPango(const Font& other) {
161 InitFromPlatformFont( 161 InitFromPlatformFont(
162 static_cast<PlatformFontGtk*>(other.platform_font())); 162 static_cast<PlatformFontPango*>(other.platform_font()));
163 } 163 }
164 164
165 PlatformFontGtk::PlatformFontGtk(NativeFont native_font) { 165 PlatformFontPango::PlatformFontPango(NativeFont native_font) {
166 const char* family_name = pango_font_description_get_family(native_font); 166 const char* family_name = pango_font_description_get_family(native_font);
167 167
168 gint size_in_pixels = 0; 168 gint size_in_pixels = 0;
169 if (pango_font_description_get_size_is_absolute(native_font)) { 169 if (pango_font_description_get_size_is_absolute(native_font)) {
170 // If the size is absolute, then it's in Pango units rather than points. 170 // If the size is absolute, then it's in Pango units rather than points.
171 // There are PANGO_SCALE Pango units in a device unit (pixel). 171 // There are PANGO_SCALE Pango units in a device unit (pixel).
172 size_in_pixels = pango_font_description_get_size(native_font) / PANGO_SCALE; 172 size_in_pixels = pango_font_description_get_size(native_font) / PANGO_SCALE;
173 } else { 173 } else {
174 // Otherwise, we need to convert from points. 174 // Otherwise, we need to convert from points.
175 size_in_pixels = 175 size_in_pixels =
(...skipping 14 matching lines...) Expand all
190 style |= gfx::Font::BOLD; 190 style |= gfx::Font::BOLD;
191 } 191 }
192 if (pango_font_description_get_style(native_font) == PANGO_STYLE_ITALIC) { 192 if (pango_font_description_get_style(native_font) == PANGO_STYLE_ITALIC) {
193 // TODO(davemoore) What about PANGO_STYLE_OBLIQUE? 193 // TODO(davemoore) What about PANGO_STYLE_OBLIQUE?
194 style |= gfx::Font::ITALIC; 194 style |= gfx::Font::ITALIC;
195 } 195 }
196 if (style != 0) 196 if (style != 0)
197 style_ = style; 197 style_ = style;
198 } 198 }
199 199
200 PlatformFontGtk::PlatformFontGtk(const string16& font_name, 200 PlatformFontPango::PlatformFontPango(const string16& font_name,
201 int font_size) { 201 int font_size) {
202 InitWithNameAndSize(font_name, font_size); 202 InitWithNameAndSize(font_name, font_size);
203 } 203 }
204 204
205 double PlatformFontGtk::underline_position() const { 205 double PlatformFontPango::underline_position() const {
206 const_cast<PlatformFontGtk*>(this)->InitPangoMetrics(); 206 const_cast<PlatformFontPango*>(this)->InitPangoMetrics();
207 return underline_position_pixels_; 207 return underline_position_pixels_;
208 } 208 }
209 209
210 double PlatformFontGtk::underline_thickness() const { 210 double PlatformFontPango::underline_thickness() const {
211 const_cast<PlatformFontGtk*>(this)->InitPangoMetrics(); 211 const_cast<PlatformFontPango*>(this)->InitPangoMetrics();
212 return underline_thickness_pixels_; 212 return underline_thickness_pixels_;
213 } 213 }
214 214
215 //////////////////////////////////////////////////////////////////////////////// 215 ////////////////////////////////////////////////////////////////////////////////
216 // PlatformFontGtk, PlatformFont implementation: 216 // PlatformFontPango, PlatformFont implementation:
217 217
218 // static 218 // static
219 void PlatformFontGtk::ReloadDefaultFont() { 219 void PlatformFontPango::ReloadDefaultFont() {
220 delete default_font_; 220 delete default_font_;
221 default_font_ = NULL; 221 default_font_ = NULL;
222 } 222 }
223 223
224 Font PlatformFontGtk::DeriveFont(int size_delta, int style) const { 224 Font PlatformFontPango::DeriveFont(int size_delta, int style) const {
225 // If the delta is negative, if must not push the size below 1 225 // If the delta is negative, if must not push the size below 1
226 if (size_delta < 0) 226 if (size_delta < 0)
227 DCHECK_LT(-size_delta, font_size_pixels_); 227 DCHECK_LT(-size_delta, font_size_pixels_);
228 228
229 if (style == style_) { 229 if (style == style_) {
230 // Fast path, we just use the same typeface at a different size 230 // Fast path, we just use the same typeface at a different size
231 return Font(new PlatformFontGtk(typeface_, 231 return Font(new PlatformFontPango(typeface_,
232 font_family_, 232 font_family_,
233 font_size_pixels_ + size_delta, 233 font_size_pixels_ + size_delta,
234 style_)); 234 style_));
235 } 235 }
236 236
237 // If the style has changed we may need to load a new face 237 // If the style has changed we may need to load a new face
238 int skstyle = SkTypeface::kNormal; 238 int skstyle = SkTypeface::kNormal;
239 if (gfx::Font::BOLD & style) 239 if (gfx::Font::BOLD & style)
240 skstyle |= SkTypeface::kBold; 240 skstyle |= SkTypeface::kBold;
241 if (gfx::Font::ITALIC & style) 241 if (gfx::Font::ITALIC & style)
242 skstyle |= SkTypeface::kItalic; 242 skstyle |= SkTypeface::kItalic;
243 243
244 SkTypeface* typeface = SkTypeface::CreateFromName( 244 SkTypeface* typeface = SkTypeface::CreateFromName(
245 UTF16ToUTF8(font_family_).c_str(), 245 UTF16ToUTF8(font_family_).c_str(),
246 static_cast<SkTypeface::Style>(skstyle)); 246 static_cast<SkTypeface::Style>(skstyle));
247 SkAutoUnref tf_helper(typeface); 247 SkAutoUnref tf_helper(typeface);
248 248
249 return Font(new PlatformFontGtk(typeface, 249 return Font(new PlatformFontPango(typeface,
250 font_family_, 250 font_family_,
251 font_size_pixels_ + size_delta, 251 font_size_pixels_ + size_delta,
252 style)); 252 style));
253 } 253 }
254 254
255 int PlatformFontGtk::GetHeight() const { 255 int PlatformFontPango::GetHeight() const {
256 return height_pixels_; 256 return height_pixels_;
257 } 257 }
258 258
259 int PlatformFontGtk::GetBaseline() const { 259 int PlatformFontPango::GetBaseline() const {
260 return ascent_pixels_; 260 return ascent_pixels_;
261 } 261 }
262 262
263 int PlatformFontGtk::GetAverageCharacterWidth() const { 263 int PlatformFontPango::GetAverageCharacterWidth() const {
264 return SkScalarRound(average_width_pixels_); 264 return SkScalarRound(average_width_pixels_);
265 } 265 }
266 266
267 int PlatformFontGtk::GetStringWidth(const string16& text) const { 267 int PlatformFontPango::GetStringWidth(const string16& text) const {
268 int width = 0, height = 0; 268 int width = 0, height = 0;
269 CanvasSkia::SizeStringInt(text, Font(const_cast<PlatformFontGtk*>(this)), 269 CanvasSkia::SizeStringInt(text, Font(const_cast<PlatformFontPango*>(this)),
270 &width, &height, gfx::Canvas::NO_ELLIPSIS); 270 &width, &height, gfx::Canvas::NO_ELLIPSIS);
271 return width; 271 return width;
272 } 272 }
273 273
274 int PlatformFontGtk::GetExpectedTextWidth(int length) const { 274 int PlatformFontPango::GetExpectedTextWidth(int length) const {
275 double char_width = const_cast<PlatformFontGtk*>(this)->GetAverageWidth(); 275 double char_width = const_cast<PlatformFontPango*>(this)->GetAverageWidth();
276 return round(static_cast<float>(length) * char_width); 276 return round(static_cast<float>(length) * char_width);
277 } 277 }
278 278
279 int PlatformFontGtk::GetStyle() const { 279 int PlatformFontPango::GetStyle() const {
280 return style_; 280 return style_;
281 } 281 }
282 282
283 string16 PlatformFontGtk::GetFontName() const { 283 string16 PlatformFontPango::GetFontName() const {
284 return font_family_; 284 return font_family_;
285 } 285 }
286 286
287 int PlatformFontGtk::GetFontSize() const { 287 int PlatformFontPango::GetFontSize() const {
288 return font_size_pixels_; 288 return font_size_pixels_;
289 } 289 }
290 290
291 NativeFont PlatformFontGtk::GetNativeFont() const { 291 NativeFont PlatformFontPango::GetNativeFont() const {
292 PangoFontDescription* pfd = pango_font_description_new(); 292 PangoFontDescription* pfd = pango_font_description_new();
293 pango_font_description_set_family(pfd, UTF16ToUTF8(GetFontName()).c_str()); 293 pango_font_description_set_family(pfd, UTF16ToUTF8(GetFontName()).c_str());
294 // Set the absolute size to avoid overflowing UI elements. 294 // Set the absolute size to avoid overflowing UI elements.
295 // pango_font_description_set_absolute_size() takes a size in Pango units. 295 // pango_font_description_set_absolute_size() takes a size in Pango units.
296 // There are PANGO_SCALE Pango units in one device unit. Screen output 296 // There are PANGO_SCALE Pango units in one device unit. Screen output
297 // devices use pixels as their device units. 297 // devices use pixels as their device units.
298 pango_font_description_set_absolute_size( 298 pango_font_description_set_absolute_size(
299 pfd, font_size_pixels_ * PANGO_SCALE); 299 pfd, font_size_pixels_ * PANGO_SCALE);
300 300
301 switch (GetStyle()) { 301 switch (GetStyle()) {
302 case gfx::Font::NORMAL: 302 case gfx::Font::NORMAL:
303 // Nothing to do, should already be PANGO_STYLE_NORMAL. 303 // Nothing to do, should already be PANGO_STYLE_NORMAL.
304 break; 304 break;
305 case gfx::Font::BOLD: 305 case gfx::Font::BOLD:
306 pango_font_description_set_weight(pfd, PANGO_WEIGHT_BOLD); 306 pango_font_description_set_weight(pfd, PANGO_WEIGHT_BOLD);
307 break; 307 break;
308 case gfx::Font::ITALIC: 308 case gfx::Font::ITALIC:
309 pango_font_description_set_style(pfd, PANGO_STYLE_ITALIC); 309 pango_font_description_set_style(pfd, PANGO_STYLE_ITALIC);
310 break; 310 break;
311 case gfx::Font::UNDERLINED: 311 case gfx::Font::UNDERLINED:
312 // TODO(deanm): How to do underlined? Where do we use it? Probably have 312 // TODO(deanm): How to do underlined? Where do we use it? Probably have
313 // to paint it ourselves, see pango_font_metrics_get_underline_position. 313 // to paint it ourselves, see pango_font_metrics_get_underline_position.
314 break; 314 break;
315 } 315 }
316 316
317 return pfd; 317 return pfd;
318 } 318 }
319 319
320 //////////////////////////////////////////////////////////////////////////////// 320 ////////////////////////////////////////////////////////////////////////////////
321 // PlatformFontGtk, private: 321 // PlatformFontPango, private:
322 322
323 PlatformFontGtk::PlatformFontGtk(SkTypeface* typeface, 323 PlatformFontPango::PlatformFontPango(SkTypeface* typeface,
324 const string16& name, 324 const string16& name,
325 int size, 325 int size,
326 int style) { 326 int style) {
327 InitWithTypefaceNameSizeAndStyle(typeface, name, size, style); 327 InitWithTypefaceNameSizeAndStyle(typeface, name, size, style);
328 } 328 }
329 329
330 PlatformFontGtk::~PlatformFontGtk() {} 330 PlatformFontPango::~PlatformFontPango() {}
331 331
332 void PlatformFontGtk::InitWithNameAndSize(const string16& font_name, 332 void PlatformFontPango::InitWithNameAndSize(const string16& font_name,
333 int font_size) { 333 int font_size) {
334 DCHECK_GT(font_size, 0); 334 DCHECK_GT(font_size, 0);
335 string16 fallback; 335 string16 fallback;
336 336
337 SkTypeface* typeface = SkTypeface::CreateFromName( 337 SkTypeface* typeface = SkTypeface::CreateFromName(
338 UTF16ToUTF8(font_name).c_str(), SkTypeface::kNormal); 338 UTF16ToUTF8(font_name).c_str(), SkTypeface::kNormal);
339 if (!typeface) { 339 if (!typeface) {
340 // A non-scalable font such as .pcf is specified. Falls back to a default 340 // A non-scalable font such as .pcf is specified. Falls back to a default
341 // scalable font. 341 // scalable font.
342 typeface = SkTypeface::CreateFromName( 342 typeface = SkTypeface::CreateFromName(
343 kFallbackFontFamilyName, SkTypeface::kNormal); 343 kFallbackFontFamilyName, SkTypeface::kNormal);
344 CHECK(typeface) << "Could not find any font: " 344 CHECK(typeface) << "Could not find any font: "
345 << UTF16ToUTF8(font_name) 345 << UTF16ToUTF8(font_name)
346 << ", " << kFallbackFontFamilyName; 346 << ", " << kFallbackFontFamilyName;
347 fallback = UTF8ToUTF16(kFallbackFontFamilyName); 347 fallback = UTF8ToUTF16(kFallbackFontFamilyName);
348 } 348 }
349 SkAutoUnref typeface_helper(typeface); 349 SkAutoUnref typeface_helper(typeface);
350 350
351 InitWithTypefaceNameSizeAndStyle(typeface, 351 InitWithTypefaceNameSizeAndStyle(typeface,
352 fallback.empty() ? font_name : fallback, 352 fallback.empty() ? font_name : fallback,
353 font_size, 353 font_size,
354 gfx::Font::NORMAL); 354 gfx::Font::NORMAL);
355 } 355 }
356 356
357 void PlatformFontGtk::InitWithTypefaceNameSizeAndStyle( 357 void PlatformFontPango::InitWithTypefaceNameSizeAndStyle(
358 SkTypeface* typeface, 358 SkTypeface* typeface,
359 const string16& font_family, 359 const string16& font_family,
360 int font_size, 360 int font_size,
361 int style) { 361 int style) {
362 typeface_helper_.reset(new SkAutoUnref(typeface)); 362 typeface_helper_.reset(new SkAutoUnref(typeface));
363 typeface_ = typeface; 363 typeface_ = typeface;
364 typeface_->ref(); 364 typeface_->ref();
365 font_family_ = font_family; 365 font_family_ = font_family;
366 font_size_pixels_ = font_size; 366 font_size_pixels_ = font_size;
367 style_ = style; 367 style_ = style;
368 pango_metrics_inited_ = false; 368 pango_metrics_inited_ = false;
369 average_width_pixels_ = 0.0f; 369 average_width_pixels_ = 0.0f;
370 underline_position_pixels_ = 0.0f; 370 underline_position_pixels_ = 0.0f;
371 underline_thickness_pixels_ = 0.0f; 371 underline_thickness_pixels_ = 0.0f;
372 372
373 SkPaint paint; 373 SkPaint paint;
374 SkPaint::FontMetrics metrics; 374 SkPaint::FontMetrics metrics;
375 PaintSetup(&paint); 375 PaintSetup(&paint);
376 paint.getFontMetrics(&metrics); 376 paint.getFontMetrics(&metrics);
377 377
378 ascent_pixels_ = SkScalarCeil(-metrics.fAscent); 378 ascent_pixels_ = SkScalarCeil(-metrics.fAscent);
379 height_pixels_ = ascent_pixels_ + SkScalarCeil(metrics.fDescent); 379 height_pixels_ = ascent_pixels_ + SkScalarCeil(metrics.fDescent);
380 } 380 }
381 381
382 void PlatformFontGtk::InitFromPlatformFont(const PlatformFontGtk* other) { 382 void PlatformFontPango::InitFromPlatformFont(const PlatformFontPango* other) {
383 typeface_helper_.reset(new SkAutoUnref(other->typeface_)); 383 typeface_helper_.reset(new SkAutoUnref(other->typeface_));
384 typeface_ = other->typeface_; 384 typeface_ = other->typeface_;
385 typeface_->ref(); 385 typeface_->ref();
386 font_family_ = other->font_family_; 386 font_family_ = other->font_family_;
387 font_size_pixels_ = other->font_size_pixels_; 387 font_size_pixels_ = other->font_size_pixels_;
388 style_ = other->style_; 388 style_ = other->style_;
389 height_pixels_ = other->height_pixels_; 389 height_pixels_ = other->height_pixels_;
390 ascent_pixels_ = other->ascent_pixels_; 390 ascent_pixels_ = other->ascent_pixels_;
391 pango_metrics_inited_ = other->pango_metrics_inited_; 391 pango_metrics_inited_ = other->pango_metrics_inited_;
392 average_width_pixels_ = other->average_width_pixels_; 392 average_width_pixels_ = other->average_width_pixels_;
393 underline_position_pixels_ = other->underline_position_pixels_; 393 underline_position_pixels_ = other->underline_position_pixels_;
394 underline_thickness_pixels_ = other->underline_thickness_pixels_; 394 underline_thickness_pixels_ = other->underline_thickness_pixels_;
395 } 395 }
396 396
397 void PlatformFontGtk::PaintSetup(SkPaint* paint) const { 397 void PlatformFontPango::PaintSetup(SkPaint* paint) const {
398 paint->setAntiAlias(false); 398 paint->setAntiAlias(false);
399 paint->setSubpixelText(false); 399 paint->setSubpixelText(false);
400 paint->setTextSize(font_size_pixels_); 400 paint->setTextSize(font_size_pixels_);
401 paint->setTypeface(typeface_); 401 paint->setTypeface(typeface_);
402 paint->setFakeBoldText((gfx::Font::BOLD & style_) && !typeface_->isBold()); 402 paint->setFakeBoldText((gfx::Font::BOLD & style_) && !typeface_->isBold());
403 paint->setTextSkewX((gfx::Font::ITALIC & style_) && !typeface_->isItalic() ? 403 paint->setTextSkewX((gfx::Font::ITALIC & style_) && !typeface_->isItalic() ?
404 -SK_Scalar1/4 : 0); 404 -SK_Scalar1/4 : 0);
405 } 405 }
406 406
407 void PlatformFontGtk::InitPangoMetrics() { 407 void PlatformFontPango::InitPangoMetrics() {
408 if (!pango_metrics_inited_) { 408 if (!pango_metrics_inited_) {
409 pango_metrics_inited_ = true; 409 pango_metrics_inited_ = true;
410 PangoFontDescription* pango_desc = GetNativeFont(); 410 PangoFontDescription* pango_desc = GetNativeFont();
411 PangoFontMetrics* pango_metrics = GetPangoFontMetrics(pango_desc); 411 PangoFontMetrics* pango_metrics = GetPangoFontMetrics(pango_desc);
412 412
413 underline_position_pixels_ = 413 underline_position_pixels_ =
414 pango_font_metrics_get_underline_position(pango_metrics) / 414 pango_font_metrics_get_underline_position(pango_metrics) /
415 PANGO_SCALE; 415 PANGO_SCALE;
416 416
417 // TODO(davemoore): Come up with a better solution. 417 // TODO(davemoore): Come up with a better solution.
(...skipping 14 matching lines...) Expand all
432 // conversions. 432 // conversions.
433 int text_width_pixels = GetStringWidth( 433 int text_width_pixels = GetStringWidth(
434 ASCIIToUTF16("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); 434 ASCIIToUTF16("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
435 double dialog_units_pixels = (text_width_pixels / 26 + 1) / 2; 435 double dialog_units_pixels = (text_width_pixels / 26 + 1) / 2;
436 average_width_pixels_ = std::min(pango_width_pixels, dialog_units_pixels); 436 average_width_pixels_ = std::min(pango_width_pixels, dialog_units_pixels);
437 pango_font_description_free(pango_desc); 437 pango_font_description_free(pango_desc);
438 } 438 }
439 } 439 }
440 440
441 441
442 double PlatformFontGtk::GetAverageWidth() const { 442 double PlatformFontPango::GetAverageWidth() const {
443 const_cast<PlatformFontGtk*>(this)->InitPangoMetrics(); 443 const_cast<PlatformFontPango*>(this)->InitPangoMetrics();
444 return average_width_pixels_; 444 return average_width_pixels_;
445 } 445 }
446 446
447 //////////////////////////////////////////////////////////////////////////////// 447 ////////////////////////////////////////////////////////////////////////////////
448 // PlatformFont, public: 448 // PlatformFont, public:
449 449
450 // static 450 // static
451 PlatformFont* PlatformFont::CreateDefault() { 451 PlatformFont* PlatformFont::CreateDefault() {
452 return new PlatformFontGtk; 452 return new PlatformFontPango;
453 } 453 }
454 454
455 // static 455 // static
456 PlatformFont* PlatformFont::CreateFromFont(const Font& other) { 456 PlatformFont* PlatformFont::CreateFromFont(const Font& other) {
457 return new PlatformFontGtk(other); 457 return new PlatformFontPango(other);
458 } 458 }
459 459
460 // static 460 // static
461 PlatformFont* PlatformFont::CreateFromNativeFont(NativeFont native_font) { 461 PlatformFont* PlatformFont::CreateFromNativeFont(NativeFont native_font) {
462 return new PlatformFontGtk(native_font); 462 return new PlatformFontPango(native_font);
463 } 463 }
464 464
465 // static 465 // static
466 PlatformFont* PlatformFont::CreateFromNameAndSize(const string16& font_name, 466 PlatformFont* PlatformFont::CreateFromNameAndSize(const string16& font_name,
467 int font_size) { 467 int font_size) {
468 return new PlatformFontGtk(font_name, font_size); 468 return new PlatformFontPango(font_name, font_size);
469 } 469 }
470 470
471 } // namespace gfx 471 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/platform_font_pango.h ('k') | ui/gfx/rect.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698