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

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: Adding missing WaylandDisplay include 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"
17 #include "third_party/skia/include/core/SkTypeface.h" 16 #include "third_party/skia/include/core/SkTypeface.h"
18 #include "third_party/skia/include/core/SkPaint.h" 17 #include "third_party/skia/include/core/SkPaint.h"
19 #include "ui/gfx/canvas_skia.h" 18 #include "ui/gfx/canvas_skia.h"
20 #include "ui/gfx/font.h" 19 #include "ui/gfx/font.h"
21 #include "ui/gfx/gtk_util.h" 20 #include "ui/gfx/gtk_util.h"
22 21
22 #if !defined(USE_WAYLAND)
23 #include <gdk/gdk.h>
24 #include <gtk/gtk.h>
25 #endif
26
23 namespace { 27 namespace {
24 28
25 // 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
26 // 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
27 // IsFallbackFontAllowed function in skia/ext/SkFontHost_fontconfig_direct.cpp. 31 // IsFallbackFontAllowed function in skia/ext/SkFontHost_fontconfig_direct.cpp.
28 const char* kFallbackFontFamilyName = "sans"; 32 const char* kFallbackFontFamilyName = "sans";
29 33
30 // Returns the number of pixels in a point. 34 // Returns the number of pixels in a point.
31 // - multiply a point size by this to get pixels ("device units") 35 // - multiply a point size by this to get pixels ("device units")
32 // - divide a pixel size by this to get points 36 // - divide a pixel size by this to get points
(...skipping 16 matching lines...) Expand all
49 } 53 }
50 54
51 // Retrieves the pango metrics for a pango font description. Caches the metrics 55 // Retrieves the pango metrics for a pango font description. Caches the metrics
52 // and never frees them. The metrics objects are relatively small and 56 // and never frees them. The metrics objects are relatively small and
53 // very expensive to look up. 57 // very expensive to look up.
54 PangoFontMetrics* GetPangoFontMetrics(PangoFontDescription* desc) { 58 PangoFontMetrics* GetPangoFontMetrics(PangoFontDescription* desc) {
55 static std::map<int, PangoFontMetrics*>* desc_to_metrics = NULL; 59 static std::map<int, PangoFontMetrics*>* desc_to_metrics = NULL;
56 static PangoContext* context = NULL; 60 static PangoContext* context = NULL;
57 61
58 if (!context) { 62 if (!context) {
59 context = gdk_pango_context_get_for_screen(gdk_screen_get_default()); 63 context = gfx::GetPangoContext();
60 pango_context_set_language(context, pango_language_get_default()); 64 pango_context_set_language(context, pango_language_get_default());
61 } 65 }
62 66
63 if (!desc_to_metrics) { 67 if (!desc_to_metrics) {
64 desc_to_metrics = new std::map<int, PangoFontMetrics*>(); 68 desc_to_metrics = new std::map<int, PangoFontMetrics*>();
65 } 69 }
66 70
67 int desc_hash = pango_font_description_hash(desc); 71 int desc_hash = pango_font_description_hash(desc);
68 std::map<int, PangoFontMetrics*>::iterator i = 72 std::map<int, PangoFontMetrics*>::iterator i =
69 desc_to_metrics->find(desc_hash); 73 desc_to_metrics->find(desc_hash);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 FcChar8* match_family; 106 FcChar8* match_family;
103 FcPatternGetString(match, FC_FAMILY, 0, &match_family); 107 FcPatternGetString(match, FC_FAMILY, 0, &match_family);
104 108
105 string16 font_family = UTF8ToUTF16(reinterpret_cast<char*>(match_family)); 109 string16 font_family = UTF8ToUTF16(reinterpret_cast<char*>(match_family));
106 FcPatternDestroy(match); 110 FcPatternDestroy(match);
107 FcPatternDestroy(pattern); 111 FcPatternDestroy(pattern);
108 free(family_name_copy); 112 free(family_name_copy);
109 return font_family; 113 return font_family;
110 } 114 }
111 115
116 std::string GetDefaultFont() {
117 #if defined(USE_WAYLAND)
118 return "sans 10";
119 #else
120 GtkSettings* settings = gtk_settings_get_default();
121
122 gchar* font_name = NULL;
123 g_object_get(settings, "gtk-font-name", &font_name, NULL);
124
125 // Temporary CHECK for helping track down
126 // http://code.google.com/p/chromium/issues/detail?id=12530
127 CHECK(font_name) << " Unable to get gtk-font-name for default font.";
128
129 std::string default_font = std::string(font_name);
130 g_free(font_name);
131 return default_font;
132 #endif
133 }
134
112 } // namespace 135 } // namespace
113 136
114 namespace gfx { 137 namespace gfx {
115 138
116 Font* PlatformFontGtk::default_font_ = NULL; 139 Font* PlatformFontGtk::default_font_ = NULL;
117 140
118 //////////////////////////////////////////////////////////////////////////////// 141 ////////////////////////////////////////////////////////////////////////////////
119 // PlatformFontGtk, public: 142 // PlatformFontGtk, public:
120 143
121 PlatformFontGtk::PlatformFontGtk() { 144 PlatformFontGtk::PlatformFontGtk() {
122 if (default_font_ == NULL) { 145 if (default_font_ == NULL) {
123 GtkSettings* settings = gtk_settings_get_default(); 146 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 147
132 PangoFontDescription* desc = 148 PangoFontDescription* desc =
133 pango_font_description_from_string(font_name); 149 pango_font_description_from_string(font_name.c_str());
134 default_font_ = new Font(desc); 150 default_font_ = new Font(desc);
135 pango_font_description_free(desc); 151 pango_font_description_free(desc);
136 g_free(font_name);
137 152
138 DCHECK(default_font_); 153 DCHECK(default_font_);
139 } 154 }
140 155
141 InitFromPlatformFont( 156 InitFromPlatformFont(
142 static_cast<PlatformFontGtk*>(default_font_->platform_font())); 157 static_cast<PlatformFontGtk*>(default_font_->platform_font()));
143 } 158 }
144 159
145 PlatformFontGtk::PlatformFontGtk(const Font& other) { 160 PlatformFontGtk::PlatformFontGtk(const Font& other) {
146 InitFromPlatformFont( 161 InitFromPlatformFont(
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 return new PlatformFontGtk(native_font); 462 return new PlatformFontGtk(native_font);
448 } 463 }
449 464
450 // static 465 // static
451 PlatformFont* PlatformFont::CreateFromNameAndSize(const string16& font_name, 466 PlatformFont* PlatformFont::CreateFromNameAndSize(const string16& font_name,
452 int font_size) { 467 int font_size) {
453 return new PlatformFontGtk(font_name, font_size); 468 return new PlatformFontGtk(font_name, font_size);
454 } 469 }
455 470
456 } // namespace gfx 471 } // 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