5738c46bce4b71edfa7b85088e3b9fa3301ea75d
[platform/core/uifw/dali-toolkit.git] / base / dali-toolkit / internal / controls / text-view / text-view-line-processor.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_TEXT_VIEW_LINE_PROCESSOR_H__
2 #define __DALI_TOOLKIT_INTERNAL_TEXT_VIEW_LINE_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  * Updates the line layout size info.
38  *
39  * @param[in,out] lineLayoutInfo The line layout info.
40  * @param[in] lineHeightOffset The line height offset.
41  */
42 void UpdateLineLayoutInfo( LineLayoutInfo& lineLayoutInfo, float lineHeightOffset );
43
44 /**
45  * Creates a data structure with info to layout the line, and data structures with useful info to modify the layout data structure if characters are added or removed.
46  *
47  * @param[in] line The styled line.
48  * @param[in,out] relayoutData Natural size (metrics), layout, text-actor info and conversion from visual to logical order and vice versa (for RTL text).
49  * @param[out] lineLayoutInfo Layout info for the whole line.
50  */
51 void CreateLineInfo( const MarkupProcessor::StyledTextArray& line,
52                      TextView::RelayoutData& relayoutData,
53                      LineLayoutInfo& lineLayoutInfo );
54
55 /**
56  * Removes a given number of words from the given line.
57  *
58  * @pre \e wordIndex and \e wordIndex + \e numberOfWords can't exceed the bounds of the line.
59  *
60  * @param[in] wordIndex Index to the word within the line with the starting position to be deleted.
61  * @param[in] numberOfWords The number of words to be deleted.
62  * @param[in] lineHeightOffset Additional space between lines. Needed to update layout info.
63  * @param[in,out] lineLayout The input is the layout info of the line. The output is the layout info of the line without the removed words.
64  */
65 void RemoveWordsFromLine( std::size_t wordIndex,
66                           std::size_t numberOfWords,
67                           float lineHeightOffset,
68                           LineLayoutInfo& lineLayout );
69
70 /**
71  * @param[in,out] relayoutData Natural size (metrics), layout, text-actor info.
72  * @param[in] numberOfCharacters The number of characters to be deleted.
73  * @param[out] mergeWords Whether words need to be merged after removing characters.
74  * @param[out] mergeLines Whether current line need to be merged with the next one.
75  * @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.
76  * @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).
77  * @param[out] textInfoMergeIndicesBegin The indices to the first part of the line and word to be merged.
78  * @param[out] textInfoMergeIndicesEnd The indices to the last part of the line and word to be merged.
79  * @param[in,out] lineLayout Layout info of the line where the word is located.
80  * @param[out] removedTextActorsFromFirstWord Stores removed text-actors of the word pointed by the 'begin' index.
81  * @param[out] removedTextActorsFromLastWord Stores removed text-actors of the word pointed by the 'end' index.
82  */
83 void RemoveCharactersFromLineInfo( TextView::RelayoutData& relayoutData,
84                                    std::size_t numberOfCharacters,
85                                    bool& mergeWords,
86                                    bool& mergeLines,
87                                    TextInfoIndices& textInfoIndicesBegin,
88                                    TextInfoIndices& textInfoIndicesEnd,
89                                    TextInfoIndices& textInfoMergeIndicesBegin,
90                                    TextInfoIndices& textInfoMergeIndicesEnd,
91                                    LineLayoutInfo& lineLayout,
92                                    std::vector<TextActor>& removedTextActorsFromFirstWord,
93                                    std::vector<TextActor>& removedTextActorsFromLastWord );
94
95 /**
96  * Splits a given line in two.
97  *
98  * @note It deletes whatever there is in the last part of the line.
99  *
100  * @param[in] indices Index to the word within the line and index to the character within the word to split the line.
101  * @param[in] lineHeightOffset Additional space between lines. Needed to update layout info.
102  * @param[in,out] firstLineLayoutInfo The input is the layout info of the given line. The output is the first part of the input line.
103  * @param[in,out] lastLineLayoutInfo Layout info of the last part of the given line.
104  */
105 void SplitLine( const TextInfoIndices& indices,
106                 const PointSize& lineHeightOffset,
107                 LineLayoutInfo& firstLineLayoutInfo,
108                 LineLayoutInfo& lastLineLayoutInfo );
109
110 /**
111  * Merges the two given lines by adding words of the last line to the firs one.
112  *
113  * @note Does nothing if last part of the line is empty.
114  * @note If the first part of the line is empty it just copy the last part to it.
115  * @note it asserts if the last word of the first line is a line separator (new line character)
116  *
117  * @param[in,out] firstLineLineLayoutInfo The input is the layout info of the first line. The output is the layout info of the merged line.
118  * @param[in] lastLineLayoutInfo Layout info of the last line.
119  *
120  */
121 void MergeLine( LineLayoutInfo& firstLineLineLayoutInfo,
122                 const LineLayoutInfo& lastLineLayoutInfo );
123
124 /**
125  * Retrieves the layout information of the last word of the given line.
126  *
127  * @param[in] lineLayoutInfo The line layout.
128  *
129  * @return Layout information of the last word of the line.
130  */
131 WordLayoutInfo GetLastWordLayoutInfo( const LineLayoutInfo& lineLayoutInfo );
132
133 /**
134  * Retrieves the layout information of the first character of the given line.
135  *
136  * @param[in] lineLayoutInfo The line layout.
137  *
138  * @return Layout information of the first character of the line.
139  */
140 CharacterLayoutInfo GetFirstCharacterLayoutInfo( const LineLayoutInfo& lineLayoutInfo );
141
142 /**
143  * Retrieves the layout information of the last character of the given line.
144  *
145  * @param[in] lineLayoutInfo The line layout.
146  *
147  * @return Layout information of the last character of the line.
148  */
149 CharacterLayoutInfo GetLastCharacterLayoutInfo( const LineLayoutInfo& lineLayoutInfo );
150
151 /**
152  * Collects text-actors from the given lines and stores them into the text-actor vector.
153  *
154  * @param[out] textActors Stores the text-actors of the given lines.
155  * @param[in] textLayoutInfo Whole text with the given lines.
156  * @param[in] lineIndexBegin The first line.
157  * @param[in] lineIndexEnd The last line.
158  */
159 void CollectTextActorsFromLines( std::vector<TextActor>& textActors, const TextLayoutInfo& textLayoutInfo, std::size_t lineIndexBegin, std::size_t lineIndexEnd );
160
161 } //namespace TextViewProcessor
162
163 } //namespace Internal
164
165 } //namespace Toolkit
166
167 } //namespace Dali
168
169 #endif // __DALI_TOOLKIT_INTERNAL_TEXT_VIEW_LINE_PROCESSOR_H__