2 * Copyright (c) 2022 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>
27 using namespace Toolkit;
30 // Tests the following functions.
32 // void CreateCharacterToGlyphTable( CharacterIndex startIndex,
33 // Length numberOfCharacters )
35 // void CreateGlyphsPerCharacterTable( CharacterIndex startIndex,
36 // Length numberOfCharacters )
38 //////////////////////////////////////////////////////////
42 struct SetGlyphsPerCharacterData
44 std::string description; ///< Description of the test.
45 std::string text; ///< Input text.
46 unsigned int startIndex; ///< The start index from where the glyphs per character table is set.
47 unsigned int numberOfCharacters; ///< The number of characters to set.
48 unsigned int totalNumberOfCharacters; ///< The total number of characters.
49 unsigned int* glyphsPerCharacter; ///< The number of glyphs per character.
52 struct SetCharacterToGlyphData
54 std::string description; ///< Description of the test.
55 std::string text; ///< Input text.
56 unsigned int startIndex; ///< The start index from where the character to glyph table is set.
57 unsigned int numberOfCharacters; ///< The number of characters to set.
58 unsigned int totalNumberOfCharacters; ///< The total number of characters.
59 unsigned int* glyphsIndices; ///< The glyph indices.
62 bool SetGlyphsPerCharacterTest(const SetGlyphsPerCharacterData& data)
64 // 1) Create the model.
67 Size textArea(100.f, 60.f);
70 const Vector<FontDescriptionRun> fontDescriptions;
71 const LayoutOptions options;
72 CreateTextModel(data.text,
82 Toolkit::DevelText::EllipsisPosition::END,
84 0.0f // characterSpacing
87 LogicalModelPtr logicalModel = textModel->mLogicalModel;
88 VisualModelPtr visualModel = textModel->mVisualModel;
90 Vector<GlyphIndex>& charactersToGlyph = visualModel->mCharactersToGlyph;
91 Vector<Length>& glyphsPerCharacter = visualModel->mGlyphsPerCharacter;
93 // 2) Clear the model.
95 GlyphIndex startGlyphIndex = 0u;
96 if(0u != charactersToGlyph.Count())
98 // The number of glyphs to be removed.
99 const Length numberOfGlyphs = charactersToGlyph[data.startIndex + data.numberOfCharacters - 1u] + glyphsPerCharacter[data.startIndex + data.numberOfCharacters - 1u] - charactersToGlyph[data.startIndex];
100 startGlyphIndex = charactersToGlyph[data.startIndex];
102 charactersToGlyph.Erase(charactersToGlyph.Begin() + data.startIndex,
103 charactersToGlyph.Begin() + data.startIndex + data.numberOfCharacters);
104 glyphsPerCharacter.Erase(glyphsPerCharacter.Begin() + data.startIndex,
105 glyphsPerCharacter.Begin() + data.startIndex + data.numberOfCharacters);
107 // Update the character to glyph indices.
108 for(Vector<GlyphIndex>::Iterator it = charactersToGlyph.Begin() + data.startIndex,
109 endIt = charactersToGlyph.End();
113 *it -= numberOfGlyphs;
117 // 3) Call the CreateGlyphsPerCharacterTable() function
118 visualModel->CreateGlyphsPerCharacterTable(data.startIndex,
120 data.numberOfCharacters);
122 // 4) Compare the results.
123 if(data.totalNumberOfCharacters != glyphsPerCharacter.Count())
125 std::cout << " Different number of characters : " << glyphsPerCharacter.Count() << ", expected : " << data.totalNumberOfCharacters << std::endl;
129 for(unsigned int i = 0u; i < data.totalNumberOfCharacters; ++i)
131 if(data.glyphsPerCharacter[i] != glyphsPerCharacter[i])
133 std::cout << " Different number of glyphs for index " << i << std::endl;
134 for(unsigned int j = 0; j < data.totalNumberOfCharacters; ++j)
136 std::cout << glyphsPerCharacter[j] << " ";
138 std::cout << std::endl;
139 std::cout << " expected" << std::endl;
140 for(unsigned int j = 0; j < data.totalNumberOfCharacters; ++j)
142 std::cout << data.glyphsPerCharacter[j] << " ";
144 std::cout << std::endl;
152 bool SetCharacterToGlyphTest(const SetCharacterToGlyphData& data)
154 // 1) Create the model.
157 Size textArea(100.f, 60.f);
160 const Vector<FontDescriptionRun> fontDescriptions;
161 const LayoutOptions options;
162 CreateTextModel(data.text,
172 Toolkit::DevelText::EllipsisPosition::END,
174 0.0f // characterSpacing
177 LogicalModelPtr logicalModel = textModel->mLogicalModel;
178 VisualModelPtr visualModel = textModel->mVisualModel;
180 Vector<GlyphIndex>& charactersToGlyph = visualModel->mCharactersToGlyph;
181 Vector<Length>& glyphsPerCharacter = visualModel->mGlyphsPerCharacter;
183 // 2) Clear the model.
185 GlyphIndex startGlyphIndex = 0u;
186 if(0u != charactersToGlyph.Count())
188 // The number of glyphs to be removed.
189 const Length numberOfGlyphs = charactersToGlyph[data.startIndex + data.numberOfCharacters - 1u] + glyphsPerCharacter[data.startIndex + data.numberOfCharacters - 1u] - charactersToGlyph[data.startIndex];
190 startGlyphIndex = charactersToGlyph[data.startIndex];
192 charactersToGlyph.Erase(charactersToGlyph.Begin() + data.startIndex,
193 charactersToGlyph.Begin() + data.startIndex + data.numberOfCharacters);
195 // Update the character to glyph indices.
196 for(Vector<GlyphIndex>::Iterator it = charactersToGlyph.Begin() + data.startIndex,
197 endIt = charactersToGlyph.End();
201 *it -= numberOfGlyphs;
205 // 3) Call the CreateCharacterToGlyphTable() function
206 visualModel->CreateCharacterToGlyphTable(data.startIndex,
208 data.numberOfCharacters);
210 // 4) Compare the results.
211 if(data.totalNumberOfCharacters != charactersToGlyph.Count())
213 std::cout << " Different number of character : " << charactersToGlyph.Count() << ", expected : " << data.totalNumberOfCharacters << std::endl;
217 for(unsigned int i = 0u; i < data.totalNumberOfCharacters; ++i)
219 if(data.glyphsIndices[i] != charactersToGlyph[i])
221 std::cout << " Different number of character to glyph index " << i << std::endl;
222 for(unsigned int j = 0; j < data.totalNumberOfCharacters; ++j)
224 std::cout << charactersToGlyph[j] << " ";
226 std::cout << std::endl;
227 std::cout << " expected" << std::endl;
228 for(unsigned int j = 0; j < data.totalNumberOfCharacters; ++j)
230 std::cout << data.glyphsIndices[j] << " ";
232 std::cout << std::endl;
242 //////////////////////////////////////////////////////////
244 int UtcDaliSetGlyphsPerCharacter(void)
246 tet_infoline(" UtcDaliSetGlyphsPerCharacter");
248 Length glyphsPerCharacter02[] = {1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u};
249 Length glyphsPerCharacter03[] = {1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 0u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u};
250 Length glyphsPerCharacter04[] = {1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 0u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 0u, 1u, 0u, 2u, 1u, 0u, 2u, 0u, 2u, 0u, 2u, 1u, 1u, 0u, 0u, 0u, 2u, 1u, 1u, 1u, 1u, 1u, 0u, 0u, 2u, 1u, 0u, 2u, 1u, 1u};
252 struct SetGlyphsPerCharacterData data[] =
254 {"Zero characters text",
261 "Simple 1 to 1 text",
266 glyphsPerCharacter02,
269 "Text with different number of glyphs and characters.",
270 "Hello different world",
274 glyphsPerCharacter03,
277 "Text paragraphs with different number of glyphs and characters. Update initial paragraphs.",
278 "Hello different world\nनमस्ते दुनिया\nမင်္ဂလာပါကမ္ဘာလောက",
282 glyphsPerCharacter04,
285 "Text paragraphs with different number of glyphs and characters. Update mid paragraphs.",
286 "Hello different world\nनमस्ते दुनिया\nမင်္ဂလာပါကမ္ဘာလောက",
290 glyphsPerCharacter04,
293 "Text paragraphs with different number of glyphs and characters. Update final paragraphs.",
294 "Hello different world\nनमस्ते दुनिया\nမင်္ဂလာပါကမ္ဘာလောက",
298 glyphsPerCharacter04,
301 const unsigned int numberOfTests = 6u;
303 for(unsigned int index = 0u; index < numberOfTests; ++index)
305 ToolkitTestApplication application;
306 if(!SetGlyphsPerCharacterTest(data[index]))
308 tet_result(TET_FAIL);
312 tet_result(TET_PASS);
316 int UtcDaliSetCharacterToGlyph(void)
318 tet_infoline(" UtcDaliSetGlyphsPerCharacter");
320 GlyphIndex glyphIndices02[] = {0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u, 9u, 10u};
321 GlyphIndex glyphIndices03[] = {0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u, 8u, 9u, 10u, 11u, 12u, 13u, 14u, 15u, 16u, 17u, 18u, 19u};
322 GlyphIndex glyphIndices04[] = {0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u, 8u, 9u, 10u, 11u, 12u, 13u, 14u, 15u, 16u, 17u, 18u, 19u, 20u, 21u, 22u, 23u, 23u, 24u, 24u, 26u, 27u, 27u, 29u, 29u, 31u, 31u, 33u, 34u, 35u, 35u, 35u, 35u, 37u, 38u, 39u, 40u, 41u, 42u, 42u, 42u, 44u, 45u, 45u, 47u, 48u};
324 struct SetCharacterToGlyphData data[] =
326 {"Zero characters text",
333 "Simple 1 to 1 text",
341 "Text with different number of glyphs and characters.",
342 "Hello different world",
349 "Text paragraphs with different number of glyphs and characters. Update initial paragraphs.",
350 "Hello different world\nनमस्ते दुनिया\nမင်္ဂလာပါကမ္ဘာလောက",
357 "Text paragraphs with different number of glyphs and characters. Update mid paragraphs.",
358 "Hello different world\nनमस्ते दुनिया\nမင်္ဂလာပါကမ္ဘာလောက",
365 "Text paragraphs with different number of glyphs and characters. Update final paragraphs.",
366 "Hello different world\nनमस्ते दुनिया\nမင်္ဂလာပါကမ္ဘာလောက",
374 const unsigned int numberOfTests = 6u;
376 for(unsigned int index = 0u; index < numberOfTests; ++index)
378 ToolkitTestApplication application;
379 if(!SetCharacterToGlyphTest(data[index]))
381 tet_result(TET_FAIL);
385 tet_result(TET_PASS);