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

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

Issue 374833005: Simplify PangoLayout configuration. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove unneeded PangoContext forward declaration Created 6 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
« no previous file with comments | « ui/gfx/platform_font_pango.h ('k') | ui/gfx/render_text_pango.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) 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>
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 66
67 #if defined(OS_CHROMEOS) 67 #if defined(OS_CHROMEOS)
68 // static 68 // static
69 std::string* PlatformFontPango::default_font_description_ = NULL; 69 std::string* PlatformFontPango::default_font_description_ = NULL;
70 #endif 70 #endif
71 71
72 //////////////////////////////////////////////////////////////////////////////// 72 ////////////////////////////////////////////////////////////////////////////////
73 // PlatformFontPango, public: 73 // PlatformFontPango, public:
74 74
75 PlatformFontPango::PlatformFontPango() { 75 PlatformFontPango::PlatformFontPango() {
76 if (default_font_ == NULL) { 76 if (!default_font_) {
77 std::string font_name = GetDefaultFont(); 77 std::string desc_string;
78 #if defined(OS_CHROMEOS)
79 // Font name must have been provided by way of SetDefaultFontDescription().
80 CHECK(default_font_description_);
81 desc_string = *default_font_description_;
82 #else
83 const gfx::LinuxFontDelegate* delegate = gfx::LinuxFontDelegate::instance();
84 desc_string = delegate ? delegate->GetDefaultFontDescription() : "sans 10";
85 #endif
78 86
79 ScopedPangoFontDescription desc( 87 ScopedPangoFontDescription desc(
80 pango_font_description_from_string(font_name.c_str())); 88 pango_font_description_from_string(desc_string.c_str()));
81 default_font_ = new Font(desc.get()); 89 default_font_ = new Font(desc.get());
82
83 DCHECK(default_font_);
84 } 90 }
85 91
86 InitFromPlatformFont( 92 InitFromPlatformFont(
87 static_cast<PlatformFontPango*>(default_font_->platform_font())); 93 static_cast<PlatformFontPango*>(default_font_->platform_font()));
88 } 94 }
89 95
90 PlatformFontPango::PlatformFontPango(NativeFont native_font) { 96 PlatformFontPango::PlatformFontPango(NativeFont native_font) {
91 std::vector<std::string> family_names; 97 std::vector<std::string> family_names;
92 base::SplitString(pango_font_description_get_family(native_font), ',', 98 base::SplitString(pango_font_description_get_family(native_font), ',',
93 &family_names); 99 &family_names);
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 247
242 PlatformFontPango::PlatformFontPango(const skia::RefPtr<SkTypeface>& typeface, 248 PlatformFontPango::PlatformFontPango(const skia::RefPtr<SkTypeface>& typeface,
243 const std::string& name, 249 const std::string& name,
244 int size, 250 int size,
245 int style) { 251 int style) {
246 InitFromDetails(typeface, name, size, style); 252 InitFromDetails(typeface, name, size, style);
247 } 253 }
248 254
249 PlatformFontPango::~PlatformFontPango() {} 255 PlatformFontPango::~PlatformFontPango() {}
250 256
251 // static
252 std::string PlatformFontPango::GetDefaultFont() {
253 #if defined(OS_CHROMEOS)
254 // Font name must have been provided by way of SetDefaultFontDescription().
255 CHECK(default_font_description_);
256 return *default_font_description_;
257 #else
258 const gfx::LinuxFontDelegate* delegate = gfx::LinuxFontDelegate::instance();
259 return delegate ? delegate->GetDefaultFontDescription() : "sans 10";
260 #endif // defined(OS_CHROMEOS)
261 }
262
263 void PlatformFontPango::InitFromDetails( 257 void PlatformFontPango::InitFromDetails(
264 const skia::RefPtr<SkTypeface>& typeface, 258 const skia::RefPtr<SkTypeface>& typeface,
265 const std::string& font_family, 259 const std::string& font_family,
266 int font_size, 260 int font_size,
267 int style) { 261 int style) {
268 DCHECK_GT(font_size, 0); 262 DCHECK_GT(font_size, 0);
269 263
270 typeface_ = typeface; 264 typeface_ = typeface;
271 font_family_ = font_family; 265 font_family_ = font_family;
272 if (!typeface_) { 266 if (!typeface_) {
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 return new PlatformFontPango(native_font); 371 return new PlatformFontPango(native_font);
378 } 372 }
379 373
380 // static 374 // static
381 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, 375 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name,
382 int font_size) { 376 int font_size) {
383 return new PlatformFontPango(font_name, font_size); 377 return new PlatformFontPango(font_name, font_size);
384 } 378 }
385 379
386 } // namespace gfx 380 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/platform_font_pango.h ('k') | ui/gfx/render_text_pango.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698