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 Vector<LineRun>& lines = textModel->mVisualModel->mLines;
98 // 4) Compare the results.
100 if( lines.Count() != data.numberOfLines )
102 std::cout << " Different number of lines : " << lines.Count() << ", expected : " << data.numberOfLines << std::endl;
106 for( unsigned int index = 0u; index < data.numberOfLines; ++index )
108 const LineRun& line = *( lines.Begin() + index );
109 const LineRun& expectedLine = *( data.lines + index );
111 if( line.characterRun.characterIndex != expectedLine.characterRun.characterIndex )
113 std::cout << " Different line info for line : " << index << std::endl;
115 std::cout << " expected" << std::endl;
116 Print( expectedLine );
119 if( line.characterRun.numberOfCharacters != expectedLine.characterRun.numberOfCharacters )
121 std::cout << " Different line info for line : " << index << std::endl;
123 std::cout << " expected" << std::endl;
124 Print( expectedLine );
135 int UtcDaliTextHyphenWrapping(void)
137 ToolkitTestApplication application;
138 tet_infoline(" UtcDaliTextHyphenWrapping");
140 // Layout some lines of left to right text.
142 const std::string fontFamily( "TizenSans" );
144 // Set a known font description
145 FontDescriptionRun fontDescriptionRun1;
146 fontDescriptionRun1.characterRun.characterIndex = 0u;
147 fontDescriptionRun1.characterRun.numberOfCharacters = 13u;
148 fontDescriptionRun1.familyLength = fontFamily.size();
149 fontDescriptionRun1.familyName = new char[fontDescriptionRun1.familyLength];
150 memcpy( fontDescriptionRun1.familyName, fontFamily.c_str(), fontDescriptionRun1.familyLength );
151 fontDescriptionRun1.familyDefined = true;
152 fontDescriptionRun1.weightDefined = false;
153 fontDescriptionRun1.widthDefined = false;
154 fontDescriptionRun1.slantDefined = false;
155 fontDescriptionRun1.sizeDefined = false;
157 Vector<FontDescriptionRun> fontDescriptionRuns;
158 fontDescriptionRuns.PushBack( fontDescriptionRun1 );
159 Size textArea(65.0f, 200.f);
188 Vector<LineRun> lines;
189 lines.PushBack( line1 );
190 lines.PushBack( line2 );
192 LayoutTextData data =
197 fontDescriptionRuns.Begin(),
200 Layout::Engine::MULTI_LINE_BOX,
203 (Text::LineWrap::Mode)DevelText::LineWrap::HYPHENATION
206 if( !LayoutTextTest( data ) )
208 tet_result(TET_FAIL);
211 tet_result(TET_PASS);
215 int UtcDaliTextMixedWrapping(void)
217 ToolkitTestApplication application;
218 tet_infoline(" UtcDaliTextMixedWrapping");
220 // Layout some lines of left to right text.
222 const std::string fontFamily( "DejaVuSans" );
224 // Set a known font description
225 FontDescriptionRun fontDescriptionRun1;
226 fontDescriptionRun1.characterRun.characterIndex = 0u;
227 fontDescriptionRun1.characterRun.numberOfCharacters = 13u;
228 fontDescriptionRun1.familyLength = fontFamily.size();
229 fontDescriptionRun1.familyName = new char[fontDescriptionRun1.familyLength];
230 memcpy( fontDescriptionRun1.familyName, fontFamily.c_str(), fontDescriptionRun1.familyLength );
231 fontDescriptionRun1.familyDefined = true;
232 fontDescriptionRun1.weightDefined = false;
233 fontDescriptionRun1.widthDefined = false;
234 fontDescriptionRun1.slantDefined = false;
235 fontDescriptionRun1.sizeDefined = false;
237 Vector<FontDescriptionRun> fontDescriptionRuns;
238 fontDescriptionRuns.PushBack( fontDescriptionRun1 );
239 Size textArea(72.0f, 200.f);
281 Vector<LineRun> lines;
282 lines.PushBack( line1 );
283 lines.PushBack( line2 );
284 lines.PushBack( line3 );
286 LayoutTextData data =
291 fontDescriptionRuns.Begin(),
294 Layout::Engine::MULTI_LINE_BOX,
297 (Text::LineWrap::Mode)DevelText::LineWrap::MIXED
300 if( !LayoutTextTest( data ) )
302 tet_result(TET_FAIL);
305 tet_result(TET_PASS);