Reduce text visual memory consumption for text with no styles and emojis
[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) 2017 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/layouts/layout-alignment.h>
26 #include <dali-toolkit/internal/text/layouts/layout-wrap-mode.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
31 namespace Dali
32 {
33
34 namespace Toolkit
35 {
36
37 namespace Text
38 {
39
40 // Forward declarations.
41 class Model;
42
43 typedef IntrusivePtr<Model> ModelPtr;
44
45 /**
46  * @brief Implementation class used to retrieve the text's model from the text-controller.
47  */
48 class Model : public RefObject, public ModelInterface
49 {
50
51 public: // Constructor.
52
53   /**
54    * @brief Create a new instance of a text Model.
55    *
56    * @return A pointer to a new text Model.
57    */
58   static ModelPtr New();
59
60 public:
61
62   /**
63    * @copydoc ModelInterface::GetControlSize()
64    */
65   virtual const Size& GetControlSize() const;
66
67   /**
68    * @copydoc ModelInterface::GetLayoutSize()
69    */
70   virtual const Size& GetLayoutSize() const;
71
72   /**
73    * @copydoc ModelInterface::GetScrollPosition()
74    */
75   virtual const Vector2& GetScrollPosition() const;
76
77   /**
78    * @copydoc ModelInterface::GetHorizontalAlignment()
79    */
80   virtual Layout::HorizontalAlignment GetHorizontalAlignment() const;
81
82   /**
83    * @copydoc ModelInterface::GetVerticalAlignment()
84    */
85   virtual Layout::VerticalAlignment GetVerticalAlignment() const;
86
87   /**
88    * @copydoc ModelInterface::IsTextElideEnabled()
89    */
90   virtual bool IsTextElideEnabled() const;
91
92   /**
93    * @copydoc ModelInterface::GetNumberOfLines()
94    */
95   virtual Length GetNumberOfLines() const;
96
97   /**
98    * @copydoc ModelInterface::GetLines()
99    */
100   virtual const LineRun* const GetLines() const;
101
102   /**
103    * @copydoc ModelInterface::GetNumberOfScripts()
104    */
105   virtual Length GetNumberOfScripts() const;
106
107   /**
108    * @copydoc ModelInterface::GetScriptRuns()
109    */
110   virtual const ScriptRun* const GetScriptRuns() const;
111
112   /**
113    * @copydoc ModelInterface::GetNumberOfGlyphs()
114    */
115   virtual Length GetNumberOfGlyphs() const;
116
117   /**
118    * @copydoc ModelInterface::GetGlyphs()
119    */
120   virtual const GlyphInfo* const GetGlyphs() const;
121
122   /**
123    * @copydoc ModelInterface::GetLayout()
124    */
125   virtual const Vector2* const GetLayout() const;
126
127   /**
128    * @copydoc ModelInterface::GetColors()
129    */
130   virtual const Vector4* const GetColors() const;
131
132   /**
133    * @copydoc ModelInterface::GetColorIndices()
134    */
135   virtual const ColorIndex* const GetColorIndices() const;
136
137   /**
138    * @copydoc ModelInterface::GetDefaultColor()
139    */
140   virtual const Vector4& GetDefaultColor() const;
141
142   /**
143    * @copydoc ModelInterface::GetShadowOffset()
144    */
145   virtual const Vector2& GetShadowOffset() const;
146
147   /**
148    * @copydoc ModelInterface::GetShadowColor()
149    */
150   virtual const Vector4& GetShadowColor() const;
151
152   /**
153    * @copydoc ModelInterface::GetUnderlineColor()
154    */
155   virtual const Vector4& GetUnderlineColor() const;
156
157   /**
158    * @copydoc ModelInterface::IsUnderlineEnabled()
159    */
160   virtual bool IsUnderlineEnabled() const;
161
162   /**
163    * @copydoc ModelInterface::GetUnderlineHeight()
164    */
165   virtual float GetUnderlineHeight() const;
166
167   /**
168    * @copydoc ModelInterface::GetNumberOfUnderlineRuns()
169    */
170   virtual Length GetNumberOfUnderlineRuns() const;
171
172   /**
173    * @copydoc ModelInterface::GetUnderlineRuns()
174    */
175   virtual void GetUnderlineRuns( GlyphRun* underlineRuns, UnderlineRunIndex index, Length numberOfRuns ) const;
176
177 private: // Private contructors & copy operator.
178
179   /**
180    * @brief Private constructor.
181    */
182   Model();
183
184   // Undefined.
185   Model( const Model& handle );
186
187   // Undefined.
188   Model& operator=( const Model& handle );
189
190 protected:
191
192   /**
193    * @brief A reference counted object may only be deleted by calling Unreference().
194    */
195   virtual ~Model();
196
197 public:
198   LogicalModelPtr             mLogicalModel;        ///< Pointer to the logical model.
199   VisualModelPtr              mVisualModel;         ///< Pointer to the visual model.
200   /**
201    * 0,0 means that the top-left corner of the layout matches the top-left corner of the UI control.
202    * Typically this will have a negative value with scrolling occurs.
203    */
204   Vector2                     mScrollPosition;      ///< The text is offset by this position when scrolling.
205   Vector2                     mScrollPositionLast;  ///< The last offset value of mScrollPosition
206   Layout::HorizontalAlignment mHorizontalAlignment; ///< The layout's horizontal alignment.
207   Layout::VerticalAlignment   mVerticalAlignment;   ///< The layout's vertical alignment.
208   Layout::LineWrap::Mode      mLineWrapMode;        ///< The text wrap mode
209   float                       mAlignmentOffset;     ///< The alignment offset.
210   bool                        mElideEnabled:1;      ///< Whether the text's elide is enabled.
211 };
212
213 } // namespace Text
214
215 } // namespace Toolkit
216
217 } // namespace Dali
218
219 #endif // DALI_TOOLKIT_TEXT_MODEL_H