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