| 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 <limits.h> | 5 #include <limits.h> |
| 6 #include <stddef.h> | 6 #include <stddef.h> |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 base::string16 adjusted_text = text; | 136 base::string16 adjusted_text = text; |
| 137 StripAcceleratorChars(flags, &adjusted_text); | 137 StripAcceleratorChars(flags, &adjusted_text); |
| 138 UpdateRenderText(rect, adjusted_text, font_list, flags, 0, | 138 UpdateRenderText(rect, adjusted_text, font_list, flags, 0, |
| 139 render_text.get()); | 139 render_text.get()); |
| 140 const SizeF& string_size = render_text->GetStringSizeF(); | 140 const SizeF& string_size = render_text->GetStringSizeF(); |
| 141 *width = string_size.width(); | 141 *width = string_size.width(); |
| 142 *height = string_size.height(); | 142 *height = string_size.height(); |
| 143 } | 143 } |
| 144 } | 144 } |
| 145 | 145 |
| 146 void Canvas::DrawStringRectWithShadows(const base::string16& text, | 146 void Canvas::DrawStringRectWithFlags(const base::string16& text, |
| 147 const FontList& font_list, | 147 const FontList& font_list, |
| 148 SkColor color, | 148 SkColor color, |
| 149 const Rect& text_bounds, | 149 const Rect& text_bounds, |
| 150 int line_height, | 150 int flags) { |
| 151 int flags, | |
| 152 const ShadowValues& shadows) { | |
| 153 if (!IntersectsClipRect(RectToSkRect(text_bounds))) | 151 if (!IntersectsClipRect(RectToSkRect(text_bounds))) |
| 154 return; | 152 return; |
| 155 | 153 |
| 156 Rect clip_rect(text_bounds); | |
| 157 clip_rect.Inset(ShadowValue::GetMargin(shadows)); | |
| 158 | |
| 159 canvas_->save(); | 154 canvas_->save(); |
| 160 ClipRect(clip_rect); | 155 ClipRect(text_bounds); |
| 161 | 156 |
| 162 Rect rect(text_bounds); | 157 Rect rect(text_bounds); |
| 163 | 158 |
| 164 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); | 159 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); |
| 165 render_text->set_shadows(shadows); | |
| 166 render_text->set_halo_effect(!!(flags & HALO_EFFECT)); | 160 render_text->set_halo_effect(!!(flags & HALO_EFFECT)); |
| 167 | 161 |
| 168 if (flags & MULTI_LINE) { | 162 if (flags & MULTI_LINE) { |
| 169 WordWrapBehavior wrap_behavior = IGNORE_LONG_WORDS; | 163 WordWrapBehavior wrap_behavior = IGNORE_LONG_WORDS; |
| 170 if (flags & CHARACTER_BREAK) | 164 if (flags & CHARACTER_BREAK) |
| 171 wrap_behavior = WRAP_LONG_WORDS; | 165 wrap_behavior = WRAP_LONG_WORDS; |
| 172 else if (!(flags & NO_ELLIPSIS)) | 166 else if (!(flags & NO_ELLIPSIS)) |
| 173 wrap_behavior = ELIDE_LONG_WORDS; | 167 wrap_behavior = ELIDE_LONG_WORDS; |
| 174 | 168 |
| 175 std::vector<base::string16> strings; | 169 std::vector<base::string16> strings; |
| 176 ElideRectangleText(text, font_list, | 170 ElideRectangleText(text, font_list, |
| 177 static_cast<float>(text_bounds.width()), | 171 static_cast<float>(text_bounds.width()), |
| 178 text_bounds.height(), wrap_behavior, &strings); | 172 text_bounds.height(), wrap_behavior, &strings); |
| 179 | 173 |
| 180 for (size_t i = 0; i < strings.size(); i++) { | 174 for (size_t i = 0; i < strings.size(); i++) { |
| 181 Range range = StripAcceleratorChars(flags, &strings[i]); | 175 Range range = StripAcceleratorChars(flags, &strings[i]); |
| 182 UpdateRenderText(rect, strings[i], font_list, flags, color, | 176 UpdateRenderText(rect, strings[i], font_list, flags, color, |
| 183 render_text.get()); | 177 render_text.get()); |
| 184 int line_padding = 0; | 178 int line_padding = 0; |
| 185 if (line_height > 0) | 179 const int line_height = render_text->GetStringSize().height(); |
| 186 line_padding = line_height - render_text->GetStringSize().height(); | |
| 187 else | |
| 188 line_height = render_text->GetStringSize().height(); | |
| 189 | 180 |
| 190 // TODO(msw|asvitkine): Center Windows multi-line text: crbug.com/107357 | 181 // TODO(msw|asvitkine): Center Windows multi-line text: crbug.com/107357 |
| 191 #if !defined(OS_WIN) | 182 #if !defined(OS_WIN) |
| 192 if (i == 0) { | 183 if (i == 0) { |
| 193 // TODO(msw|asvitkine): Support multi-line text with varied heights. | 184 // TODO(msw|asvitkine): Support multi-line text with varied heights. |
| 194 const int text_height = strings.size() * line_height - line_padding; | 185 const int text_height = strings.size() * line_height - line_padding; |
| 195 rect += Vector2d(0, (text_bounds.height() - text_height) / 2); | 186 rect += Vector2d(0, (text_bounds.height() - text_height) / 2); |
| 196 } | 187 } |
| 197 #endif | 188 #endif |
| 198 | 189 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 UpdateRenderText(rect, text, font_list, flags, color, render_text.get()); | 267 UpdateRenderText(rect, text, font_list, flags, color, render_text.get()); |
| 277 render_text->SetElideBehavior(FADE_TAIL); | 268 render_text->SetElideBehavior(FADE_TAIL); |
| 278 | 269 |
| 279 canvas_->save(); | 270 canvas_->save(); |
| 280 ClipRect(display_rect); | 271 ClipRect(display_rect); |
| 281 render_text->Draw(this); | 272 render_text->Draw(this); |
| 282 canvas_->restore(); | 273 canvas_->restore(); |
| 283 } | 274 } |
| 284 | 275 |
| 285 } // namespace gfx | 276 } // namespace gfx |
| OLD | NEW |