Merge "fix issue in negative line spacing with key arrow down" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-model.cpp
1 /*
2  * Copyright (c) 2022 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 Text::Underline::Type Model::GetUnderlineType() const
196 {
197   return mVisualModel->GetUnderlineType();
198 }
199
200 float Model::GetDashedUnderlineWidth() const
201 {
202   return mVisualModel->GetDashedUnderlineWidth();
203 }
204
205 float Model::GetDashedUnderlineGap() const
206 {
207   return mVisualModel->GetDashedUnderlineGap();
208 }
209
210 Length Model::GetNumberOfUnderlineRuns() const
211 {
212   return mVisualModel->GetNumberOfUnderlineRuns();
213 }
214
215 void Model::GetUnderlineRuns(UnderlinedGlyphRun* underlineRuns, UnderlineRunIndex index, Length numberOfRuns) const
216 {
217   mVisualModel->GetUnderlineRuns(underlineRuns, index, numberOfRuns);
218 }
219
220 const Vector4& Model::GetOutlineColor() const
221 {
222   return mVisualModel->GetOutlineColor();
223 }
224
225 uint16_t Model::GetOutlineWidth() const
226 {
227   return mVisualModel->GetOutlineWidth();
228 }
229
230 const Vector4& Model::GetBackgroundColor() const
231 {
232   return mVisualModel->GetBackgroundColor();
233 }
234
235 bool Model::IsBackgroundEnabled() const
236 {
237   return mVisualModel->IsBackgroundEnabled();
238 }
239
240 bool Model::IsMarkupProcessorEnabled() const
241 {
242   return mVisualModel->IsMarkupProcessorEnabled();
243 }
244
245 const GlyphInfo* Model::GetHyphens() const
246 {
247   return mVisualModel->mHyphen.glyph.Begin();
248 }
249
250 const Length* Model::GetHyphenIndices() const
251 {
252   return mVisualModel->mHyphen.index.Begin();
253 }
254
255 Length Model::GetHyphensCount() const
256 {
257   return mVisualModel->mHyphen.glyph.Size();
258 }
259 const Vector4& Model::GetStrikethroughColor() const
260 {
261   return mVisualModel->GetStrikethroughColor();
262 }
263
264 bool Model::IsStrikethroughEnabled() const
265 {
266   return mVisualModel->IsStrikethroughEnabled();
267 }
268
269 float Model::GetStrikethroughHeight() const
270 {
271   return mVisualModel->GetStrikethroughHeight();
272 }
273
274 Length Model::GetNumberOfStrikethroughRuns() const
275 {
276   return mVisualModel->GetNumberOfStrikethroughRuns();
277 }
278
279 Length Model::GetNumberOfBoundedParagraphRuns() const
280 {
281   return mLogicalModel->GetNumberOfBoundedParagraphRuns();
282 }
283
284 const Vector<BoundedParagraphRun>& Model::GetBoundedParagraphRuns() const
285 {
286   return mLogicalModel->GetBoundedParagraphRuns();
287 }
288
289 void Model::GetStrikethroughRuns(StrikethroughGlyphRun* strikethroughRuns, StrikethroughRunIndex index, Length numberOfRuns) const
290 {
291   mVisualModel->GetStrikethroughRuns(strikethroughRuns, index, numberOfRuns);
292 }
293
294 Length Model::GetNumberOfCharacterSpacingGlyphRuns() const
295 {
296   return mVisualModel->GetNumberOfCharacterSpacingGlyphRuns();
297 }
298
299 const Vector<CharacterSpacingGlyphRun>& Model::GetCharacterSpacingGlyphRuns() const
300 {
301   return mVisualModel->GetCharacterSpacingGlyphRuns();
302 }
303
304 const float Model::GetCharacterSpacing() const
305 {
306   return mVisualModel->GetCharacterSpacing();
307 }
308
309 const Character* Model::GetTextBuffer() const
310 {
311   return mLogicalModel->mText.Begin();
312 }
313
314 const Vector<CharacterIndex>& Model::GetGlyphsToCharacters() const
315 {
316   return mVisualModel->mGlyphsToCharacters;
317 }
318
319 Model::Model()
320 : mLogicalModel(),
321   mVisualModel(),
322   mScrollPosition(),
323   mScrollPositionLast(),
324   mHorizontalAlignment(Text::HorizontalAlignment::BEGIN),
325   mVerticalAlignment(Text::VerticalAlignment::TOP),
326   mVerticalLineAlignment(DevelText::VerticalLineAlignment::TOP),
327   mLineWrapMode(Text::LineWrap::WORD),
328   mAlignmentOffset(0.0f),
329   mElideEnabled(false),
330   mIgnoreSpacesAfterText(true),
331   mMatchLayoutDirection(DevelText::MatchLayoutDirection::INHERIT),
332   mEllipsisPosition(DevelText::EllipsisPosition::END)
333 {
334   mLogicalModel = LogicalModel::New();
335   mVisualModel  = VisualModel::New();
336
337   // Check environment variable for DALI_MATCH_SYSTEM_LANGUAGE_DIRECTION
338   auto match = Dali::EnvironmentVariable::GetEnvironmentVariable(DALI_ENV_MATCH_SYSTEM_LANGUAGE_DIRECTION);
339   if(match && (std::atoi(match) == 0))
340   {
341     mMatchLayoutDirection = DevelText::MatchLayoutDirection::CONTENTS;
342   }
343 }
344
345 Model::~Model()
346 {
347 }
348
349 } // namespace Text
350
351 } // namespace Toolkit
352
353 } // namespace Dali