c7b0b183df3ebf97bc441db2bee9e80643ab8d88
[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) 2022 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/bounded-paragraph-run.h>
27 #include <dali-toolkit/internal/text/text-model-interface.h>
28 #include <dali-toolkit/public-api/text/text-enumerations.h>
29
30 namespace Dali
31 {
32 namespace Toolkit
33 {
34 namespace Text
35 {
36 /**
37  * @brief Responsible of creating and store temporary modifications of the text model.
38  * i.e. The elide of text.
39  */
40 class ViewModel : public ModelInterface
41 {
42 public:
43   /**
44    * @brief Constructor.
45    *
46    * Keeps the pointer to the text's model. It initializes all the members of the class to their defaults.
47    *
48    * @param[in] model Pointer to the text's model interface.
49    */
50   ViewModel(const ModelInterface* const model);
51
52   /**
53    * @brief Virtual destructor.
54    *
55    * It's a default destructor.
56    */
57   virtual ~ViewModel();
58
59   /**
60    * @copydoc ModelInterface::GetControlSize()
61    */
62   const Size& GetControlSize() const override;
63
64   /**
65    * @copydoc ModelInterface::GetLayoutSize()
66    */
67   const Size& GetLayoutSize() const override;
68
69   /**
70    * @copydoc ModelInterface::GetScrollPosition()
71    */
72   const Vector2& GetScrollPosition() const override;
73
74   /**
75    * @copydoc ModelInterface::GetHorizontalAlignment()
76    */
77   Text::HorizontalAlignment::Type GetHorizontalAlignment() const override;
78
79   /**
80    * @copydoc ModelInterface::GetVerticalAlignment()
81    */
82   Text::VerticalAlignment::Type GetVerticalAlignment() const override;
83
84   /**
85   * @copydoc ModelInterface::GetVerticalLineAlignment()
86   */
87   DevelText::VerticalLineAlignment::Type GetVerticalLineAlignment() const override;
88
89   /**
90   * @copydoc ModelInterface::GetEllipsisPosition()
91   */
92   DevelText::EllipsisPosition::Type GetEllipsisPosition() const override;
93
94   /**
95    * @copydoc ModelInterface::IsTextElideEnabled()
96    */
97   bool IsTextElideEnabled() const override;
98
99   /**
100    * @copydoc ModelInterface::GetNumberOfLines()
101    */
102   Length GetNumberOfLines() const override;
103
104   /**
105    * @copydoc ModelInterface::GetLines()
106    */
107   const LineRun* const GetLines() const override;
108
109   /**
110    * @copydoc ModelInterface::GetNumberOfScripts()
111    */
112   Length GetNumberOfScripts() const override;
113
114   /**
115    * @copydoc ModelInterface::GetScriptRuns()
116    */
117   const ScriptRun* const GetScriptRuns() const override;
118
119   /**
120    * @copydoc ModelInterface::GetNumberOfGlyphs()
121    */
122   Length GetNumberOfGlyphs() const override;
123
124   /**
125    * @copydoc ModelInterface::GetStartIndexOfElidedGlyphs()
126    */
127   GlyphIndex GetStartIndexOfElidedGlyphs() const override;
128
129   /**
130    * @copydoc ModelInterface::GetEndIndexOfElidedGlyphs()
131    */
132   GlyphIndex GetEndIndexOfElidedGlyphs() const override;
133
134   /**
135    * @copydoc ModelInterface::GetFirstMiddleIndexOfElidedGlyphs()
136    */
137   GlyphIndex GetFirstMiddleIndexOfElidedGlyphs() const override;
138
139   /**
140    * @copydoc ModelInterface::GetSecondMiddleIndexOfElidedGlyphs()
141    */
142   GlyphIndex GetSecondMiddleIndexOfElidedGlyphs() const override;
143
144   /**
145    * @copydoc ModelInterface::GetGlyphs()
146    */
147   const GlyphInfo* const GetGlyphs() const override;
148
149   /**
150    * @copydoc ModelInterface::GetLayout()
151    */
152   const Vector2* const GetLayout() const override;
153
154   /**
155    * @copydoc ModelInterface::GetColors()
156    */
157   const Vector4* const GetColors() const override;
158
159   /**
160    * @copydoc ModelInterface::GetColorIndices()
161    */
162   const ColorIndex* const GetColorIndices() const override;
163
164   /**
165    * @copydoc ModelInterface::GetBackgroundColors()
166    */
167   const Vector4* const GetBackgroundColors() const override;
168
169   /**
170    * @copydoc ModelInterface::GetBackgroundColorIndices()
171    */
172   const ColorIndex* const GetBackgroundColorIndices() const override;
173
174   /**
175    * @copydoc ModelInterface::IsMarkupBackgroundColorSet()
176    */
177   bool const IsMarkupBackgroundColorSet() const override;
178
179   /**
180    * @copydoc ModelInterface::GetDefaultColor()
181    */
182   const Vector4& GetDefaultColor() const override;
183
184   /**
185    * @copydoc ModelInterface::GetShadowOffset()
186    */
187   const Vector2& GetShadowOffset() const override;
188
189   /**
190    * @copydoc ModelInterface::GetShadowColor()
191    */
192   const Vector4& GetShadowColor() const override;
193
194   /**
195    * @copydoc ModelInterface::GetShadowBlurRadius()
196    */
197   const float& GetShadowBlurRadius() const override;
198
199   /**
200    * @copydoc ModelInterface::GetUnderlineColor()
201    */
202   const Vector4& GetUnderlineColor() const override;
203
204   /**
205    * @copydoc ModelInterface::IsUnderlineEnabled()
206    */
207   bool IsUnderlineEnabled() const override;
208
209   /**
210    * @copydoc ModelInterface::GetUnderlineHeight()
211    */
212   float GetUnderlineHeight() const override;
213
214   /**
215    * @copydoc ModelInterface::GetUnderlineType()
216    */
217   Text::Underline::Type GetUnderlineType() const override;
218
219   /**
220    * @copydoc ModelInterface::GetDashedUnderlineWidth()
221    */
222   float GetDashedUnderlineWidth() const override;
223
224   /**
225    * @copydoc ModelInterface::GetDashedUnderlineGap()
226    */
227   float GetDashedUnderlineGap() const override;
228
229   /**
230    * @copydoc ModelInterface::GetNumberOfUnderlineRuns()
231    */
232   Length GetNumberOfUnderlineRuns() const override;
233
234   /**
235    * @copydoc ModelInterface::GetUnderlineRuns()
236    */
237   void GetUnderlineRuns(UnderlinedGlyphRun* underlineRuns, UnderlineRunIndex index, Length numberOfRuns) const override;
238
239   /**
240    * @copydoc ModelInterface::GetOutlineColor()
241    */
242   const Vector4& GetOutlineColor() const override;
243
244   /**
245    * @copydoc ModelInterface::GetOutlineWidth()
246    */
247   uint16_t GetOutlineWidth() const override;
248
249   /**
250    * @copydoc ModelInterface::GetBackgroundColor()
251    */
252   const Vector4& GetBackgroundColor() const override;
253
254   /**
255    * @copydoc ModelInterface::IsBackgroundEnabled()
256    */
257   bool IsBackgroundEnabled() const override;
258
259   /**
260    * @copydoc ModelInterface::IsMarkupProcessorEnabled()
261    */
262   bool IsMarkupProcessorEnabled() const override;
263
264   /**
265   * @copydoc ModelInterface::GetHyphens()
266   */
267   const GlyphInfo* GetHyphens() const override;
268
269   /**
270   * @copydoc ModelInterface::GetHyphens()
271   */
272   const Length* GetHyphenIndices() const override;
273
274   /**
275   * @copydoc ModelInterface::GetHyphens()
276   */
277   Length GetHyphensCount() const override;
278
279   /**
280   * @copydoc ModelInterface::GetCharacterSpacing()
281   */
282   const float GetCharacterSpacing() const override;
283
284   /**
285   * @copydoc ModelInterface::GetTextBuffer()
286   */
287   const Character* GetTextBuffer() const override;
288
289   /**
290   * @copydoc ModelInterface::GetGlyphsToCharacters()
291   */
292   const Vector<CharacterIndex>& GetGlyphsToCharacters() const override;
293
294   /**
295    * @brief Does the text elide at the end, start or middle of text according to ellipsis position
296    *
297    * It stores a copy of the visible glyphs and removes as many glyphs as needed
298    * from the last visible line to add the ellipsis glyph in END case,
299    * from the first visible line to add the ellipsis glyph in START case,
300    * between the first and last visible lines to add the ellipsis glyph.
301    *
302    * It stores as well a copy of the positions for each visible glyph.
303    */
304   void ElideGlyphs();
305
306   float GetStrikethroughHeight() const override;
307
308   const Vector4& GetStrikethroughColor() const override;
309
310   bool IsStrikethroughEnabled() const override;
311
312   /**
313    * @copydoc ModelInterface::GetNumberOfStrikethroughRuns()
314    */
315   Length GetNumberOfStrikethroughRuns() const override;
316
317   /**
318    * @copydoc ModelInterface::GetNumberOfBoundedParagraphRuns()
319    */
320   virtual Length GetNumberOfBoundedParagraphRuns() const override;
321
322   /**
323    * @copydoc ModelInterface::GetBoundedParagraphRuns()
324    */
325   virtual const Vector<BoundedParagraphRun>& GetBoundedParagraphRuns() const override;
326
327   /**
328    * @copydoc ModelInterface::GetStrikethroughRuns()
329    */
330   void GetStrikethroughRuns(StrikethroughGlyphRun* strikethroughRuns, StrikethroughRunIndex index, Length numberOfRuns) const override;
331
332   /**
333    * @copydoc ModelInterface::GetNumberOfCharacterSpacingGlyphRuns()
334    */
335   Length GetNumberOfCharacterSpacingGlyphRuns() const override;
336
337   /**
338    * @copydoc ModelInterface::GetCharacterSpacingGlyphRuns()
339    */
340   const Vector<CharacterSpacingGlyphRun>& GetCharacterSpacingGlyphRuns() const override;
341
342 private:
343   const ModelInterface* const mModel;                           ///< Pointer to the text's model.
344   Vector<GlyphInfo>           mElidedGlyphs;                    ///< Stores the glyphs of the elided text.
345   Vector<Vector2>             mElidedLayout;                    ///< Stores the positions of each glyph of the elided text.
346   bool                        mIsTextElided : 1;                ///< Whether the text has been elided.
347   GlyphIndex                  mStartIndexOfElidedGlyphs;        ///< The start index of elided glyphs.
348   GlyphIndex                  mEndIndexOfElidedGlyphs;          ///< The end index of elided glyphs.
349   GlyphIndex                  mFirstMiddleIndexOfElidedGlyphs;  ///< The first end index of elided glyphs, index before ellipsis of middle.
350   GlyphIndex                  mSecondMiddleIndexOfElidedGlyphs; ///< The second end index of elided glyphs, index of ellipsis of middle.
351 };
352
353 } // namespace Text
354
355 } // namespace Toolkit
356
357 } // namespace Dali
358
359 #endif // DALI_TOOLKIT_TEXT_VIEW_MODEL_H