2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali-toolkit/internal/text/text-model.h>
22 #include <dali/devel-api/adaptor-framework/environment-variable.h>
32 const char* DALI_ENV_MATCH_SYSTEM_LANGUAGE_DIRECTION("DALI_MATCH_SYSTEM_LANGUAGE_DIRECTION");
37 return ModelPtr(new Model());
40 const Size& Model::GetControlSize() const
42 return mVisualModel->mControlSize;
45 const Size& Model::GetLayoutSize() const
47 return mVisualModel->GetLayoutSize();
50 const Vector2& Model::GetScrollPosition() const
52 return mScrollPosition;
55 HorizontalAlignment::Type Model::GetHorizontalAlignment() const
57 return mHorizontalAlignment;
60 VerticalAlignment::Type Model::GetVerticalAlignment() const
62 return mVerticalAlignment;
65 DevelText::VerticalLineAlignment::Type Model::GetVerticalLineAlignment() const
67 return mVerticalLineAlignment;
70 DevelText::EllipsisPosition::Type Model::GetEllipsisPosition() const
72 return mEllipsisPosition;
75 bool Model::IsTextElideEnabled() const
80 Length Model::GetNumberOfLines() const
82 return mVisualModel->mLines.Count();
85 const LineRun* const Model::GetLines() const
87 return mVisualModel->mLines.Begin();
90 Length Model::GetNumberOfScripts() const
92 return mLogicalModel->mScriptRuns.Count();
95 const ScriptRun* const Model::GetScriptRuns() const
97 return mLogicalModel->mScriptRuns.Begin();
100 Length Model::GetNumberOfGlyphs() const
102 return mVisualModel->mGlyphs.Count();
105 GlyphIndex Model::GetStartIndexOfElidedGlyphs() const
107 return mVisualModel->GetStartIndexOfElidedGlyphs();
110 GlyphIndex Model::GetEndIndexOfElidedGlyphs() const
112 return mVisualModel->GetEndIndexOfElidedGlyphs();
115 GlyphIndex Model::GetFirstMiddleIndexOfElidedGlyphs() const
117 return mVisualModel->GetFirstMiddleIndexOfElidedGlyphs();
120 GlyphIndex Model::GetSecondMiddleIndexOfElidedGlyphs() const
122 return mVisualModel->GetSecondMiddleIndexOfElidedGlyphs();
125 const GlyphInfo* const Model::GetGlyphs() const
127 return mVisualModel->mGlyphs.Begin();
130 const Vector2* const Model::GetLayout() const
132 return mVisualModel->mGlyphPositions.Begin();
135 const Vector4* const Model::GetColors() const
137 return mVisualModel->mColors.Begin();
140 const ColorIndex* const Model::GetColorIndices() const
142 return mVisualModel->mColorIndices.Begin();
145 const Vector4* const Model::GetBackgroundColors() const
147 return mVisualModel->mBackgroundColors.Begin();
150 const ColorIndex* const Model::GetBackgroundColorIndices() const
152 return mVisualModel->mBackgroundColorIndices.Begin();
155 bool const Model::IsMarkupBackgroundColorSet() const
157 return (mVisualModel->mBackgroundColors.Count() > 0);
160 const Vector4& Model::GetDefaultColor() const
162 return mVisualModel->mTextColor;
165 const Vector2& Model::GetShadowOffset() const
167 return mVisualModel->mShadowOffset;
170 const Vector4& Model::GetShadowColor() const
172 return mVisualModel->mShadowColor;
175 const float& Model::GetShadowBlurRadius() const
177 return mVisualModel->mShadowBlurRadius;
180 const Vector4& Model::GetUnderlineColor() const
182 return mVisualModel->GetUnderlineColor();
185 bool Model::IsUnderlineEnabled() const
187 return mVisualModel->IsUnderlineEnabled();
190 float Model::GetUnderlineHeight() const
192 return mVisualModel->GetUnderlineHeight();
195 Length Model::GetNumberOfUnderlineRuns() const
197 return mVisualModel->GetNumberOfUnderlineRuns();
200 void Model::GetUnderlineRuns(GlyphRun* underlineRuns, UnderlineRunIndex index, Length numberOfRuns) const
202 mVisualModel->GetUnderlineRuns(underlineRuns, index, numberOfRuns);
205 const Vector4& Model::GetOutlineColor() const
207 return mVisualModel->GetOutlineColor();
210 uint16_t Model::GetOutlineWidth() const
212 return mVisualModel->GetOutlineWidth();
215 const Vector4& Model::GetBackgroundColor() const
217 return mVisualModel->GetBackgroundColor();
220 bool Model::IsBackgroundEnabled() const
222 return mVisualModel->IsBackgroundEnabled();
225 bool Model::IsMarkupProcessorEnabled() const
227 return mVisualModel->IsMarkupProcessorEnabled();
230 const GlyphInfo* Model::GetHyphens() const
232 return mVisualModel->mHyphen.glyph.Begin();
235 const Length* Model::GetHyphenIndices() const
237 return mVisualModel->mHyphen.index.Begin();
240 Length Model::GetHyphensCount() const
242 return mVisualModel->mHyphen.glyph.Size();
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)
260 mLogicalModel = LogicalModel::New();
261 mVisualModel = VisualModel::New();
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))
267 mMatchLayoutDirection = DevelText::MatchLayoutDirection::CONTENTS;
277 } // namespace Toolkit