OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "views/view_text_utils.h" | 5 #include "views/view_text_utils.h" |
6 | 6 |
7 #include "app/bidi_line_iterator.h" | 7 #include "app/bidi_line_iterator.h" |
8 #include "base/i18n/word_iterator.h" | 8 #include "base/i18n/word_iterator.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 // iterate to the next line breaking opportunity. | 110 // iterate to the next line breaking opportunity. |
111 while (iter.Advance()) { | 111 while (iter.Advance()) { |
112 // Get the word and figure out the dimensions. | 112 // Get the word and figure out the dimensions. |
113 std::wstring word; | 113 std::wstring word; |
114 if (!ltr_within_rtl) | 114 if (!ltr_within_rtl) |
115 word = UTF16ToWide(iter.GetWord()); // Get the next word. | 115 word = UTF16ToWide(iter.GetWord()); // Get the next word. |
116 else | 116 else |
117 word = text; // Draw the whole text at once. | 117 word = text; // Draw the whole text at once. |
118 | 118 |
119 int w = font.GetStringWidth(word), h = font.GetHeight(); | 119 int w = font.GetStringWidth(word), h = font.GetHeight(); |
120 gfx::CanvasSkia::SizeStringInt(word, font, &w, &h, flags); | 120 gfx::CanvasSkia::SizeStringInt(WideToUTF16Hack(word), font, &w, &h, flags); |
121 | 121 |
122 // If we exceed the boundaries, we need to wrap. | 122 // If we exceed the boundaries, we need to wrap. |
123 WrapIfWordDoesntFit(w, font.GetHeight(), position, bounds); | 123 WrapIfWordDoesntFit(w, font.GetHeight(), position, bounds); |
124 | 124 |
125 int x = label->MirroredXCoordinateInsideView(position->width()) + | 125 int x = label->MirroredXCoordinateInsideView(position->width()) + |
126 bounds.x(); | 126 bounds.x(); |
127 if (text_direction_is_rtl) { | 127 if (text_direction_is_rtl) { |
128 x -= w; | 128 x -= w; |
129 // When drawing LTR strings inside RTL text we need to make sure we | 129 // When drawing LTR strings inside RTL text we need to make sure we |
130 // draw the trailing space (if one exists after the LTR text) to the | 130 // draw the trailing space (if one exists after the LTR text) to the |
131 // left of the LTR string. | 131 // left of the LTR string. |
132 if (ltr_within_rtl && word[word.size() - 1] == L' ') { | 132 if (ltr_within_rtl && word[word.size() - 1] == L' ') { |
133 int space_w = font.GetStringWidth(L" "), space_h = font.GetHeight(); | 133 int space_w = font.GetStringWidth(L" "), space_h = font.GetHeight(); |
134 gfx::CanvasSkia::SizeStringInt(L" ", font, &space_w, &space_h, flags); | 134 gfx::CanvasSkia::SizeStringInt(UTF8ToUTF16(" "), font, &space_w, |
| 135 &space_h, flags); |
135 x += space_w; | 136 x += space_w; |
136 } | 137 } |
137 } | 138 } |
138 int y = position->height() + bounds.y(); | 139 int y = position->height() + bounds.y(); |
139 | 140 |
140 // Draw the text on the screen (mirrored, if RTL run). | 141 // Draw the text on the screen (mirrored, if RTL run). |
141 canvas->DrawStringInt(word, font, text_color, x, y, w, font.GetHeight(), | 142 canvas->DrawStringInt(word, font, text_color, x, y, w, font.GetHeight(), |
142 flags); | 143 flags); |
143 | 144 |
144 if (word.size() > 0 && word[word.size() - 1] == L'\x0a') { | 145 if (word.size() > 0 && word[word.size() - 1] == L'\x0a') { |
(...skipping 14 matching lines...) Expand all Loading... |
159 int font_height, | 160 int font_height, |
160 gfx::Size* position, | 161 gfx::Size* position, |
161 const gfx::Rect& bounds) { | 162 const gfx::Rect& bounds) { |
162 if (position->width() + word_width > bounds.right()) { | 163 if (position->width() + word_width > bounds.right()) { |
163 position->set_width(0); | 164 position->set_width(0); |
164 position->Enlarge(0, font_height); | 165 position->Enlarge(0, font_height); |
165 } | 166 } |
166 } | 167 } |
167 | 168 |
168 } // namespace view_text_utils | 169 } // namespace view_text_utils |
OLD | NEW |