2 * Copyright (c) 2016 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-model.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.
68 LogicalModelPtr logicalModel;
69 VisualModelPtr visualModel;
71 Size textArea(100.f, 60.f);
74 const Vector<FontDescriptionRun> fontDescriptions;
75 const LayoutOptions options;
76 CreateTextModel( data.text,
85 Vector<GlyphIndex>& charactersToGlyph = visualModel->mCharactersToGlyph;
86 Vector<Length>& glyphsPerCharacter = visualModel->mGlyphsPerCharacter;
88 // 2) Clear the model.
90 GlyphIndex startGlyphIndex = 0u;
91 if( 0u != charactersToGlyph.Count() )
93 // The number of glyphs to be removed.
94 const Length numberOfGlyphs = charactersToGlyph[data.startIndex + data.numberOfCharacters - 1u] + glyphsPerCharacter[data.startIndex + data.numberOfCharacters - 1u] - charactersToGlyph[data.startIndex];
95 startGlyphIndex = charactersToGlyph[data.startIndex];
97 charactersToGlyph.Erase( charactersToGlyph.Begin() + data.startIndex,
98 charactersToGlyph.Begin() + data.startIndex + data.numberOfCharacters );
99 glyphsPerCharacter.Erase( glyphsPerCharacter.Begin() + data.startIndex,
100 glyphsPerCharacter.Begin() + data.startIndex + data.numberOfCharacters );
102 // Update the character to glyph indices.
103 for( Vector<GlyphIndex>::Iterator it = charactersToGlyph.Begin() + data.startIndex,
104 endIt = charactersToGlyph.End();
108 *it -= numberOfGlyphs;
112 // 3) Call the CreateGlyphsPerCharacterTable() function
113 visualModel->CreateGlyphsPerCharacterTable( data.startIndex,
115 data.numberOfCharacters );
117 // 4) Compare the results.
118 if( data.totalNumberOfCharacters != glyphsPerCharacter.Count() )
120 std::cout << " Different number of characters : " << glyphsPerCharacter.Count() << ", expected : " << data.totalNumberOfCharacters << std::endl;
124 for( unsigned int i = 0u; i < data.totalNumberOfCharacters; ++i )
126 if( data.glyphsPerCharacter[i] != glyphsPerCharacter[i] )
128 std::cout << " Different number of glyphs for index " << i << std::endl;
129 for( unsigned int j = 0; j < data.totalNumberOfCharacters; ++j )
131 std::cout << glyphsPerCharacter[j] << " ";
133 std::cout << std::endl;
134 std::cout << " expected" << std::endl;
135 for( unsigned int j = 0; j < data.totalNumberOfCharacters; ++j )
137 std::cout << data.glyphsPerCharacter[j] << " ";
139 std::cout << std::endl;
147 bool SetCharacterToGlyphTest( const SetCharacterToGlyphData& data )
149 // 1) Create the model.
150 LogicalModelPtr logicalModel;
151 VisualModelPtr visualModel;
153 Size textArea(100.f, 60.f);
156 const Vector<FontDescriptionRun> fontDescriptions;
157 const LayoutOptions options;
158 CreateTextModel( data.text,
167 Vector<GlyphIndex>& charactersToGlyph = visualModel->mCharactersToGlyph;
168 Vector<Length>& glyphsPerCharacter = visualModel->mGlyphsPerCharacter;
170 // 2) Clear the model.
172 GlyphIndex startGlyphIndex = 0u;
173 if( 0u != charactersToGlyph.Count() )
175 // The number of glyphs to be removed.
176 const Length numberOfGlyphs = charactersToGlyph[data.startIndex + data.numberOfCharacters - 1u] + glyphsPerCharacter[data.startIndex + data.numberOfCharacters - 1u] - charactersToGlyph[data.startIndex];
177 startGlyphIndex = charactersToGlyph[data.startIndex];
179 charactersToGlyph.Erase( charactersToGlyph.Begin() + data.startIndex,
180 charactersToGlyph.Begin() + data.startIndex + data.numberOfCharacters );
182 // Update the character to glyph indices.
183 for( Vector<GlyphIndex>::Iterator it = charactersToGlyph.Begin() + data.startIndex,
184 endIt = charactersToGlyph.End();
188 *it -= numberOfGlyphs;
192 // 3) Call the CreateCharacterToGlyphTable() function
193 visualModel->CreateCharacterToGlyphTable( data.startIndex,
195 data.numberOfCharacters );
197 // 4) Compare the results.
198 if( data.totalNumberOfCharacters != charactersToGlyph.Count() )
200 std::cout << " Different number of character : " << charactersToGlyph.Count() << ", expected : " << data.totalNumberOfCharacters << std::endl;
204 for( unsigned int i = 0u; i < data.totalNumberOfCharacters; ++i )
206 if( data.glyphsIndices[i] != charactersToGlyph[i] )
208 std::cout << " Different number of character to glyph index " << i << std::endl;
209 for( unsigned int j = 0; j < data.totalNumberOfCharacters; ++j )
211 std::cout << charactersToGlyph[j] << " ";
213 std::cout << std::endl;
214 std::cout << " expected" << std::endl;
215 for( unsigned int j = 0; j < data.totalNumberOfCharacters; ++j )
217 std::cout << data.glyphsIndices[j] << " ";
219 std::cout << std::endl;
229 //////////////////////////////////////////////////////////
231 int UtcDaliSetGlyphsPerCharacter(void)
233 tet_infoline(" UtcDaliSetGlyphsPerCharacter");
235 Length glyphsPerCharacter02[] = { 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u };
236 Length glyphsPerCharacter03[] = { 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 0u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u };
237 Length glyphsPerCharacter04[] = { 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 0u, 1u,
238 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
239 1u, 1u, 1u, 1u, 0u, 1u, 0u, 2u, 1u, 0u,
240 2u, 0u, 2u, 0u, 2u, 1u, 1u, 0u, 0u, 0u,
241 2u, 1u, 1u, 1u, 1u, 1u, 0u, 0u, 2u, 1u,
244 struct SetGlyphsPerCharacterData data[] =
247 "Zero characters text",
255 "Simple 1 to 1 text",
260 glyphsPerCharacter02,
263 "Text with different number of glyphs and characters.",
264 "Hello different world",
268 glyphsPerCharacter03,
271 "Text paragraphs with different number of glyphs and characters. Update initial paragraphs.",
272 "Hello different world\nनमस्ते दुनिया\nမင်္ဂလာပါကမ္ဘာလောက",
276 glyphsPerCharacter04,
279 "Text paragraphs with different number of glyphs and characters. Update mid paragraphs.",
280 "Hello different world\nनमस्ते दुनिया\nမင်္ဂလာပါကမ္ဘာလောက",
284 glyphsPerCharacter04,
287 "Text paragraphs with different number of glyphs and characters. Update final paragraphs.",
288 "Hello different world\nनमस्ते दुनिया\nမင်္ဂလာပါကမ္ဘာလောက",
292 glyphsPerCharacter04,
295 const unsigned int numberOfTests = 6u;
297 for( unsigned int index = 0u; index < numberOfTests; ++index )
299 ToolkitTestApplication application;
300 if( !SetGlyphsPerCharacterTest( data[index] ) )
302 tet_result(TET_FAIL);
306 tet_result(TET_PASS);
310 int UtcDaliSetCharacterToGlyph(void)
312 tet_infoline(" UtcDaliSetGlyphsPerCharacter");
314 GlyphIndex glyphIndices02[] = { 0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u, 9u, 10u };
315 GlyphIndex glyphIndices03[] = { 0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u, 8u, 9u, 10u, 11u, 12u, 13u, 14u, 15u, 16u, 17u, 18u, 19u };
316 GlyphIndex glyphIndices04[] = { 0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u, 8u, 9u, 10u, 11u, 12u, 13u, 14u, 15u, 16u, 17u, 18u, 19u, 20u,
317 21u, 22u, 23u, 23u, 24u, 24u, 26u, 27u, 27u, 29u, 29u, 31u, 31u, 33u,
318 34u, 35u, 35u, 35u, 35u, 37u, 38u, 39u, 40u, 41u, 42u, 42u, 42u, 44u, 45u, 45u, 47u, 48u };
320 struct SetCharacterToGlyphData data[] =
323 "Zero characters text",
331 "Simple 1 to 1 text",
339 "Text with different number of glyphs and characters.",
340 "Hello different world",
347 "Text paragraphs with different number of glyphs and characters. Update initial paragraphs.",
348 "Hello different world\nनमस्ते दुनिया\nမင်္ဂလာပါကမ္ဘာလောက",
355 "Text paragraphs with different number of glyphs and characters. Update mid paragraphs.",
356 "Hello different world\nनमस्ते दुनिया\nမင်္ဂလာပါကမ္ဘာလောက",
363 "Text paragraphs with different number of glyphs and characters. Update final paragraphs.",
364 "Hello different world\nनमस्ते दुनिया\nမင်္ဂလာပါကမ္ဘာလောက",
372 const unsigned int numberOfTests = 6u;
374 for( unsigned int index = 0u; index < numberOfTests; ++index )
376 ToolkitTestApplication application;
377 if( !SetCharacterToGlyphTest( data[index] ) )
379 tet_result(TET_FAIL);
383 tet_result(TET_PASS);