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 = LogicalModel::New();
69 VisualModelPtr visualModel = VisualModel::New();
70 Size textArea(100.f, 60.f);
73 const Vector<FontDescriptionRun> fontDescriptions;
74 const LayoutOptions options;
75 CreateTextModel( data.text,
83 // 2) Clear the model.
84 Vector<GlyphIndex>& charactersToGlyph = visualModel->mCharactersToGlyph;
85 Vector<Length>& glyphsPerCharacter = visualModel->mGlyphsPerCharacter;
87 GlyphIndex startGlyphIndex = 0u;
88 if( 0u != charactersToGlyph.Count() )
90 // The number of glyphs to be removed.
91 const Length numberOfGlyphs = charactersToGlyph[data.startIndex + data.numberOfCharacters - 1u] + glyphsPerCharacter[data.startIndex + data.numberOfCharacters - 1u] - charactersToGlyph[data.startIndex];
92 startGlyphIndex = charactersToGlyph[data.startIndex];
94 charactersToGlyph.Erase( charactersToGlyph.Begin() + data.startIndex,
95 charactersToGlyph.Begin() + data.startIndex + data.numberOfCharacters );
96 glyphsPerCharacter.Erase( glyphsPerCharacter.Begin() + data.startIndex,
97 glyphsPerCharacter.Begin() + data.startIndex + data.numberOfCharacters );
99 // Update the character to glyph indices.
100 for( Vector<GlyphIndex>::Iterator it = charactersToGlyph.Begin() + data.startIndex,
101 endIt = charactersToGlyph.End();
105 *it -= numberOfGlyphs;
109 // 3) Call the CreateGlyphsPerCharacterTable() function
110 visualModel->CreateGlyphsPerCharacterTable( data.startIndex,
112 data.numberOfCharacters );
114 // 4) Compare the results.
115 if( data.totalNumberOfCharacters != glyphsPerCharacter.Count() )
117 std::cout << " Different number of characters : " << glyphsPerCharacter.Count() << ", expected : " << data.totalNumberOfCharacters << std::endl;
121 for( unsigned int i = 0u; i < data.totalNumberOfCharacters; ++i )
123 if( data.glyphsPerCharacter[i] != glyphsPerCharacter[i] )
125 std::cout << " Different number of glyphs for index " << i << std::endl;
126 for( unsigned int j = 0; j < data.totalNumberOfCharacters; ++j )
128 std::cout << glyphsPerCharacter[j] << " ";
130 std::cout << std::endl;
131 std::cout << " expected" << std::endl;
132 for( unsigned int j = 0; j < data.totalNumberOfCharacters; ++j )
134 std::cout << data.glyphsPerCharacter[j] << " ";
136 std::cout << std::endl;
144 bool SetCharacterToGlyphTest( const SetCharacterToGlyphData& data )
146 // 1) Create the model.
147 LogicalModelPtr logicalModel = LogicalModel::New();
148 VisualModelPtr visualModel = VisualModel::New();
149 Size textArea(100.f, 60.f);
152 const Vector<FontDescriptionRun> fontDescriptions;
153 const LayoutOptions options;
154 CreateTextModel( data.text,
162 // 2) Clear the model.
163 Vector<GlyphIndex>& charactersToGlyph = visualModel->mCharactersToGlyph;
164 Vector<Length>& glyphsPerCharacter = visualModel->mGlyphsPerCharacter;
166 GlyphIndex startGlyphIndex = 0u;
167 if( 0u != charactersToGlyph.Count() )
169 // The number of glyphs to be removed.
170 const Length numberOfGlyphs = charactersToGlyph[data.startIndex + data.numberOfCharacters - 1u] + glyphsPerCharacter[data.startIndex + data.numberOfCharacters - 1u] - charactersToGlyph[data.startIndex];
171 startGlyphIndex = charactersToGlyph[data.startIndex];
173 charactersToGlyph.Erase( charactersToGlyph.Begin() + data.startIndex,
174 charactersToGlyph.Begin() + data.startIndex + data.numberOfCharacters );
176 // Update the character to glyph indices.
177 for( Vector<GlyphIndex>::Iterator it = charactersToGlyph.Begin() + data.startIndex,
178 endIt = charactersToGlyph.End();
182 *it -= numberOfGlyphs;
186 // 3) Call the CreateCharacterToGlyphTable() function
187 visualModel->CreateCharacterToGlyphTable( data.startIndex,
189 data.numberOfCharacters );
191 // 4) Compare the results.
192 if( data.totalNumberOfCharacters != charactersToGlyph.Count() )
194 std::cout << " Different number of character : " << charactersToGlyph.Count() << ", expected : " << data.totalNumberOfCharacters << std::endl;
198 for( unsigned int i = 0u; i < data.totalNumberOfCharacters; ++i )
200 if( data.glyphsIndices[i] != charactersToGlyph[i] )
202 std::cout << " Different number of character to glyph index " << i << std::endl;
203 for( unsigned int j = 0; j < data.totalNumberOfCharacters; ++j )
205 std::cout << charactersToGlyph[j] << " ";
207 std::cout << std::endl;
208 std::cout << " expected" << std::endl;
209 for( unsigned int j = 0; j < data.totalNumberOfCharacters; ++j )
211 std::cout << data.glyphsIndices[j] << " ";
213 std::cout << std::endl;
223 //////////////////////////////////////////////////////////
225 int UtcDaliSetGlyphsPerCharacter(void)
227 ToolkitTestApplication application;
228 tet_infoline(" UtcDaliSetGlyphsPerCharacter");
230 Length glyphsPerCharacter02[] = { 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u };
231 Length glyphsPerCharacter03[] = { 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 0u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u };
232 Length glyphsPerCharacter04[] = { 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 0u, 1u,
233 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
234 1u, 1u, 1u, 1u, 0u, 1u, 0u, 2u, 1u, 0u,
235 2u, 0u, 2u, 0u, 2u, 1u, 1u, 0u, 0u, 0u,
236 2u, 1u, 1u, 1u, 1u, 1u, 0u, 0u, 2u, 1u,
239 struct SetGlyphsPerCharacterData data[] =
242 "Zero characters text",
250 "Simple 1 to 1 text",
255 glyphsPerCharacter02,
258 "Text with different number of glyphs and characters.",
259 "Hello different world",
263 glyphsPerCharacter03,
266 "Text paragraphs with different number of glyphs and characters. Update initial paragraphs.",
267 "Hello different world\nनमस्ते दुनिया\nမင်္ဂလာပါကမ္ဘာလောက",
271 glyphsPerCharacter04,
274 "Text paragraphs with different number of glyphs and characters. Update mid paragraphs.",
275 "Hello different world\nनमस्ते दुनिया\nမင်္ဂလာပါကမ္ဘာလောက",
279 glyphsPerCharacter04,
282 "Text paragraphs with different number of glyphs and characters. Update final paragraphs.",
283 "Hello different world\nनमस्ते दुनिया\nမင်္ဂလာပါကမ္ဘာလောက",
287 glyphsPerCharacter04,
290 const unsigned int numberOfTests = 6u;
292 for( unsigned int index = 0u; index < numberOfTests; ++index )
294 if( !SetGlyphsPerCharacterTest( data[index] ) )
296 tet_result(TET_FAIL);
300 tet_result(TET_PASS);
304 int UtcDaliSetCharacterToGlyph(void)
306 ToolkitTestApplication application;
307 tet_infoline(" UtcDaliSetGlyphsPerCharacter");
309 GlyphIndex glyphIndices02[] = { 0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u, 9u, 10u };
310 GlyphIndex glyphIndices03[] = { 0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u, 8u, 9u, 10u, 11u, 12u, 13u, 14u, 15u, 16u, 17u, 18u, 19u };
311 GlyphIndex glyphIndices04[] = { 0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u, 8u, 9u, 10u, 11u, 12u, 13u, 14u, 15u, 16u, 17u, 18u, 19u, 20u,
312 21u, 22u, 23u, 23u, 24u, 24u, 26u, 27u, 27u, 29u, 29u, 31u, 31u, 33u,
313 34u, 35u, 35u, 35u, 35u, 37u, 38u, 39u, 40u, 41u, 42u, 42u, 42u, 44u, 45u, 45u, 47u, 48u };
315 struct SetCharacterToGlyphData data[] =
318 "Zero characters text",
326 "Simple 1 to 1 text",
334 "Text with different number of glyphs and characters.",
335 "Hello different world",
342 "Text paragraphs with different number of glyphs and characters. Update initial paragraphs.",
343 "Hello different world\nनमस्ते दुनिया\nမင်္ဂလာပါကမ္ဘာလောက",
350 "Text paragraphs with different number of glyphs and characters. Update mid paragraphs.",
351 "Hello different world\nनमस्ते दुनिया\nမင်္ဂလာပါကမ္ဘာလောက",
358 "Text paragraphs with different number of glyphs and characters. Update final paragraphs.",
359 "Hello different world\nनमस्ते दुनिया\nမင်္ဂလာပါကမ္ဘာလောက",
367 const unsigned int numberOfTests = 6u;
369 for( unsigned int index = 0u; index < numberOfTests; ++index )
371 if( !SetCharacterToGlyphTest( data[index] ) )
373 tet_result(TET_FAIL);
377 tet_result(TET_PASS);