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

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

Issue 232773008: More removal of GTK code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove base/ so I don't need another stamp. Created 6 years, 8 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/image/image.h ('k') | ui/gl/gl_surface_glx.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) 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>
11 #include <string> 11 #include <string>
12 12
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/strings/string_piece.h" 14 #include "base/strings/string_piece.h"
15 #include "base/strings/string_split.h" 15 #include "base/strings/string_split.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "third_party/skia/include/core/SkPaint.h" 17 #include "third_party/skia/include/core/SkPaint.h"
18 #include "third_party/skia/include/core/SkString.h" 18 #include "third_party/skia/include/core/SkString.h"
19 #include "third_party/skia/include/core/SkTypeface.h" 19 #include "third_party/skia/include/core/SkTypeface.h"
20 #include "ui/gfx/canvas.h" 20 #include "ui/gfx/canvas.h"
21 #include "ui/gfx/font.h" 21 #include "ui/gfx/font.h"
22 #include "ui/gfx/font_list.h" 22 #include "ui/gfx/font_list.h"
23 #include "ui/gfx/linux_font_delegate.h" 23 #include "ui/gfx/linux_font_delegate.h"
24 #include "ui/gfx/pango_util.h" 24 #include "ui/gfx/pango_util.h"
25 #include "ui/gfx/text_utils.h" 25 #include "ui/gfx/text_utils.h"
26 26
27 #if defined(TOOLKIT_GTK)
28 #include <gdk/gdk.h>
29 #include <gtk/gtk.h>
30 #endif
31
32 namespace { 27 namespace {
33 28
34 // 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
35 // 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
36 // IsFallbackFontAllowed function in skia/ext/SkFontHost_fontconfig_direct.cpp. 31 // IsFallbackFontAllowed function in skia/ext/SkFontHost_fontconfig_direct.cpp.
37 const char* kFallbackFontFamilyName = "sans"; 32 const char* kFallbackFontFamilyName = "sans";
38 33
39 // Returns the available font family that best (in FontConfig's eyes) matches 34 // Returns the available font family that best (in FontConfig's eyes) matches
40 // the supplied list of family names. 35 // the supplied list of family names.
41 std::string FindBestMatchFontFamilyName( 36 std::string FindBestMatchFontFamilyName(
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 const std::string& name, 244 const std::string& name,
250 int size, 245 int size,
251 int style) { 246 int style) {
252 InitWithTypefaceNameSizeAndStyle(typeface, name, size, style); 247 InitWithTypefaceNameSizeAndStyle(typeface, name, size, style);
253 } 248 }
254 249
255 PlatformFontPango::~PlatformFontPango() {} 250 PlatformFontPango::~PlatformFontPango() {}
256 251
257 // static 252 // static
258 std::string PlatformFontPango::GetDefaultFont() { 253 std::string PlatformFontPango::GetDefaultFont() {
259 #if !defined(TOOLKIT_GTK)
260 #if defined(OS_CHROMEOS) 254 #if defined(OS_CHROMEOS)
261 // Font name must have been provided by way of SetDefaultFontDescription(). 255 // Font name must have been provided by way of SetDefaultFontDescription().
262 CHECK(default_font_description_); 256 CHECK(default_font_description_);
263 return *default_font_description_; 257 return *default_font_description_;
264 #else 258 #else
265 const gfx::LinuxFontDelegate* delegate = gfx::LinuxFontDelegate::instance(); 259 const gfx::LinuxFontDelegate* delegate = gfx::LinuxFontDelegate::instance();
266 if (delegate) 260 if (delegate)
267 return delegate->GetDefaultFontName(); 261 return delegate->GetDefaultFontName();
268 262
269 return "sans 10"; 263 return "sans 10";
270 #endif // defined(OS_CHROMEOS) 264 #endif // defined(OS_CHROMEOS)
271 #else
272 GtkSettings* settings = gtk_settings_get_default();
273
274 gchar* font_name = NULL;
275 g_object_get(settings, "gtk-font-name", &font_name, NULL);
276
277 // Temporary CHECK for helping track down
278 // http://code.google.com/p/chromium/issues/detail?id=12530
279 CHECK(font_name) << " Unable to get gtk-font-name for default font.";
280
281 std::string default_font = std::string(font_name);
282 g_free(font_name);
283 return default_font;
284 #endif // !defined(TOOLKIT_GTK)
285 } 265 }
286 266
287
288 void PlatformFontPango::InitWithNameAndSize(const std::string& font_name, 267 void PlatformFontPango::InitWithNameAndSize(const std::string& font_name,
289 int font_size) { 268 int font_size) {
290 DCHECK_GT(font_size, 0); 269 DCHECK_GT(font_size, 0);
291 std::string fallback; 270 std::string fallback;
292 271
293 skia::RefPtr<SkTypeface> typeface = skia::AdoptRef( 272 skia::RefPtr<SkTypeface> typeface = skia::AdoptRef(
294 SkTypeface::CreateFromName(font_name.c_str(), SkTypeface::kNormal)); 273 SkTypeface::CreateFromName(font_name.c_str(), SkTypeface::kNormal));
295 if (!typeface) { 274 if (!typeface) {
296 // A non-scalable font such as .pcf is specified. Falls back to a default 275 // A non-scalable font such as .pcf is specified. Falls back to a default
297 // scalable font. 276 // scalable font.
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 return new PlatformFontPango(native_font); 390 return new PlatformFontPango(native_font);
412 } 391 }
413 392
414 // static 393 // static
415 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, 394 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name,
416 int font_size) { 395 int font_size) {
417 return new PlatformFontPango(font_name, font_size); 396 return new PlatformFontPango(font_name, font_size);
418 } 397 }
419 398
420 } // namespace gfx 399 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/image/image.h ('k') | ui/gl/gl_surface_glx.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698