Conversion to Apache 2.0 license
[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 "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  * Updates the line layout size info.
39  *
40  * @param[in,out] lineLayoutInfo The line layout info.
41  * @param[in] lineHeightOffset The line height offset.
42  */
43 void UpdateLineLayoutInfo( TextViewProcessor::LineLayoutInfo& lineLayoutInfo, float lineHeightOffset );
44
45 /**
46  * 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.
47  *
48  * @param[in] line The styled line.
49  * @param[in,out] relayoutData Natural size (metrics), layout, text-actor info and conversion from visual to logical order and vice versa (for RTL text).
50  * @param[out] lineLayoutInfo Layout info for the whole line.
51  */
52 void CreateLineInfo( const MarkupProcessor::StyledTextArray& line,
53                      TextView::RelayoutData& relayoutData,
54                      TextViewProcessor::LineLayoutInfo& lineLayoutInfo );
55
56 /**
57  * Removes a given number of groups of words from the given line.
58  *
59  * @pre \e groupIndex and \e groupIndex + \e numberOfGroups can't exceed the bounds of the line.
60  *
61  * @param[in] groupIndex Index to the group of words within the line with the starting position to be deleted.
62  * @param[in] numberOfGroups The number of group of words to be deleted.
63  * @param[in] lineHeightOffset Additional space between lines. Needed to update layout info.
64  * @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 group of words.
65  */
66 void RemoveWordGroupsFromLine( std::size_t groupIndex,
67                                std::size_t numberOfGroups,
68                                const PointSize& lineHeightOffset,
69                                LineLayoutInfo& lineLayout );
70
71 /**
72  * Splits a given line in two.
73  *
74  * @note It deletes whatever there is in the last part of the line.
75  *
76  * @param[in] indices Index to the group of words within the line, index to the word and index to the character within the word to split the line.
77  * @param[in] lineHeightOffset Additional space between lines. Needed to update layout info.
78  * @param[in,out] firstLineLayoutInfo The input is the layout info of the given line. The output is the first part of the input line (from the group of words \e 0 to the group of words \e groupPosition).
79  * @param[in,out] lastLineLayoutInfo Layout info of the last part of the given line ( from the group of words \e groupPosition + \e 1 to the end of the line).
80  */
81 void SplitLine( const TextInfoIndices& indices,
82                 const PointSize& lineHeightOffset,
83                 LineLayoutInfo& firstLineLayoutInfo,
84                 LineLayoutInfo& lastLineLayoutInfo );
85
86 /**
87  * Merges the two given lines by adding groups of words of the last line to the firs one.
88  *
89  * @note Does nothing if last part of the line is empty.
90  * @note If the first part of the line is empty it just copy the last part to it.
91  * @note it asserts if the last word of the first group is a line separator (new line character)
92  *
93  * @param[in,out] firstLineLineLayoutInfo The input is the layout info of the first line. The output is the layout info of the merged line.
94  * @param[in] lastLineLayoutInfo Layout info of the last line.
95  *
96  */
97 void MergeLine( LineLayoutInfo& firstLineLineLayoutInfo,
98                 const LineLayoutInfo& lastLineLayoutInfo );
99
100 /**
101  * Retrieves the layout information of the last word of the given line.
102  *
103  * @param[in] lineLayoutInfo The line layout.
104  *
105  * @return Layout information of the last word of the line.
106  */
107 WordLayoutInfo GetLastWordLayoutInfo( const LineLayoutInfo& lineLayoutInfo );
108
109 /**
110  * Retrieves the layout information of the first character of the given line.
111  *
112  * @param[in] lineLayoutInfo The line layout.
113  *
114  * @return Layout information of the first character of the line.
115  */
116 CharacterLayoutInfo GetFirstCharacterLayoutInfo( const LineLayoutInfo& lineLayoutInfo );
117
118 /**
119  * Retrieves the layout information of the last character of the given line.
120  *
121  * @param[in] lineLayoutInfo The line layout.
122  *
123  * @return Layout information of the last character of the line.
124  */
125 CharacterLayoutInfo GetLastCharacterLayoutInfo( const LineLayoutInfo& lineLayoutInfo );
126
127 /**
128  * Collects text-actors from the given lines and stores them into the text-actor vector.
129  *
130  * @param[out] textActors Stores the text-actors of the given lines.
131  * @param[in] textLayoutInfo Whole text with the given lines.
132  * @param[in] lineIndexBegin The first line.
133  * @param[in] lineIndexEnd The last line.
134  */
135 void CollectTextActorsFromLines( std::vector<TextActor>& textActors, const TextLayoutInfo& textLayoutInfo, std::size_t lineIndexBegin, std::size_t lineIndexEnd );
136
137 } //namespace TextViewProcessor
138
139 } //namespace Internal
140
141 } //namespace Toolkit
142
143 } //namespace Dali
144
145 #endif // __DALI_TOOLKIT_INTERNAL_TEXT_VIEW_LINE_PROCESSOR_H__