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.
22 #include <dali-toolkit/internal/text/layouts/layout-engine.h>
23 #include <dali-toolkit/internal/text/layouts/layout-parameters.h>
24 #include <dali-toolkit/internal/text/text-run-container.h>
25 #include <dali-toolkit-test-suite-utils.h>
26 #include <dali-toolkit/dali-toolkit.h>
27 #include <toolkit-text-utils.h>
30 using namespace Toolkit;
37 const std::string DEFAULT_FONT_DIR( "/resources/fonts" );
43 unsigned int numberOfFonts;
44 FontDescriptionRun *fontDescriptions;
45 unsigned int numberOfLines;
47 Layout::Engine::Type layout;
48 unsigned int startIndex;
49 unsigned int numberOfGlyphs;
50 Text::LineWrap::Mode wrapMode;
53 void Print( const LineRun& line )
55 std::cout << " glyph run, index : " << line.glyphRun.glyphIndex << ", num glyphs : " << line.glyphRun.numberOfGlyphs << std::endl;
56 std::cout << " character run, index : " << line.characterRun.characterIndex << ", num chars : " << line.characterRun.numberOfCharacters << std::endl;
59 bool LayoutTextTest( const LayoutTextData& data )
62 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
63 fontClient.SetDpi( 96u, 96u );
65 char* pathNamePtr = get_current_dir_name();
66 const std::string pathName( pathNamePtr );
69 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansRegular.ttf" );
71 // 1) Create the model.
76 Vector<FontDescriptionRun> fontDescriptionRuns;
77 if( 0u != data.numberOfFonts )
79 fontDescriptionRuns.Insert( fontDescriptionRuns.End(),
80 data.fontDescriptions,
81 data.fontDescriptions + data.numberOfFonts );
84 LayoutOptions options;
85 options.align = false;
86 CreateTextModel( data.text,
96 Toolkit::DevelText::EllipsisPosition::END,
99 Vector<LineRun>& lines = textModel->mVisualModel->mLines;
101 // 4) Compare the results.
103 if( lines.Count() != data.numberOfLines )
105 std::cout << " Different number of lines : " << lines.Count() << ", expected : " << data.numberOfLines << std::endl;
109 for( unsigned int index = 0u; index < data.numberOfLines; ++index )
111 const LineRun& line = *( lines.Begin() + index );
112 const LineRun& expectedLine = *( data.lines + index );
114 if( line.characterRun.characterIndex != expectedLine.characterRun.characterIndex )
116 std::cout << " Different line info for line : " << index << std::endl;
118 std::cout << " expected" << std::endl;
119 Print( expectedLine );
122 if( line.characterRun.numberOfCharacters != expectedLine.characterRun.numberOfCharacters )
124 std::cout << " Different line info for line : " << index << std::endl;
126 std::cout << " expected" << std::endl;
127 Print( expectedLine );
138 int UtcDaliTextHyphenWrapping(void)
140 ToolkitTestApplication application;
141 tet_infoline(" UtcDaliTextHyphenWrapping");
143 // Layout some lines of left to right text.
145 const std::string fontFamily( "TizenSans" );
147 // Set a known font description
148 FontDescriptionRun fontDescriptionRun1;
149 fontDescriptionRun1.characterRun.characterIndex = 0u;
150 fontDescriptionRun1.characterRun.numberOfCharacters = 13u;
151 fontDescriptionRun1.familyLength = fontFamily.size();
152 fontDescriptionRun1.familyName = new char[fontDescriptionRun1.familyLength];
153 memcpy( fontDescriptionRun1.familyName, fontFamily.c_str(), fontDescriptionRun1.familyLength );
154 fontDescriptionRun1.familyDefined = true;
155 fontDescriptionRun1.weightDefined = false;
156 fontDescriptionRun1.widthDefined = false;
157 fontDescriptionRun1.slantDefined = false;
158 fontDescriptionRun1.sizeDefined = false;
160 Vector<FontDescriptionRun> fontDescriptionRuns;
161 fontDescriptionRuns.PushBack( fontDescriptionRun1 );
162 Size textArea(65.0f, 200.f);
191 Vector<LineRun> lines;
192 lines.PushBack( line1 );
193 lines.PushBack( line2 );
195 LayoutTextData data =
200 fontDescriptionRuns.Begin(),
203 Layout::Engine::MULTI_LINE_BOX,
206 (Text::LineWrap::Mode)DevelText::LineWrap::HYPHENATION
209 if( !LayoutTextTest( data ) )
211 tet_result(TET_FAIL);
214 tet_result(TET_PASS);
218 int UtcDaliTextMixedWrapping(void)
220 ToolkitTestApplication application;
221 tet_infoline(" UtcDaliTextMixedWrapping");
223 // Layout some lines of left to right text.
225 const std::string fontFamily( "DejaVuSans" );
227 // Set a known font description
228 FontDescriptionRun fontDescriptionRun1;
229 fontDescriptionRun1.characterRun.characterIndex = 0u;
230 fontDescriptionRun1.characterRun.numberOfCharacters = 13u;
231 fontDescriptionRun1.familyLength = fontFamily.size();
232 fontDescriptionRun1.familyName = new char[fontDescriptionRun1.familyLength];
233 memcpy( fontDescriptionRun1.familyName, fontFamily.c_str(), fontDescriptionRun1.familyLength );
234 fontDescriptionRun1.familyDefined = true;
235 fontDescriptionRun1.weightDefined = false;
236 fontDescriptionRun1.widthDefined = false;
237 fontDescriptionRun1.slantDefined = false;
238 fontDescriptionRun1.sizeDefined = false;
240 Vector<FontDescriptionRun> fontDescriptionRuns;
241 fontDescriptionRuns.PushBack( fontDescriptionRun1 );
242 Size textArea(72.0f, 200.f);
284 Vector<LineRun> lines;
285 lines.PushBack( line1 );
286 lines.PushBack( line2 );
287 lines.PushBack( line3 );
289 LayoutTextData data =
294 fontDescriptionRuns.Begin(),
297 Layout::Engine::MULTI_LINE_BOX,
300 (Text::LineWrap::Mode)DevelText::LineWrap::MIXED
303 if( !LayoutTextTest( data ) )
305 tet_result(TET_FAIL);
308 tet_result(TET_PASS);