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