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

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

Issue 10406014: Add a ScopedPangoFontDescription helper class and use it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 7 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/pango_util.h ('k') | ui/gfx/platform_font_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/pango_util.h" 5 #include "ui/gfx/pango_util.h"
6 6
7 #include <cairo/cairo.h> 7 #include <cairo/cairo.h>
8 #include <fontconfig/fontconfig.h> 8 #include <fontconfig/fontconfig.h>
9 #include <pango/pango.h> 9 #include <pango/pango.h>
10 #include <pango/pangocairo.h> 10 #include <pango/pangocairo.h>
11 #include <string>
11 12
12 #include <algorithm> 13 #include <algorithm>
13 #include <map> 14 #include <map>
14 #include <vector> 15 #include <vector>
15 16
16 #include "base/logging.h" 17 #include "base/logging.h"
17 #include "base/utf_string_conversions.h" 18 #include "base/utf_string_conversions.h"
18 #include "ui/gfx/canvas.h" 19 #include "ui/gfx/canvas.h"
19 #include "ui/gfx/font.h" 20 #include "ui/gfx/font.h"
20 #include "ui/gfx/platform_font_pango.h" 21 #include "ui/gfx/platform_font_pango.h"
21 #include "ui/gfx/rect.h" 22 #include "ui/gfx/rect.h"
23 #include "ui/gfx/skia_util.h"
22 24
23 #if defined(TOOLKIT_GTK) 25 #if defined(TOOLKIT_GTK)
24 #include <gdk/gdk.h> 26 #include <gdk/gdk.h>
25 #include <gtk/gtk.h> 27 #include <gtk/gtk.h>
26 #include "ui/gfx/gtk_util.h" 28 #include "ui/gfx/gtk_util.h"
27 #else 29 #else
28 #include "base/command_line.h" 30 #include "base/command_line.h"
29 #include "ui/base/ui_base_switches.h" 31 #include "ui/base/ui_base_switches.h"
30 #endif 32 #endif
31 33
32 #include "ui/gfx/skia_util.h"
33
34 namespace { 34 namespace {
35 35
36 // Marker for accelerators in the text. 36 // Marker for accelerators in the text.
37 const gunichar kAcceleratorChar = '&'; 37 const gunichar kAcceleratorChar = '&';
38 38
39 // Multiply by the text height to determine how much text should be faded 39 // Multiply by the text height to determine how much text should be faded
40 // when elliding. 40 // when elliding.
41 const double kFadeWidthFactor = 1.5; 41 const double kFadeWidthFactor = 1.5;
42 42
43 // End state of the elliding fade. 43 // End state of the elliding fade.
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 } 345 }
346 346
347 void SetupPangoLayout(PangoLayout* layout, 347 void SetupPangoLayout(PangoLayout* layout,
348 const string16& text, 348 const string16& text,
349 const Font& font, 349 const Font& font,
350 int width, 350 int width,
351 base::i18n::TextDirection text_direction, 351 base::i18n::TextDirection text_direction,
352 int flags) { 352 int flags) {
353 SetupPangoLayoutWithoutFont(layout, text, width, text_direction, flags); 353 SetupPangoLayoutWithoutFont(layout, text, width, text_direction, flags);
354 354
355 PangoFontDescription* desc = font.GetNativeFont(); 355 ScopedPangoFontDescription desc(font.GetNativeFont());
356 pango_layout_set_font_description(layout, desc); 356 pango_layout_set_font_description(layout, desc.get());
357 pango_font_description_free(desc);
358 } 357 }
359 358
360 void SetupPangoLayoutWithFontDescription( 359 void SetupPangoLayoutWithFontDescription(
361 PangoLayout* layout, 360 PangoLayout* layout,
362 const string16& text, 361 const string16& text,
363 const std::string& font_description, 362 const std::string& font_description,
364 int width, 363 int width,
365 base::i18n::TextDirection text_direction, 364 base::i18n::TextDirection text_direction,
366 int flags) { 365 int flags) {
367 SetupPangoLayoutWithoutFont(layout, text, width, text_direction, flags); 366 SetupPangoLayoutWithoutFont(layout, text, width, text_direction, flags);
368 367
369 PangoFontDescription* desc = pango_font_description_from_string( 368 ScopedPangoFontDescription desc(
370 font_description.c_str()); 369 pango_font_description_from_string(font_description.c_str()));
371 pango_layout_set_font_description(layout, desc); 370 pango_layout_set_font_description(layout, desc.get());
372 pango_font_description_free(desc);
373 } 371 }
374 372
375 void AdjustTextRectBasedOnLayout(PangoLayout* layout, 373 void AdjustTextRectBasedOnLayout(PangoLayout* layout,
376 const gfx::Rect& bounds, 374 const gfx::Rect& bounds,
377 int flags, 375 int flags,
378 gfx::Rect* text_rect) { 376 gfx::Rect* text_rect) {
379 int text_width, text_height; 377 int text_width, text_height;
380 pango_layout_get_pixel_size(layout, &text_width, &text_height); 378 pango_layout_get_pixel_size(layout, &text_width, &text_height);
381 text_rect->set_width(text_width); 379 text_rect->set_width(text_width);
382 text_rect->set_height(text_height); 380 text_rect->set_height(text_height);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 493
496 if (i == desc_to_metrics->end()) { 494 if (i == desc_to_metrics->end()) {
497 PangoFontMetrics* metrics = pango_context_get_metrics(context, desc, NULL); 495 PangoFontMetrics* metrics = pango_context_get_metrics(context, desc, NULL);
498 desc_to_metrics->insert(std::make_pair(desc_hash, metrics)); 496 desc_to_metrics->insert(std::make_pair(desc_hash, metrics));
499 return metrics; 497 return metrics;
500 } 498 }
501 return i->second; 499 return i->second;
502 } 500 }
503 501
504 } // namespace gfx 502 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/pango_util.h ('k') | ui/gfx/platform_font_pango.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698