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

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: Accidentally pulled in some extra changes in common.gypi 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
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 #if !defined(USE_WAYLAND)
sky 2011/07/27 15:51:05 conditionals after non-conditionals.
9 #include <gdk/gdk.h> 10 #include <gdk/gdk.h>
10 #include <gtk/gtk.h> 11 #include <gtk/gtk.h>
12 #endif
11 #include <map> 13 #include <map>
12 #include <pango/pango.h> 14 #include <pango/pango.h>
13 15
14 #include "base/logging.h" 16 #include "base/logging.h"
15 #include "base/string_piece.h" 17 #include "base/string_piece.h"
16 #include "base/utf_string_conversions.h" 18 #include "base/utf_string_conversions.h"
19 #include "pango/pangocairo.h"
17 #include "third_party/skia/include/core/SkTypeface.h" 20 #include "third_party/skia/include/core/SkTypeface.h"
18 #include "third_party/skia/include/core/SkPaint.h" 21 #include "third_party/skia/include/core/SkPaint.h"
19 #include "ui/gfx/canvas_skia.h" 22 #include "ui/gfx/canvas_skia.h"
20 #include "ui/gfx/font.h" 23 #include "ui/gfx/font.h"
21 #include "ui/gfx/gtk_util.h" 24 #include "ui/gfx/gtk_util.h"
22 25
23 namespace { 26 namespace {
24 27
25 // The font family name which is used when a user's application font for 28 // 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 29 // GNOME/KDE is a non-scalable one. The name should be listed in the
(...skipping 22 matching lines...) Expand all
49 } 52 }
50 53
51 // Retrieves the pango metrics for a pango font description. Caches the metrics 54 // Retrieves the pango metrics for a pango font description. Caches the metrics
52 // and never frees them. The metrics objects are relatively small and 55 // and never frees them. The metrics objects are relatively small and
53 // very expensive to look up. 56 // very expensive to look up.
54 PangoFontMetrics* GetPangoFontMetrics(PangoFontDescription* desc) { 57 PangoFontMetrics* GetPangoFontMetrics(PangoFontDescription* desc) {
55 static std::map<int, PangoFontMetrics*>* desc_to_metrics = NULL; 58 static std::map<int, PangoFontMetrics*>* desc_to_metrics = NULL;
56 static PangoContext* context = NULL; 59 static PangoContext* context = NULL;
57 60
58 if (!context) { 61 if (!context) {
62 #if defined(USE_WAYLAND)
63 PangoFontMap *font_map = pango_cairo_font_map_get_default();
sky 2011/07/27 15:51:05 This looks to be the same as in gtk_util. Create a
64 context = pango_font_map_create_context(font_map);
65 #else
59 context = gdk_pango_context_get_for_screen(gdk_screen_get_default()); 66 context = gdk_pango_context_get_for_screen(gdk_screen_get_default());
67 #endif
60 pango_context_set_language(context, pango_language_get_default()); 68 pango_context_set_language(context, pango_language_get_default());
61 } 69 }
62 70
63 if (!desc_to_metrics) { 71 if (!desc_to_metrics) {
64 desc_to_metrics = new std::map<int, PangoFontMetrics*>(); 72 desc_to_metrics = new std::map<int, PangoFontMetrics*>();
65 } 73 }
66 74
67 int desc_hash = pango_font_description_hash(desc); 75 int desc_hash = pango_font_description_hash(desc);
68 std::map<int, PangoFontMetrics*>::iterator i = 76 std::map<int, PangoFontMetrics*>::iterator i =
69 desc_to_metrics->find(desc_hash); 77 desc_to_metrics->find(desc_hash);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 121
114 namespace gfx { 122 namespace gfx {
115 123
116 Font* PlatformFontGtk::default_font_ = NULL; 124 Font* PlatformFontGtk::default_font_ = NULL;
117 125
118 //////////////////////////////////////////////////////////////////////////////// 126 ////////////////////////////////////////////////////////////////////////////////
119 // PlatformFontGtk, public: 127 // PlatformFontGtk, public:
120 128
121 PlatformFontGtk::PlatformFontGtk() { 129 PlatformFontGtk::PlatformFontGtk() {
122 if (default_font_ == NULL) { 130 if (default_font_ == NULL) {
131 #if defined(USE_WAYLAND)
sky 2011/07/27 15:51:05 This code is a bit hard to read. Create a function
132 char font_name[] = "sans 10";
133 #else
123 GtkSettings* settings = gtk_settings_get_default(); 134 GtkSettings* settings = gtk_settings_get_default();
124 135
125 gchar* font_name = NULL; 136 gchar* font_name = NULL;
126 g_object_get(settings, "gtk-font-name", &font_name, NULL); 137 g_object_get(settings, "gtk-font-name", &font_name, NULL);
127 138
128 // Temporary CHECK for helping track down 139 // Temporary CHECK for helping track down
129 // http://code.google.com/p/chromium/issues/detail?id=12530 140 // http://code.google.com/p/chromium/issues/detail?id=12530
130 CHECK(font_name) << " Unable to get gtk-font-name for default font."; 141 CHECK(font_name) << " Unable to get gtk-font-name for default font.";
142 #endif
131 143
132 PangoFontDescription* desc = 144 PangoFontDescription* desc =
133 pango_font_description_from_string(font_name); 145 pango_font_description_from_string(font_name);
134 default_font_ = new Font(desc); 146 default_font_ = new Font(desc);
135 pango_font_description_free(desc); 147 pango_font_description_free(desc);
148
149 #if !defined(USE_WAYLAND)
136 g_free(font_name); 150 g_free(font_name);
151 #endif
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

Powered by Google App Engine
This is Rietveld 408576698