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