DALi Version 1.0.33
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-view / text-view-word-processor.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_TEXT_VIEW_WORD_PROCESSOR_H__
2 #define __DALI_TOOLKIT_INTERNAL_TEXT_VIEW_WORD_PROCESSOR_H__
3
4 /*
5  * Copyright (c) 2014 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/controls/text-view/text-view-impl.h>
23
24 namespace Dali
25 {
26
27 namespace Toolkit
28 {
29
30 namespace Internal
31 {
32
33 namespace TextViewProcessor
34 {
35
36 /**
37  * Creates a data structure with info to layout the word, and data structures with useful info to modify the layout data structure if characters are added or removed.
38  *
39  * @param[in] paragraphText The paragraph's text.
40  * @param[in] textStyles The styles for each character of the paragraph.
41  * @param[out] wordLayoutInfo Layout info for all characters of the word.
42  */
43 void CreateWordTextInfo( const Text& paragraphText,
44                          Vector<TextStyle*>& textStyles,
45                          WordLayoutInfo& wordLayoutInfo );
46
47 /**
48  * Updates the word size and ascender.
49  *
50  * It's called after deleting some characters, split a word in two,
51  * or when a new word is created when right to left text is reordered.
52  *
53  * @param[in] wordLayout The word layout info.
54  */
55 void UpdateLayoutInfo( WordLayoutInfo& wordLayout );
56
57 /**
58  * Removes a given number of characters from the given word.
59  *
60  * It calls the RemoveCharactersFromWord() function to remove characters from the word.
61  *
62  * If the word is a white space \e mergeWords will return \e true and \e textInfoMergeIndicesBegin and \e textInfoMergeIndicesEnd will be set to merge the two adjacent words.
63  * If the word is a new paragraph character \e mergeParagraphs will return \e true and \e textInfoMergeIndicesBegin and \e textInfoMergeIndicesEnd will be set to merge the two paragraphs.
64  *
65  * @param[in,out] relayoutData Natural size (metrics), layout, text-actor info.
66  * @param[in] numberOfCharacters The number of characters to be deleted.
67  * @param[out] mergeWords Whether adjacent words need to be merged.
68  * @param[out] mergeParagraphs Whether current paragraph need to be merged with the next one.
69  * @param[in,out] textInfoIndicesBegin Indices to the paragraph, word and characters from where to delete characters. It returns from where words need to be removed.
70  * @param[out] textInfoIndicesEnd If paragraphs or words need to be merged it returns info to delete them (If a word is merged, it has to be removed. Equal for paragraphs).
71  * @param[out] textInfoMergeIndicesBegin The indices to the first part of the paragraph and word to be merged.
72  * @param[out] textInfoMergeIndicesEnd The indices to the last part of the paragraph and word to be merged.
73  * @param[in,out] paragraphLayout Layout info of the paragraph where the word is located.
74  * @param[out] removedTextActors Stores handles of temoved text-actors.
75  */
76 void RemoveCharactersFromWordInfo( TextView::RelayoutData& relayoutData,
77                                    std::size_t numberOfCharacters,
78                                    bool& mergeWords,
79                                    bool& mergeParagraphs,
80                                    TextInfoIndices& textInfoIndicesBegin,
81                                    TextInfoIndices& textInfoIndicesEnd,
82                                    TextInfoIndices& textInfoMergeIndicesBegin,
83                                    TextInfoIndices& textInfoMergeIndicesEnd,
84                                    ParagraphLayoutInfo& paragraphLayout,
85                                    std::vector<TextActor>& removedTextActors );
86 /**
87  * Removes a given number of characters from the given word.
88  *
89  * @pre \e positon and \e position + \e numberOfCharacters can't exceed the bounds of the word.
90  *
91  * @param[in] position Character index within the word with the starting position to be deleted.
92  * @param[in] numberOfCharacters The number of characters to be deleted.
93  * @param[in,out] wordLayout The input is the layout info of the word. The output is the layout info of the word without the removed characters.
94  */
95 void RemoveCharactersFromWord( std::size_t position,
96                                std::size_t numberOfCharacters,
97                                WordLayoutInfo& wordLayout );
98
99 /**
100  * Splits a word in two.
101  *
102  * Removes part of the text from the input word and creates a new word with the removed text.
103  *
104  * i.e. The result of split 'word' by the position 3 would be 'wor' and 'd'.
105  *
106  * @note It deletes whatever there is in the last part of the word.
107  *
108  * @param[in] position Character index where to split the word.
109  * @param[in,out] firstWordLayoutInfo The input is the layout info of the given word. The output is the first part of the input word (from the character \e 0 to the character \e position - \e 1).
110  * @param[out] lastWordLayoutInfo Layout info of the last part of the given word ( from the character \e position to the end of the word).
111  */
112 void SplitWord( std::size_t position,
113                 WordLayoutInfo& firstWordLayoutInfo,
114                 WordLayoutInfo& lastWordLayoutInfo );
115
116 /**
117  * Merges the two given words by adding characters of the last word to the firs one.
118  *
119  * @note Does nothing if last part of the word is empty.
120  * @note If the first part of the word is empty it just copy the last part to it.
121  * @note It asserts if the first or the last word is a word separator (white space) or a paragraph separator (new paragraph character)
122  *
123  * @param[in,out] firstWordLayoutInfo The input is the layout info of the first word. The output is the layout info of the merged word.
124  * @param[in] lastWordLayoutInfo Layout info of the last word.
125  */
126 void MergeWord( WordLayoutInfo& firstWordLayoutInfo,
127                 const WordLayoutInfo& lastWordLayoutInfo );
128
129 /**
130  * Retrieves the layout information of the first character of the given word.
131  *
132  * @param[in] wordLayoutInfo The word layout.
133  *
134  * @return Layout information of the first character of the word.
135  */
136 CharacterLayoutInfo GetFirstCharacterLayoutInfo( const WordLayoutInfo& wordLayoutInfo );
137
138 /**
139  * Retrieves the layout information of the last character of the given word.
140  *
141  * @param[in] wordLayoutInfo The word layout.
142  *
143  * @return Layout information of the last character of the word.
144  */
145 CharacterLayoutInfo GetLastCharacterLayoutInfo( const WordLayoutInfo& wordLayoutInfo );
146
147 /**
148  * Collects text-actors from the given word, within the given indices, and stores them into the text-actor vector.
149  *
150  * @param[out] textActors Stores the text-actors of the given word.
151  * @param[in] characterIndexBegin The first text-actor to be stored.
152  * @param[in] characterIndexEnd The last text-actor to be stored.
153  */
154 void CollectTextActors( std::vector<TextActor>& textActors, const WordLayoutInfo& word, std::size_t characterIndexBegin, std::size_t characterIndexEnd );
155
156 /**
157  * Collects text-actors from the given paragraph, within the given indices, and stores them into the text-actor vector.
158  *
159  * @param[out] textActors Stores the text-actors of the given paragraph.
160  * @param[in] paragraph The paragraph with the words.
161  * @param[in] wordIndexBegin Index to the first word.
162  * @param[in] wordIndexEnd Index to the last word.
163  */
164 void CollectTextActorsFromWords( std::vector<TextActor>& textActors, const ParagraphLayoutInfo& paragraph, std::size_t wordIndexBegin, std::size_t wordIndexEnd );
165
166 } //namespace TextViewProcessor
167
168 } //namespace Internal
169
170 } //namespace Toolkit
171
172 } //namespace Dali
173
174 #endif // __DALI_TOOLKIT_INTERNAL_TEXT_VIEW_WORD_PROCESSOR_H__