Add a callback for navigation policy in web view.
[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 DevelText::EllipsisPosition::Type Model::GetEllipsisPosition() const
71 {
72   return mEllipsisPosition;
73 }
74
75 bool Model::IsTextElideEnabled() const
76 {
77   return mElideEnabled;
78 }
79
80 Length Model::GetNumberOfLines() const
81 {
82   return mVisualModel->mLines.Count();
83 }
84
85 const LineRun* const Model::GetLines() const
86 {
87   return mVisualModel->mLines.Begin();
88 }
89
90 Length Model::GetNumberOfScripts() const
91 {
92   return mLogicalModel->mScriptRuns.Count();
93 }
94
95 const ScriptRun* const Model::GetScriptRuns() const
96 {
97   return mLogicalModel->mScriptRuns.Begin();
98 }
99
100 Length Model::GetNumberOfGlyphs() const
101 {
102   return mVisualModel->mGlyphs.Count();
103 }
104
105 GlyphIndex Model::GetStartIndexOfElidedGlyphs() const
106 {
107   return mVisualModel->GetStartIndexOfElidedGlyphs();
108 }
109
110 GlyphIndex Model::GetEndIndexOfElidedGlyphs() const
111 {
112   return mVisualModel->GetEndIndexOfElidedGlyphs();
113 }
114
115 GlyphIndex Model::GetFirstMiddleIndexOfElidedGlyphs() const
116 {
117   return mVisualModel->GetFirstMiddleIndexOfElidedGlyphs();
118 }
119
120 GlyphIndex Model::GetSecondMiddleIndexOfElidedGlyphs() const
121 {
122   return mVisualModel->GetSecondMiddleIndexOfElidedGlyphs();
123 }
124
125 const GlyphInfo* const Model::GetGlyphs() const
126 {
127   return mVisualModel->mGlyphs.Begin();
128 }
129
130 const Vector2* const Model::GetLayout() const
131 {
132   return mVisualModel->mGlyphPositions.Begin();
133 }
134
135 const Vector4* const Model::GetColors() const
136 {
137   return mVisualModel->mColors.Begin();
138 }
139
140 const ColorIndex* const Model::GetColorIndices() const
141 {
142   return mVisualModel->mColorIndices.Begin();
143 }
144
145 const Vector4* const Model::GetBackgroundColors() const
146 {
147   return mVisualModel->mBackgroundColors.Begin();
148 }
149
150 const ColorIndex* const Model::GetBackgroundColorIndices() const
151 {
152   return mVisualModel->mBackgroundColorIndices.Begin();
153 }
154
155 bool const Model::IsMarkupBackgroundColorSet() const
156 {
157   return (mVisualModel->mBackgroundColors.Count() > 0);
158 }
159
160 const Vector4& Model::GetDefaultColor() const
161 {
162   return mVisualModel->mTextColor;
163 }
164
165 const Vector2& Model::GetShadowOffset() const
166 {
167   return mVisualModel->mShadowOffset;
168 }
169
170 const Vector4& Model::GetShadowColor() const
171 {
172   return mVisualModel->mShadowColor;
173 }
174
175 const float& Model::GetShadowBlurRadius() const
176 {
177   return mVisualModel->mShadowBlurRadius;
178 }
179
180 const Vector4& Model::GetUnderlineColor() const
181 {
182   return mVisualModel->GetUnderlineColor();
183 }
184
185 bool Model::IsUnderlineEnabled() const
186 {
187   return mVisualModel->IsUnderlineEnabled();
188 }
189
190 float Model::GetUnderlineHeight() const
191 {
192   return mVisualModel->GetUnderlineHeight();
193 }
194
195 Length Model::GetNumberOfUnderlineRuns() const
196 {
197   return mVisualModel->GetNumberOfUnderlineRuns();
198 }
199
200 void Model::GetUnderlineRuns(GlyphRun* underlineRuns, UnderlineRunIndex index, Length numberOfRuns) const
201 {
202   mVisualModel->GetUnderlineRuns(underlineRuns, index, numberOfRuns);
203 }
204
205 const Vector4& Model::GetOutlineColor() const
206 {
207   return mVisualModel->GetOutlineColor();
208 }
209
210 uint16_t Model::GetOutlineWidth() const
211 {
212   return mVisualModel->GetOutlineWidth();
213 }
214
215 const Vector4& Model::GetBackgroundColor() const
216 {
217   return mVisualModel->GetBackgroundColor();
218 }
219
220 bool Model::IsBackgroundEnabled() const
221 {
222   return mVisualModel->IsBackgroundEnabled();
223 }
224
225 bool Model::IsMarkupProcessorEnabled() const
226 {
227   return mVisualModel->IsMarkupProcessorEnabled();
228 }
229
230 const GlyphInfo* Model::GetHyphens() const
231 {
232   return mVisualModel->mHyphen.glyph.Begin();
233 }
234
235 const Length* Model::GetHyphenIndices() const
236 {
237   return mVisualModel->mHyphen.index.Begin();
238 }
239
240 Length Model::GetHyphensCount() const
241 {
242   return mVisualModel->mHyphen.glyph.Size();
243 }
244
245 Model::Model()
246 : mLogicalModel(),
247   mVisualModel(),
248   mScrollPosition(),
249   mScrollPositionLast(),
250   mHorizontalAlignment(Text::HorizontalAlignment::BEGIN),
251   mVerticalAlignment(Text::VerticalAlignment::TOP),
252   mVerticalLineAlignment(DevelText::VerticalLineAlignment::TOP),
253   mLineWrapMode(Text::LineWrap::WORD),
254   mAlignmentOffset(0.0f),
255   mElideEnabled(false),
256   mIgnoreSpacesAfterText(true),
257   mMatchLayoutDirection(DevelText::MatchLayoutDirection::INHERIT),
258   mEllipsisPosition(DevelText::EllipsisPosition::END)
259 {
260   mLogicalModel = LogicalModel::New();
261   mVisualModel  = VisualModel::New();
262
263   // Check environment variable for DALI_MATCH_SYSTEM_LANGUAGE_DIRECTION
264   auto match = Dali::EnvironmentVariable::GetEnvironmentVariable(DALI_ENV_MATCH_SYSTEM_LANGUAGE_DIRECTION);
265   if(match && (std::atoi(match) == 0))
266   {
267     mMatchLayoutDirection = DevelText::MatchLayoutDirection::CONTENTS;
268   }
269 }
270
271 Model::~Model()
272 {
273 }
274
275 } // namespace Text
276
277 } // namespace Toolkit
278
279 } // namespace Dali