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

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: Update and expand on unit tests. 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
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());
289
290 // Set the base text direction yeilded by the directionality mode.
291 pango_context_set_base_dir(pango_layout_get_context(layout_),
292 ((GetTextDirection() == base::i18n::RIGHT_TO_LEFT) ?
Alexei Svitkine (slow) 2012/07/30 22:29:16 Nit: Too many parentheses. Suggest omitting the in
msw 2012/07/31 03:03:06 Done.
293 PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR));
298 294
299 // No width set so that the x-axis position is relative to the start of the 295 // 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 296 // text. ToViewPoint and ToTextPoint take care of the position conversion
301 // between text space and view spaces. 297 // between text space and view spaces.
302 pango_layout_set_width(layout_, -1); 298 pango_layout_set_width(layout_, -1);
303 // TODO(xji): If RenderText will be used for displaying purpose, such as 299 // TODO(xji): If RenderText will be used for displaying purpose, such as
304 // label, we will need to remove the single-line-mode setting. 300 // label, we will need to remove the single-line-mode setting.
305 pango_layout_set_single_paragraph_mode(layout_, true); 301 pango_layout_set_single_paragraph_mode(layout_, true);
306 302
307 // These are used by SetupPangoAttributes. 303 // These are used by SetupPangoAttributes.
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 if (selection_visual_bounds_.empty()) 545 if (selection_visual_bounds_.empty())
550 selection_visual_bounds_ = CalculateSubstringBounds(selection()); 546 selection_visual_bounds_ = CalculateSubstringBounds(selection());
551 return selection_visual_bounds_; 547 return selection_visual_bounds_;
552 } 548 }
553 549
554 RenderText* RenderText::CreateInstance() { 550 RenderText* RenderText::CreateInstance() {
555 return new RenderTextLinux; 551 return new RenderTextLinux;
556 } 552 }
557 553
558 } // namespace gfx 554 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698