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-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,
84 LogicalModelPtr logicalModel = textModel->mLogicalModel;
85 VisualModelPtr visualModel = textModel->mVisualModel;
87 Vector<GlyphIndex>& charactersToGlyph = visualModel->mCharactersToGlyph;
88 Vector<Length>& glyphsPerCharacter = visualModel->mGlyphsPerCharacter;
90 // 2) Clear the model.
92 GlyphIndex startGlyphIndex = 0u;
93 if( 0u != charactersToGlyph.Count() )
95 // The number of glyphs to be removed.
96 const Length numberOfGlyphs = charactersToGlyph[data.startIndex + data.numberOfCharacters - 1u] + glyphsPerCharacter[data.startIndex + data.numberOfCharacters - 1u] - charactersToGlyph[data.startIndex];
97 startGlyphIndex = charactersToGlyph[data.startIndex];
99 charactersToGlyph.Erase( charactersToGlyph.Begin() + data.startIndex,
100 charactersToGlyph.Begin() + data.startIndex + data.numberOfCharacters );
101 glyphsPerCharacter.Erase( glyphsPerCharacter.Begin() + data.startIndex,
102 glyphsPerCharacter.Begin() + data.startIndex + data.numberOfCharacters );
104 // Update the character to glyph indices.
105 for( Vector<GlyphIndex>::Iterator it = charactersToGlyph.Begin() + data.startIndex,
106 endIt = charactersToGlyph.End();
110 *it -= numberOfGlyphs;
114 // 3) Call the CreateGlyphsPerCharacterTable() function
115 visualModel->CreateGlyphsPerCharacterTable( data.startIndex,
117 data.numberOfCharacters );
119 // 4) Compare the results.
120 if( data.totalNumberOfCharacters != glyphsPerCharacter.Count() )
122 std::cout << " Different number of characters : " << glyphsPerCharacter.Count() << ", expected : " << data.totalNumberOfCharacters << std::endl;
126 for( unsigned int i = 0u; i < data.totalNumberOfCharacters; ++i )
128 if( data.glyphsPerCharacter[i] != glyphsPerCharacter[i] )
130 std::cout << " Different number of glyphs for index " << i << std::endl;
131 for( unsigned int j = 0; j < data.totalNumberOfCharacters; ++j )
133 std::cout << glyphsPerCharacter[j] << " ";
135 std::cout << std::endl;
136 std::cout << " expected" << std::endl;
137 for( unsigned int j = 0; j < data.totalNumberOfCharacters; ++j )
139 std::cout << data.glyphsPerCharacter[j] << " ";
141 std::cout << std::endl;
149 bool SetCharacterToGlyphTest( const SetCharacterToGlyphData& data )
151 // 1) Create the model.
154 Size textArea(100.f, 60.f);
157 const Vector<FontDescriptionRun> fontDescriptions;
158 const LayoutOptions options;
159 CreateTextModel( data.text,
168 LogicalModelPtr logicalModel = textModel->mLogicalModel;
169 VisualModelPtr visualModel = textModel->mVisualModel;
171 Vector<GlyphIndex>& charactersToGlyph = visualModel->mCharactersToGlyph;
172 Vector<Length>& glyphsPerCharacter = visualModel->mGlyphsPerCharacter;
174 // 2) Clear the model.
176 GlyphIndex startGlyphIndex = 0u;
177 if( 0u != charactersToGlyph.Count() )
179 // The number of glyphs to be removed.
180 const Length numberOfGlyphs = charactersToGlyph[data.startIndex + data.numberOfCharacters - 1u] + glyphsPerCharacter[data.startIndex + data.numberOfCharacters - 1u] - charactersToGlyph[data.startIndex];
181 startGlyphIndex = charactersToGlyph[data.startIndex];
183 charactersToGlyph.Erase( charactersToGlyph.Begin() + data.startIndex,
184 charactersToGlyph.Begin() + data.startIndex + data.numberOfCharacters );
186 // Update the character to glyph indices.
187 for( Vector<GlyphIndex>::Iterator it = charactersToGlyph.Begin() + data.startIndex,
188 endIt = charactersToGlyph.End();
192 *it -= numberOfGlyphs;
196 // 3) Call the CreateCharacterToGlyphTable() function
197 visualModel->CreateCharacterToGlyphTable( data.startIndex,
199 data.numberOfCharacters );
201 // 4) Compare the results.
202 if( data.totalNumberOfCharacters != charactersToGlyph.Count() )
204 std::cout << " Different number of character : " << charactersToGlyph.Count() << ", expected : " << data.totalNumberOfCharacters << std::endl;
208 for( unsigned int i = 0u; i < data.totalNumberOfCharacters; ++i )
210 if( data.glyphsIndices[i] != charactersToGlyph[i] )
212 std::cout << " Different number of character to glyph index " << i << std::endl;
213 for( unsigned int j = 0; j < data.totalNumberOfCharacters; ++j )
215 std::cout << charactersToGlyph[j] << " ";
217 std::cout << std::endl;
218 std::cout << " expected" << std::endl;
219 for( unsigned int j = 0; j < data.totalNumberOfCharacters; ++j )
221 std::cout << data.glyphsIndices[j] << " ";
223 std::cout << std::endl;
233 //////////////////////////////////////////////////////////
235 int UtcDaliSetGlyphsPerCharacter(void)
237 tet_infoline(" UtcDaliSetGlyphsPerCharacter");
239 Length glyphsPerCharacter02[] = { 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u };
240 Length glyphsPerCharacter03[] = { 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 0u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u };
241 Length glyphsPerCharacter04[] = { 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 0u, 1u,
242 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
243 1u, 1u, 1u, 1u, 0u, 1u, 0u, 2u, 1u, 0u,
244 2u, 0u, 2u, 0u, 2u, 1u, 1u, 0u, 0u, 0u,
245 2u, 1u, 1u, 1u, 1u, 1u, 0u, 0u, 2u, 1u,
248 struct SetGlyphsPerCharacterData data[] =
251 "Zero characters text",
259 "Simple 1 to 1 text",
264 glyphsPerCharacter02,
267 "Text with different number of glyphs and characters.",
268 "Hello different world",
272 glyphsPerCharacter03,
275 "Text paragraphs with different number of glyphs and characters. Update initial paragraphs.",
276 "Hello different world\nनमस्ते दुनिया\nမင်္ဂလာပါကမ္ဘာလောက",
280 glyphsPerCharacter04,
283 "Text paragraphs with different number of glyphs and characters. Update mid paragraphs.",
284 "Hello different world\nनमस्ते दुनिया\nမင်္ဂလာပါကမ္ဘာလောက",
288 glyphsPerCharacter04,
291 "Text paragraphs with different number of glyphs and characters. Update final paragraphs.",
292 "Hello different world\nनमस्ते दुनिया\nမင်္ဂလာပါကမ္ဘာလောက",
296 glyphsPerCharacter04,
299 const unsigned int numberOfTests = 6u;
301 for( unsigned int index = 0u; index < numberOfTests; ++index )
303 ToolkitTestApplication application;
304 if( !SetGlyphsPerCharacterTest( data[index] ) )
306 tet_result(TET_FAIL);
310 tet_result(TET_PASS);
314 int UtcDaliSetCharacterToGlyph(void)
316 tet_infoline(" UtcDaliSetGlyphsPerCharacter");
318 GlyphIndex glyphIndices02[] = { 0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u, 9u, 10u };
319 GlyphIndex glyphIndices03[] = { 0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u, 8u, 9u, 10u, 11u, 12u, 13u, 14u, 15u, 16u, 17u, 18u, 19u };
320 GlyphIndex glyphIndices04[] = { 0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u, 8u, 9u, 10u, 11u, 12u, 13u, 14u, 15u, 16u, 17u, 18u, 19u, 20u,
321 21u, 22u, 23u, 23u, 24u, 24u, 26u, 27u, 27u, 29u, 29u, 31u, 31u, 33u,
322 34u, 35u, 35u, 35u, 35u, 37u, 38u, 39u, 40u, 41u, 42u, 42u, 42u, 44u, 45u, 45u, 47u, 48u };
324 struct SetCharacterToGlyphData data[] =
327 "Zero characters text",
335 "Simple 1 to 1 text",
343 "Text with different number of glyphs and characters.",
344 "Hello different world",
351 "Text paragraphs with different number of glyphs and characters. Update initial paragraphs.",
352 "Hello different world\nनमस्ते दुनिया\nမင်္ဂလာပါကမ္ဘာလောက",
359 "Text paragraphs with different number of glyphs and characters. Update mid paragraphs.",
360 "Hello different world\nनमस्ते दुनिया\nမင်္ဂလာပါကမ္ဘာလောက",
367 "Text paragraphs with different number of glyphs and characters. Update final paragraphs.",
368 "Hello different world\nनमस्ते दुनिया\nမင်္ဂလာပါကမ္ဘာလောက",
376 const unsigned int numberOfTests = 6u;
378 for( unsigned int index = 0u; index < numberOfTests; ++index )
380 ToolkitTestApplication application;
381 if( !SetCharacterToGlyphTest( data[index] ) )
383 tet_result(TET_FAIL);
387 tet_result(TET_PASS);