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 );
98 Vector<LineRun>& lines = textModel->mVisualModel->mLines;
100 // 4) Compare the results.
102 if( lines.Count() != data.numberOfLines )
104 std::cout << " Different number of lines : " << lines.Count() << ", expected : " << data.numberOfLines << std::endl;
108 for( unsigned int index = 0u; index < data.numberOfLines; ++index )
110 const LineRun& line = *( lines.Begin() + index );
111 const LineRun& expectedLine = *( data.lines + index );
113 if( line.characterRun.characterIndex != expectedLine.characterRun.characterIndex )
115 std::cout << " Different line info for line : " << index << std::endl;
117 std::cout << " expected" << std::endl;
118 Print( expectedLine );
121 if( line.characterRun.numberOfCharacters != expectedLine.characterRun.numberOfCharacters )
123 std::cout << " Different line info for line : " << index << std::endl;
125 std::cout << " expected" << std::endl;
126 Print( expectedLine );
137 int UtcDaliTextHyphenWrapping(void)
139 ToolkitTestApplication application;
140 tet_infoline(" UtcDaliTextHyphenWrapping");
142 // Layout some lines of left to right text.
144 const std::string fontFamily( "TizenSans" );
146 // Set a known font description
147 FontDescriptionRun fontDescriptionRun1;
148 fontDescriptionRun1.characterRun.characterIndex = 0u;
149 fontDescriptionRun1.characterRun.numberOfCharacters = 13u;
150 fontDescriptionRun1.familyLength = fontFamily.size();
151 fontDescriptionRun1.familyName = new char[fontDescriptionRun1.familyLength];
152 memcpy( fontDescriptionRun1.familyName, fontFamily.c_str(), fontDescriptionRun1.familyLength );
153 fontDescriptionRun1.familyDefined = true;
154 fontDescriptionRun1.weightDefined = false;
155 fontDescriptionRun1.widthDefined = false;
156 fontDescriptionRun1.slantDefined = false;
157 fontDescriptionRun1.sizeDefined = false;
159 Vector<FontDescriptionRun> fontDescriptionRuns;
160 fontDescriptionRuns.PushBack( fontDescriptionRun1 );
161 Size textArea(65.0f, 200.f);
190 Vector<LineRun> lines;
191 lines.PushBack( line1 );
192 lines.PushBack( line2 );
194 LayoutTextData data =
199 fontDescriptionRuns.Begin(),
202 Layout::Engine::MULTI_LINE_BOX,
205 (Text::LineWrap::Mode)DevelText::LineWrap::HYPHENATION
208 if( !LayoutTextTest( data ) )
210 tet_result(TET_FAIL);
213 tet_result(TET_PASS);
217 int UtcDaliTextMixedWrapping(void)
219 ToolkitTestApplication application;
220 tet_infoline(" UtcDaliTextMixedWrapping");
222 // Layout some lines of left to right text.
224 const std::string fontFamily( "DejaVuSans" );
226 // Set a known font description
227 FontDescriptionRun fontDescriptionRun1;
228 fontDescriptionRun1.characterRun.characterIndex = 0u;
229 fontDescriptionRun1.characterRun.numberOfCharacters = 13u;
230 fontDescriptionRun1.familyLength = fontFamily.size();
231 fontDescriptionRun1.familyName = new char[fontDescriptionRun1.familyLength];
232 memcpy( fontDescriptionRun1.familyName, fontFamily.c_str(), fontDescriptionRun1.familyLength );
233 fontDescriptionRun1.familyDefined = true;
234 fontDescriptionRun1.weightDefined = false;
235 fontDescriptionRun1.widthDefined = false;
236 fontDescriptionRun1.slantDefined = false;
237 fontDescriptionRun1.sizeDefined = false;
239 Vector<FontDescriptionRun> fontDescriptionRuns;
240 fontDescriptionRuns.PushBack( fontDescriptionRun1 );
241 Size textArea(72.0f, 200.f);
283 Vector<LineRun> lines;
284 lines.PushBack( line1 );
285 lines.PushBack( line2 );
286 lines.PushBack( line3 );
288 LayoutTextData data =
293 fontDescriptionRuns.Begin(),
296 Layout::Engine::MULTI_LINE_BOX,
299 (Text::LineWrap::Mode)DevelText::LineWrap::MIXED
302 if( !LayoutTextTest( data ) )
304 tet_result(TET_FAIL);
307 tet_result(TET_PASS);