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/rtl.h" | 10 #include "base/i18n/rtl.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "base/win/windows_version.h" | 14 #include "base/win/windows_version.h" |
15 #include "third_party/icu/source/common/unicode/uchar.h" | |
16 #include "third_party/icu/source/common/unicode/utf16.h" | |
15 #include "ui/base/text/utf16_indexing.h" | 17 #include "ui/base/text/utf16_indexing.h" |
16 #include "ui/gfx/canvas.h" | 18 #include "ui/gfx/canvas.h" |
17 #include "ui/gfx/font_fallback_win.h" | 19 #include "ui/gfx/font_fallback_win.h" |
18 #include "ui/gfx/font_smoothing_win.h" | 20 #include "ui/gfx/font_smoothing_win.h" |
19 #include "ui/gfx/platform_font_win.h" | 21 #include "ui/gfx/platform_font_win.h" |
20 | 22 |
21 namespace gfx { | 23 namespace gfx { |
22 | 24 |
23 namespace { | 25 namespace { |
24 | 26 |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
585 run->font_style, &run->font); | 587 run->font_style, &run->font); |
586 run->strike = style.style(STRIKE); | 588 run->strike = style.style(STRIKE); |
587 run->diagonal_strike = style.style(DIAGONAL_STRIKE); | 589 run->diagonal_strike = style.style(DIAGONAL_STRIKE); |
588 run->underline = style.style(UNDERLINE); | 590 run->underline = style.style(UNDERLINE); |
589 run->script_analysis = script_item->a; | 591 run->script_analysis = script_item->a; |
590 | 592 |
591 // Find the next break and advance the iterators as needed. | 593 // Find the next break and advance the iterators as needed. |
592 const size_t script_item_break = (script_item + 1)->iCharPos; | 594 const size_t script_item_break = (script_item + 1)->iCharPos; |
593 run_break = std::min(script_item_break, | 595 run_break = std::min(script_item_break, |
594 TextIndexToLayoutIndex(style.GetRange().end())); | 596 TextIndexToLayoutIndex(style.GetRange().end())); |
597 | |
595 // Clamp run lengths to avoid exceeding the maximum supported glyph count. | 598 // Clamp run lengths to avoid exceeding the maximum supported glyph count. |
596 if ((run_break - run->range.start()) > max_run_length) | 599 if ((run_break - run->range.start()) > max_run_length) |
597 run_break = run->range.start() + max_run_length; | 600 run_break = run->range.start() + max_run_length; |
601 | |
602 // Break runs between any two characters that are not in the same code | |
msw
2013/09/03 16:15:31
Can you explain why you chose to break runs betwee
ckocagil
2013/09/04 13:02:50
I simply didn't know Unicode had classification by
| |
603 // block. http://crbug.com/278913 | |
msw
2013/09/03 16:15:31
nit: consider using a comment like:
// Break runs
ckocagil
2013/09/04 13:02:50
Done.
| |
604 size_t i = run->range.start(); | |
605 UChar32 current_char = 0; | |
606 U16_NEXT(text().c_str(), i, text().length(), current_char); | |
msw
2013/09/03 16:15:31
Use base::i18n::UTF16CharIterator instead.
ckocagil
2013/09/04 13:02:50
Done.
| |
607 const UBlockCode first_block = ublock_getCode(current_char); | |
608 while (i < run_break) { | |
609 const size_t current_index = i; | |
610 U16_NEXT(text().c_str(), i, text().length(), current_char); | |
611 if (ublock_getCode(current_char) != first_block) { | |
612 DCHECK_LE(current_index, run_break); | |
613 run_break = current_index; | |
614 break; | |
615 } | |
616 } | |
617 DCHECK_LT(run->range.start(), run_break); | |
618 | |
598 style.UpdatePosition(LayoutIndexToTextIndex(run_break)); | 619 style.UpdatePosition(LayoutIndexToTextIndex(run_break)); |
599 if (script_item_break == run_break) | 620 if (script_item_break == run_break) |
600 script_item++; | 621 script_item++; |
601 run->range.set_end(run_break); | 622 run->range.set_end(run_break); |
602 runs_.push_back(run); | 623 runs_.push_back(run); |
603 } | 624 } |
604 | 625 |
605 // Undo the temporarily applied composition underlines and selection colors. | 626 // Undo the temporarily applied composition underlines and selection colors. |
606 UndoCompositionAndSelectionStyles(); | 627 UndoCompositionAndSelectionStyles(); |
607 } | 628 } |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
897 size_t position = LayoutIndexToTextIndex(run->range.end()); | 918 size_t position = LayoutIndexToTextIndex(run->range.end()); |
898 position = IndexOfAdjacentGrapheme(position, CURSOR_BACKWARD); | 919 position = IndexOfAdjacentGrapheme(position, CURSOR_BACKWARD); |
899 return SelectionModel(position, CURSOR_FORWARD); | 920 return SelectionModel(position, CURSOR_FORWARD); |
900 } | 921 } |
901 | 922 |
902 RenderText* RenderText::CreateInstance() { | 923 RenderText* RenderText::CreateInstance() { |
903 return new RenderTextWin; | 924 return new RenderTextWin; |
904 } | 925 } |
905 | 926 |
906 } // namespace gfx | 927 } // namespace gfx |
OLD | NEW |