Support Ellipsis Position Property
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / rendering / view-model.h
1 #ifndef DALI_TOOLKIT_TEXT_VIEW_MODEL_H
2 #define DALI_TOOLKIT_TEXT_VIEW_MODEL_H
3
4 /*
5  * Copyright (c) 2021 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 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/dali-vector.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/devel-api/text/text-enumerations-devel.h>
26 #include <dali-toolkit/internal/text/text-model-interface.h>
27 #include <dali-toolkit/public-api/text/text-enumerations.h>
28
29 namespace Dali
30 {
31 namespace Toolkit
32 {
33 namespace Text
34 {
35 /**
36  * @brief Responsible of creating and store temporary modifications of the text model.
37  * i.e. The elide of text.
38  */
39 class ViewModel : public ModelInterface
40 {
41 public:
42   /**
43    * @brief Constructor.
44    *
45    * Keeps the pointer to the text's model. It initializes all the members of the class to their defaults.
46    *
47    * @param[in] model Pointer to the text's model interface.
48    */
49   ViewModel(const ModelInterface* const model);
50
51   /**
52    * @brief Virtual destructor.
53    *
54    * It's a default destructor.
55    */
56   virtual ~ViewModel();
57
58   /**
59    * @copydoc ModelInterface::GetControlSize()
60    */
61   const Size& GetControlSize() const override;
62
63   /**
64    * @copydoc ModelInterface::GetLayoutSize()
65    */
66   const Size& GetLayoutSize() const override;
67
68   /**
69    * @copydoc ModelInterface::GetScrollPosition()
70    */
71   const Vector2& GetScrollPosition() const override;
72
73   /**
74    * @copydoc ModelInterface::GetHorizontalAlignment()
75    */
76   Text::HorizontalAlignment::Type GetHorizontalAlignment() const override;
77
78   /**
79    * @copydoc ModelInterface::GetVerticalAlignment()
80    */
81   Text::VerticalAlignment::Type GetVerticalAlignment() const override;
82
83   /**
84   * @copydoc ModelInterface::GetVerticalLineAlignment()
85   */
86   DevelText::VerticalLineAlignment::Type GetVerticalLineAlignment() const override;
87
88   /**
89   * @copydoc ModelInterface::GetEllipsisPosition()
90   */
91   DevelText::EllipsisPosition::Type GetEllipsisPosition() const override;
92
93   /**
94    * @copydoc ModelInterface::IsTextElideEnabled()
95    */
96   bool IsTextElideEnabled() const override;
97
98   /**
99    * @copydoc ModelInterface::GetNumberOfLines()
100    */
101   Length GetNumberOfLines() const override;
102
103   /**
104    * @copydoc ModelInterface::GetLines()
105    */
106   const LineRun* const GetLines() const override;
107
108   /**
109    * @copydoc ModelInterface::GetNumberOfScripts()
110    */
111   Length GetNumberOfScripts() const override;
112
113   /**
114    * @copydoc ModelInterface::GetScriptRuns()
115    */
116   const ScriptRun* const GetScriptRuns() const override;
117
118   /**
119    * @copydoc ModelInterface::GetNumberOfGlyphs()
120    */
121   Length GetNumberOfGlyphs() const override;
122
123   /**
124    * @copydoc ModelInterface::GetStartIndexOfElidedGlyphs()
125    */
126   GlyphIndex GetStartIndexOfElidedGlyphs() const override;
127
128   /**
129    * @copydoc ModelInterface::GetEndIndexOfElidedGlyphs()
130    */
131   GlyphIndex GetEndIndexOfElidedGlyphs() const override;
132
133   /**
134    * @copydoc ModelInterface::GetFirstMiddleIndexOfElidedGlyphs()
135    */
136   GlyphIndex GetFirstMiddleIndexOfElidedGlyphs() const override;
137
138   /**
139    * @copydoc ModelInterface::GetSecondMiddleIndexOfElidedGlyphs()
140    */
141   GlyphIndex GetSecondMiddleIndexOfElidedGlyphs() const override;
142
143   /**
144    * @copydoc ModelInterface::GetGlyphs()
145    */
146   const GlyphInfo* const GetGlyphs() const override;
147
148   /**
149    * @copydoc ModelInterface::GetLayout()
150    */
151   const Vector2* const GetLayout() const override;
152
153   /**
154    * @copydoc ModelInterface::GetColors()
155    */
156   const Vector4* const GetColors() const override;
157
158   /**
159    * @copydoc ModelInterface::GetColorIndices()
160    */
161   const ColorIndex* const GetColorIndices() const override;
162
163   /**
164    * @copydoc ModelInterface::GetBackgroundColors()
165    */
166   const Vector4* const GetBackgroundColors() const override;
167
168   /**
169    * @copydoc ModelInterface::GetBackgroundColorIndices()
170    */
171   const ColorIndex* const GetBackgroundColorIndices() const override;
172
173   /**
174    * @copydoc ModelInterface::IsMarkupBackgroundColorSet()
175    */
176   bool const IsMarkupBackgroundColorSet() const override;
177
178   /**
179    * @copydoc ModelInterface::GetDefaultColor()
180    */
181   const Vector4& GetDefaultColor() const override;
182
183   /**
184    * @copydoc ModelInterface::GetShadowOffset()
185    */
186   const Vector2& GetShadowOffset() const override;
187
188   /**
189    * @copydoc ModelInterface::GetShadowColor()
190    */
191   const Vector4& GetShadowColor() const override;
192
193   /**
194    * @copydoc ModelInterface::GetShadowBlurRadius()
195    */
196   const float& GetShadowBlurRadius() const override;
197
198   /**
199    * @copydoc ModelInterface::GetUnderlineColor()
200    */
201   const Vector4& GetUnderlineColor() const override;
202
203   /**
204    * @copydoc ModelInterface::IsUnderlineEnabled()
205    */
206   bool IsUnderlineEnabled() const override;
207
208   /**
209    * @copydoc ModelInterface::GetUnderlineHeight()
210    */
211   float GetUnderlineHeight() const override;
212
213   /**
214    * @copydoc ModelInterface::GetNumberOfUnderlineRuns()
215    */
216   Length GetNumberOfUnderlineRuns() const override;
217
218   /**
219    * @copydoc ModelInterface::GetUnderlineRuns()
220    */
221   void GetUnderlineRuns(GlyphRun* underlineRuns, UnderlineRunIndex index, Length numberOfRuns) const override;
222
223   /**
224    * @copydoc ModelInterface::GetOutlineColor()
225    */
226   const Vector4& GetOutlineColor() const override;
227
228   /**
229    * @copydoc ModelInterface::GetOutlineWidth()
230    */
231   uint16_t GetOutlineWidth() const override;
232
233   /**
234    * @copydoc ModelInterface::GetBackgroundColor()
235    */
236   const Vector4& GetBackgroundColor() const override;
237
238   /**
239    * @copydoc ModelInterface::IsBackgroundEnabled()
240    */
241   bool IsBackgroundEnabled() const override;
242
243   /**
244    * @copydoc ModelInterface::IsMarkupProcessorEnabled()
245    */
246   bool IsMarkupProcessorEnabled() const override;
247
248   /**
249   * @copydoc ModelInterface::GetHyphens()
250   */
251   const GlyphInfo* GetHyphens() const override;
252
253   /**
254   * @copydoc ModelInterface::GetHyphens()
255   */
256   const Length* GetHyphenIndices() const override;
257
258   /**
259   * @copydoc ModelInterface::GetHyphens()
260   */
261   Length GetHyphensCount() const override;
262
263   /**
264    * @brief Does the text elide at the end, start or middle of text according to ellipsis position
265    *
266    * It stores a copy of the visible glyphs and removes as many glyphs as needed
267    * from the last visible line to add the ellipsis glyph in END case,
268    * from the first visible line to add the ellipsis glyph in START case,
269    * between the first and last visible lines to add the ellipsis glyph.
270    *
271    * It stores as well a copy of the positions for each visible glyph.
272    */
273   void ElideGlyphs();
274
275 private:
276   const ModelInterface* const mModel;                           ///< Pointer to the text's model.
277   Vector<GlyphInfo>           mElidedGlyphs;                    ///< Stores the glyphs of the elided text.
278   Vector<Vector2>             mElidedLayout;                    ///< Stores the positions of each glyph of the elided text.
279   bool                        mIsTextElided : 1;                ///< Whether the text has been elided.
280   GlyphIndex                  mStartIndexOfElidedGlyphs;        ///< The start index of elided glyphs.
281   GlyphIndex                  mEndIndexOfElidedGlyphs;          ///< The end index of elided glyphs.
282   GlyphIndex                  mFirstMiddleIndexOfElidedGlyphs;  ///< The first end index of elided glyphs, index before ellipsis of middle.
283   GlyphIndex                  mSecondMiddleIndexOfElidedGlyphs; ///< The second end index of elided glyphs, index of ellipsis of middle.
284 };
285
286 } // namespace Text
287
288 } // namespace Toolkit
289
290 } // namespace Dali
291
292 #endif // DALI_TOOLKIT_TEXT_VIEW_MODEL_H