OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "core/layout/ng/inline/ng_bidi_paragraph.h" | 5 #include "core/layout/ng/inline/ng_bidi_paragraph.h" |
6 | 6 |
7 #include "core/layout/ng/inline/ng_inline_node.h" | 7 #include "core/layout/ng/inline/ng_inline_node.h" |
8 #include "core/style/ComputedStyle.h" | 8 #include "core/style/ComputedStyle.h" |
9 #include "platform/text/ICUError.h" | 9 #include "platform/text/ICUError.h" |
10 | 10 |
11 namespace blink { | 11 namespace blink { |
12 | 12 |
13 NGBidiParagraph::~NGBidiParagraph() { | 13 NGBidiParagraph::~NGBidiParagraph() { |
14 ubidi_close(ubidi_); | 14 ubidi_close(ubidi_); |
15 } | 15 } |
16 | 16 |
17 bool NGBidiParagraph::SetParagraph(const String& text, | 17 bool NGBidiParagraph::SetParagraph(const String& text, |
18 const ComputedStyle& block_style) { | 18 const ComputedStyle& block_style) { |
19 DCHECK(!ubidi_); | 19 DCHECK(!ubidi_); |
20 ubidi_ = ubidi_open(); | 20 ubidi_ = ubidi_open(); |
| 21 |
| 22 bool use_heuristic_base_direction = |
| 23 block_style.GetUnicodeBidi() == UnicodeBidi::kPlaintext; |
| 24 UBiDiLevel para_level; |
| 25 if (use_heuristic_base_direction) { |
| 26 para_level = UBIDI_DEFAULT_LTR; |
| 27 } else { |
| 28 base_direction_ = block_style.Direction(); |
| 29 para_level = IsLtr(base_direction_) ? UBIDI_LTR : UBIDI_RTL; |
| 30 } |
| 31 |
21 ICUError error; | 32 ICUError error; |
22 ubidi_setPara( | 33 ubidi_setPara(ubidi_, text.Characters16(), text.length(), para_level, nullptr, |
23 ubidi_, text.Characters16(), text.length(), | 34 &error); |
24 block_style.GetUnicodeBidi() == UnicodeBidi::kPlaintext | |
25 ? UBIDI_DEFAULT_LTR | |
26 : (block_style.Direction() == TextDirection::kRtl ? UBIDI_RTL | |
27 : UBIDI_LTR), | |
28 nullptr, &error); | |
29 if (U_FAILURE(error)) { | 35 if (U_FAILURE(error)) { |
30 NOTREACHED(); | 36 NOTREACHED(); |
31 ubidi_close(ubidi_); | 37 ubidi_close(ubidi_); |
32 ubidi_ = nullptr; | 38 ubidi_ = nullptr; |
33 return false; | 39 return false; |
34 } | 40 } |
| 41 |
| 42 if (use_heuristic_base_direction) |
| 43 base_direction_ = DirectionFromLevel(ubidi_getParaLevel(ubidi_)); |
| 44 |
35 return true; | 45 return true; |
36 } | 46 } |
37 | 47 |
38 unsigned NGBidiParagraph::GetLogicalRun(unsigned start, | 48 unsigned NGBidiParagraph::GetLogicalRun(unsigned start, |
39 UBiDiLevel* level) const { | 49 UBiDiLevel* level) const { |
40 int32_t end; | 50 int32_t end; |
41 ubidi_getLogicalRun(ubidi_, start, &end, level); | 51 ubidi_getLogicalRun(ubidi_, start, &end, level); |
42 return end; | 52 return end; |
43 } | 53 } |
44 | 54 |
45 void NGBidiParagraph::IndicesInVisualOrder( | 55 void NGBidiParagraph::IndicesInVisualOrder( |
46 const Vector<UBiDiLevel, 32>& levels, | 56 const Vector<UBiDiLevel, 32>& levels, |
47 Vector<int32_t, 32>* indices_in_visual_order_out) { | 57 Vector<int32_t, 32>* indices_in_visual_order_out) { |
48 // Check the size before passing the raw pointers to ICU. | 58 // Check the size before passing the raw pointers to ICU. |
49 CHECK_EQ(levels.size(), indices_in_visual_order_out->size()); | 59 CHECK_EQ(levels.size(), indices_in_visual_order_out->size()); |
50 ubidi_reorderVisual(levels.data(), levels.size(), | 60 ubidi_reorderVisual(levels.data(), levels.size(), |
51 indices_in_visual_order_out->data()); | 61 indices_in_visual_order_out->data()); |
52 } | 62 } |
53 | 63 |
54 } // namespace blink | 64 } // namespace blink |
OLD | NEW |