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

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

Issue 692803004: For multiline text use the maximum of the string height and the line height while calculating the h… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed build error Created 6 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | 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/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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 UpdateRenderText(rect, base::string16(), font_list, flags, 0, 184 UpdateRenderText(rect, base::string16(), font_list, flags, 0,
185 render_text.get()); 185 render_text.get());
186 186
187 float h = 0; 187 float h = 0;
188 float w = 0; 188 float w = 0;
189 for (size_t i = 0; i < strings.size(); ++i) { 189 for (size_t i = 0; i < strings.size(); ++i) {
190 StripAcceleratorChars(flags, &strings[i]); 190 StripAcceleratorChars(flags, &strings[i]);
191 render_text->SetText(strings[i]); 191 render_text->SetText(strings[i]);
192 const SizeF& string_size = render_text->GetStringSizeF(); 192 const SizeF& string_size = render_text->GetStringSizeF();
193 w = std::max(w, string_size.width()); 193 w = std::max(w, string_size.width());
194 h += (i > 0 && line_height > 0) ? line_height : string_size.height(); 194 h += (i > 0 && line_height > 0) ?
195 std::max(static_cast<float>(line_height), string_size.height())
196 : string_size.height();
195 } 197 }
196 *width = w; 198 *width = w;
197 *height = h; 199 *height = h;
198 } else { 200 } else {
199 // If the string is too long, the call by |RenderTextWin| to |ScriptShape()| 201 // If the string is too long, the call by |RenderTextWin| to |ScriptShape()|
200 // will inexplicably fail with result E_INVALIDARG. Guard against this. 202 // will inexplicably fail with result E_INVALIDARG. Guard against this.
201 const size_t kMaxRenderTextLength = 5000; 203 const size_t kMaxRenderTextLength = 5000;
202 if (adjusted_text.length() >= kMaxRenderTextLength) { 204 if (adjusted_text.length() >= kMaxRenderTextLength) {
203 *width = static_cast<float>( 205 *width = static_cast<float>(
204 font_list.GetExpectedTextWidth(adjusted_text.length())); 206 font_list.GetExpectedTextWidth(adjusted_text.length()));
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 UpdateRenderText(rect, text, font_list, flags, color, render_text.get()); 395 UpdateRenderText(rect, text, font_list, flags, color, render_text.get());
394 render_text->SetElideBehavior(FADE_TAIL); 396 render_text->SetElideBehavior(FADE_TAIL);
395 397
396 canvas_->save(); 398 canvas_->save();
397 ClipRect(display_rect); 399 ClipRect(display_rect);
398 render_text->Draw(this); 400 render_text->Draw(this);
399 canvas_->restore(); 401 canvas_->restore();
400 } 402 }
401 403
402 } // namespace gfx 404 } // namespace gfx
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698