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