Fix corrupted markup background
[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 // EXTERNAL INCLUDES
22 #include <dali/devel-api/adaptor-framework/environment-variable.h>
23
24 namespace Dali
25 {
26 namespace Toolkit
27 {
28 namespace Text
29 {
30 namespace
31 {
32 const char* DALI_ENV_MATCH_SYSTEM_LANGUAGE_DIRECTION("DALI_MATCH_SYSTEM_LANGUAGE_DIRECTION");
33 }
34
35 ModelPtr Model::New()
36 {
37   return ModelPtr(new Model());
38 }
39
40 const Size& Model::GetControlSize() const
41 {
42   return mVisualModel->mControlSize;
43 }
44
45 const Size& Model::GetLayoutSize() const
46 {
47   return mVisualModel->GetLayoutSize();
48 }
49
50 const Vector2& Model::GetScrollPosition() const
51 {
52   return mScrollPosition;
53 }
54
55 HorizontalAlignment::Type Model::GetHorizontalAlignment() const
56 {
57   return mHorizontalAlignment;
58 }
59
60 VerticalAlignment::Type Model::GetVerticalAlignment() const
61 {
62   return mVerticalAlignment;
63 }
64
65 DevelText::VerticalLineAlignment::Type Model::GetVerticalLineAlignment() const
66 {
67   return mVerticalLineAlignment;
68 }
69
70 bool Model::IsTextElideEnabled() const
71 {
72   return mElideEnabled;
73 }
74
75 Length Model::GetNumberOfLines() const
76 {
77   return mVisualModel->mLines.Count();
78 }
79
80 const LineRun* const Model::GetLines() const
81 {
82   return mVisualModel->mLines.Begin();
83 }
84
85 Length Model::GetNumberOfScripts() const
86 {
87   return mLogicalModel->mScriptRuns.Count();
88 }
89
90 const ScriptRun* const Model::GetScriptRuns() const
91 {
92   return mLogicalModel->mScriptRuns.Begin();
93 }
94
95 Length Model::GetNumberOfGlyphs() const
96 {
97   return mVisualModel->mGlyphs.Count();
98 }
99
100 const GlyphInfo* const Model::GetGlyphs() const
101 {
102   return mVisualModel->mGlyphs.Begin();
103 }
104
105 const Vector2* const Model::GetLayout() const
106 {
107   return mVisualModel->mGlyphPositions.Begin();
108 }
109
110 const Vector4* const Model::GetColors() const
111 {
112   return mVisualModel->mColors.Begin();
113 }
114
115 const ColorIndex* const Model::GetColorIndices() const
116 {
117   return mVisualModel->mColorIndices.Begin();
118 }
119
120 const Vector4* const Model::GetBackgroundColors() const
121 {
122   return mVisualModel->mBackgroundColors.Begin();
123 }
124
125 const ColorIndex* const Model::GetBackgroundColorIndices() const
126 {
127   return mVisualModel->mBackgroundColorIndices.Begin();
128 }
129
130 bool const Model::IsMarkupBackgroundColorSet() const
131 {
132   return (mVisualModel->mBackgroundColors.Count() > 0);
133 }
134
135 const Vector4& Model::GetDefaultColor() const
136 {
137   return mVisualModel->mTextColor;
138 }
139
140 const Vector2& Model::GetShadowOffset() const
141 {
142   return mVisualModel->mShadowOffset;
143 }
144
145 const Vector4& Model::GetShadowColor() const
146 {
147   return mVisualModel->mShadowColor;
148 }
149
150 const float& Model::GetShadowBlurRadius() const
151 {
152   return mVisualModel->mShadowBlurRadius;
153 }
154
155 const Vector4& Model::GetUnderlineColor() const
156 {
157   return mVisualModel->GetUnderlineColor();
158 }
159
160 bool Model::IsUnderlineEnabled() const
161 {
162   return mVisualModel->IsUnderlineEnabled();
163 }
164
165 float Model::GetUnderlineHeight() const
166 {
167   return mVisualModel->GetUnderlineHeight();
168 }
169
170 Length Model::GetNumberOfUnderlineRuns() const
171 {
172   return mVisualModel->GetNumberOfUnderlineRuns();
173 }
174
175 void Model::GetUnderlineRuns(GlyphRun* underlineRuns, UnderlineRunIndex index, Length numberOfRuns) const
176 {
177   mVisualModel->GetUnderlineRuns(underlineRuns, index, numberOfRuns);
178 }
179
180 const Vector4& Model::GetOutlineColor() const
181 {
182   return mVisualModel->GetOutlineColor();
183 }
184
185 uint16_t Model::GetOutlineWidth() const
186 {
187   return mVisualModel->GetOutlineWidth();
188 }
189
190 const Vector4& Model::GetBackgroundColor() const
191 {
192   return mVisualModel->GetBackgroundColor();
193 }
194
195 bool Model::IsBackgroundEnabled() const
196 {
197   return mVisualModel->IsBackgroundEnabled();
198 }
199
200 bool Model::IsMarkupProcessorEnabled() const
201 {
202   return mVisualModel->IsMarkupProcessorEnabled();
203 }
204
205 const GlyphInfo* Model::GetHyphens() const
206 {
207   return mVisualModel->mHyphen.glyph.Begin();
208 }
209
210 const Length* Model::GetHyphenIndices() const
211 {
212   return mVisualModel->mHyphen.index.Begin();
213 }
214
215 Length Model::GetHyphensCount() const
216 {
217   return mVisualModel->mHyphen.glyph.Size();
218 }
219
220 Model::Model()
221 : mLogicalModel(),
222   mVisualModel(),
223   mScrollPosition(),
224   mScrollPositionLast(),
225   mHorizontalAlignment(Text::HorizontalAlignment::BEGIN),
226   mVerticalAlignment(Text::VerticalAlignment::TOP),
227   mVerticalLineAlignment(DevelText::VerticalLineAlignment::TOP),
228   mLineWrapMode(Text::LineWrap::WORD),
229   mAlignmentOffset(0.0f),
230   mElideEnabled(false),
231   mIgnoreSpacesAfterText(true),
232   mMatchSystemLanguageDirection(true)
233 {
234   mLogicalModel = LogicalModel::New();
235   mVisualModel  = VisualModel::New();
236
237   // Check environment variable for DALI_MATCH_SYSTEM_LANGUAGE_DIRECTION
238   auto match                    = Dali::EnvironmentVariable::GetEnvironmentVariable(DALI_ENV_MATCH_SYSTEM_LANGUAGE_DIRECTION);
239   mMatchSystemLanguageDirection = match ? (std::atoi(match) == 0 ? false : true) : mMatchSystemLanguageDirection;
240 }
241
242 Model::~Model()
243 {
244 }
245
246 } // namespace Text
247
248 } // namespace Toolkit
249
250 } // namespace Dali