2 * Copyright (c) 2023 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/devel-api/text-abstraction/font-client.h>
23 #include <dali-toolkit/internal/text/character-set-conversion.h>
24 #include <dali-toolkit/internal/text/logical-model-impl.h>
25 #include <dali-toolkit/internal/text/multi-language-helper-functions.h>
26 #include <dali-toolkit/internal/text/multi-language-support.h>
27 #include <dali-toolkit/internal/text/multi-language-support-impl.h>
28 #include <dali-toolkit/internal/text/segmentation.h>
29 #include <dali-toolkit/internal/text/text-run-container.h>
30 #include <dali-toolkit-test-suite-utils.h>
31 #include <dali-toolkit/dali-toolkit.h>
34 using namespace Toolkit;
38 // Tests the following functions with different scripts.
40 // void MergeFontDescriptions(const Vector<FontDescriptionRun>& fontDescriptions,
41 // const TextAbstraction::FontDescription& defaultFontDescription,
42 // TextAbstraction::PointSize26Dot6 defaultPointSize,
43 // float fontSizeScale,
44 // CharacterIndex characterIndex,
45 // TextAbstraction::FontDescription& fontDescription,
46 // TextAbstraction::PointSize26Dot6& fontPointSize,
47 // bool& isDefaultFont);
49 // Script GetScript(Length index,
50 // Vector<ScriptRun>::ConstIterator& scriptRunIt,
51 // const Vector<ScriptRun>::ConstIterator& scriptRunEndIt);
53 // Constructor, destructor and MultilanguageSupport::Get()
55 // void MultilanguageSupport::SetScripts(const Vector<Character>& text,
56 // CharacterIndex startIndex,
57 // Length numberOfCharacters,
58 // Vector<ScriptRun>& scripts);
60 // void MultilanguageSupport::ValidateFonts(const Vector<Character>& text,
61 // const Vector<ScriptRun>& scripts,
62 // const Vector<FontDescriptionRun>& fontDescriptions,
63 // const TextAbstraction::FontDescription& defaultFontDescription,
64 // TextAbstraction::PointSize26Dot6 defaultFontPointSize,
65 // float fontSizeScale,
66 // CharacterIndex startIndex,
67 // Length numberOfCharacters,
68 // Vector<FontRun>& fonts);
70 //////////////////////////////////////////////////////////
75 const std::string DEFAULT_FONT_DIR( "/resources/fonts" );
76 const unsigned int EMOJI_FONT_SIZE = 3840u; // 60 * 64
77 const unsigned int NON_DEFAULT_FONT_SIZE = 40u;
79 struct MergeFontDescriptionsData
81 std::string description; ///< Description of the experiment.
82 Vector<FontDescriptionRun> fontDescriptionRuns; ///< The font description runs.
83 TextAbstraction::FontDescription defaultFontDescription; ///< The default font description.
84 TextAbstraction::PointSize26Dot6 defaultPointSize; ///< The default point size.
85 float fontSizeScale; ///< The font's size scale.
86 unsigned int startIndex; ///< The start index.
87 unsigned int numberOfCharacters; ///< The number of characters.
88 Vector<FontId> expectedFontIds; ///< The expected font ids.
89 Vector<bool> expectedIsDefault; ///< The expected font ids.
94 std::string description; ///< Description of the experiment.
95 std::string text; ///< Input text.
96 unsigned int index; ///< The index of the first character to update the script.
97 unsigned int numberOfCharacters; ///< The numbers of characters to update the script.
98 Vector<ScriptRun> scriptRuns; ///< Expected script runs.
101 struct ValidateFontsData
103 std::string description; ///< Description of the experiment.
104 std::string text; ///< Input text.
105 std::string defaultFont; ///< The default font.
106 unsigned int defaultFontSize; ///< The default font size.
107 float fontSizeScale; ///< The font's size scale.
108 unsigned int index; ///< The index of the first character to update the script.
109 unsigned int numberOfCharacters; ///< The numbers of characters to update the script.
110 Vector<FontDescriptionRun> fontDescriptionRuns; ///< The font description runs.
111 Vector<FontRun> fontRuns; ///< The expected font runs.
114 //////////////////////////////////////////////////////////
115 bool MergeFontDescriptionsTest( const MergeFontDescriptionsData& data )
117 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
119 Vector<FontId> fontIds;
120 fontIds.Resize( data.startIndex + data.numberOfCharacters, 0u );
121 Vector<bool> isDefaultFont;
122 isDefaultFont.Resize( data.startIndex + data.numberOfCharacters, true );
124 for( unsigned int index = data.startIndex; index < data.startIndex + data.numberOfCharacters; ++index )
126 TextAbstraction::FontDescription fontDescription;
127 TextAbstraction::PointSize26Dot6 fontPointSize = TextAbstraction::FontClient::DEFAULT_POINT_SIZE;
129 MergeFontDescriptions( data.fontDescriptionRuns,
130 data.defaultFontDescription,
131 data.defaultPointSize,
136 isDefaultFont[index] );
138 if( !isDefaultFont[index] )
140 fontIds[index] = fontClient.GetFontId( fontDescription, fontPointSize );
144 if( fontIds.Count() != data.expectedFontIds.Count() )
146 std::cout << data.description << " Different number of font ids : " << fontIds.Count() << ", expected : " << data.expectedFontIds.Count() << std::endl;
150 for( unsigned int index = 0u; index < fontIds.Count(); ++index )
152 if( fontIds[index] != data.expectedFontIds[index] )
154 std::cout << data.description << " Different font id at index : " << index << ", font id : " << fontIds[index] << ", expected : " << data.expectedFontIds[index] << std::endl;
155 std::cout << " font ids : ";
156 for( unsigned int i=0;i<fontIds.Count();++i)
158 std::cout << fontIds[i] << " ";
160 std::cout << std::endl;
161 std::cout << " expected font ids : ";
162 for( unsigned int i=0;i<data.expectedFontIds.Count();++i)
164 std::cout << data.expectedFontIds[i] << " ";
166 std::cout << std::endl;
170 if( isDefaultFont[index] != data.expectedIsDefault[index] )
172 std::cout << data.description << " Different 'is font default' at index : " << index << ", is font default : " << isDefaultFont[index] << ", expected : " << data.expectedIsDefault[index] << std::endl;
180 bool ScriptsTest( const ScriptsData& data )
182 MultilanguageSupport multilanguageSupport = MultilanguageSupport::Get();
184 // 1) Convert to utf32
185 Vector<Character> utf32;
186 utf32.Resize( data.text.size() );
188 const uint32_t numberOfCharacters = ( data.text.size() == 0 ) ? 0 :
189 Utf8ToUtf32( reinterpret_cast<const uint8_t* const>( data.text.c_str() ),
193 utf32.Resize( numberOfCharacters );
195 // 2) Set the script info.
196 Vector<ScriptRun> scripts;
197 multilanguageSupport.SetScripts( utf32,
202 if( ( 0u != data.index ) ||
203 ( numberOfCharacters != data.numberOfCharacters ) )
205 // 3) Clear the scripts.
206 ClearCharacterRuns( data.index,
207 data.index + data.numberOfCharacters - 1u,
210 multilanguageSupport.SetScripts( utf32,
212 data.numberOfCharacters,
216 // 4) Compare the results.
218 tet_printf( "Testing %s\n", data.description.c_str() );
219 if( scripts.Count() != data.scriptRuns.Count() )
221 tet_printf("ScriptsTest FAIL: different number of scripts. %d, should be %d\n", scripts.Count(), data.scriptRuns.Count() );
222 for( Vector<ScriptRun>::ConstIterator it = scripts.Begin(); it != scripts.End(); ++it)
224 const ScriptRun& run = *it;
226 std::cout << " index : " << run.characterRun.characterIndex << ", num chars : " << run.characterRun.numberOfCharacters << ", script : [" << TextAbstraction::ScriptName[run.script] << "]" << std::endl;
231 for( unsigned int index = 0u; index < scripts.Count(); ++index )
233 const ScriptRun& scriptRun1 = scripts[index];
234 const ScriptRun& scriptRun2 = data.scriptRuns[index];
236 if( scriptRun1.characterRun.characterIndex != scriptRun2.characterRun.characterIndex )
238 tet_printf("ScriptsTest FAIL: different character index. %d, should be %d\n", scriptRun1.characterRun.characterIndex, scriptRun2.characterRun.characterIndex );
242 if( scriptRun1.characterRun.numberOfCharacters != scriptRun2.characterRun.numberOfCharacters )
244 tet_printf("ScriptsTest FAIL: different number of characters. %d, should be %d\n", scriptRun1.characterRun.numberOfCharacters, scriptRun2.characterRun.numberOfCharacters );
248 if( scriptRun1.script != scriptRun2.script )
250 tet_printf("ScriptsTest FAIL: script index: %u, different script. %s, should be %s\n", index, TextAbstraction::ScriptName[scriptRun1.script], TextAbstraction::ScriptName[scriptRun2.script] );
258 bool ValidateFontTest( const ValidateFontsData& data )
260 MultilanguageSupport multilanguageSupport = MultilanguageSupport::Get();
261 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
263 // 1) Convert to utf32
264 Vector<Character> utf32;
265 utf32.Resize( data.text.size() );
267 const uint32_t numberOfCharacters = (data.text.size() == 0 ) ? 0 :
268 Utf8ToUtf32( reinterpret_cast<const uint8_t* const>( data.text.c_str() ),
271 utf32.Resize( numberOfCharacters );
273 // 2) Set the script info.
274 Vector<ScriptRun> scripts;
275 multilanguageSupport.SetScripts( utf32,
280 char* pathNamePtr = get_current_dir_name();
281 const std::string pathName( pathNamePtr );
284 // Get the default font id.
285 const FontId defaultFontId = fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + data.defaultFont,
286 data.defaultFontSize );
287 TextAbstraction::FontDescription defaultFontDescription;
288 fontClient.GetDescription( defaultFontId, defaultFontDescription );
290 const TextAbstraction::PointSize26Dot6 defaultPointSize = fontClient.GetPointSize( defaultFontId );
292 Vector<FontRun> fontRuns;
294 // 3) Validate the fonts.
295 multilanguageSupport.ValidateFonts( utf32,
297 data.fontDescriptionRuns,
298 defaultFontDescription,
305 if( ( 0u != data.index ) ||
306 ( numberOfCharacters != data.numberOfCharacters ) )
308 // 4) Clear the fonts.
309 ClearCharacterRuns( data.index,
310 data.index + data.numberOfCharacters - 1u,
313 multilanguageSupport.ValidateFonts( utf32,
315 data.fontDescriptionRuns,
316 defaultFontDescription,
320 data.numberOfCharacters,
324 // 5) Compare the results.
325 if( data.fontRuns.Count() != fontRuns.Count() )
327 std::cout << " Different number of font runs : " << fontRuns.Count() << ", expected : " << data.fontRuns.Count() << std::endl;
332 for( unsigned int index = 0; index < data.fontRuns.Count(); ++index )
334 const FontRun& run = fontRuns[index];
335 const FontRun& expectedRun = data.fontRuns[index];
337 if( run.characterRun.characterIndex != expectedRun.characterRun.characterIndex )
339 std::cout << " character run : " << index << ", index : " << run.characterRun.characterIndex << ", expected : " << expectedRun.characterRun.characterIndex << std::endl;
342 if( run.characterRun.numberOfCharacters != expectedRun.characterRun.numberOfCharacters )
344 std::cout << " character run : " << index << ", num chars : " << run.characterRun.numberOfCharacters << ", expected : " << expectedRun.characterRun.numberOfCharacters << std::endl;
347 if( run.fontId != expectedRun.fontId )
349 std::cout << " character run : " << index << ", font : " << run.fontId << ", expected : " << expectedRun.fontId << std::endl;
359 int UtcDaliTextGetScript(void)
361 ToolkitTestApplication application;
362 tet_infoline(" UtcDaliTextGetScript");
364 Script script = TextAbstraction::LATIN;
366 // Text with no scripts.
367 Vector<ScriptRun> scriptRuns;
368 Vector<ScriptRun>::ConstIterator scriptRunIt = scriptRuns.Begin();
369 script = GetScript( 0u,
373 DALI_TEST_CHECK( TextAbstraction::UNKNOWN == script );
375 const unsigned int numberOfCharacters = 7u;
377 ScriptRun scriptRun01 =
383 TextAbstraction::LATIN
385 ScriptRun scriptRun02 =
391 TextAbstraction::HEBREW
393 ScriptRun scriptRun03 =
399 TextAbstraction::ARABIC
401 scriptRuns.PushBack( scriptRun01 );
402 scriptRuns.PushBack( scriptRun02 );
403 scriptRuns.PushBack( scriptRun03 );
406 TextAbstraction::Script expectedScripts[]=
408 TextAbstraction::LATIN,
409 TextAbstraction::LATIN,
410 TextAbstraction::HEBREW,
411 TextAbstraction::HEBREW,
412 TextAbstraction::ARABIC,
413 TextAbstraction::ARABIC,
414 TextAbstraction::UNKNOWN
417 scriptRunIt = scriptRuns.Begin();
418 for( unsigned int index = 0u; index < numberOfCharacters; ++index )
420 script = GetScript( index,
424 DALI_TEST_CHECK( expectedScripts[index] == script );
426 DALI_TEST_CHECK( scriptRunIt == scriptRuns.End() );
428 tet_result(TET_PASS);
432 int UtcDaliTextMergeFontDescriptions(void)
434 ToolkitTestApplication application;
435 tet_infoline(" UtcDaliTextMergeFontDescriptions");
439 char* pathNamePtr = get_current_dir_name();
440 const std::string pathName( pathNamePtr );
443 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
444 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSans.ttf" );
445 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf" );
446 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", NON_DEFAULT_FONT_SIZE );
447 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf" );
448 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Italic.ttf" );
450 // To test the font width as GetFontId() with the font file path can't cache the width property.
451 TextAbstraction::FontDescription widthDescription;
452 widthDescription.path = "";
453 widthDescription.family = "DejaVu Serif";
454 widthDescription.weight = TextAbstraction::FontWeight::NORMAL;
455 widthDescription.width = TextAbstraction::FontWidth::EXPANDED;
456 widthDescription.slant = TextAbstraction::FontSlant::NORMAL;
457 fontClient.GetFontId( widthDescription );
461 TextAbstraction::FontDescription defaultFontDescription01;
462 Vector<FontDescriptionRun> fontDescriptionRuns01;
463 Vector<FontId> expectedFontIds01;
464 Vector<bool> expectedIsFontDefault01;
466 TextAbstraction::FontDescription defaultFontDescription02;
467 Vector<FontDescriptionRun> fontDescriptionRuns02;
468 Vector<FontId> expectedFontIds02;
469 expectedFontIds02.PushBack( 0u );
470 expectedFontIds02.PushBack( 0u );
471 Vector<bool> expectedIsFontDefault02;
472 expectedIsFontDefault02.PushBack( true );
473 expectedIsFontDefault02.PushBack( true );
475 TextAbstraction::FontDescription defaultFontDescription03;
476 defaultFontDescription03.family = "DejaVu Serif";
477 Vector<FontDescriptionRun> fontDescriptionRuns03;
479 FontDescriptionRun fontDescription0301 =
485 const_cast<char*>( "DejaVu Sans" ),
487 TextAbstraction::FontWeight::NONE,
488 TextAbstraction::FontWidth::NONE,
489 TextAbstraction::FontSlant::NONE,
490 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
497 FontDescriptionRun fontDescription0302 =
505 TextAbstraction::FontWeight::NONE,
506 TextAbstraction::FontWidth::NONE,
507 TextAbstraction::FontSlant::ITALIC,
508 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
515 FontDescriptionRun fontDescription0303 =
523 TextAbstraction::FontWeight::BOLD,
524 TextAbstraction::FontWidth::NONE,
525 TextAbstraction::FontSlant::NONE,
526 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
533 FontDescriptionRun fontDescription0304 =
541 TextAbstraction::FontWeight::NONE,
542 TextAbstraction::FontWidth::NONE,
543 TextAbstraction::FontSlant::NONE,
544 NON_DEFAULT_FONT_SIZE,
551 FontDescriptionRun fontDescription0305 =
559 TextAbstraction::FontWeight::NONE,
560 TextAbstraction::FontWidth::EXPANDED,
561 TextAbstraction::FontSlant::NONE,
562 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
570 fontDescriptionRuns03.PushBack( fontDescription0301 );
571 fontDescriptionRuns03.PushBack( fontDescription0302 );
572 fontDescriptionRuns03.PushBack( fontDescription0303 );
573 fontDescriptionRuns03.PushBack( fontDescription0304 );
574 fontDescriptionRuns03.PushBack( fontDescription0305 );
576 Vector<FontId> expectedFontIds03;
577 expectedFontIds03.PushBack( 1u );
578 expectedFontIds03.PushBack( 1u );
579 expectedFontIds03.PushBack( 5u );
580 expectedFontIds03.PushBack( 5u );
581 expectedFontIds03.PushBack( 4u );
582 expectedFontIds03.PushBack( 4u );
583 expectedFontIds03.PushBack( 3u );
584 expectedFontIds03.PushBack( 3u );
585 expectedFontIds03.PushBack( 6u );
586 expectedFontIds03.PushBack( 6u );
587 Vector<bool> expectedIsFontDefault03;
588 expectedIsFontDefault03.PushBack( false );
589 expectedIsFontDefault03.PushBack( false );
590 expectedIsFontDefault03.PushBack( false );
591 expectedIsFontDefault03.PushBack( false );
592 expectedIsFontDefault03.PushBack( false );
593 expectedIsFontDefault03.PushBack( false );
594 expectedIsFontDefault03.PushBack( false );
595 expectedIsFontDefault03.PushBack( false );
596 expectedIsFontDefault03.PushBack( false );
597 expectedIsFontDefault03.PushBack( false );
599 const MergeFontDescriptionsData data[] =
603 fontDescriptionRuns01,
604 defaultFontDescription01,
605 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
610 expectedIsFontDefault01
613 "No description runs.",
614 fontDescriptionRuns02,
615 defaultFontDescription02,
616 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
621 expectedIsFontDefault02
624 "Some description runs.",
625 fontDescriptionRuns03,
626 defaultFontDescription03,
627 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
632 expectedIsFontDefault03
635 const unsigned int numberOfTests = 3u;
637 for( unsigned int index = 0u; index < numberOfTests; ++index )
639 if( !MergeFontDescriptionsTest( data[index] ) )
641 tet_result(TET_FAIL);
645 tet_result(TET_PASS);
649 int UtcDaliTextMultiLanguageConstructor(void)
651 ToolkitTestApplication application;
652 tet_infoline(" UtcDaliTextMultiLanguageConstructor");
654 MultilanguageSupport multilanguageSupport;
655 DALI_TEST_CHECK( !multilanguageSupport );
657 MultilanguageSupport multilanguageSupport1 = MultilanguageSupport::Get();
658 DALI_TEST_CHECK( multilanguageSupport1 );
660 // To increase coverage.
661 MultilanguageSupport multilanguageSupport2 = MultilanguageSupport::Get();
662 DALI_TEST_CHECK( multilanguageSupport2 );
664 DALI_TEST_CHECK( multilanguageSupport1 == multilanguageSupport2 );
666 tet_result(TET_PASS);
670 int UtcDaliTextMultiLanguageSetScripts(void)
672 ToolkitTestApplication application;
673 tet_infoline(" UtcDaliTextMultiLanguageSetScripts" );
676 Vector<ScriptRun> scriptRuns00;
679 Vector<ScriptRun> scriptRuns01;
680 ScriptRun scriptRun0100 =
686 TextAbstraction::LATIN
688 scriptRuns01.PushBack( scriptRun0100 );
690 // Mix of LTR '\n'and RTL
691 Vector<ScriptRun> scriptRuns02;
692 ScriptRun scriptRun0200 =
698 TextAbstraction::LATIN
700 ScriptRun scriptRun0201 =
706 TextAbstraction::ARABIC
708 scriptRuns02.PushBack( scriptRun0200 );
709 scriptRuns02.PushBack( scriptRun0201 );
711 // Mix of RTL '\n'and LTR
712 Vector<ScriptRun> scriptRuns03;
713 ScriptRun scriptRun0300 =
719 TextAbstraction::ARABIC
721 ScriptRun scriptRun0301 =
727 TextAbstraction::LATIN
729 scriptRuns03.PushBack( scriptRun0300 );
730 scriptRuns03.PushBack( scriptRun0301 );
732 // White spaces. At the beginning of the text.
733 Vector<ScriptRun> scriptRuns04;
734 ScriptRun scriptRun0400 =
740 TextAbstraction::LATIN
742 scriptRuns04.PushBack( scriptRun0400 );
744 // White spaces. At the end of the text.
745 Vector<ScriptRun> scriptRuns05;
746 ScriptRun scriptRun0500 =
752 TextAbstraction::LATIN
754 scriptRuns05.PushBack( scriptRun0500 );
756 // White spaces. At the middle of the text.
757 Vector<ScriptRun> scriptRuns06;
758 ScriptRun scriptRun0600 =
764 TextAbstraction::LATIN
766 scriptRuns06.PushBack( scriptRun0600 );
768 // White spaces between different scripts.
769 Vector<ScriptRun> scriptRuns07;
770 ScriptRun scriptRun0700 =
776 TextAbstraction::LATIN
778 ScriptRun scriptRun0701 =
784 TextAbstraction::HANGUL
786 scriptRuns07.PushBack( scriptRun0700 );
787 scriptRuns07.PushBack( scriptRun0701 );
789 // White spaces between different scripts and differetn directions. Starting LTR.
790 Vector<ScriptRun> scriptRuns08;
791 ScriptRun scriptRun0800 =
797 TextAbstraction::LATIN
799 ScriptRun scriptRun0801 =
805 TextAbstraction::ARABIC
807 ScriptRun scriptRun0802 =
813 TextAbstraction::HANGUL
815 scriptRuns08.PushBack( scriptRun0800 );
816 scriptRuns08.PushBack( scriptRun0801 );
817 scriptRuns08.PushBack( scriptRun0802 );
819 // White spaces between different scripts and differetn directions. Starting RTL.
820 Vector<ScriptRun> scriptRuns09;
821 ScriptRun scriptRun0900 =
827 TextAbstraction::ARABIC
829 ScriptRun scriptRun0901 =
835 TextAbstraction::LATIN
837 ScriptRun scriptRun0902 =
843 TextAbstraction::HANGUL
845 ScriptRun scriptRun0903 =
851 TextAbstraction::ARABIC
853 scriptRuns09.PushBack( scriptRun0900 );
854 scriptRuns09.PushBack( scriptRun0901 );
855 scriptRuns09.PushBack( scriptRun0902 );
856 scriptRuns09.PushBack( scriptRun0903 );
858 // Paragraphs with different directions.
859 Vector<ScriptRun> scriptRuns10;
860 ScriptRun scriptRun1000 =
866 TextAbstraction::ARABIC
868 ScriptRun scriptRun1001 =
874 TextAbstraction::HEBREW
876 ScriptRun scriptRun1002 =
882 TextAbstraction::ARABIC
884 ScriptRun scriptRun1003 =
890 TextAbstraction::LATIN
892 ScriptRun scriptRun1004 =
898 TextAbstraction::HANGUL
900 ScriptRun scriptRun1005 =
906 TextAbstraction::ARABIC
908 ScriptRun scriptRun1006 =
914 TextAbstraction::LATIN
916 ScriptRun scriptRun1007 =
922 TextAbstraction::HEBREW
924 ScriptRun scriptRun1008 =
930 TextAbstraction::LATIN
932 ScriptRun scriptRun1009 =
938 TextAbstraction::ARABIC
940 ScriptRun scriptRun1010 =
946 TextAbstraction::HANGUL
948 ScriptRun scriptRun1011 =
954 TextAbstraction::HANGUL
956 scriptRuns10.PushBack( scriptRun1000 );
957 scriptRuns10.PushBack( scriptRun1001 );
958 scriptRuns10.PushBack( scriptRun1002 );
959 scriptRuns10.PushBack( scriptRun1003 );
960 scriptRuns10.PushBack( scriptRun1004 );
961 scriptRuns10.PushBack( scriptRun1005 );
962 scriptRuns10.PushBack( scriptRun1006 );
963 scriptRuns10.PushBack( scriptRun1007 );
964 scriptRuns10.PushBack( scriptRun1008 );
965 scriptRuns10.PushBack( scriptRun1009 );
966 scriptRuns10.PushBack( scriptRun1010 );
967 scriptRuns10.PushBack( scriptRun1011 );
969 // Paragraphs with no scripts mixed with paragraphs with scripts.
970 Vector<ScriptRun> scriptRuns11;
971 ScriptRun scriptRun1100 =
977 TextAbstraction::UNKNOWN
979 ScriptRun scriptRun1101 =
985 TextAbstraction::UNKNOWN
987 ScriptRun scriptRun1102 =
993 TextAbstraction::LATIN
995 ScriptRun scriptRun1103 =
1001 TextAbstraction::UNKNOWN
1003 ScriptRun scriptRun1104 =
1009 TextAbstraction::UNKNOWN
1011 ScriptRun scriptRun1105 =
1017 TextAbstraction::HEBREW
1019 ScriptRun scriptRun1106 =
1025 TextAbstraction::UNKNOWN
1027 ScriptRun scriptRun1107 =
1033 TextAbstraction::UNKNOWN
1035 ScriptRun scriptRun1108 =
1041 TextAbstraction::UNKNOWN
1043 scriptRuns11.PushBack( scriptRun1100 );
1044 scriptRuns11.PushBack( scriptRun1101 );
1045 scriptRuns11.PushBack( scriptRun1102 );
1046 scriptRuns11.PushBack( scriptRun1103 );
1047 scriptRuns11.PushBack( scriptRun1104 );
1048 scriptRuns11.PushBack( scriptRun1105 );
1049 scriptRuns11.PushBack( scriptRun1106 );
1050 scriptRuns11.PushBack( scriptRun1107 );
1051 scriptRuns11.PushBack( scriptRun1108 );
1053 // Paragraphs with no scripts.
1054 Vector<ScriptRun> scriptRuns12;
1055 ScriptRun scriptRun1200 =
1061 TextAbstraction::UNKNOWN
1063 ScriptRun scriptRun1201 =
1069 TextAbstraction::UNKNOWN
1071 ScriptRun scriptRun1202 =
1077 TextAbstraction::UNKNOWN
1079 ScriptRun scriptRun1203 =
1085 TextAbstraction::UNKNOWN
1087 scriptRuns12.PushBack( scriptRun1200 );
1088 scriptRuns12.PushBack( scriptRun1201 );
1089 scriptRuns12.PushBack( scriptRun1202 );
1090 scriptRuns12.PushBack( scriptRun1203 );
1092 Vector<ScriptRun> scriptRuns13;
1093 ScriptRun scriptRun1301 =
1099 TextAbstraction::UNKNOWN
1101 scriptRuns13.PushBack( scriptRun1301 );
1103 const ScriptsData data[] =
1113 "Easy latin script",
1120 "Mix of LTR '\\n'and RTL",
1121 "Hello world\nمرحبا بالعالم",
1127 "Update mix of LTR '\\n'and RTL. Update LTR",
1128 "Hello world\nمرحبا بالعالم",
1134 "Update mix of LTR '\\n'and RTL. Update RTL",
1135 "Hello world\nمرحبا بالعالم",
1141 "Mix of RTL '\\n'and LTR",
1142 "مرحبا بالعالم\nHello world",
1148 "Update mix of RTL '\\n'and LTR. Update RTL",
1149 "مرحبا بالعالم\nHello world",
1155 "Update mix of RTL '\\n'and LTR. Update LTR",
1156 "مرحبا بالعالم\nHello world",
1162 "White spaces. At the beginning of the text.",
1169 "White spaces. At the end of the text.",
1176 "White spaces. At the middle of the text.",
1183 "White spaces between different scripts.",
1190 "White spaces between different scripts and differetn directions. Starting LTR.",
1191 " Hello world مرحبا بالعالم 안녕하세요 세계 ",
1197 "White spaces between different scripts and differetn directions. Starting RTL.",
1198 " مرحبا بالعالم Hello world 안녕하세요 세계 مرحبا بالعالم ",
1204 "Paragraphs with different directions.",
1205 " مرحبا بالعالم שלום עולם مرحبا بالعالم \n "
1206 " Hello world 안녕하세요 세계 \n "
1207 " مرحبا بالعالم Hello world שלום עולם \n "
1208 " Hello world مرحبا بالعالم 안녕하세요 세계 \n "
1215 "Update paragraphs with different directions. Update initial paragraphs.",
1216 " مرحبا بالعالم שלום עולם مرحبا بالعالم \n "
1217 " Hello world 안녕하세요 세계 \n "
1218 " مرحبا بالعالم Hello world שלום עולם \n "
1219 " Hello world مرحبا بالعالم 안녕하세요 세계 \n "
1226 "Update paragraphs with different directions. Update middle paragraphs.",
1227 " مرحبا بالعالم שלום עולם مرحبا بالعالم \n "
1228 " Hello world 안녕하세요 세계 \n "
1229 " مرحبا بالعالم Hello world שלום עולם \n "
1230 " Hello world مرحبا بالعالم 안녕하세요 세계 \n "
1237 "Update paragraphs with different directions. Update final paragraphs.",
1238 " مرحبا بالعالم שלום עולם مرحبا بالعالم \n "
1239 " Hello world 안녕하세요 세계 \n "
1240 " مرحبا بالعالم Hello world שלום עולם \n "
1241 " Hello world مرحبا بالعالم 안녕하세요 세계 \n "
1248 "Paragraphs with no scripts mixed with paragraphs with scripts.",
1249 " \n \n Hello world \n \n \n שלום עולם \n \n \n ",
1255 "Paragraphs with no scripts.",
1262 "Update paragraphs with no scripts. Update initial paragraphs.",
1269 "Update paragraphs with no scripts. Update middle paragraphs.",
1276 "Update paragraphs with no scripts. Update final paragraphs.",
1284 "ᚩᚯᚱᚸ", // Runic script not currentlu supported.
1290 const unsigned int numberOfTests = 24u;
1292 for( unsigned int index = 0u; index < numberOfTests; ++index )
1294 if( !ScriptsTest( data[index] ) )
1296 tet_result(TET_FAIL);
1300 tet_result(TET_PASS);
1304 int UtcDaliTextMultiLanguageValidateFonts01(void)
1306 ToolkitTestApplication application;
1307 tet_infoline(" UtcDaliTextMultiLanguageValidateFonts");
1309 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1311 char* pathNamePtr = get_current_dir_name();
1312 const std::string pathName( pathNamePtr );
1313 free( pathNamePtr );
1315 const PointSize26Dot6 pointSize01 = static_cast<PointSize26Dot6>( 21.f * 64.f );
1316 const PointSize26Dot6 pointSize02 = static_cast<PointSize26Dot6>( 35.f * 64.f );
1319 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansArabicRegular.ttf" );
1320 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansHebrewRegular.ttf" );
1321 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/BreezeColorEmoji.ttf", EMOJI_FONT_SIZE );
1322 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansRegular.ttf", pointSize01 );
1323 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansRegular.ttf", pointSize02 );
1324 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansHebrewRegular.ttf", pointSize01 );
1325 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansHebrewRegular.ttf", pointSize02 );
1327 // Font id 1 --> TizenSansArabicRegular.ttf
1328 // Font id 2 --> TizenSansHebrewRegular.ttf
1329 // Font id 3 --> BreezeColorEmoji.ttf
1330 // Font id 4 --> TizenSansRegular.ttf, size 8
1331 // Font id 5 --> TizenSansRegular.ttf, size 16
1332 // Font id 6 --> TizenSansHebrewRegular.ttf, size 8
1333 // Font id 7 --> TizenSansHebrewRegular.ttf, size 16
1334 // Font id 8 --> (default)
1336 Vector<FontRun> fontRuns01;
1337 Vector<FontDescriptionRun> fontDescriptions01;
1339 FontRun fontRun0201 =
1347 Vector<FontRun> fontRuns02;
1348 fontRuns02.PushBack( fontRun0201 );
1350 FontDescriptionRun fontDescription0201 =
1356 const_cast<char*>( "TizenSans" ),
1358 TextAbstraction::FontWeight::NORMAL,
1359 TextAbstraction::FontWidth::NORMAL,
1360 TextAbstraction::FontSlant::NORMAL,
1368 Vector<FontDescriptionRun> fontDescriptions02;
1369 fontDescriptions02.PushBack( fontDescription0201 );
1371 FontRun fontRun0301 =
1379 FontRun fontRun0302 =
1387 FontRun fontRun0303 =
1395 Vector<FontRun> fontRuns03;
1396 fontRuns03.PushBack( fontRun0301 );
1397 fontRuns03.PushBack( fontRun0302 );
1398 fontRuns03.PushBack( fontRun0303 );
1400 Vector<FontDescriptionRun> fontDescriptions03;
1402 FontRun fontRun0701 =
1410 FontRun fontRun0702 =
1418 FontRun fontRun0703 =
1426 Vector<FontRun> fontRuns07;
1427 fontRuns07.PushBack( fontRun0701 );
1428 fontRuns07.PushBack( fontRun0702 );
1429 fontRuns07.PushBack( fontRun0703 );
1431 FontDescriptionRun fontDescription0701 =
1437 const_cast<char*>( "TizenSansHebrew" ),
1439 TextAbstraction::FontWeight::NORMAL,
1440 TextAbstraction::FontWidth::NORMAL,
1441 TextAbstraction::FontSlant::NORMAL,
1449 FontDescriptionRun fontDescription0702 =
1455 const_cast<char*>( "TizenSansHebrew" ),
1457 TextAbstraction::FontWeight::NORMAL,
1458 TextAbstraction::FontWidth::NORMAL,
1459 TextAbstraction::FontSlant::NORMAL,
1467 Vector<FontDescriptionRun> fontDescriptions07;
1468 fontDescriptions07.PushBack( fontDescription0701 );
1469 fontDescriptions07.PushBack( fontDescription0702 );
1471 FontRun fontRun0801 =
1479 Vector<FontRun> fontRuns08;
1480 fontRuns08.PushBack( fontRun0801 );
1482 Vector<FontDescriptionRun> fontDescriptions08;
1484 FontRun fontRun0901 =
1492 Vector<FontRun> fontRuns09;
1493 fontRuns09.PushBack( fontRun0901 );
1495 Vector<FontDescriptionRun> fontDescriptions09;
1496 FontDescriptionRun fontDescription0901 =
1502 const_cast<char*>( "BreezeColorEmoji" ),
1504 TextAbstraction::FontWeight::NORMAL,
1505 TextAbstraction::FontWidth::NORMAL,
1506 TextAbstraction::FontSlant::NORMAL,
1514 fontDescriptions09.PushBack( fontDescription0901 );
1516 FontRun fontRun1001 =
1524 FontRun fontRun1002 =
1532 FontRun fontRun1003 =
1540 FontRun fontRun1004 =
1548 Vector<FontRun> fontRuns10;
1549 fontRuns10.PushBack( fontRun1001 );
1550 fontRuns10.PushBack( fontRun1002 );
1551 fontRuns10.PushBack( fontRun1003 );
1552 fontRuns10.PushBack( fontRun1004 );
1554 FontDescriptionRun fontDescription1001 =
1560 const_cast<char*>( "TizenSans" ),
1562 TextAbstraction::FontWeight::NORMAL,
1563 TextAbstraction::FontWidth::NORMAL,
1564 TextAbstraction::FontSlant::NORMAL,
1572 FontDescriptionRun fontDescription1002 =
1578 const_cast<char*>( "TizenSansHebrew" ),
1580 TextAbstraction::FontWeight::NORMAL,
1581 TextAbstraction::FontWidth::NORMAL,
1582 TextAbstraction::FontSlant::NORMAL,
1590 FontDescriptionRun fontDescription1003 =
1596 const_cast<char*>( "TizenSans" ),
1598 TextAbstraction::FontWeight::NORMAL,
1599 TextAbstraction::FontWidth::NORMAL,
1600 TextAbstraction::FontSlant::NORMAL,
1608 FontDescriptionRun fontDescription1004 =
1614 const_cast<char*>( "TizenSansHebrew" ),
1616 TextAbstraction::FontWeight::NORMAL,
1617 TextAbstraction::FontWidth::NORMAL,
1618 TextAbstraction::FontSlant::NORMAL,
1626 Vector<FontDescriptionRun> fontDescriptions10;
1627 fontDescriptions10.PushBack( fontDescription1001 );
1628 fontDescriptions10.PushBack( fontDescription1002 );
1629 fontDescriptions10.PushBack( fontDescription1003 );
1630 fontDescriptions10.PushBack( fontDescription1004 );
1632 FontRun fontRun1101 =
1640 Vector<FontRun> fontRuns11;
1641 fontRuns11.PushBack( fontRun1101 );
1643 FontDescriptionRun fontDescription1101 =
1649 const_cast<char*>( "TizenSans" ),
1651 TextAbstraction::FontWeight::NORMAL,
1652 TextAbstraction::FontWidth::NORMAL,
1653 TextAbstraction::FontSlant::NORMAL,
1661 Vector<FontDescriptionRun> fontDescriptions11;
1662 fontDescriptions11.PushBack( fontDescription1101 );
1664 FontRun fontRun1201 =
1672 FontRun fontRun1202 =
1680 FontRun fontRun1203 =
1688 Vector<FontRun> fontRuns12;
1689 fontRuns12.PushBack( fontRun1201 );
1690 fontRuns12.PushBack( fontRun1202 );
1691 fontRuns12.PushBack( fontRun1203 );
1693 FontDescriptionRun fontDescription1201 =
1699 const_cast<char*>( "TizenSans" ),
1701 TextAbstraction::FontWeight::NORMAL,
1702 TextAbstraction::FontWidth::NORMAL,
1703 TextAbstraction::FontSlant::NORMAL,
1711 FontDescriptionRun fontDescription1202 =
1717 const_cast<char*>( "TizenSans" ),
1719 TextAbstraction::FontWeight::NORMAL,
1720 TextAbstraction::FontWidth::NORMAL,
1721 TextAbstraction::FontSlant::NORMAL,
1729 FontDescriptionRun fontDescription1203 =
1735 const_cast<char*>( "TizenSans" ),
1737 TextAbstraction::FontWeight::NORMAL,
1738 TextAbstraction::FontWidth::NORMAL,
1739 TextAbstraction::FontSlant::NORMAL,
1747 Vector<FontDescriptionRun> fontDescriptions12;
1748 fontDescriptions12.PushBack( fontDescription1201 );
1749 fontDescriptions12.PushBack( fontDescription1202 );
1750 fontDescriptions12.PushBack( fontDescription1203 );
1752 const ValidateFontsData data[] =
1757 "/tizen/TizenSansRegular.ttf",
1758 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
1766 "Easy latin script.",
1768 "/tizen/TizenSansRegular.ttf",
1769 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
1777 "Different paragraphs.",
1778 "Hello world\nhello world\ndemo",
1779 "/tizen/TizenSansRegular.ttf",
1780 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
1788 "Different paragraphs. Update the initial paragraph.",
1789 "Hello world\nhello world\ndemo",
1790 "/tizen/TizenSansRegular.ttf",
1791 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
1799 "Different paragraphs. Update the middle paragraph.",
1800 "Hello world\nhello world\ndemo",
1801 "/tizen/TizenSansRegular.ttf",
1802 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
1810 "Different paragraphs. Update the final paragraph.",
1811 "Hello world\nhello world\ndemo",
1812 "/tizen/TizenSansRegular.ttf",
1813 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
1821 "Hebrew text. Default font: latin",
1823 "/tizen/TizenSansRegular.ttf",
1824 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
1832 "Hebrew text. Default font: hebrew",
1834 "/tizen/TizenSansHebrewRegular.ttf",
1835 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
1844 "\xF0\x9F\x98\x81\xF0\x9F\x98\x82\xF0\x9F\x98\x83\xF0\x9F\x98\x84",
1845 "/tizen/BreezeColorEmoji.ttf",
1854 "Mix text. Default font: latin. Different font sizes",
1855 "Hello world, שלום עולם, hello world, שלום עולם",
1856 "/tizen/TizenSansRegular.ttf",
1857 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
1865 "Unknown script -> changed to LATIN",
1866 "WRC – The Official App",
1867 "/tizen/TizenSansRegular.ttf",
1868 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
1878 "/tizen/TizenSansRegular.ttf",
1879 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
1887 const unsigned int numberOfTests = 12u;
1889 for( unsigned int index = 0u; index < numberOfTests; ++index )
1891 if( !ValidateFontTest( data[index] ) )
1893 tet_result(TET_FAIL);
1897 tet_result(TET_PASS);
1901 int UtcDaliTextMultiLanguageValidateFontsPerScriptCache(void)
1903 ToolkitTestApplication application;
1904 tet_infoline(" UtcDaliTextMultiLanguageValidateFontsPerScriptCache");
1906 std::size_t MAX_VALIDATE_FONTS_PER_SCRIPT_CACHE_SIZE = 63u;
1907 std::size_t VALIDATE_FONTS_PER_SCRIPT_REMAIN_COUNT = 8u;
1909 Dali::Toolkit::Text::Internal::ValidateFontsPerScript* validateFontsPerScript = new Dali::Toolkit::Text::Internal::ValidateFontsPerScript();
1911 for(std::size_t i = 0u; i < MAX_VALIDATE_FONTS_PER_SCRIPT_CACHE_SIZE; i ++)
1914 validateFontsPerScript->Cache(fontId);
1917 DALI_TEST_EQUALS(MAX_VALIDATE_FONTS_PER_SCRIPT_CACHE_SIZE, validateFontsPerScript->mValidFonts.Count(), TEST_LOCATION);
1919 FontId fontId = MAX_VALIDATE_FONTS_PER_SCRIPT_CACHE_SIZE;
1920 validateFontsPerScript->Cache(fontId);
1922 DALI_TEST_EQUALS(VALIDATE_FONTS_PER_SCRIPT_REMAIN_COUNT, validateFontsPerScript->mValidFonts.Count(), TEST_LOCATION);
1927 int UtcDaliTextMultiLanguageDefaultFontsCache(void)
1929 ToolkitTestApplication application;
1930 tet_infoline(" UtcDaliTextMultiLanguageDefaultFontsCache");
1932 std::size_t MAX_DEFAULT_FONTS_CACHE_SIZE = 15;
1933 std::size_t DEFAULT_FONTS_REMAIN_COUNT = 2;
1935 Dali::Toolkit::Text::Internal::DefaultFonts* defaultFontsPerScript = new Dali::Toolkit::Text::Internal::DefaultFonts();
1937 for(std::size_t i = 0u; i < MAX_DEFAULT_FONTS_CACHE_SIZE; i ++)
1939 TextAbstraction::FontDescription fontDescription;
1941 defaultFontsPerScript->Cache(fontDescription, fontId);
1944 DALI_TEST_EQUALS(MAX_DEFAULT_FONTS_CACHE_SIZE, defaultFontsPerScript->mFonts.size(), TEST_LOCATION);
1946 TextAbstraction::FontDescription fontDescription;
1947 FontId fontId = MAX_DEFAULT_FONTS_CACHE_SIZE;
1948 defaultFontsPerScript->Cache(fontDescription, fontId);
1950 DALI_TEST_EQUALS(DEFAULT_FONTS_REMAIN_COUNT, defaultFontsPerScript->mFonts.size(), TEST_LOCATION);