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

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

Issue 10807082: Add RenderText DirectionalityMode enum and support; etc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove errant blank line. Created 8 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/render_text_linux.h ('k') | ui/gfx/render_text_mac.h » ('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/render_text_linux.h" 5 #include "ui/gfx/render_text_linux.h"
6 6
7 #include <pango/pangocairo.h> 7 #include <pango/pangocairo.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 log_attrs_(NULL), 73 log_attrs_(NULL),
74 num_log_attrs_(0), 74 num_log_attrs_(0),
75 layout_text_(NULL), 75 layout_text_(NULL),
76 layout_text_len_(0) { 76 layout_text_len_(0) {
77 } 77 }
78 78
79 RenderTextLinux::~RenderTextLinux() { 79 RenderTextLinux::~RenderTextLinux() {
80 ResetLayout(); 80 ResetLayout();
81 } 81 }
82 82
83 base::i18n::TextDirection RenderTextLinux::GetTextDirection() {
84 EnsureLayout();
85
86 PangoDirection base_dir = pango_find_base_dir(layout_text_, -1);
87 if (base_dir == PANGO_DIRECTION_RTL || base_dir == PANGO_DIRECTION_WEAK_RTL)
88 return base::i18n::RIGHT_TO_LEFT;
89 return base::i18n::LEFT_TO_RIGHT;
90 }
91
92 Size RenderTextLinux::GetStringSize() { 83 Size RenderTextLinux::GetStringSize() {
93 EnsureLayout(); 84 EnsureLayout();
94 int width = 0, height = 0; 85 int width = 0, height = 0;
95 pango_layout_get_pixel_size(layout_, &width, &height); 86 pango_layout_get_pixel_size(layout_, &width, &height);
96 return Size(width, height); 87 return Size(width, height);
97 } 88 }
98 89
99 int RenderTextLinux::GetBaseline() { 90 int RenderTextLinux::GetBaseline() {
100 EnsureLayout(); 91 EnsureLayout();
101 return PANGO_PIXELS(pango_layout_get_baseline(layout_)); 92 return PANGO_PIXELS(pango_layout_get_baseline(layout_));
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 272
282 void RenderTextLinux::EnsureLayout() { 273 void RenderTextLinux::EnsureLayout() {
283 if (layout_ == NULL) { 274 if (layout_ == NULL) {
284 cairo_surface_t* surface = 275 cairo_surface_t* surface =
285 cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 0, 0); 276 cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 0, 0);
286 cairo_t* cr = cairo_create(surface); 277 cairo_t* cr = cairo_create(surface);
287 278
288 layout_ = pango_cairo_create_layout(cr); 279 layout_ = pango_cairo_create_layout(cr);
289 cairo_destroy(cr); 280 cairo_destroy(cr);
290 cairo_surface_destroy(surface); 281 cairo_surface_destroy(surface);
291 SetupPangoLayoutWithFontDescription( 282
292 layout_, 283 SetupPangoLayoutWithFontDescription(layout_,
293 GetDisplayText(), 284 GetDisplayText(),
294 font_list().GetFontDescriptionString(), 285 font_list().GetFontDescriptionString(),
295 display_rect().width(), 286 display_rect().width(),
296 base::i18n::GetFirstStrongCharacterDirection(text()), 287 GetTextDirection(),
297 Canvas::DefaultCanvasTextAlignment()); 288 Canvas::DefaultCanvasTextAlignment());
298 289
299 // No width set so that the x-axis position is relative to the start of the 290 // No width set so that the x-axis position is relative to the start of the
300 // text. ToViewPoint and ToTextPoint take care of the position conversion 291 // text. ToViewPoint and ToTextPoint take care of the position conversion
301 // between text space and view spaces. 292 // between text space and view spaces.
302 pango_layout_set_width(layout_, -1); 293 pango_layout_set_width(layout_, -1);
303 // TODO(xji): If RenderText will be used for displaying purpose, such as 294 // TODO(xji): If RenderText will be used for displaying purpose, such as
304 // label, we will need to remove the single-line-mode setting. 295 // label, we will need to remove the single-line-mode setting.
305 pango_layout_set_single_paragraph_mode(layout_, true); 296 pango_layout_set_single_paragraph_mode(layout_, true);
306 297
307 // These are used by SetupPangoAttributes. 298 // These are used by SetupPangoAttributes.
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 if (selection_visual_bounds_.empty()) 540 if (selection_visual_bounds_.empty())
550 selection_visual_bounds_ = CalculateSubstringBounds(selection()); 541 selection_visual_bounds_ = CalculateSubstringBounds(selection());
551 return selection_visual_bounds_; 542 return selection_visual_bounds_;
552 } 543 }
553 544
554 RenderText* RenderText::CreateInstance() { 545 RenderText* RenderText::CreateInstance() {
555 return new RenderTextLinux; 546 return new RenderTextLinux;
556 } 547 }
557 548
558 } // namespace gfx 549 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/render_text_linux.h ('k') | ui/gfx/render_text_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698