[dali_1.9.29] Merge branch 'devel/master'
[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) 2018 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/public-api/text/text-enumerations.h>
26 #include <dali-toolkit/internal/text/text-model-interface.h>
27 #include <dali-toolkit/devel-api/text/text-enumerations-devel.h>
28
29 namespace Dali
30 {
31
32 namespace Toolkit
33 {
34
35 namespace Text
36 {
37
38 /**
39  * @brief Responsible of creating and store temporary modifications of the text model.
40  * i.e. The elide of text.
41  */
42 class ViewModel : public ModelInterface
43 {
44 public:
45   /**
46    * @brief Constructor.
47    *
48    * Keeps the pointer to the text's model. It initializes all the members of the class to their defaults.
49    *
50    * @param[in] model Pointer to the text's model interface.
51    */
52   ViewModel( const ModelInterface* const model );
53
54   /**
55    * @brief Virtual destructor.
56    *
57    * It's a default destructor.
58    */
59   virtual ~ViewModel();
60
61   /**
62    * @copydoc ModelInterface::GetControlSize()
63    */
64   const Size& GetControlSize() const override;
65
66   /**
67    * @copydoc ModelInterface::GetLayoutSize()
68    */
69   const Size& GetLayoutSize() const override;
70
71   /**
72    * @copydoc ModelInterface::GetScrollPosition()
73    */
74   const Vector2& GetScrollPosition() const override;
75
76   /**
77    * @copydoc ModelInterface::GetHorizontalAlignment()
78    */
79   Text::HorizontalAlignment::Type GetHorizontalAlignment() const override;
80
81   /**
82    * @copydoc ModelInterface::GetVerticalAlignment()
83    */
84   Text::VerticalAlignment::Type GetVerticalAlignment() const override;
85
86   /**
87  * @copydoc ModelInterface::GetVerticalLineAlignment()
88  */
89   DevelText::VerticalLineAlignment::Type GetVerticalLineAlignment() const override;
90
91   /**
92    * @copydoc ModelInterface::IsTextElideEnabled()
93    */
94   bool IsTextElideEnabled() const override;
95
96   /**
97    * @copydoc ModelInterface::GetNumberOfLines()
98    */
99   Length GetNumberOfLines() const override;
100
101   /**
102    * @copydoc ModelInterface::GetLines()
103    */
104   const LineRun* const GetLines() const override;
105
106   /**
107    * @copydoc ModelInterface::GetNumberOfScripts()
108    */
109   Length GetNumberOfScripts() const override;
110
111   /**
112    * @copydoc ModelInterface::GetScriptRuns()
113    */
114   const ScriptRun* const GetScriptRuns() const override;
115
116   /**
117    * @copydoc ModelInterface::GetNumberOfGlyphs()
118    */
119   Length GetNumberOfGlyphs() const override;
120
121   /**
122    * @copydoc ModelInterface::GetGlyphs()
123    */
124   const GlyphInfo* const GetGlyphs() const override;
125
126   /**
127    * @copydoc ModelInterface::GetLayout()
128    */
129   const Vector2* const GetLayout() const override;
130
131   /**
132    * @copydoc ModelInterface::GetColors()
133    */
134   const Vector4* const GetColors() const override;
135
136   /**
137    * @copydoc ModelInterface::GetColorIndices()
138    */
139   const ColorIndex* const GetColorIndices() const override;
140
141   /**
142    * @copydoc ModelInterface::GetBackgroundColors()
143    */
144   const Vector4* const GetBackgroundColors() const override;
145
146   /**
147    * @copydoc ModelInterface::GetBackgroundColorIndices()
148    */
149   const ColorIndex* const GetBackgroundColorIndices() const override;
150
151   /**
152    * @copydoc ModelInterface::GetDefaultColor()
153    */
154   const Vector4& GetDefaultColor() const override;
155
156   /**
157    * @copydoc ModelInterface::GetShadowOffset()
158    */
159   const Vector2& GetShadowOffset() const override;
160
161   /**
162    * @copydoc ModelInterface::GetShadowColor()
163    */
164   const Vector4& GetShadowColor() const override;
165
166   /**
167    * @copydoc ModelInterface::GetShadowBlurRadius()
168    */
169   const float& GetShadowBlurRadius() const override;
170
171   /**
172    * @copydoc ModelInterface::GetUnderlineColor()
173    */
174   const Vector4& GetUnderlineColor() const override;
175
176   /**
177    * @copydoc ModelInterface::IsUnderlineEnabled()
178    */
179   bool IsUnderlineEnabled() const override;
180
181   /**
182    * @copydoc ModelInterface::GetUnderlineHeight()
183    */
184   float GetUnderlineHeight() const override;
185
186   /**
187    * @copydoc ModelInterface::GetNumberOfUnderlineRuns()
188    */
189   Length GetNumberOfUnderlineRuns() const override;
190
191   /**
192    * @copydoc ModelInterface::GetUnderlineRuns()
193    */
194   void GetUnderlineRuns( GlyphRun* underlineRuns, UnderlineRunIndex index, Length numberOfRuns ) const override;
195
196   /**
197    * @copydoc ModelInterface::GetOutlineColor()
198    */
199   const Vector4& GetOutlineColor() const override;
200
201   /**
202    * @copydoc ModelInterface::GetOutlineWidth()
203    */
204   uint16_t GetOutlineWidth() const override;
205
206   /**
207    * @copydoc ModelInterface::GetBackgroundColor()
208    */
209   const Vector4& GetBackgroundColor() const override;
210
211   /**
212    * @copydoc ModelInterface::IsBackgroundEnabled()
213    */
214   bool IsBackgroundEnabled() const override;
215
216 /**
217    * @brief Does the text elide.
218    *
219    * It stores a copy of the visible glyphs and removes as many glyphs as needed
220    * from the last visible line to add the ellipsis glyph.
221    *
222    * It stores as well a copy of the positions for each visible glyph.
223    */
224   void ElideGlyphs();
225
226 private:
227   const ModelInterface* const mModel;            ///< Pointer to the text's model.
228   Vector<GlyphInfo>           mElidedGlyphs;     ///< Stores the glyphs of the elided text.
229   Vector<Vector2>             mElidedLayout;     ///< Stores the positions of each glyph of the elided text.
230   bool                        mIsTextElided : 1; ///< Whether the text has been elided.
231 };
232
233 } // namespace Text
234
235 } // namespace Toolkit
236
237 } // namespace Dali
238
239 #endif // DALI_TOOLKIT_TEXT_VIEW_MODEL_H