add support for background markup tag
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-model.cpp
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali-toolkit/internal/text/text-model.h>
20
21 namespace Dali
22 {
23 namespace Toolkit
24 {
25 namespace Text
26 {
27 ModelPtr Model::New()
28 {
29   return ModelPtr(new Model());
30 }
31
32 const Size& Model::GetControlSize() const
33 {
34   return mVisualModel->mControlSize;
35 }
36
37 const Size& Model::GetLayoutSize() const
38 {
39   return mVisualModel->GetLayoutSize();
40 }
41
42 const Vector2& Model::GetScrollPosition() const
43 {
44   return mScrollPosition;
45 }
46
47 HorizontalAlignment::Type Model::GetHorizontalAlignment() const
48 {
49   return mHorizontalAlignment;
50 }
51
52 VerticalAlignment::Type Model::GetVerticalAlignment() const
53 {
54   return mVerticalAlignment;
55 }
56
57 DevelText::VerticalLineAlignment::Type Model::GetVerticalLineAlignment() const
58 {
59   return mVerticalLineAlignment;
60 }
61
62 bool Model::IsTextElideEnabled() const
63 {
64   return mElideEnabled;
65 }
66
67 Length Model::GetNumberOfLines() const
68 {
69   return mVisualModel->mLines.Count();
70 }
71
72 const LineRun* const Model::GetLines() const
73 {
74   return mVisualModel->mLines.Begin();
75 }
76
77 Length Model::GetNumberOfScripts() const
78 {
79   return mLogicalModel->mScriptRuns.Count();
80 }
81
82 const ScriptRun* const Model::GetScriptRuns() const
83 {
84   return mLogicalModel->mScriptRuns.Begin();
85 }
86
87 Length Model::GetNumberOfGlyphs() const
88 {
89   return mVisualModel->mGlyphs.Count();
90 }
91
92 const GlyphInfo* const Model::GetGlyphs() const
93 {
94   return mVisualModel->mGlyphs.Begin();
95 }
96
97 const Vector2* const Model::GetLayout() const
98 {
99   return mVisualModel->mGlyphPositions.Begin();
100 }
101
102 const Vector4* const Model::GetColors() const
103 {
104   return mVisualModel->mColors.Begin();
105 }
106
107 const ColorIndex* const Model::GetColorIndices() const
108 {
109   return mVisualModel->mColorIndices.Begin();
110 }
111
112 const Vector4* const Model::GetBackgroundColors() const
113 {
114   return mVisualModel->mBackgroundColors.Begin();
115 }
116
117 const ColorIndex* const Model::GetBackgroundColorIndices() const
118 {
119   return mVisualModel->mBackgroundColorIndices.Begin();
120 }
121
122 bool const Model::IsMarkupBackgroundColorSet() const
123 {
124   return (mVisualModel->mBackgroundColorIndices.Count() > 0);
125 }
126
127 const Vector4& Model::GetDefaultColor() const
128 {
129   return mVisualModel->mTextColor;
130 }
131
132 const Vector2& Model::GetShadowOffset() const
133 {
134   return mVisualModel->mShadowOffset;
135 }
136
137 const Vector4& Model::GetShadowColor() const
138 {
139   return mVisualModel->mShadowColor;
140 }
141
142 const float& Model::GetShadowBlurRadius() const
143 {
144   return mVisualModel->mShadowBlurRadius;
145 }
146
147 const Vector4& Model::GetUnderlineColor() const
148 {
149   return mVisualModel->GetUnderlineColor();
150 }
151
152 bool Model::IsUnderlineEnabled() const
153 {
154   return mVisualModel->IsUnderlineEnabled();
155 }
156
157 float Model::GetUnderlineHeight() const
158 {
159   return mVisualModel->GetUnderlineHeight();
160 }
161
162 Length Model::GetNumberOfUnderlineRuns() const
163 {
164   return mVisualModel->GetNumberOfUnderlineRuns();
165 }
166
167 void Model::GetUnderlineRuns(GlyphRun* underlineRuns, UnderlineRunIndex index, Length numberOfRuns) const
168 {
169   mVisualModel->GetUnderlineRuns(underlineRuns, index, numberOfRuns);
170 }
171
172 const Vector4& Model::GetOutlineColor() const
173 {
174   return mVisualModel->GetOutlineColor();
175 }
176
177 uint16_t Model::GetOutlineWidth() const
178 {
179   return mVisualModel->GetOutlineWidth();
180 }
181
182 const Vector4& Model::GetBackgroundColor() const
183 {
184   return mVisualModel->GetBackgroundColor();
185 }
186
187 bool Model::IsBackgroundEnabled() const
188 {
189   return mVisualModel->IsBackgroundEnabled();
190 }
191
192 bool Model::IsMarkupProcessorEnabled() const
193 {
194   return mVisualModel->IsMarkupProcessorEnabled();
195 }
196
197 const GlyphInfo* Model::GetHyphens() const
198 {
199   return mVisualModel->mHyphen.glyph.Begin();
200 }
201
202 const Length* Model::GetHyphenIndices() const
203 {
204   return mVisualModel->mHyphen.index.Begin();
205 }
206
207 Length Model::GetHyphensCount() const
208 {
209   return mVisualModel->mHyphen.glyph.Size();
210 }
211
212 Model::Model()
213 : mLogicalModel(),
214   mVisualModel(),
215   mScrollPosition(),
216   mScrollPositionLast(),
217   mHorizontalAlignment(Text::HorizontalAlignment::BEGIN),
218   mVerticalAlignment(Text::VerticalAlignment::TOP),
219   mVerticalLineAlignment(DevelText::VerticalLineAlignment::TOP),
220   mLineWrapMode(Text::LineWrap::WORD),
221   mAlignmentOffset(0.0f),
222   mElideEnabled(false),
223   mIgnoreSpacesAfterText(true),
224   mMatchSystemLanguageDirection(false)
225 {
226   mLogicalModel = LogicalModel::New();
227   mVisualModel  = VisualModel::New();
228 }
229
230 Model::~Model()
231 {
232 }
233
234 } // namespace Text
235
236 } // namespace Toolkit
237
238 } // namespace Dali