Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/canvas.h" | 5 #include "ui/gfx/canvas.h" |
| 6 | 6 |
| 7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "ui/gfx/font_list.h" | 10 #include "ui/gfx/font_list.h" |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 | 169 |
| 170 if ((flags & MULTI_LINE) && *width != 0) { | 170 if ((flags & MULTI_LINE) && *width != 0) { |
| 171 WordWrapBehavior wrap_behavior = TRUNCATE_LONG_WORDS; | 171 WordWrapBehavior wrap_behavior = TRUNCATE_LONG_WORDS; |
| 172 if (flags & CHARACTER_BREAK) | 172 if (flags & CHARACTER_BREAK) |
| 173 wrap_behavior = WRAP_LONG_WORDS; | 173 wrap_behavior = WRAP_LONG_WORDS; |
| 174 else if (!(flags & NO_ELLIPSIS)) | 174 else if (!(flags & NO_ELLIPSIS)) |
| 175 wrap_behavior = ELIDE_LONG_WORDS; | 175 wrap_behavior = ELIDE_LONG_WORDS; |
| 176 | 176 |
| 177 Rect rect(*width, INT_MAX); | 177 Rect rect(*width, INT_MAX); |
| 178 std::vector<base::string16> strings; | 178 std::vector<base::string16> strings; |
| 179 ElideRectangleText(adjusted_text, font_list, rect.width(), rect.height(), | 179 float w = 0.0; |
| 180 wrap_behavior, &strings); | 180 ElideRectangleText(adjusted_text, |
| 181 font_list, | |
| 182 rect.width(), | |
| 183 rect.height(), | |
| 184 wrap_behavior, | |
| 185 &strings, | |
| 186 &w); | |
| 181 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | 187 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
| 182 UpdateRenderText(rect, base::string16(), font_list, flags, 0, | 188 UpdateRenderText(rect, base::string16(), font_list, flags, 0, |
| 183 render_text.get()); | 189 render_text.get()); |
| 184 | 190 |
| 185 float h = 0; | 191 float h = 0.0; |
| 186 float w = 0; | |
| 187 for (size_t i = 0; i < strings.size(); ++i) { | 192 for (size_t i = 0; i < strings.size(); ++i) { |
| 188 StripAcceleratorChars(flags, &strings[i]); | 193 StripAcceleratorChars(flags, &strings[i]); |
| 189 render_text->SetText(strings[i]); | 194 render_text->SetText(strings[i]); |
| 190 const SizeF& string_size = render_text->GetStringSizeF(); | 195 const SizeF& string_size = render_text->GetStringSizeF(); |
| 191 w = std::max(w, string_size.width()); | 196 w = std::max(w, string_size.width()); |
|
Alexei Svitkine (slow)
2014/10/06 17:59:58
I actually don't understand your fix.
Can you cla
Roman Sorokin (ftl)
2014/10/07 09:21:53
See the CL description, please
On 2014/10/06 17:59
| |
| 192 h += (i > 0 && line_height > 0) ? line_height : string_size.height(); | 197 h += (i > 0 && line_height > 0) ? line_height : string_size.height(); |
| 193 } | 198 } |
| 194 *width = w; | 199 *width = w; |
| 195 *height = h; | 200 *height = h; |
| 196 } else { | 201 } else { |
| 197 // If the string is too long, the call by |RenderTextWin| to |ScriptShape()| | 202 // If the string is too long, the call by |RenderTextWin| to |ScriptShape()| |
| 198 // will inexplicably fail with result E_INVALIDARG. Guard against this. | 203 // will inexplicably fail with result E_INVALIDARG. Guard against this. |
| 199 const size_t kMaxRenderTextLength = 5000; | 204 const size_t kMaxRenderTextLength = 5000; |
| 200 if (adjusted_text.length() >= kMaxRenderTextLength) { | 205 if (adjusted_text.length() >= kMaxRenderTextLength) { |
| 201 *width = font_list.GetExpectedTextWidth(adjusted_text.length()); | 206 *width = font_list.GetExpectedTextWidth(adjusted_text.length()); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 render_text->set_shadows(shadows); | 245 render_text->set_shadows(shadows); |
| 241 | 246 |
| 242 if (flags & MULTI_LINE) { | 247 if (flags & MULTI_LINE) { |
| 243 WordWrapBehavior wrap_behavior = IGNORE_LONG_WORDS; | 248 WordWrapBehavior wrap_behavior = IGNORE_LONG_WORDS; |
| 244 if (flags & CHARACTER_BREAK) | 249 if (flags & CHARACTER_BREAK) |
| 245 wrap_behavior = WRAP_LONG_WORDS; | 250 wrap_behavior = WRAP_LONG_WORDS; |
| 246 else if (!(flags & NO_ELLIPSIS)) | 251 else if (!(flags & NO_ELLIPSIS)) |
| 247 wrap_behavior = ELIDE_LONG_WORDS; | 252 wrap_behavior = ELIDE_LONG_WORDS; |
| 248 | 253 |
| 249 std::vector<base::string16> strings; | 254 std::vector<base::string16> strings; |
| 250 ElideRectangleText(adjusted_text, font_list, text_bounds.width(), | 255 ElideRectangleText(adjusted_text, |
| 251 text_bounds.height(), wrap_behavior, &strings); | 256 font_list, |
| 257 text_bounds.width(), | |
| 258 text_bounds.height(), | |
| 259 wrap_behavior, | |
| 260 &strings, | |
| 261 nullptr); | |
| 252 | 262 |
| 253 for (size_t i = 0; i < strings.size(); i++) { | 263 for (size_t i = 0; i < strings.size(); i++) { |
| 254 Range range = StripAcceleratorChars(flags, &strings[i]); | 264 Range range = StripAcceleratorChars(flags, &strings[i]); |
| 255 UpdateRenderText(rect, strings[i], font_list, flags, color, | 265 UpdateRenderText(rect, strings[i], font_list, flags, color, |
| 256 render_text.get()); | 266 render_text.get()); |
| 257 int line_padding = 0; | 267 int line_padding = 0; |
| 258 if (line_height > 0) | 268 if (line_height > 0) |
| 259 line_padding = line_height - render_text->GetStringSize().height(); | 269 line_padding = line_height - render_text->GetStringSize().height(); |
| 260 else | 270 else |
| 261 line_height = render_text->GetStringSize().height(); | 271 line_height = render_text->GetStringSize().height(); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 388 UpdateRenderText(rect, text, font_list, flags, color, render_text.get()); | 398 UpdateRenderText(rect, text, font_list, flags, color, render_text.get()); |
| 389 render_text->SetElideBehavior(FADE_TAIL); | 399 render_text->SetElideBehavior(FADE_TAIL); |
| 390 | 400 |
| 391 canvas_->save(); | 401 canvas_->save(); |
| 392 ClipRect(display_rect); | 402 ClipRect(display_rect); |
| 393 render_text->Draw(this); | 403 render_text->Draw(this); |
| 394 canvas_->restore(); | 404 canvas_->restore(); |
| 395 } | 405 } |
| 396 | 406 |
| 397 } // namespace gfx | 407 } // namespace gfx |
| OLD | NEW |