864f6a36ccf42a96c7470caee0a920992e77a5af
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / bidirectional-support.h
1 #ifndef DALI_TOOLKIT_TEXT_BIDIRECTIONAL_SUPPORT_H
2 #define DALI_TOOLKIT_TEXT_BIDIRECTIONAL_SUPPORT_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/actors/actor-enumerations.h>
23 #include <dali/public-api/common/dali-vector.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/internal/text/bidirectional-line-info-run.h>
27 #include <dali-toolkit/internal/text/bidirectional-paragraph-info-run.h>
28 #include <dali-toolkit/internal/text/line-run.h>
29 #include <dali-toolkit/internal/text/script-run.h>
30
31 namespace Dali
32 {
33 namespace Toolkit
34 {
35 namespace Text
36 {
37 /**
38  * Sets the bidirectional info into the logical model.
39  *
40  * @param[in] text Vector of UTF-32 characters.
41  * @param[in] scripts Vector containing the script runs for the whole text.
42  * @param[in] lineBreakInfo The line break info.
43  * @param[in] startIndex The character from where the bidirectional info is set.
44  * @param[in] numberOfCharacters The number of characters.
45  * @param[out] bidirectionalInfo Vector with the bidirectional infor for each paragraph.
46  * @param[in] matchLayoutDirection Whether match for layout direction or not.
47  * @param[in] layoutDirection The direction of the layout.
48  */
49 void SetBidirectionalInfo(const Vector<Character>&               text,
50                           const Vector<ScriptRun>&               scripts,
51                           const Vector<LineBreakInfo>&           lineBreakInfo,
52                           CharacterIndex                         startIndex,
53                           Length                                 numberOfCharacters,
54                           Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo,
55                           bool                                   matchLayoutDirection = false,
56                           Dali::LayoutDirection::Type            layoutDirection      = LayoutDirection::LEFT_TO_RIGHT);
57
58 /**
59  * @brief Sets the visual to logical map table for a given line.
60  *
61  * @param[in] bidirectionalParagraphInfo The paragraph's bidirectional info.
62  * @param[out] lineInfoRuns Line runs with the visual to logical conversion maps.
63  * @param[in] bidiLineIndex Index to the line's bidirectional info.
64  * @param[in] startIndex The character from where the bidirectional info is set.
65  * @param[in] numberOfCharacters The number of characters.
66  * @param[in] direction The direction of the line.
67  */
68 void ReorderLine(const BidirectionalParagraphInfoRun& bidirectionalParagraphInfo,
69                  Vector<BidirectionalLineInfoRun>&    lineInfoRuns,
70                  BidirectionalLineRunIndex            bidiLineIndex,
71                  CharacterIndex                       startIndex,
72                  Length                               numberOfCharacters,
73                  CharacterDirection                   direction);
74
75 /**
76  * @brief Replaces any character in the right to left paragraphs which could be mirrored.
77  *
78  * @param[in] text The text.
79  * @param[in] directions Vector with the direction of each paragraph.
80  * @param[in] bidirectionalInfo Vector with the bidirectional infor for each paragraph.
81  * @param[in] startIndex The character from where the text is mirrored.
82  * @param[in] numberOfCharacters The number of characters.
83  * @param[out] mirroredText The mirroredText.
84  *
85  * @return @e true if a character has been replaced.
86  */
87 bool GetMirroredText(const Vector<Character>&                     text,
88                      const Vector<CharacterDirection>&            directions,
89                      const Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo,
90                      CharacterIndex                               startIndex,
91                      Length                                       numberOfCharacters,
92                      Vector<Character>&                           mirroredText);
93
94 /**
95  * @brief Retrieves the characters' directions.
96  *
97  * @pre The @p logicalModel needs to have a text set.
98  * @pre The @p logicalModel needs to have the bidirectional info indices for each paragraph set.
99  *
100  * @param[in] bidirectionalInfo Vector with the bidirectional infor for each paragraph.
101  * @param[in] totalNumberOfCharacters The number of characters of the whole text.
102  * @param[in] startIndex The character from where the direction info is set.
103  * @param[in] numberOfCharacters The number of characters.
104  * @param[out] directions The direction, @e false is left to right and @e true is right to left, of each character of the paragraph.
105  */
106 void GetCharactersDirection(const Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo,
107                             Length                                       totalNumberOfCharacters,
108                             CharacterIndex                               startIndex,
109                             Length                                       numberOfCharacters,
110                             Vector<CharacterDirection>&                  directions);
111
112 } // namespace Text
113
114 } // namespace Toolkit
115
116 } // namespace Dali
117
118 #endif // DALI_TOOLKIT_TEXT_BIDIRECTIONAL_SUPPORT_H