Support Emoji sequences
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / emoji-helper.h
1 #ifndef DALI_TOOLKIT_TEXT_EMOJI_HELPER_H
2 #define DALI_TOOLKIT_TEXT_EMOJI_HELPER_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-toolkit/internal/text/text-definitions.h>
23
24 // EXTERNAL INCLUDES
25 #include <dali/devel-api/text-abstraction/emoji-character-properties.h>
26 #include <dali/devel-api/text-abstraction/emoji-helper.h>
27 #include <dali/devel-api/text-abstraction/script.h>
28
29 namespace Dali
30 {
31 namespace Toolkit
32 {
33 namespace Text
34 {
35 /**
36  * @brief Whether the sequence is a variation sequence consisting of an emoji character followed by a text presentation selector.
37  *
38  * @param[in] currentRunScript The script of current run.
39  * @param[in] character The next character.
40  *
41  * @return @e true if the sequence is text presentation sequence.
42  */
43 bool IsTextPresentationSequence(const TextAbstraction::Script& currentRunScript, const TextAbstraction::Character& character);
44
45 /**
46  * @brief Whether the sequence is a variation sequence consisting of an emoji character followed by a emoji presentation selector.
47  *
48  * @param[in] currentRunScript The script of current run.
49  * @param[in] character The next character.
50  *
51  * @return @e true if the sequence is emoji presentation sequence.
52  */
53 bool IsEmojiPresentationSequence(const TextAbstraction::Script&    currentRunScript,
54                                  const TextAbstraction::Character& character);
55
56 /**
57  * @brief Whether the sequence is an emoji sequence.
58  *
59  * @param[in] currentRunScript The script of current run.
60  * @param[in] character The next character.
61  * @param[in] characterScript The script of the next character.
62  *
63  * @return @e true if the sequence is an emoji sequence.
64  */
65 bool IsEmojiSequence(const TextAbstraction::Script&    currentRunScript,
66                      const TextAbstraction::Character& character,
67                      const TextAbstraction::Script&    characterScript);
68
69 /**
70  * @brief Whether the sequence is a keycap sequence and set script according to the case.
71  *
72  * @param[in] textBuffer The text.
73  * @param[in] currentCharacterIndex The index of current character.
74  * @param[in] lastCharacterIndex The index of last character.
75  * @param[out] currentCharacterScript The current character script to update it in-case it's the Keycap sequence.
76  *
77  * @return @e true if @p currentRunScript is ASCII_DIGITS and @p character is COMBINING_ENCLOSING_KEYCAP
78  */
79 bool IsNewKeycapSequence(const Character* const   textBuffer,
80                          const Length&            currentCharacterIndex,
81                          const Length&            lastCharacterIndex,
82                          TextAbstraction::Script& currentCharacterScript);
83
84 /**
85  * @brief Whether the sequence is a variation selector sequence and set script according to the case.
86  *
87  * @param[in] textBuffer The text.
88  * @param[in] currentRunScript The script of current run.
89  * @param[in] currentCharacterIndex The index of current character.
90  * @param[in] lastCharacterIndex The index of last character.
91  * @param[out] currentCharacterScript The current character script to update it in-case it's the VariationSelector sequence.
92  *
93  * @return @e true if @p currentRunScript is ASCII_DIGITS and @p character is COMBINING_ENCLOSING_KEYCAP
94  */
95 bool IsNewVariationSelectorSequence(const Character* const         textBuffer,
96                                     const TextAbstraction::Script& currentRunScript,
97                                     const Length&                  currentCharacterIndex,
98                                     const Length&                  lastCharacterIndex,
99                                     TextAbstraction::Script&       currentCharacterScript);
100
101 /**
102  * @brief Whether the case is a new sequence and set script according to the case.
103  *
104  * @param[in] textBuffer The text.
105  * @param[in] currentRunScript The script of current run.
106  * @param[in] currentCharacterIndex The index of current character.
107  * @param[in] lastCharacterIndex The index of last character.
108  * @param[out] currentCharacterScript The current character script to update according to sequence.
109  *
110  * @return @e true the case is a new sequence
111  */
112 bool IsNewSequence(const Character* const         textBuffer,
113                    const TextAbstraction::Script& currentRunScript,
114                    const Length&                  currentCharacterIndex,
115                    const Length&                  lastCharacterIndex,
116                    TextAbstraction::Script&       currentCharacterScript);
117
118 /**
119  * @brief Whether the character is ASCII digits | # Number Sign | * Asterisk.
120  *
121  * @param[in] character The character.
122  *
123  * @return @e true if the character is ASCII digits | # Number Sign | * Asterisk.
124  */
125 bool IsStartForKeycapSequence(const TextAbstraction::Character& character);
126
127 /**
128  * @brief Check sequence case and update script of character if needed.
129  *
130  * @param[in] currentRunScript The script of current run.
131  * @param[in] character The next character.
132  * @param[out] script The current character script to update according to sequence.
133  *
134  * @return @e true if the script is changed
135  */
136 bool IsScriptChangedToFollowSequence(const TextAbstraction::Script&    currentRunScript,
137                                      const TextAbstraction::Character& character,
138                                      TextAbstraction::Script&          script);
139
140 /**
141  * @brief Check sequence case and update script of character if needed.
142  *
143  * @param[in] currentRunScript The script of current run.
144  * @param[in] character The next character.
145  * @param[out] script The current character script to update according to sequence.
146  *
147  * @return @e true if the script is changed
148  */
149 bool HandleEmojiSequence(const Character* const         textBuffer,
150                          const Length&                  currentCharacterIndex,
151                          const Length&                  lastCharacterIndex,
152                          const TextAbstraction::Script& currentRunScript,
153                          TextAbstraction::Script&       currentCharacterScript);
154
155 /**
156  * @brief Determine the Variation Selector according to script.
157  *
158  * @param[in] script The script.
159  *
160  * @return CHAR_VARIATION_SELECTOR_15 in-case EMOJI_TEXT or CHAR_VARIATION_SELECTOR_16 in-case EMOJI_COLOR or 0 otherwise
161  */
162 Character GetVariationSelectorByScript(const TextAbstraction::Script& script);
163
164 } // namespace Text
165
166 } // namespace Toolkit
167
168 } // namespace Dali
169
170 #endif // DALI_TOOLKIT_TEXT_EMOJI_HELPER_H