Merge "fix issue in negative line spacing with key arrow down" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-model.h
1 #ifndef DALI_TOOLKIT_TEXT_MODEL_H
2 #define DALI_TOOLKIT_TEXT_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/object/ref-object.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/internal/text/bounded-paragraph-run.h>
26 #include <dali-toolkit/internal/text/character-spacing-glyph-run.h>
27 #include <dali-toolkit/internal/text/logical-model-impl.h>
28 #include <dali-toolkit/internal/text/text-model-interface.h>
29 #include <dali-toolkit/internal/text/visual-model-impl.h>
30 #include <dali-toolkit/public-api/text/text-enumerations.h>
31
32 namespace Dali
33 {
34 namespace Toolkit
35 {
36 namespace Text
37 {
38 // Forward declarations.
39 class Model;
40
41 typedef IntrusivePtr<Model> ModelPtr;
42
43 /**
44  * @brief Implementation class used to retrieve the text's model from the text-controller.
45  */
46 class Model : public RefObject, public ModelInterface
47 {
48 public: // Constructor.
49   /**
50    * @brief Create a new instance of a text Model.
51    *
52    * @return A pointer to a new text Model.
53    */
54   static ModelPtr New();
55
56 public:
57   /**
58    * @copydoc ModelInterface::GetControlSize()
59    */
60   const Size& GetControlSize() const override;
61
62   /**
63    * @copydoc ModelInterface::GetLayoutSize()
64    */
65   const Size& GetLayoutSize() const override;
66
67   /**
68    * @copydoc ModelInterface::GetScrollPosition()
69    */
70   const Vector2& GetScrollPosition() const override;
71
72   /**
73    * @copydoc ModelInterface::GetHorizontalAlignment()
74    */
75   HorizontalAlignment::Type GetHorizontalAlignment() const override;
76
77   /**
78    * @copydoc ModelInterface::GetVerticalAlignment()
79    */
80   VerticalAlignment::Type GetVerticalAlignment() const override;
81
82   /**
83    * @copydoc ModelInterface::GetVerticalLineAlignment()
84    */
85   DevelText::VerticalLineAlignment::Type GetVerticalLineAlignment() const override;
86
87   /**
88    * @copydoc ModelInterface::GetEllipsisPosition()
89    */
90   DevelText::EllipsisPosition::Type GetEllipsisPosition() const override;
91
92   /**
93    * @copydoc ModelInterface::IsTextElideEnabled()
94    */
95   bool IsTextElideEnabled() const override;
96
97   /**
98    * @copydoc ModelInterface::GetNumberOfLines()
99    */
100   Length GetNumberOfLines() const override;
101
102   /**
103    * @copydoc ModelInterface::GetLines()
104    */
105   const LineRun* const GetLines() const override;
106
107   /**
108    * @copydoc ModelInterface::GetNumberOfScripts()
109    */
110   Length GetNumberOfScripts() const override;
111
112   /**
113    * @copydoc ModelInterface::GetScriptRuns()
114    */
115   const ScriptRun* const GetScriptRuns() const override;
116
117   /**
118    * @copydoc ModelInterface::GetNumberOfGlyphs()
119    */
120   Length GetNumberOfGlyphs() const override;
121
122   /**
123    * @copydoc ModelInterface::GetStartIndexOfElidedGlyphs()
124    */
125   GlyphIndex GetStartIndexOfElidedGlyphs() const override;
126
127   /**
128    * @copydoc ModelInterface::GetEndIndexOfElidedGlyphs()
129    */
130   GlyphIndex GetEndIndexOfElidedGlyphs() const override;
131
132   /**
133    * @copydoc ModelInterface::GetFirstMiddleIndexOfElidedGlyphs()
134    */
135   GlyphIndex GetFirstMiddleIndexOfElidedGlyphs() const override;
136
137   /**
138    * @copydoc ModelInterface::GetSecondMiddleIndexOfElidedGlyphs()
139    */
140   GlyphIndex GetSecondMiddleIndexOfElidedGlyphs() const override;
141
142   /**
143    * @copydoc ModelInterface::GetGlyphs()
144    */
145   const GlyphInfo* const GetGlyphs() const override;
146
147   /**
148    * @copydoc ModelInterface::GetLayout()
149    */
150   const Vector2* const GetLayout() const override;
151
152   /**
153    * @copydoc ModelInterface::GetColors()
154    */
155   const Vector4* const GetColors() const override;
156
157   /**
158    * @copydoc ModelInterface::GetColorIndices()
159    */
160   const ColorIndex* const GetColorIndices() const override;
161
162   /**
163    * @copydoc ModelInterface::GetBackgroundColors()
164    */
165   const Vector4* const GetBackgroundColors() const override;
166
167   /**
168    * @copydoc ModelInterface::GetBackgroundColorIndices()
169    */
170   const ColorIndex* const GetBackgroundColorIndices() const override;
171
172   /**
173    * @copydoc ModelInterface::IsMarkupBackgroundColorSet()
174    */
175   bool const IsMarkupBackgroundColorSet() const override;
176
177   /**
178    * @copydoc ModelInterface::GetDefaultColor()
179    */
180   const Vector4& GetDefaultColor() const override;
181
182   /**
183    * @copydoc ModelInterface::GetShadowOffset()
184    */
185   const Vector2& GetShadowOffset() const override;
186
187   /**
188    * @copydoc ModelInterface::GetShadowColor()
189    */
190   const Vector4& GetShadowColor() const override;
191
192   /**
193    * @copydoc ModelInterface::GetShadowBlurRadius()
194    */
195   const float& GetShadowBlurRadius() const override;
196
197   /**
198    * @copydoc ModelInterface::GetUnderlineColor()
199    */
200   const Vector4& GetUnderlineColor() const override;
201
202   /**
203    * @copydoc ModelInterface::IsUnderlineEnabled()
204    */
205   bool IsUnderlineEnabled() const override;
206
207   /**
208    * @copydoc ModelInterface::GetUnderlineHeight()
209    */
210   float GetUnderlineHeight() const override;
211
212   /**
213    * @copydoc ModelInterface::GetUnderlineType()
214    */
215   Text::Underline::Type GetUnderlineType() const override;
216
217   /**
218    * @copydoc ModelInterface::GetDashedUnderlineWidth()
219    */
220   float GetDashedUnderlineWidth() const override;
221
222   /**
223    * @copydoc ModelInterface::GetDashedUnderlineGap()
224    */
225   float GetDashedUnderlineGap() const override;
226
227   /**
228    * @copydoc ModelInterface::GetNumberOfUnderlineRuns()
229    */
230   Length GetNumberOfUnderlineRuns() const override;
231
232   /**
233    * @copydoc ModelInterface::GetUnderlineRuns()
234    */
235   void GetUnderlineRuns(UnderlinedGlyphRun* underlineRuns, UnderlineRunIndex index, Length numberOfRuns) const override;
236
237   /**
238    * @copydoc ModelInterface::GetOutlineColor()
239    */
240   const Vector4& GetOutlineColor() const override;
241
242   /**
243    * @copydoc ModelInterface::GetOutlineWidth()
244    */
245   uint16_t GetOutlineWidth() const override;
246
247   /**
248    * @copydoc ModelInterface::GetBackgroundColor()
249    */
250   const Vector4& GetBackgroundColor() const override;
251
252   /**
253    * @copydoc ModelInterface::IsBackgroundEnabled()
254    */
255   bool IsBackgroundEnabled() const override;
256
257   /**
258    * @copydoc ModelInterface::IsMarkupProcessorEnabled()
259    */
260   bool IsMarkupProcessorEnabled() const override;
261
262   /**
263   * @copydoc ModelInterface::GetHyphens()
264   */
265   const GlyphInfo* GetHyphens() const override;
266
267   /**
268   * @copydoc ModelInterface::GetHyphens()
269   */
270   const Length* GetHyphenIndices() const override;
271
272   /**
273   * @copydoc ModelInterface::GetHyphens()
274   */
275   Length GetHyphensCount() const override;
276
277   float GetStrikethroughHeight() const override;
278
279   const Vector4& GetStrikethroughColor() const override;
280
281   bool IsStrikethroughEnabled() const override;
282   /**
283    * @copydoc ModelInterface::GetCharacterSpacing()
284    */
285   const float GetCharacterSpacing() const override;
286
287   /**
288    * @copydoc ModelInterface::GetTextBuffer()
289    */
290   const Character* GetTextBuffer() const override;
291
292   /**
293    * @copydoc ModelInterface::GetGlyphsToCharacters()
294    */
295   const Vector<CharacterIndex>& GetGlyphsToCharacters() const override;
296
297   /**
298    * @copydoc ModelInterface::GetNumberOfStrikethroughRuns()
299    */
300   Length GetNumberOfStrikethroughRuns() const override;
301
302   /**
303    * @copydoc ModelInterface::GetStrikethroughRuns()
304    */
305   void GetStrikethroughRuns(StrikethroughGlyphRun* strikethroughRuns, StrikethroughRunIndex index, Length numberOfRuns) const override;
306
307   /**
308    * @copydoc ModelInterface::GetNumberOfBoundedParagraphRuns()
309    */
310   virtual Length GetNumberOfBoundedParagraphRuns() const override;
311
312   /**
313    * @copydoc ModelInterface::GetBoundedParagraphRuns()
314    */
315   virtual const Vector<BoundedParagraphRun>& GetBoundedParagraphRuns() const override;
316
317   /**
318    * @copydoc ModelInterface::GetNumberOfCharacterSpacingGlyphRuns()
319    */
320   Length GetNumberOfCharacterSpacingGlyphRuns() const override;
321
322   /**
323    * @copydoc ModelInterface::GetCharacterSpacingGlyphRuns()
324    */
325   const Vector<CharacterSpacingGlyphRun>& GetCharacterSpacingGlyphRuns() const override;
326
327 private: // Private contructors & copy operator.
328   /**
329    * @brief Private constructor.
330    */
331   Model();
332
333   // Undefined.
334   Model(const Model& handle);
335
336   // Undefined.
337   Model& operator=(const Model& handle);
338
339 protected:
340   /**
341    * @brief A reference counted object may only be deleted by calling Unreference().
342    */
343   virtual ~Model();
344
345 public:
346   LogicalModelPtr mLogicalModel; ///< Pointer to the logical model.
347   VisualModelPtr  mVisualModel;  ///< Pointer to the visual model.
348   /**
349    * 0,0 means that the top-left corner of the layout matches the top-left corner of the UI control.
350    * Typically this will have a negative value with scrolling occurs.
351    */
352   Vector2                                mScrollPosition;            ///< The text is offset by this position when scrolling.
353   Vector2                                mScrollPositionLast;        ///< The last offset value of mScrollPosition
354   HorizontalAlignment::Type              mHorizontalAlignment;       ///< The layout's horizontal alignment.
355   VerticalAlignment::Type                mVerticalAlignment;         ///< The layout's vertical alignment.
356   DevelText::VerticalLineAlignment::Type mVerticalLineAlignment;     ///< The layout's vertical line alignment.
357   Text::LineWrap::Mode                   mLineWrapMode;              ///< The text wrap mode
358   float                                  mAlignmentOffset;           ///< The alignment offset.
359   bool                                   mElideEnabled : 1;          ///< Whether the text's elide is enabled.
360   bool                                   mIgnoreSpacesAfterText : 1; ///< Whether ignoring spaces after text or not. Default is true.
361   DevelText::MatchLayoutDirection        mMatchLayoutDirection;      ///< Whether to match text alignment with layout direction or not.
362   DevelText::EllipsisPosition::Type      mEllipsisPosition;          ///< Where is the location the text elide
363 };
364
365 } // namespace Text
366
367 } // namespace Toolkit
368
369 } // namespace Dali
370
371 #endif // DALI_TOOLKIT_TEXT_MODEL_H