| 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_skia.h" | 5 #include "ui/gfx/canvas_skia.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/base/range/range.h" | 10 #include "ui/base/range/range.h" |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 ui::ElideRectangleText(text, font, rect.width(), rect.height(), | 196 ui::ElideRectangleText(text, font, rect.width(), rect.height(), |
| 197 wrap_behavior, &strings); | 197 wrap_behavior, &strings); |
| 198 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); | 198 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); |
| 199 UpdateRenderText(rect, string16(), font, flags, 0, render_text.get()); | 199 UpdateRenderText(rect, string16(), font, flags, 0, render_text.get()); |
| 200 | 200 |
| 201 int h = 0; | 201 int h = 0; |
| 202 int w = 0; | 202 int w = 0; |
| 203 for (size_t i = 0; i < strings.size(); ++i) { | 203 for (size_t i = 0; i < strings.size(); ++i) { |
| 204 StripAcceleratorChars(flags, &strings[i]); | 204 StripAcceleratorChars(flags, &strings[i]); |
| 205 render_text->SetText(strings[i]); | 205 render_text->SetText(strings[i]); |
| 206 w = std::max(w, render_text->GetStringWidth()); | 206 w = std::max(w, render_text->GetStringSize().width()); |
| 207 h += font.GetHeight(); | 207 h += font.GetHeight(); |
| 208 } | 208 } |
| 209 *width = w; | 209 *width = w; |
| 210 *height = h; | 210 *height = h; |
| 211 } else { | 211 } else { |
| 212 // If the string is too long, the call by |RenderTextWin| to |ScriptShape()| | 212 // If the string is too long, the call by |RenderTextWin| to |ScriptShape()| |
| 213 // will inexplicably fail with result E_INVALIDARG. Guard against this. | 213 // will inexplicably fail with result E_INVALIDARG. Guard against this. |
| 214 const size_t kMaxRenderTextLength = 5000; | 214 const size_t kMaxRenderTextLength = 5000; |
| 215 if (text.length() >= kMaxRenderTextLength) { | 215 if (text.length() >= kMaxRenderTextLength) { |
| 216 *width = text.length() * font.GetAverageCharacterWidth(); | 216 *width = text.length() * font.GetAverageCharacterWidth(); |
| 217 } else { | 217 } else { |
| 218 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); | 218 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); |
| 219 gfx::Rect rect(*width, *height); | 219 gfx::Rect rect(*width, *height); |
| 220 string16 adjusted_text = text; | 220 string16 adjusted_text = text; |
| 221 StripAcceleratorChars(flags, &adjusted_text); | 221 StripAcceleratorChars(flags, &adjusted_text); |
| 222 UpdateRenderText(rect, adjusted_text, font, flags, 0, render_text.get()); | 222 UpdateRenderText(rect, adjusted_text, font, flags, 0, render_text.get()); |
| 223 *width = render_text->GetStringWidth(); | 223 *width = render_text->GetStringSize().width(); |
| 224 } | 224 } |
| 225 *height = font.GetHeight(); | 225 *height = font.GetHeight(); |
| 226 } | 226 } |
| 227 } | 227 } |
| 228 | 228 |
| 229 void CanvasSkia::DrawStringInt(const string16& text, | 229 void CanvasSkia::DrawStringInt(const string16& text, |
| 230 const gfx::Font& font, | 230 const gfx::Font& font, |
| 231 const SkColor& color, | 231 const SkColor& color, |
| 232 int x, int y, int w, int h, | 232 int x, int y, int w, int h, |
| 233 int flags) { | 233 int flags) { |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 UpdateRenderText(rect, clipped_text, font, flags, color, render_text.get()); | 410 UpdateRenderText(rect, clipped_text, font, flags, color, render_text.get()); |
| 411 | 411 |
| 412 canvas_->save(SkCanvas::kClip_SaveFlag); | 412 canvas_->save(SkCanvas::kClip_SaveFlag); |
| 413 ClipRect(display_rect); | 413 ClipRect(display_rect); |
| 414 render_text->Draw(this); | 414 render_text->Draw(this); |
| 415 canvas_->restore(); | 415 canvas_->restore(); |
| 416 } | 416 } |
| 417 #endif | 417 #endif |
| 418 | 418 |
| 419 } // namespace gfx | 419 } // namespace gfx |
| OLD | NEW |