Makes the LTR/RTL alignment of text follow the system language by default.
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / text-abstraction / bidirectional-support.h
1 #ifndef DALI_PLATFORM_TEXT_ABSTRACTION_BIDIRECTIONAL_SUPPORT_H
2 #define DALI_PLATFORM_TEXT_ABSTRACTION_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 // INTERNAL INCLUDES
22 #include <dali/devel-api/text-abstraction/text-abstraction-definitions.h>
23
24 // EXTERNAL INCLUDES
25 #include <dali/public-api/actors/actor-enumerations.h>
26 #include <dali/public-api/object/base-handle.h>
27
28 // INTERNAL INCLUDES
29 #include <dali/public-api/dali-adaptor-common.h>
30
31 namespace Dali
32 {
33 namespace TextAbstraction
34 {
35 namespace Internal DALI_INTERNAL
36 {
37 class BidirectionalSupport;
38
39 } // namespace DALI_INTERNAL
40
41 /**
42  * BidirectionalSupport API
43  *
44  */
45 class DALI_ADAPTOR_API BidirectionalSupport : public BaseHandle
46 {
47 public:
48   /**
49    * @brief Create an uninitialized TextAbstraction handle.
50    *
51    */
52   BidirectionalSupport();
53
54   /**
55    * @brief Destructor
56    *
57    * This is non-virtual since derived Handle types must not contain data or virtual methods.
58    */
59   ~BidirectionalSupport();
60
61   /**
62    * @brief This constructor is used by BidirectionalSupport::Get().
63    *
64    * @param[in] implementation a pointer to the internal bidirectional support object.
65    */
66   explicit DALI_INTERNAL BidirectionalSupport(Internal::BidirectionalSupport* implementation);
67
68   /**
69    * @brief Retrieve a handle to the BidirectionalSupport instance.
70    *
71    * @return A handle to the BidirectionalSupport
72    */
73   static BidirectionalSupport Get();
74
75   /**
76    * @brief Creates bidirectional data for the whole paragraph.
77    *
78    * @param[in] paragraph Pointer to the first character of the paragraph coded in UTF32.
79    * @param[in] numberOfCharacters The number of characters of the paragraph.
80    * @param[in] matchLayoutDirection Whether match for layout direction or not.
81    * @param[in] layoutDirection The direction of the layout direction.
82    * @return An index of an object inside a table storing the bidirectional data.
83    */
84   BidiInfoIndex CreateInfo(const Character* const paragraph,
85                            Length                 numberOfCharacters,
86                            bool                   matchLayoutDirection,
87                            LayoutDirection::Type  layoutDirection);
88
89   /**
90    * @brief Destroys the bidirectional data.
91    *
92    * @param[in] bidiInfoIndex The index to the of the object inside the table storing the bidirectional data for the current paragraph.
93    */
94   void DestroyInfo(BidiInfoIndex bidiInfoIndex);
95
96   /**
97    * @brief Reorders a line of a paragraph.
98    *
99    * @pre visualToLogicalMap must have enough space allocated for @p numberOfCharacters.
100    *
101    * @param[in] bidiInfoIndex The index to the of the object inside the table storing the bidirectional data for the current paragraph.
102    * @param[in] firstCharacterIndex The first character of the line within the whole paragraph.
103    * @param[in] numberOfCharacters The number of characters of the line.
104    * @param[out] visualToLogicalMap The visual to logical conversion map.
105    */
106   void Reorder(BidiInfoIndex   bidiInfoIndex,
107                CharacterIndex  firstCharacterIndex,
108                Length          numberOfCharacters,
109                CharacterIndex* visualToLogicalMap);
110
111   /**
112    * @brief Replaces any character which could be mirrored.
113    *
114    * @param[in,out] text The text.
115    * @param[in] directions The direction of each paragraph.
116    * @param[in] numberOfCharacters The number of characters.
117    *
118    * @return @e true if a character has been replaced.
119    */
120   bool GetMirroredText(Character*          text,
121                        CharacterDirection* directions,
122                        Length              numberOfCharacters);
123
124   /**
125    * @brief Retrieves the paragrpah's direction.
126    *
127    * @param[in] bidiInfoIndex The index to the of the object inside the table storing the bidirectional data for the current paragraph.
128    *
129    * @return @e true if the paragraph is right to left, otherwise @e false.
130    */
131   bool GetParagraphDirection(BidiInfoIndex bidiInfoIndex) const;
132
133   /**
134    * @brief Retrieves the character's directions.
135    *
136    * @param[in] bidiInfoIndex The index to the of the object inside the table storing the bidirectional data for the current paragraph.
137    * @param[out] directions The direction, @e false is left to right and @e true is right to left, of each character of the paragraph.
138    * @param[in] numberOfCharacters The number of characters.
139    */
140   void GetCharactersDirection(BidiInfoIndex       bidiInfoIndex,
141                               CharacterDirection* directions,
142                               Length              numberOfCharacters);
143 };
144
145 } // namespace TextAbstraction
146
147 } // namespace Dali
148
149 #endif // DALI_PLATFORM_TEXT_ABSTRACTION_BIDIRECTIONAL_SUPPORT_H