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

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

Issue 7467007: Adding Wayland support for ui/gfx (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Fixed order of includes Created 9 years, 4 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/native_widget_types.h ('k') | ui/gfx/screen_wayland.cc » ('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_gtk.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <fontconfig/fontconfig.h> 8 #include <fontconfig/fontconfig.h>
9 #include <gdk/gdk.h>
10 #include <gtk/gtk.h>
11 #include <map> 9 #include <map>
12 #include <pango/pango.h> 10 #include <pango/pango.h>
11 #include <string>
13 12
14 #include "base/logging.h" 13 #include "base/logging.h"
15 #include "base/string_piece.h" 14 #include "base/string_piece.h"
16 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "pango/pangocairo.h"
17 #include "third_party/skia/include/core/SkTypeface.h" 17 #include "third_party/skia/include/core/SkTypeface.h"
18 #include "third_party/skia/include/core/SkPaint.h" 18 #include "third_party/skia/include/core/SkPaint.h"
19 #include "ui/gfx/canvas_skia.h" 19 #include "ui/gfx/canvas_skia.h"
20 #include "ui/gfx/font.h" 20 #include "ui/gfx/font.h"
21 #include "ui/gfx/gtk_util.h" 21 #include "ui/gfx/gtk_util.h"
22 22
23 #if !defined(USE_WAYLAND)
24 #include <gdk/gdk.h>
25 #include <gtk/gtk.h>
26 #endif
27
23 namespace { 28 namespace {
24 29
25 // The font family name which is used when a user's application font for 30 // The font family name which is used when a user's application font for
26 // GNOME/KDE is a non-scalable one. The name should be listed in the 31 // GNOME/KDE is a non-scalable one. The name should be listed in the
27 // IsFallbackFontAllowed function in skia/ext/SkFontHost_fontconfig_direct.cpp. 32 // IsFallbackFontAllowed function in skia/ext/SkFontHost_fontconfig_direct.cpp.
28 const char* kFallbackFontFamilyName = "sans"; 33 const char* kFallbackFontFamilyName = "sans";
29 34
30 // Returns the number of pixels in a point. 35 // Returns the number of pixels in a point.
31 // - multiply a point size by this to get pixels ("device units") 36 // - multiply a point size by this to get pixels ("device units")
32 // - divide a pixel size by this to get points 37 // - divide a pixel size by this to get points
(...skipping 16 matching lines...) Expand all
49 } 54 }
50 55
51 // Retrieves the pango metrics for a pango font description. Caches the metrics 56 // Retrieves the pango metrics for a pango font description. Caches the metrics
52 // and never frees them. The metrics objects are relatively small and 57 // and never frees them. The metrics objects are relatively small and
53 // very expensive to look up. 58 // very expensive to look up.
54 PangoFontMetrics* GetPangoFontMetrics(PangoFontDescription* desc) { 59 PangoFontMetrics* GetPangoFontMetrics(PangoFontDescription* desc) {
55 static std::map<int, PangoFontMetrics*>* desc_to_metrics = NULL; 60 static std::map<int, PangoFontMetrics*>* desc_to_metrics = NULL;
56 static PangoContext* context = NULL; 61 static PangoContext* context = NULL;
57 62
58 if (!context) { 63 if (!context) {
59 context = gdk_pango_context_get_for_screen(gdk_screen_get_default()); 64 context = gfx::GetPangoContext();
60 pango_context_set_language(context, pango_language_get_default()); 65 pango_context_set_language(context, pango_language_get_default());
61 } 66 }
62 67
63 if (!desc_to_metrics) { 68 if (!desc_to_metrics) {
64 desc_to_metrics = new std::map<int, PangoFontMetrics*>(); 69 desc_to_metrics = new std::map<int, PangoFontMetrics*>();
65 } 70 }
66 71
67 int desc_hash = pango_font_description_hash(desc); 72 int desc_hash = pango_font_description_hash(desc);
68 std::map<int, PangoFontMetrics*>::iterator i = 73 std::map<int, PangoFontMetrics*>::iterator i =
69 desc_to_metrics->find(desc_hash); 74 desc_to_metrics->find(desc_hash);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 FcChar8* match_family; 107 FcChar8* match_family;
103 FcPatternGetString(match, FC_FAMILY, 0, &match_family); 108 FcPatternGetString(match, FC_FAMILY, 0, &match_family);
104 109
105 string16 font_family = UTF8ToUTF16(reinterpret_cast<char*>(match_family)); 110 string16 font_family = UTF8ToUTF16(reinterpret_cast<char*>(match_family));
106 FcPatternDestroy(match); 111 FcPatternDestroy(match);
107 FcPatternDestroy(pattern); 112 FcPatternDestroy(pattern);
108 free(family_name_copy); 113 free(family_name_copy);
109 return font_family; 114 return font_family;
110 } 115 }
111 116
117 std::string GetDefaultFont() {
118 std::string default_font("sans 10");
sky 2011/07/27 22:22:22 simplify this to: #if defined(WAYLAND) return "s
119
120 #if !defined(USE_WAYLAND)
121 GtkSettings* settings = gtk_settings_get_default();
122
123 gchar* font_name = NULL;
124 g_object_get(settings, "gtk-font-name", &font_name, NULL);
125
126 // Temporary CHECK for helping track down
127 // http://code.google.com/p/chromium/issues/detail?id=12530
128 CHECK(font_name) << " Unable to get gtk-font-name for default font.";
129
130 default_font = std::string(font_name);
131 g_free(font_name);
132 #endif
133
134 return default_font;
135 }
136
112 } // namespace 137 } // namespace
113 138
114 namespace gfx { 139 namespace gfx {
115 140
116 Font* PlatformFontGtk::default_font_ = NULL; 141 Font* PlatformFontGtk::default_font_ = NULL;
117 142
118 //////////////////////////////////////////////////////////////////////////////// 143 ////////////////////////////////////////////////////////////////////////////////
119 // PlatformFontGtk, public: 144 // PlatformFontGtk, public:
120 145
121 PlatformFontGtk::PlatformFontGtk() { 146 PlatformFontGtk::PlatformFontGtk() {
122 if (default_font_ == NULL) { 147 if (default_font_ == NULL) {
123 GtkSettings* settings = gtk_settings_get_default(); 148 std::string font_name = GetDefaultFont();
124
125 gchar* font_name = NULL;
126 g_object_get(settings, "gtk-font-name", &font_name, NULL);
127
128 // Temporary CHECK for helping track down
129 // http://code.google.com/p/chromium/issues/detail?id=12530
130 CHECK(font_name) << " Unable to get gtk-font-name for default font.";
131 149
132 PangoFontDescription* desc = 150 PangoFontDescription* desc =
133 pango_font_description_from_string(font_name); 151 pango_font_description_from_string(font_name.c_str());
134 default_font_ = new Font(desc); 152 default_font_ = new Font(desc);
135 pango_font_description_free(desc); 153 pango_font_description_free(desc);
136 g_free(font_name);
137 154
138 DCHECK(default_font_); 155 DCHECK(default_font_);
139 } 156 }
140 157
141 InitFromPlatformFont( 158 InitFromPlatformFont(
142 static_cast<PlatformFontGtk*>(default_font_->platform_font())); 159 static_cast<PlatformFontGtk*>(default_font_->platform_font()));
143 } 160 }
144 161
145 PlatformFontGtk::PlatformFontGtk(const Font& other) { 162 PlatformFontGtk::PlatformFontGtk(const Font& other) {
146 InitFromPlatformFont( 163 InitFromPlatformFont(
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 return new PlatformFontGtk(native_font); 464 return new PlatformFontGtk(native_font);
448 } 465 }
449 466
450 // static 467 // static
451 PlatformFont* PlatformFont::CreateFromNameAndSize(const string16& font_name, 468 PlatformFont* PlatformFont::CreateFromNameAndSize(const string16& font_name,
452 int font_size) { 469 int font_size) {
453 return new PlatformFontGtk(font_name, font_size); 470 return new PlatformFontGtk(font_name, font_size);
454 } 471 }
455 472
456 } // namespace gfx 473 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/native_widget_types.h ('k') | ui/gfx/screen_wayland.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698