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

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: Replaced the way WaylandDisplay is being retrieved Created 9 years, 5 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)
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) {
59 context = gdk_pango_context_get_for_screen(gdk_screen_get_default()); 62 PangoFontMap *font_map = pango_cairo_font_map_get_default();
63 context = pango_font_map_create_context(font_map);
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 117
114 namespace gfx { 118 namespace gfx {
115 119
116 Font* PlatformFontGtk::default_font_ = NULL; 120 Font* PlatformFontGtk::default_font_ = NULL;
117 121
118 //////////////////////////////////////////////////////////////////////////////// 122 ////////////////////////////////////////////////////////////////////////////////
119 // PlatformFontGtk, public: 123 // PlatformFontGtk, public:
120 124
121 PlatformFontGtk::PlatformFontGtk() { 125 PlatformFontGtk::PlatformFontGtk() {
122 if (default_font_ == NULL) { 126 if (default_font_ == NULL) {
127 #if defined(USE_WAYLAND)
128 char font_name[] = "sans 10";
129 #else
123 GtkSettings* settings = gtk_settings_get_default(); 130 GtkSettings* settings = gtk_settings_get_default();
124 131
125 gchar* font_name = NULL; 132 gchar* font_name = NULL;
126 g_object_get(settings, "gtk-font-name", &font_name, NULL); 133 g_object_get(settings, "gtk-font-name", &font_name, NULL);
127 134
128 // Temporary CHECK for helping track down 135 // Temporary CHECK for helping track down
129 // http://code.google.com/p/chromium/issues/detail?id=12530 136 // http://code.google.com/p/chromium/issues/detail?id=12530
130 CHECK(font_name) << " Unable to get gtk-font-name for default font."; 137 CHECK(font_name) << " Unable to get gtk-font-name for default font.";
138 #endif
131 139
132 PangoFontDescription* desc = 140 PangoFontDescription* desc =
133 pango_font_description_from_string(font_name); 141 pango_font_description_from_string(font_name);
134 default_font_ = new Font(desc); 142 default_font_ = new Font(desc);
135 pango_font_description_free(desc); 143 pango_font_description_free(desc);
144
145 #if !defined(USE_WAYLAND)
136 g_free(font_name); 146 g_free(font_name);
147 #endif
137 148
138 DCHECK(default_font_); 149 DCHECK(default_font_);
139 } 150 }
140 151
141 InitFromPlatformFont( 152 InitFromPlatformFont(
142 static_cast<PlatformFontGtk*>(default_font_->platform_font())); 153 static_cast<PlatformFontGtk*>(default_font_->platform_font()));
143 } 154 }
144 155
145 PlatformFontGtk::PlatformFontGtk(const Font& other) { 156 PlatformFontGtk::PlatformFontGtk(const Font& other) {
146 InitFromPlatformFont( 157 InitFromPlatformFont(
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 return new PlatformFontGtk(native_font); 458 return new PlatformFontGtk(native_font);
448 } 459 }
449 460
450 // static 461 // static
451 PlatformFont* PlatformFont::CreateFromNameAndSize(const string16& font_name, 462 PlatformFont* PlatformFont::CreateFromNameAndSize(const string16& font_name,
452 int font_size) { 463 int font_size) {
453 return new PlatformFontGtk(font_name, font_size); 464 return new PlatformFontGtk(font_name, font_size);
454 } 465 }
455 466
456 } // namespace gfx 467 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698