2 * Copyright (c) 2022 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 bool const Model::IsMarkupUnderlineSet() const
192 return (mVisualModel->mUnderlineRuns.Count() > 0u);
195 float Model::GetUnderlineHeight() const
197 return mVisualModel->GetUnderlineHeight();
200 Text::Underline::Type Model::GetUnderlineType() const
202 return mVisualModel->GetUnderlineType();
205 float Model::GetDashedUnderlineWidth() const
207 return mVisualModel->GetDashedUnderlineWidth();
210 float Model::GetDashedUnderlineGap() const
212 return mVisualModel->GetDashedUnderlineGap();
215 Length Model::GetNumberOfUnderlineRuns() const
217 return mVisualModel->GetNumberOfUnderlineRuns();
220 void Model::GetUnderlineRuns(UnderlinedGlyphRun* underlineRuns, UnderlineRunIndex index, Length numberOfRuns) const
222 mVisualModel->GetUnderlineRuns(underlineRuns, index, numberOfRuns);
225 const Vector4& Model::GetOutlineColor() const
227 return mVisualModel->GetOutlineColor();
230 uint16_t Model::GetOutlineWidth() const
232 return mVisualModel->GetOutlineWidth();
235 const Vector4& Model::GetBackgroundColor() const
237 return mVisualModel->GetBackgroundColor();
240 bool Model::IsBackgroundEnabled() const
242 return mVisualModel->IsBackgroundEnabled();
245 bool Model::IsMarkupProcessorEnabled() const
247 return mVisualModel->IsMarkupProcessorEnabled();
250 const GlyphInfo* Model::GetHyphens() const
252 return mVisualModel->mHyphen.glyph.Begin();
255 const Length* Model::GetHyphenIndices() const
257 return mVisualModel->mHyphen.index.Begin();
260 Length Model::GetHyphensCount() const
262 return mVisualModel->mHyphen.glyph.Size();
264 const Vector4& Model::GetStrikethroughColor() const
266 return mVisualModel->GetStrikethroughColor();
269 bool Model::IsStrikethroughEnabled() const
271 return mVisualModel->IsStrikethroughEnabled();
274 bool const Model::IsMarkupStrikethroughSet() const
276 return (mVisualModel->mStrikethroughRuns.Count() > 0u);
279 float Model::GetStrikethroughHeight() const
281 return mVisualModel->GetStrikethroughHeight();
284 Length Model::GetNumberOfStrikethroughRuns() const
286 return mVisualModel->GetNumberOfStrikethroughRuns();
289 Length Model::GetNumberOfBoundedParagraphRuns() const
291 return mLogicalModel->GetNumberOfBoundedParagraphRuns();
294 const Vector<BoundedParagraphRun>& Model::GetBoundedParagraphRuns() const
296 return mLogicalModel->GetBoundedParagraphRuns();
299 void Model::GetStrikethroughRuns(StrikethroughGlyphRun* strikethroughRuns, StrikethroughRunIndex index, Length numberOfRuns) const
301 mVisualModel->GetStrikethroughRuns(strikethroughRuns, index, numberOfRuns);
304 Length Model::GetNumberOfCharacterSpacingGlyphRuns() const
306 return mVisualModel->GetNumberOfCharacterSpacingGlyphRuns();
309 const Vector<CharacterSpacingGlyphRun>& Model::GetCharacterSpacingGlyphRuns() const
311 return mVisualModel->GetCharacterSpacingGlyphRuns();
314 const float Model::GetCharacterSpacing() const
316 return mVisualModel->GetCharacterSpacing();
319 const Character* Model::GetTextBuffer() const
321 return mLogicalModel->mText.Begin();
324 const Vector<CharacterIndex>& Model::GetGlyphsToCharacters() const
326 return mVisualModel->mGlyphsToCharacters;
333 mScrollPositionLast(),
334 mHorizontalAlignment(Text::HorizontalAlignment::BEGIN),
335 mVerticalAlignment(Text::VerticalAlignment::TOP),
336 mVerticalLineAlignment(DevelText::VerticalLineAlignment::TOP),
337 mLineWrapMode(Text::LineWrap::WORD),
338 mAlignmentOffset(0.0f),
339 mElideEnabled(false),
340 mIgnoreSpacesAfterText(true),
341 mMatchLayoutDirection(DevelText::MatchLayoutDirection::INHERIT),
342 mEllipsisPosition(DevelText::EllipsisPosition::END)
344 mLogicalModel = LogicalModel::New();
345 mVisualModel = VisualModel::New();
347 // Check environment variable for DALI_MATCH_SYSTEM_LANGUAGE_DIRECTION
348 auto match = Dali::EnvironmentVariable::GetEnvironmentVariable(DALI_ENV_MATCH_SYSTEM_LANGUAGE_DIRECTION);
349 if(match && (std::atoi(match) == 0))
351 mMatchLayoutDirection = DevelText::MatchLayoutDirection::CONTENTS;
361 } // namespace Toolkit