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