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/render_text_win.h" | 5 #include "ui/gfx/render_text_win.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/i18n/break_iterator.h" | 9 #include "base/i18n/break_iterator.h" |
10 #include "base/i18n/char_iterator.h" | 10 #include "base/i18n/char_iterator.h" |
11 #include "base/i18n/rtl.h" | 11 #include "base/i18n/rtl.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "base/win/windows_version.h" | 15 #include "base/win/windows_version.h" |
16 #include "third_party/icu/source/common/unicode/uchar.h" | 16 #include "third_party/icu/source/common/unicode/uchar.h" |
17 #include "ui/gfx/canvas.h" | 17 #include "ui/gfx/canvas.h" |
18 #include "ui/gfx/font_fallback_win.h" | 18 #include "ui/gfx/font_fallback_win.h" |
19 #include "ui/gfx/font_render_params.h" | 19 #include "ui/gfx/font_render_params.h" |
| 20 #include "ui/gfx/geometry/size_conversions.h" |
20 #include "ui/gfx/platform_font_win.h" | 21 #include "ui/gfx/platform_font_win.h" |
21 #include "ui/gfx/utf16_indexing.h" | 22 #include "ui/gfx/utf16_indexing.h" |
22 | 23 |
23 namespace gfx { | 24 namespace gfx { |
24 | 25 |
25 namespace { | 26 namespace { |
26 | 27 |
27 // The maximum length of text supported for Uniscribe layout and display. | 28 // The maximum length of text supported for Uniscribe layout and display. |
28 // This empirically chosen value should prevent major performance degradations. | 29 // This empirically chosen value should prevent major performance degradations. |
29 // TODO(msw): Support longer text, partial layout/painting, etc. | 30 // TODO(msw): Support longer text, partial layout/painting, etc. |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 line_descent_ = min_height_ - min_baseline_; | 383 line_descent_ = min_height_ - min_baseline_; |
383 } | 384 } |
384 // Set the single-line mode Line's metrics to be at least | 385 // Set the single-line mode Line's metrics to be at least |
385 // |RenderText::font_list()| to not break the current single-line code. | 386 // |RenderText::font_list()| to not break the current single-line code. |
386 line_ascent_ = std::max(line_ascent_, min_baseline_); | 387 line_ascent_ = std::max(line_ascent_, min_baseline_); |
387 line_descent_ = std::max(line_descent_, min_height_ - min_baseline_); | 388 line_descent_ = std::max(line_descent_, min_height_ - min_baseline_); |
388 | 389 |
389 line->baseline = line_ascent_; | 390 line->baseline = line_ascent_; |
390 line->size.set_height(line_ascent_ + line_descent_); | 391 line->size.set_height(line_ascent_ + line_descent_); |
391 line->preceding_heights = total_size_.height(); | 392 line->preceding_heights = total_size_.height(); |
392 total_size_.set_height(total_size_.height() + line->size.height()); | 393 const Size line_size(ToCeiledSize(line->size)); |
393 total_size_.set_width(std::max(total_size_.width(), line->size.width())); | 394 total_size_.set_height(total_size_.height() + line_size.height()); |
| 395 total_size_.set_width(std::max(total_size_.width(), line_size.width())); |
394 } | 396 } |
395 line_x_ = 0; | 397 line_x_ = 0; |
396 line_ascent_ = 0; | 398 line_ascent_ = 0; |
397 line_descent_ = 0; | 399 line_descent_ = 0; |
398 lines_.push_back(Line()); | 400 lines_.push_back(Line()); |
399 } | 401 } |
400 | 402 |
401 // Adds a new segment with the given properties to |lines_.back()|. | 403 // Adds a new segment with the given properties to |lines_.back()|. |
402 void AddSegment(int run_index, Range char_range, int width) { | 404 void AddSegment(int run_index, Range char_range, int width) { |
403 if (char_range.is_empty()) { | 405 if (char_range.is_empty()) { |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 background_is_transparent()); | 757 background_is_transparent()); |
756 | 758 |
757 ApplyCompositionAndSelectionStyles(); | 759 ApplyCompositionAndSelectionStyles(); |
758 | 760 |
759 for (size_t i = 0; i < lines().size(); ++i) { | 761 for (size_t i = 0; i < lines().size(); ++i) { |
760 const internal::Line& line = lines()[i]; | 762 const internal::Line& line = lines()[i]; |
761 const Vector2d line_offset = GetLineOffset(i); | 763 const Vector2d line_offset = GetLineOffset(i); |
762 | 764 |
763 // Skip painting empty lines or lines outside the display rect area. | 765 // Skip painting empty lines or lines outside the display rect area. |
764 if (!display_rect().Intersects(Rect(PointAtOffsetFromOrigin(line_offset), | 766 if (!display_rect().Intersects(Rect(PointAtOffsetFromOrigin(line_offset), |
765 line.size))) | 767 ToCeiledSize(line.size)))) |
766 continue; | 768 continue; |
767 | 769 |
768 const Vector2d text_offset = line_offset + Vector2d(0, line.baseline); | 770 const Vector2d text_offset = line_offset + Vector2d(0, line.baseline); |
769 int preceding_segment_widths = 0; | 771 int preceding_segment_widths = 0; |
770 | 772 |
771 for (size_t j = 0; j < line.segments.size(); ++j) { | 773 for (size_t j = 0; j < line.segments.size(); ++j) { |
772 const internal::LineSegment* segment = &line.segments[j]; | 774 const internal::LineSegment* segment = &line.segments[j]; |
773 const int segment_width = segment->x_range.length(); | 775 const int segment_width = segment->x_range.length(); |
774 const internal::TextRun* run = runs_[segment->run]; | 776 const internal::TextRun* run = runs_[segment->run]; |
775 DCHECK(!segment->char_range.is_empty()); | 777 DCHECK(!segment->char_range.is_empty()); |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1222 size_t position = LayoutIndexToTextIndex(run->range.end()); | 1224 size_t position = LayoutIndexToTextIndex(run->range.end()); |
1223 position = IndexOfAdjacentGrapheme(position, CURSOR_BACKWARD); | 1225 position = IndexOfAdjacentGrapheme(position, CURSOR_BACKWARD); |
1224 return SelectionModel(position, CURSOR_FORWARD); | 1226 return SelectionModel(position, CURSOR_FORWARD); |
1225 } | 1227 } |
1226 | 1228 |
1227 RenderText* RenderText::CreateNativeInstance() { | 1229 RenderText* RenderText::CreateNativeInstance() { |
1228 return new RenderTextWin; | 1230 return new RenderTextWin; |
1229 } | 1231 } |
1230 | 1232 |
1231 } // namespace gfx | 1233 } // namespace gfx |
OLD | NEW |