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-test-suite-utils.h>
23 #include <dali-toolkit/dali-toolkit.h>
24 #include <toolkit-text-utils.h>
28 using namespace Toolkit;
31 // Tests the following functions.
33 // void CreateCharacterToGlyphTable( CharacterIndex startIndex,
34 // Length numberOfCharacters )
36 // void CreateGlyphsPerCharacterTable( CharacterIndex startIndex,
37 // Length numberOfCharacters )
40 //////////////////////////////////////////////////////////
45 struct SetGlyphsPerCharacterData
47 std::string description; ///< Description of the test.
48 std::string text; ///< Input text.
49 unsigned int startIndex; ///< The start index from where the glyphs per character table is set.
50 unsigned int numberOfCharacters; ///< The number of characters to set.
51 unsigned int totalNumberOfCharacters; ///< The total number of characters.
52 unsigned int* glyphsPerCharacter; ///< The number of glyphs per character.
55 struct SetCharacterToGlyphData
57 std::string description; ///< Description of the test.
58 std::string text; ///< Input text.
59 unsigned int startIndex; ///< The start index from where the character to glyph table is set.
60 unsigned int numberOfCharacters; ///< The number of characters to set.
61 unsigned int totalNumberOfCharacters; ///< The total number of characters.
62 unsigned int* glyphsIndices; ///< The glyph indices.
65 bool SetGlyphsPerCharacterTest( const SetGlyphsPerCharacterData& data )
67 // 1) Create the model.
70 Size textArea(100.f, 60.f);
73 const Vector<FontDescriptionRun> fontDescriptions;
74 const LayoutOptions options;
75 CreateTextModel( data.text,
85 Toolkit::DevelText::EllipsisPosition::END,
88 LogicalModelPtr logicalModel = textModel->mLogicalModel;
89 VisualModelPtr visualModel = textModel->mVisualModel;
91 Vector<GlyphIndex>& charactersToGlyph = visualModel->mCharactersToGlyph;
92 Vector<Length>& glyphsPerCharacter = visualModel->mGlyphsPerCharacter;
94 // 2) Clear the model.
96 GlyphIndex startGlyphIndex = 0u;
97 if( 0u != charactersToGlyph.Count() )
99 // The number of glyphs to be removed.
100 const Length numberOfGlyphs = charactersToGlyph[data.startIndex + data.numberOfCharacters - 1u] + glyphsPerCharacter[data.startIndex + data.numberOfCharacters - 1u] - charactersToGlyph[data.startIndex];
101 startGlyphIndex = charactersToGlyph[data.startIndex];
103 charactersToGlyph.Erase( charactersToGlyph.Begin() + data.startIndex,
104 charactersToGlyph.Begin() + data.startIndex + data.numberOfCharacters );
105 glyphsPerCharacter.Erase( glyphsPerCharacter.Begin() + data.startIndex,
106 glyphsPerCharacter.Begin() + data.startIndex + data.numberOfCharacters );
108 // Update the character to glyph indices.
109 for( Vector<GlyphIndex>::Iterator it = charactersToGlyph.Begin() + data.startIndex,
110 endIt = charactersToGlyph.End();
114 *it -= numberOfGlyphs;
118 // 3) Call the CreateGlyphsPerCharacterTable() function
119 visualModel->CreateGlyphsPerCharacterTable( data.startIndex,
121 data.numberOfCharacters );
123 // 4) Compare the results.
124 if( data.totalNumberOfCharacters != glyphsPerCharacter.Count() )
126 std::cout << " Different number of characters : " << glyphsPerCharacter.Count() << ", expected : " << data.totalNumberOfCharacters << std::endl;
130 for( unsigned int i = 0u; i < data.totalNumberOfCharacters; ++i )
132 if( data.glyphsPerCharacter[i] != glyphsPerCharacter[i] )
134 std::cout << " Different number of glyphs for index " << i << std::endl;
135 for( unsigned int j = 0; j < data.totalNumberOfCharacters; ++j )
137 std::cout << glyphsPerCharacter[j] << " ";
139 std::cout << std::endl;
140 std::cout << " expected" << std::endl;
141 for( unsigned int j = 0; j < data.totalNumberOfCharacters; ++j )
143 std::cout << data.glyphsPerCharacter[j] << " ";
145 std::cout << std::endl;
153 bool SetCharacterToGlyphTest( const SetCharacterToGlyphData& data )
155 // 1) Create the model.
158 Size textArea(100.f, 60.f);
161 const Vector<FontDescriptionRun> fontDescriptions;
162 const LayoutOptions options;
163 CreateTextModel( data.text,
173 Toolkit::DevelText::EllipsisPosition::END,
176 LogicalModelPtr logicalModel = textModel->mLogicalModel;
177 VisualModelPtr visualModel = textModel->mVisualModel;
179 Vector<GlyphIndex>& charactersToGlyph = visualModel->mCharactersToGlyph;
180 Vector<Length>& glyphsPerCharacter = visualModel->mGlyphsPerCharacter;
182 // 2) Clear the model.
184 GlyphIndex startGlyphIndex = 0u;
185 if( 0u != charactersToGlyph.Count() )
187 // The number of glyphs to be removed.
188 const Length numberOfGlyphs = charactersToGlyph[data.startIndex + data.numberOfCharacters - 1u] + glyphsPerCharacter[data.startIndex + data.numberOfCharacters - 1u] - charactersToGlyph[data.startIndex];
189 startGlyphIndex = charactersToGlyph[data.startIndex];
191 charactersToGlyph.Erase( charactersToGlyph.Begin() + data.startIndex,
192 charactersToGlyph.Begin() + data.startIndex + data.numberOfCharacters );
194 // Update the character to glyph indices.
195 for( Vector<GlyphIndex>::Iterator it = charactersToGlyph.Begin() + data.startIndex,
196 endIt = charactersToGlyph.End();
200 *it -= numberOfGlyphs;
204 // 3) Call the CreateCharacterToGlyphTable() function
205 visualModel->CreateCharacterToGlyphTable( data.startIndex,
207 data.numberOfCharacters );
209 // 4) Compare the results.
210 if( data.totalNumberOfCharacters != charactersToGlyph.Count() )
212 std::cout << " Different number of character : " << charactersToGlyph.Count() << ", expected : " << data.totalNumberOfCharacters << std::endl;
216 for( unsigned int i = 0u; i < data.totalNumberOfCharacters; ++i )
218 if( data.glyphsIndices[i] != charactersToGlyph[i] )
220 std::cout << " Different number of character to glyph index " << i << std::endl;
221 for( unsigned int j = 0; j < data.totalNumberOfCharacters; ++j )
223 std::cout << charactersToGlyph[j] << " ";
225 std::cout << std::endl;
226 std::cout << " expected" << std::endl;
227 for( unsigned int j = 0; j < data.totalNumberOfCharacters; ++j )
229 std::cout << data.glyphsIndices[j] << " ";
231 std::cout << std::endl;
241 //////////////////////////////////////////////////////////
243 int UtcDaliSetGlyphsPerCharacter(void)
245 tet_infoline(" UtcDaliSetGlyphsPerCharacter");
247 Length glyphsPerCharacter02[] = { 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u };
248 Length glyphsPerCharacter03[] = { 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 0u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u };
249 Length glyphsPerCharacter04[] = { 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 0u, 1u,
250 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
251 1u, 1u, 1u, 1u, 0u, 1u, 0u, 2u, 1u, 0u,
252 2u, 0u, 2u, 0u, 2u, 1u, 1u, 0u, 0u, 0u,
253 2u, 1u, 1u, 1u, 1u, 1u, 0u, 0u, 2u, 1u,
256 struct SetGlyphsPerCharacterData data[] =
259 "Zero characters text",
267 "Simple 1 to 1 text",
272 glyphsPerCharacter02,
275 "Text with different number of glyphs and characters.",
276 "Hello different world",
280 glyphsPerCharacter03,
283 "Text paragraphs with different number of glyphs and characters. Update initial paragraphs.",
284 "Hello different world\nनमस्ते दुनिया\nမင်္ဂလာပါကမ္ဘာလောက",
288 glyphsPerCharacter04,
291 "Text paragraphs with different number of glyphs and characters. Update mid paragraphs.",
292 "Hello different world\nनमस्ते दुनिया\nမင်္ဂလာပါကမ္ဘာလောက",
296 glyphsPerCharacter04,
299 "Text paragraphs with different number of glyphs and characters. Update final paragraphs.",
300 "Hello different world\nनमस्ते दुनिया\nမင်္ဂလာပါကမ္ဘာလောက",
304 glyphsPerCharacter04,
307 const unsigned int numberOfTests = 6u;
309 for( unsigned int index = 0u; index < numberOfTests; ++index )
311 ToolkitTestApplication application;
312 if( !SetGlyphsPerCharacterTest( data[index] ) )
314 tet_result(TET_FAIL);
318 tet_result(TET_PASS);
322 int UtcDaliSetCharacterToGlyph(void)
324 tet_infoline(" UtcDaliSetGlyphsPerCharacter");
326 GlyphIndex glyphIndices02[] = { 0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u, 9u, 10u };
327 GlyphIndex glyphIndices03[] = { 0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u, 8u, 9u, 10u, 11u, 12u, 13u, 14u, 15u, 16u, 17u, 18u, 19u };
328 GlyphIndex glyphIndices04[] = { 0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u, 8u, 9u, 10u, 11u, 12u, 13u, 14u, 15u, 16u, 17u, 18u, 19u, 20u,
329 21u, 22u, 23u, 23u, 24u, 24u, 26u, 27u, 27u, 29u, 29u, 31u, 31u, 33u,
330 34u, 35u, 35u, 35u, 35u, 37u, 38u, 39u, 40u, 41u, 42u, 42u, 42u, 44u, 45u, 45u, 47u, 48u };
332 struct SetCharacterToGlyphData data[] =
335 "Zero characters text",
343 "Simple 1 to 1 text",
351 "Text with different number of glyphs and characters.",
352 "Hello different world",
359 "Text paragraphs with different number of glyphs and characters. Update initial paragraphs.",
360 "Hello different world\nनमस्ते दुनिया\nမင်္ဂလာပါကမ္ဘာလောက",
367 "Text paragraphs with different number of glyphs and characters. Update mid paragraphs.",
368 "Hello different world\nनमस्ते दुनिया\nမင်္ဂလာပါကမ္ဘာလောက",
375 "Text paragraphs with different number of glyphs and characters. Update final paragraphs.",
376 "Hello different world\nनमस्ते दुनिया\nမင်္ဂလာပါကမ္ဘာလောက",
384 const unsigned int numberOfTests = 6u;
386 for( unsigned int index = 0u; index < numberOfTests; ++index )
388 ToolkitTestApplication application;
389 if( !SetCharacterToGlyphTest( data[index] ) )
391 tet_result(TET_FAIL);
395 tet_result(TET_PASS);