2 * Copyright (c) 2018 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/segmentation.h>
28 #include <dali-toolkit/internal/text/text-run-container.h>
29 #include <dali-toolkit-test-suite-utils.h>
30 #include <dali-toolkit/dali-toolkit.h>
33 using namespace Toolkit;
36 // Tests the following functions with different scripts.
38 // void MergeFontDescriptions(const Vector<FontDescriptionRun>& fontDescriptions,
39 // const TextAbstraction::FontDescription& defaultFontDescription,
40 // TextAbstraction::PointSize26Dot6 defaultPointSize,
41 // float fontSizeScale,
42 // CharacterIndex characterIndex,
43 // TextAbstraction::FontDescription& fontDescription,
44 // TextAbstraction::PointSize26Dot6& fontPointSize,
45 // bool& isDefaultFont);
47 // Script GetScript(Length index,
48 // Vector<ScriptRun>::ConstIterator& scriptRunIt,
49 // const Vector<ScriptRun>::ConstIterator& scriptRunEndIt);
51 // Constructor, destructor and MultilanguageSupport::Get()
53 // void MultilanguageSupport::SetScripts(const Vector<Character>& text,
54 // CharacterIndex startIndex,
55 // Length numberOfCharacters,
56 // Vector<ScriptRun>& scripts);
58 // void MultilanguageSupport::ValidateFonts(const Vector<Character>& text,
59 // const Vector<ScriptRun>& scripts,
60 // const Vector<FontDescriptionRun>& fontDescriptions,
61 // const TextAbstraction::FontDescription& defaultFontDescription,
62 // TextAbstraction::PointSize26Dot6 defaultFontPointSize,
63 // float fontSizeScale,
64 // CharacterIndex startIndex,
65 // Length numberOfCharacters,
66 // Vector<FontRun>& fonts);
68 //////////////////////////////////////////////////////////
73 const std::string DEFAULT_FONT_DIR( "/resources/fonts" );
74 const unsigned int EMOJI_FONT_SIZE = 3840u; // 60 * 64
75 const unsigned int NON_DEFAULT_FONT_SIZE = 40u;
77 struct MergeFontDescriptionsData
79 std::string description; ///< Description of the experiment.
80 Vector<FontDescriptionRun> fontDescriptionRuns; ///< The font description runs.
81 TextAbstraction::FontDescription defaultFontDescription; ///< The default font description.
82 TextAbstraction::PointSize26Dot6 defaultPointSize; ///< The default point size.
83 float fontSizeScale; ///< The font's size scale.
84 unsigned int startIndex; ///< The start index.
85 unsigned int numberOfCharacters; ///< The number of characters.
86 Vector<FontId> expectedFontIds; ///< The expected font ids.
87 Vector<bool> expectedIsDefault; ///< The expected font ids.
92 std::string description; ///< Description of the experiment.
93 std::string text; ///< Input text.
94 unsigned int index; ///< The index of the first character to update the script.
95 unsigned int numberOfCharacters; ///< The numbers of characters to update the script.
96 Vector<ScriptRun> scriptRuns; ///< Expected script runs.
99 struct ValidateFontsData
101 std::string description; ///< Description of the experiment.
102 std::string text; ///< Input text.
103 std::string defaultFont; ///< The default font.
104 unsigned int defaultFontSize; ///< The default font size.
105 float fontSizeScale; ///< The font's size scale.
106 unsigned int index; ///< The index of the first character to update the script.
107 unsigned int numberOfCharacters; ///< The numbers of characters to update the script.
108 Vector<FontDescriptionRun> fontDescriptionRuns; ///< The font description runs.
109 Vector<FontRun> fontRuns; ///< The expected font runs.
112 //////////////////////////////////////////////////////////
113 bool MergeFontDescriptionsTest( const MergeFontDescriptionsData& data )
115 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
117 Vector<FontId> fontIds;
118 fontIds.Resize( data.startIndex + data.numberOfCharacters, 0u );
119 Vector<bool> isDefaultFont;
120 isDefaultFont.Resize( data.startIndex + data.numberOfCharacters, true );
122 for( unsigned int index = data.startIndex; index < data.startIndex + data.numberOfCharacters; ++index )
124 TextAbstraction::FontDescription fontDescription;
125 TextAbstraction::PointSize26Dot6 fontPointSize = TextAbstraction::FontClient::DEFAULT_POINT_SIZE;
127 MergeFontDescriptions( data.fontDescriptionRuns,
128 data.defaultFontDescription,
129 data.defaultPointSize,
134 isDefaultFont[index] );
136 if( !isDefaultFont[index] )
138 fontIds[index] = fontClient.GetFontId( fontDescription, fontPointSize );
142 if( fontIds.Count() != data.expectedFontIds.Count() )
144 std::cout << data.description << " Different number of font ids : " << fontIds.Count() << ", expected : " << data.expectedFontIds.Count() << std::endl;
148 for( unsigned int index = 0u; index < fontIds.Count(); ++index )
150 if( fontIds[index] != data.expectedFontIds[index] )
152 std::cout << data.description << " Different font id at index : " << index << ", font id : " << fontIds[index] << ", expected : " << data.expectedFontIds[index] << std::endl;
153 std::cout << " font ids : ";
154 for( unsigned int i=0;i<fontIds.Count();++i)
156 std::cout << fontIds[i] << " ";
158 std::cout << std::endl;
159 std::cout << " expected font ids : ";
160 for( unsigned int i=0;i<data.expectedFontIds.Count();++i)
162 std::cout << data.expectedFontIds[i] << " ";
164 std::cout << std::endl;
168 if( isDefaultFont[index] != data.expectedIsDefault[index] )
170 std::cout << data.description << " Different 'is font default' at index : " << index << ", is font default : " << isDefaultFont[index] << ", expected : " << data.expectedIsDefault[index] << std::endl;
178 bool ScriptsTest( const ScriptsData& data )
180 MultilanguageSupport multilanguageSupport = MultilanguageSupport::Get();
182 // 1) Convert to utf32
183 Vector<Character> utf32;
184 utf32.Resize( data.text.size() );
186 const uint32_t numberOfCharacters = ( data.text.size() == 0 ) ? 0 :
187 Utf8ToUtf32( reinterpret_cast<const uint8_t* const>( data.text.c_str() ),
191 utf32.Resize( numberOfCharacters );
193 // 2) Set the script info.
194 Vector<ScriptRun> scripts;
195 multilanguageSupport.SetScripts( utf32,
200 if( ( 0u != data.index ) ||
201 ( numberOfCharacters != data.numberOfCharacters ) )
203 // 3) Clear the scripts.
204 ClearCharacterRuns( data.index,
205 data.index + data.numberOfCharacters - 1u,
208 multilanguageSupport.SetScripts( utf32,
210 data.numberOfCharacters,
214 // 4) Compare the results.
216 tet_printf( "Testing %s\n", data.description.c_str() );
217 if( scripts.Count() != data.scriptRuns.Count() )
219 tet_printf("ScriptsTest FAIL: different number of scripts. %d, should be %d\n", scripts.Count(), data.scriptRuns.Count() );
220 for( Vector<ScriptRun>::ConstIterator it = scripts.Begin(); it != scripts.End(); ++it)
222 const ScriptRun& run = *it;
224 std::cout << " index : " << run.characterRun.characterIndex << ", num chars : " << run.characterRun.numberOfCharacters << ", script : [" << TextAbstraction::ScriptName[run.script] << "]" << std::endl;
229 for( unsigned int index = 0u; index < scripts.Count(); ++index )
231 const ScriptRun& scriptRun1 = scripts[index];
232 const ScriptRun& scriptRun2 = data.scriptRuns[index];
234 if( scriptRun1.characterRun.characterIndex != scriptRun2.characterRun.characterIndex )
236 tet_printf("ScriptsTest FAIL: different character index. %d, should be %d\n", scriptRun1.characterRun.characterIndex, scriptRun2.characterRun.characterIndex );
240 if( scriptRun1.characterRun.numberOfCharacters != scriptRun2.characterRun.numberOfCharacters )
242 tet_printf("ScriptsTest FAIL: different number of characters. %d, should be %d\n", scriptRun1.characterRun.numberOfCharacters, scriptRun2.characterRun.numberOfCharacters );
246 if( scriptRun1.script != scriptRun2.script )
248 tet_printf("ScriptsTest FAIL: script index: %u, different script. %s, should be %s\n", index, TextAbstraction::ScriptName[scriptRun1.script], TextAbstraction::ScriptName[scriptRun2.script] );
256 bool ValidateFontTest( const ValidateFontsData& data )
258 MultilanguageSupport multilanguageSupport = MultilanguageSupport::Get();
259 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
261 // 1) Convert to utf32
262 Vector<Character> utf32;
263 utf32.Resize( data.text.size() );
265 const uint32_t numberOfCharacters = (data.text.size() == 0 ) ? 0 :
266 Utf8ToUtf32( reinterpret_cast<const uint8_t* const>( data.text.c_str() ),
269 utf32.Resize( numberOfCharacters );
271 // 2) Set the script info.
272 Vector<ScriptRun> scripts;
273 multilanguageSupport.SetScripts( utf32,
278 char* pathNamePtr = get_current_dir_name();
279 const std::string pathName( pathNamePtr );
282 // Get the default font id.
283 const FontId defaultFontId = fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + data.defaultFont,
284 data.defaultFontSize );
285 TextAbstraction::FontDescription defaultFontDescription;
286 fontClient.GetDescription( defaultFontId, defaultFontDescription );
288 const TextAbstraction::PointSize26Dot6 defaultPointSize = fontClient.GetPointSize( defaultFontId );
290 Vector<FontRun> fontRuns;
292 // 3) Validate the fonts.
293 multilanguageSupport.ValidateFonts( utf32,
295 data.fontDescriptionRuns,
296 defaultFontDescription,
303 if( ( 0u != data.index ) ||
304 ( numberOfCharacters != data.numberOfCharacters ) )
306 // 4) Clear the fonts.
307 ClearCharacterRuns( data.index,
308 data.index + data.numberOfCharacters - 1u,
311 multilanguageSupport.ValidateFonts( utf32,
313 data.fontDescriptionRuns,
314 defaultFontDescription,
318 data.numberOfCharacters,
322 // 5) Compare the results.
323 if( data.fontRuns.Count() != fontRuns.Count() )
325 std::cout << " Different number of font runs : " << fontRuns.Count() << ", expected : " << data.fontRuns.Count() << std::endl;
330 for( unsigned int index = 0; index < data.fontRuns.Count(); ++index )
332 const FontRun& run = fontRuns[index];
333 const FontRun& expectedRun = data.fontRuns[index];
335 if( run.characterRun.characterIndex != expectedRun.characterRun.characterIndex )
337 std::cout << " character run : " << index << ", index : " << run.characterRun.characterIndex << ", expected : " << expectedRun.characterRun.characterIndex << std::endl;
340 if( run.characterRun.numberOfCharacters != expectedRun.characterRun.numberOfCharacters )
342 std::cout << " character run : " << index << ", num chars : " << run.characterRun.numberOfCharacters << ", expected : " << expectedRun.characterRun.numberOfCharacters << std::endl;
345 if( run.fontId != expectedRun.fontId )
347 std::cout << " character run : " << index << ", font : " << run.fontId << ", expected : " << expectedRun.fontId << std::endl;
357 int UtcDaliTextGetScript(void)
359 ToolkitTestApplication application;
360 tet_infoline(" UtcDaliTextGetScript");
362 Script script = TextAbstraction::LATIN;
364 // Text with no scripts.
365 Vector<ScriptRun> scriptRuns;
366 Vector<ScriptRun>::ConstIterator scriptRunIt = scriptRuns.Begin();
367 script = GetScript( 0u,
371 DALI_TEST_CHECK( TextAbstraction::UNKNOWN == script );
373 const unsigned int numberOfCharacters = 7u;
375 ScriptRun scriptRun01 =
381 TextAbstraction::LATIN
383 ScriptRun scriptRun02 =
389 TextAbstraction::HEBREW
391 ScriptRun scriptRun03 =
397 TextAbstraction::ARABIC
399 scriptRuns.PushBack( scriptRun01 );
400 scriptRuns.PushBack( scriptRun02 );
401 scriptRuns.PushBack( scriptRun03 );
404 TextAbstraction::Script expectedScripts[]=
406 TextAbstraction::LATIN,
407 TextAbstraction::LATIN,
408 TextAbstraction::HEBREW,
409 TextAbstraction::HEBREW,
410 TextAbstraction::ARABIC,
411 TextAbstraction::ARABIC,
412 TextAbstraction::UNKNOWN
415 scriptRunIt = scriptRuns.Begin();
416 for( unsigned int index = 0u; index < numberOfCharacters; ++index )
418 script = GetScript( index,
422 DALI_TEST_CHECK( expectedScripts[index] == script );
424 DALI_TEST_CHECK( scriptRunIt == scriptRuns.End() );
426 tet_result(TET_PASS);
430 int UtcDaliTextMergeFontDescriptions(void)
432 ToolkitTestApplication application;
433 tet_infoline(" UtcDaliTextMergeFontDescriptions");
437 char* pathNamePtr = get_current_dir_name();
438 const std::string pathName( pathNamePtr );
441 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
442 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSans.ttf" );
443 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf" );
444 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", NON_DEFAULT_FONT_SIZE );
445 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf" );
446 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Italic.ttf" );
448 // To test the font width as GetFontId() with the font file path can't cache the width property.
449 TextAbstraction::FontDescription widthDescription;
450 widthDescription.path = "";
451 widthDescription.family = "DejaVu Serif";
452 widthDescription.weight = TextAbstraction::FontWeight::NORMAL;
453 widthDescription.width = TextAbstraction::FontWidth::EXPANDED;
454 widthDescription.slant = TextAbstraction::FontSlant::NORMAL;
455 fontClient.GetFontId( widthDescription );
459 TextAbstraction::FontDescription defaultFontDescription01;
460 Vector<FontDescriptionRun> fontDescriptionRuns01;
461 Vector<FontId> expectedFontIds01;
462 Vector<bool> expectedIsFontDefault01;
464 TextAbstraction::FontDescription defaultFontDescription02;
465 Vector<FontDescriptionRun> fontDescriptionRuns02;
466 Vector<FontId> expectedFontIds02;
467 expectedFontIds02.PushBack( 0u );
468 expectedFontIds02.PushBack( 0u );
469 Vector<bool> expectedIsFontDefault02;
470 expectedIsFontDefault02.PushBack( true );
471 expectedIsFontDefault02.PushBack( true );
473 TextAbstraction::FontDescription defaultFontDescription03;
474 defaultFontDescription03.family = "DejaVu Serif";
475 Vector<FontDescriptionRun> fontDescriptionRuns03;
477 FontDescriptionRun fontDescription0301 =
483 const_cast<char*>( "DejaVu Sans" ),
485 TextAbstraction::FontWeight::NONE,
486 TextAbstraction::FontWidth::NONE,
487 TextAbstraction::FontSlant::NONE,
488 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
495 FontDescriptionRun fontDescription0302 =
503 TextAbstraction::FontWeight::NONE,
504 TextAbstraction::FontWidth::NONE,
505 TextAbstraction::FontSlant::ITALIC,
506 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
513 FontDescriptionRun fontDescription0303 =
521 TextAbstraction::FontWeight::BOLD,
522 TextAbstraction::FontWidth::NONE,
523 TextAbstraction::FontSlant::NONE,
524 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
531 FontDescriptionRun fontDescription0304 =
539 TextAbstraction::FontWeight::NONE,
540 TextAbstraction::FontWidth::NONE,
541 TextAbstraction::FontSlant::NONE,
542 NON_DEFAULT_FONT_SIZE,
549 FontDescriptionRun fontDescription0305 =
557 TextAbstraction::FontWeight::NONE,
558 TextAbstraction::FontWidth::EXPANDED,
559 TextAbstraction::FontSlant::NONE,
560 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
568 fontDescriptionRuns03.PushBack( fontDescription0301 );
569 fontDescriptionRuns03.PushBack( fontDescription0302 );
570 fontDescriptionRuns03.PushBack( fontDescription0303 );
571 fontDescriptionRuns03.PushBack( fontDescription0304 );
572 fontDescriptionRuns03.PushBack( fontDescription0305 );
574 Vector<FontId> expectedFontIds03;
575 expectedFontIds03.PushBack( 1u );
576 expectedFontIds03.PushBack( 1u );
577 expectedFontIds03.PushBack( 5u );
578 expectedFontIds03.PushBack( 5u );
579 expectedFontIds03.PushBack( 4u );
580 expectedFontIds03.PushBack( 4u );
581 expectedFontIds03.PushBack( 3u );
582 expectedFontIds03.PushBack( 3u );
583 expectedFontIds03.PushBack( 6u );
584 expectedFontIds03.PushBack( 6u );
585 Vector<bool> expectedIsFontDefault03;
586 expectedIsFontDefault03.PushBack( false );
587 expectedIsFontDefault03.PushBack( false );
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 );
597 const MergeFontDescriptionsData data[] =
601 fontDescriptionRuns01,
602 defaultFontDescription01,
603 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
608 expectedIsFontDefault01
611 "No description runs.",
612 fontDescriptionRuns02,
613 defaultFontDescription02,
614 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
619 expectedIsFontDefault02
622 "Some description runs.",
623 fontDescriptionRuns03,
624 defaultFontDescription03,
625 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
630 expectedIsFontDefault03
633 const unsigned int numberOfTests = 3u;
635 for( unsigned int index = 0u; index < numberOfTests; ++index )
637 if( !MergeFontDescriptionsTest( data[index] ) )
639 tet_result(TET_FAIL);
643 tet_result(TET_PASS);
647 int UtcDaliTextMultiLanguageConstructor(void)
649 ToolkitTestApplication application;
650 tet_infoline(" UtcDaliTextMultiLanguageConstructor");
652 MultilanguageSupport multilanguageSupport;
653 DALI_TEST_CHECK( !multilanguageSupport );
655 MultilanguageSupport multilanguageSupport1 = MultilanguageSupport::Get();
656 DALI_TEST_CHECK( multilanguageSupport1 );
658 // To increase coverage.
659 MultilanguageSupport multilanguageSupport2 = MultilanguageSupport::Get();
660 DALI_TEST_CHECK( multilanguageSupport2 );
662 DALI_TEST_CHECK( multilanguageSupport1 == multilanguageSupport2 );
664 tet_result(TET_PASS);
668 int UtcDaliTextMultiLanguageSetScripts(void)
670 ToolkitTestApplication application;
671 tet_infoline(" UtcDaliTextMultiLanguageSetScripts" );
674 Vector<ScriptRun> scriptRuns00;
677 Vector<ScriptRun> scriptRuns01;
678 ScriptRun scriptRun0100 =
684 TextAbstraction::LATIN
686 scriptRuns01.PushBack( scriptRun0100 );
688 // Mix of LTR '\n'and RTL
689 Vector<ScriptRun> scriptRuns02;
690 ScriptRun scriptRun0200 =
696 TextAbstraction::LATIN
698 ScriptRun scriptRun0201 =
704 TextAbstraction::ARABIC
706 scriptRuns02.PushBack( scriptRun0200 );
707 scriptRuns02.PushBack( scriptRun0201 );
709 // Mix of RTL '\n'and LTR
710 Vector<ScriptRun> scriptRuns03;
711 ScriptRun scriptRun0300 =
717 TextAbstraction::ARABIC
719 ScriptRun scriptRun0301 =
725 TextAbstraction::LATIN
727 scriptRuns03.PushBack( scriptRun0300 );
728 scriptRuns03.PushBack( scriptRun0301 );
730 // White spaces. At the beginning of the text.
731 Vector<ScriptRun> scriptRuns04;
732 ScriptRun scriptRun0400 =
738 TextAbstraction::LATIN
740 scriptRuns04.PushBack( scriptRun0400 );
742 // White spaces. At the end of the text.
743 Vector<ScriptRun> scriptRuns05;
744 ScriptRun scriptRun0500 =
750 TextAbstraction::LATIN
752 scriptRuns05.PushBack( scriptRun0500 );
754 // White spaces. At the middle of the text.
755 Vector<ScriptRun> scriptRuns06;
756 ScriptRun scriptRun0600 =
762 TextAbstraction::LATIN
764 scriptRuns06.PushBack( scriptRun0600 );
766 // White spaces between different scripts.
767 Vector<ScriptRun> scriptRuns07;
768 ScriptRun scriptRun0700 =
774 TextAbstraction::LATIN
776 ScriptRun scriptRun0701 =
782 TextAbstraction::HANGUL
784 scriptRuns07.PushBack( scriptRun0700 );
785 scriptRuns07.PushBack( scriptRun0701 );
787 // White spaces between different scripts and differetn directions. Starting LTR.
788 Vector<ScriptRun> scriptRuns08;
789 ScriptRun scriptRun0800 =
795 TextAbstraction::LATIN
797 ScriptRun scriptRun0801 =
803 TextAbstraction::ARABIC
805 ScriptRun scriptRun0802 =
811 TextAbstraction::HANGUL
813 scriptRuns08.PushBack( scriptRun0800 );
814 scriptRuns08.PushBack( scriptRun0801 );
815 scriptRuns08.PushBack( scriptRun0802 );
817 // White spaces between different scripts and differetn directions. Starting RTL.
818 Vector<ScriptRun> scriptRuns09;
819 ScriptRun scriptRun0900 =
825 TextAbstraction::ARABIC
827 ScriptRun scriptRun0901 =
833 TextAbstraction::LATIN
835 ScriptRun scriptRun0902 =
841 TextAbstraction::HANGUL
843 ScriptRun scriptRun0903 =
849 TextAbstraction::ARABIC
851 scriptRuns09.PushBack( scriptRun0900 );
852 scriptRuns09.PushBack( scriptRun0901 );
853 scriptRuns09.PushBack( scriptRun0902 );
854 scriptRuns09.PushBack( scriptRun0903 );
856 // Paragraphs with different directions.
857 Vector<ScriptRun> scriptRuns10;
858 ScriptRun scriptRun1000 =
864 TextAbstraction::ARABIC
866 ScriptRun scriptRun1001 =
872 TextAbstraction::HEBREW
874 ScriptRun scriptRun1002 =
880 TextAbstraction::ARABIC
882 ScriptRun scriptRun1003 =
888 TextAbstraction::LATIN
890 ScriptRun scriptRun1004 =
896 TextAbstraction::HANGUL
898 ScriptRun scriptRun1005 =
904 TextAbstraction::ARABIC
906 ScriptRun scriptRun1006 =
912 TextAbstraction::LATIN
914 ScriptRun scriptRun1007 =
920 TextAbstraction::HEBREW
922 ScriptRun scriptRun1008 =
928 TextAbstraction::LATIN
930 ScriptRun scriptRun1009 =
936 TextAbstraction::ARABIC
938 ScriptRun scriptRun1010 =
944 TextAbstraction::HANGUL
946 ScriptRun scriptRun1011 =
952 TextAbstraction::HANGUL
954 scriptRuns10.PushBack( scriptRun1000 );
955 scriptRuns10.PushBack( scriptRun1001 );
956 scriptRuns10.PushBack( scriptRun1002 );
957 scriptRuns10.PushBack( scriptRun1003 );
958 scriptRuns10.PushBack( scriptRun1004 );
959 scriptRuns10.PushBack( scriptRun1005 );
960 scriptRuns10.PushBack( scriptRun1006 );
961 scriptRuns10.PushBack( scriptRun1007 );
962 scriptRuns10.PushBack( scriptRun1008 );
963 scriptRuns10.PushBack( scriptRun1009 );
964 scriptRuns10.PushBack( scriptRun1010 );
965 scriptRuns10.PushBack( scriptRun1011 );
967 // Paragraphs with no scripts mixed with paragraphs with scripts.
968 Vector<ScriptRun> scriptRuns11;
969 ScriptRun scriptRun1100 =
975 TextAbstraction::UNKNOWN
977 ScriptRun scriptRun1101 =
983 TextAbstraction::UNKNOWN
985 ScriptRun scriptRun1102 =
991 TextAbstraction::LATIN
993 ScriptRun scriptRun1103 =
999 TextAbstraction::UNKNOWN
1001 ScriptRun scriptRun1104 =
1007 TextAbstraction::UNKNOWN
1009 ScriptRun scriptRun1105 =
1015 TextAbstraction::HEBREW
1017 ScriptRun scriptRun1106 =
1023 TextAbstraction::UNKNOWN
1025 ScriptRun scriptRun1107 =
1031 TextAbstraction::UNKNOWN
1033 ScriptRun scriptRun1108 =
1039 TextAbstraction::UNKNOWN
1041 scriptRuns11.PushBack( scriptRun1100 );
1042 scriptRuns11.PushBack( scriptRun1101 );
1043 scriptRuns11.PushBack( scriptRun1102 );
1044 scriptRuns11.PushBack( scriptRun1103 );
1045 scriptRuns11.PushBack( scriptRun1104 );
1046 scriptRuns11.PushBack( scriptRun1105 );
1047 scriptRuns11.PushBack( scriptRun1106 );
1048 scriptRuns11.PushBack( scriptRun1107 );
1049 scriptRuns11.PushBack( scriptRun1108 );
1051 // Paragraphs with no scripts.
1052 Vector<ScriptRun> scriptRuns12;
1053 ScriptRun scriptRun1200 =
1059 TextAbstraction::UNKNOWN
1061 ScriptRun scriptRun1201 =
1067 TextAbstraction::UNKNOWN
1069 ScriptRun scriptRun1202 =
1075 TextAbstraction::UNKNOWN
1077 ScriptRun scriptRun1203 =
1083 TextAbstraction::UNKNOWN
1085 scriptRuns12.PushBack( scriptRun1200 );
1086 scriptRuns12.PushBack( scriptRun1201 );
1087 scriptRuns12.PushBack( scriptRun1202 );
1088 scriptRuns12.PushBack( scriptRun1203 );
1090 Vector<ScriptRun> scriptRuns13;
1091 ScriptRun scriptRun1301 =
1097 TextAbstraction::UNKNOWN
1099 scriptRuns13.PushBack( scriptRun1301 );
1101 const ScriptsData data[] =
1111 "Easy latin script",
1118 "Mix of LTR '\\n'and RTL",
1119 "Hello world\nمرحبا بالعالم",
1125 "Update mix of LTR '\\n'and RTL. Update LTR",
1126 "Hello world\nمرحبا بالعالم",
1132 "Update mix of LTR '\\n'and RTL. Update RTL",
1133 "Hello world\nمرحبا بالعالم",
1139 "Mix of RTL '\\n'and LTR",
1140 "مرحبا بالعالم\nHello world",
1146 "Update mix of RTL '\\n'and LTR. Update RTL",
1147 "مرحبا بالعالم\nHello world",
1153 "Update mix of RTL '\\n'and LTR. Update LTR",
1154 "مرحبا بالعالم\nHello world",
1160 "White spaces. At the beginning of the text.",
1167 "White spaces. At the end of the text.",
1174 "White spaces. At the middle of the text.",
1181 "White spaces between different scripts.",
1188 "White spaces between different scripts and differetn directions. Starting LTR.",
1189 " Hello world مرحبا بالعالم 안녕하세요 세계 ",
1195 "White spaces between different scripts and differetn directions. Starting RTL.",
1196 " مرحبا بالعالم Hello world 안녕하세요 세계 مرحبا بالعالم ",
1202 "Paragraphs with different directions.",
1203 " مرحبا بالعالم שלום עולם مرحبا بالعالم \n "
1204 " Hello world 안녕하세요 세계 \n "
1205 " مرحبا بالعالم Hello world שלום עולם \n "
1206 " Hello world مرحبا بالعالم 안녕하세요 세계 \n "
1213 "Update paragraphs with different directions. Update initial paragraphs.",
1214 " مرحبا بالعالم שלום עולם مرحبا بالعالم \n "
1215 " Hello world 안녕하세요 세계 \n "
1216 " مرحبا بالعالم Hello world שלום עולם \n "
1217 " Hello world مرحبا بالعالم 안녕하세요 세계 \n "
1224 "Update paragraphs with different directions. Update middle paragraphs.",
1225 " مرحبا بالعالم שלום עולם مرحبا بالعالم \n "
1226 " Hello world 안녕하세요 세계 \n "
1227 " مرحبا بالعالم Hello world שלום עולם \n "
1228 " Hello world مرحبا بالعالم 안녕하세요 세계 \n "
1235 "Update paragraphs with different directions. Update final paragraphs.",
1236 " مرحبا بالعالم שלום עולם مرحبا بالعالم \n "
1237 " Hello world 안녕하세요 세계 \n "
1238 " مرحبا بالعالم Hello world שלום עולם \n "
1239 " Hello world مرحبا بالعالم 안녕하세요 세계 \n "
1246 "Paragraphs with no scripts mixed with paragraphs with scripts.",
1247 " \n \n Hello world \n \n \n שלום עולם \n \n \n ",
1253 "Paragraphs with no scripts.",
1260 "Update paragraphs with no scripts. Update initial paragraphs.",
1267 "Update paragraphs with no scripts. Update middle paragraphs.",
1274 "Update paragraphs with no scripts. Update final paragraphs.",
1282 "ᚩᚯᚱᚸ", // Runic script not currentlu supported.
1288 const unsigned int numberOfTests = 24u;
1290 for( unsigned int index = 0u; index < numberOfTests; ++index )
1292 if( !ScriptsTest( data[index] ) )
1294 tet_result(TET_FAIL);
1298 tet_result(TET_PASS);
1302 int UtcDaliTextMultiLanguageValidateFonts01(void)
1304 ToolkitTestApplication application;
1305 tet_infoline(" UtcDaliTextMultiLanguageValidateFonts");
1307 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1309 char* pathNamePtr = get_current_dir_name();
1310 const std::string pathName( pathNamePtr );
1311 free( pathNamePtr );
1313 const PointSize26Dot6 pointSize01 = static_cast<PointSize26Dot6>( 21.f * 64.f );
1314 const PointSize26Dot6 pointSize02 = static_cast<PointSize26Dot6>( 35.f * 64.f );
1317 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansArabicRegular.ttf" );
1318 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansHebrewRegular.ttf" );
1319 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/BreezeColorEmoji.ttf", EMOJI_FONT_SIZE );
1320 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansRegular.ttf", pointSize01 );
1321 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansRegular.ttf", pointSize02 );
1322 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansHebrewRegular.ttf", pointSize01 );
1323 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansHebrewRegular.ttf", pointSize02 );
1325 // Font id 1 --> TizenSansArabicRegular.ttf
1326 // Font id 2 --> TizenSansHebrewRegular.ttf
1327 // Font id 3 --> BreezeColorEmoji.ttf
1328 // Font id 4 --> TizenSansRegular.ttf, size 8
1329 // Font id 5 --> TizenSansRegular.ttf, size 16
1330 // Font id 6 --> TizenSansHebrewRegular.ttf, size 8
1331 // Font id 7 --> TizenSansHebrewRegular.ttf, size 16
1332 // Font id 8 --> (default)
1334 Vector<FontRun> fontRuns01;
1335 Vector<FontDescriptionRun> fontDescriptions01;
1337 FontRun fontRun0201 =
1345 Vector<FontRun> fontRuns02;
1346 fontRuns02.PushBack( fontRun0201 );
1348 FontDescriptionRun fontDescription0201 =
1354 const_cast<char*>( "TizenSans" ),
1356 TextAbstraction::FontWeight::NORMAL,
1357 TextAbstraction::FontWidth::NORMAL,
1358 TextAbstraction::FontSlant::NORMAL,
1366 Vector<FontDescriptionRun> fontDescriptions02;
1367 fontDescriptions02.PushBack( fontDescription0201 );
1369 FontRun fontRun0301 =
1377 FontRun fontRun0302 =
1385 FontRun fontRun0303 =
1393 Vector<FontRun> fontRuns03;
1394 fontRuns03.PushBack( fontRun0301 );
1395 fontRuns03.PushBack( fontRun0302 );
1396 fontRuns03.PushBack( fontRun0303 );
1398 Vector<FontDescriptionRun> fontDescriptions03;
1400 FontRun fontRun0701 =
1408 FontRun fontRun0702 =
1416 FontRun fontRun0703 =
1424 Vector<FontRun> fontRuns07;
1425 fontRuns07.PushBack( fontRun0701 );
1426 fontRuns07.PushBack( fontRun0702 );
1427 fontRuns07.PushBack( fontRun0703 );
1429 FontDescriptionRun fontDescription0701 =
1435 const_cast<char*>( "TizenSansHebrew" ),
1437 TextAbstraction::FontWeight::NORMAL,
1438 TextAbstraction::FontWidth::NORMAL,
1439 TextAbstraction::FontSlant::NORMAL,
1447 FontDescriptionRun fontDescription0702 =
1453 const_cast<char*>( "TizenSansHebrew" ),
1455 TextAbstraction::FontWeight::NORMAL,
1456 TextAbstraction::FontWidth::NORMAL,
1457 TextAbstraction::FontSlant::NORMAL,
1465 Vector<FontDescriptionRun> fontDescriptions07;
1466 fontDescriptions07.PushBack( fontDescription0701 );
1467 fontDescriptions07.PushBack( fontDescription0702 );
1469 FontRun fontRun0801 =
1477 Vector<FontRun> fontRuns08;
1478 fontRuns08.PushBack( fontRun0801 );
1480 Vector<FontDescriptionRun> fontDescriptions08;
1482 FontRun fontRun0901 =
1490 Vector<FontRun> fontRuns09;
1491 fontRuns09.PushBack( fontRun0901 );
1493 Vector<FontDescriptionRun> fontDescriptions09;
1494 FontDescriptionRun fontDescription0901 =
1500 const_cast<char*>( "BreezeColorEmoji" ),
1502 TextAbstraction::FontWeight::NORMAL,
1503 TextAbstraction::FontWidth::NORMAL,
1504 TextAbstraction::FontSlant::NORMAL,
1512 fontDescriptions09.PushBack( fontDescription0901 );
1514 FontRun fontRun1001 =
1522 FontRun fontRun1002 =
1530 FontRun fontRun1003 =
1538 FontRun fontRun1004 =
1546 Vector<FontRun> fontRuns10;
1547 fontRuns10.PushBack( fontRun1001 );
1548 fontRuns10.PushBack( fontRun1002 );
1549 fontRuns10.PushBack( fontRun1003 );
1550 fontRuns10.PushBack( fontRun1004 );
1552 FontDescriptionRun fontDescription1001 =
1558 const_cast<char*>( "TizenSans" ),
1560 TextAbstraction::FontWeight::NORMAL,
1561 TextAbstraction::FontWidth::NORMAL,
1562 TextAbstraction::FontSlant::NORMAL,
1570 FontDescriptionRun fontDescription1002 =
1576 const_cast<char*>( "TizenSansHebrew" ),
1578 TextAbstraction::FontWeight::NORMAL,
1579 TextAbstraction::FontWidth::NORMAL,
1580 TextAbstraction::FontSlant::NORMAL,
1588 FontDescriptionRun fontDescription1003 =
1594 const_cast<char*>( "TizenSans" ),
1596 TextAbstraction::FontWeight::NORMAL,
1597 TextAbstraction::FontWidth::NORMAL,
1598 TextAbstraction::FontSlant::NORMAL,
1606 FontDescriptionRun fontDescription1004 =
1612 const_cast<char*>( "TizenSansHebrew" ),
1614 TextAbstraction::FontWeight::NORMAL,
1615 TextAbstraction::FontWidth::NORMAL,
1616 TextAbstraction::FontSlant::NORMAL,
1624 Vector<FontDescriptionRun> fontDescriptions10;
1625 fontDescriptions10.PushBack( fontDescription1001 );
1626 fontDescriptions10.PushBack( fontDescription1002 );
1627 fontDescriptions10.PushBack( fontDescription1003 );
1628 fontDescriptions10.PushBack( fontDescription1004 );
1630 FontRun fontRun1101 =
1638 Vector<FontRun> fontRuns11;
1639 fontRuns11.PushBack( fontRun1101 );
1641 FontDescriptionRun fontDescription1101 =
1647 const_cast<char*>( "TizenSans" ),
1649 TextAbstraction::FontWeight::NORMAL,
1650 TextAbstraction::FontWidth::NORMAL,
1651 TextAbstraction::FontSlant::NORMAL,
1659 Vector<FontDescriptionRun> fontDescriptions11;
1660 fontDescriptions11.PushBack( fontDescription1101 );
1662 FontRun fontRun1201 =
1670 FontRun fontRun1202 =
1678 FontRun fontRun1203 =
1686 Vector<FontRun> fontRuns12;
1687 fontRuns12.PushBack( fontRun1201 );
1688 fontRuns12.PushBack( fontRun1202 );
1689 fontRuns12.PushBack( fontRun1203 );
1691 FontDescriptionRun fontDescription1201 =
1697 const_cast<char*>( "TizenSans" ),
1699 TextAbstraction::FontWeight::NORMAL,
1700 TextAbstraction::FontWidth::NORMAL,
1701 TextAbstraction::FontSlant::NORMAL,
1709 FontDescriptionRun fontDescription1202 =
1715 const_cast<char*>( "TizenSans" ),
1717 TextAbstraction::FontWeight::NORMAL,
1718 TextAbstraction::FontWidth::NORMAL,
1719 TextAbstraction::FontSlant::NORMAL,
1727 FontDescriptionRun fontDescription1203 =
1733 const_cast<char*>( "TizenSans" ),
1735 TextAbstraction::FontWeight::NORMAL,
1736 TextAbstraction::FontWidth::NORMAL,
1737 TextAbstraction::FontSlant::NORMAL,
1745 Vector<FontDescriptionRun> fontDescriptions12;
1746 fontDescriptions12.PushBack( fontDescription1201 );
1747 fontDescriptions12.PushBack( fontDescription1202 );
1748 fontDescriptions12.PushBack( fontDescription1203 );
1750 const ValidateFontsData data[] =
1755 "/tizen/TizenSansRegular.ttf",
1756 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
1764 "Easy latin script.",
1766 "/tizen/TizenSansRegular.ttf",
1767 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
1775 "Different paragraphs.",
1776 "Hello world\nhello world\ndemo",
1777 "/tizen/TizenSansRegular.ttf",
1778 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
1786 "Different paragraphs. Update the initial paragraph.",
1787 "Hello world\nhello world\ndemo",
1788 "/tizen/TizenSansRegular.ttf",
1789 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
1797 "Different paragraphs. Update the middle paragraph.",
1798 "Hello world\nhello world\ndemo",
1799 "/tizen/TizenSansRegular.ttf",
1800 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
1808 "Different paragraphs. Update the final paragraph.",
1809 "Hello world\nhello world\ndemo",
1810 "/tizen/TizenSansRegular.ttf",
1811 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
1819 "Hebrew text. Default font: latin",
1821 "/tizen/TizenSansRegular.ttf",
1822 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
1830 "Hebrew text. Default font: hebrew",
1832 "/tizen/TizenSansHebrewRegular.ttf",
1833 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
1842 "\xF0\x9F\x98\x81\xF0\x9F\x98\x82\xF0\x9F\x98\x83\xF0\x9F\x98\x84",
1843 "/tizen/BreezeColorEmoji.ttf",
1852 "Mix text. Default font: latin. Different font sizes",
1853 "Hello world, שלום עולם, hello world, שלום עולם",
1854 "/tizen/TizenSansRegular.ttf",
1855 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
1863 "Unknown script -> changed to LATIN",
1864 "WRC – The Official App",
1865 "/tizen/TizenSansRegular.ttf",
1866 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
1876 "/tizen/TizenSansRegular.ttf",
1877 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
1885 const unsigned int numberOfTests = 12u;
1887 for( unsigned int index = 0u; index < numberOfTests; ++index )
1889 if( !ValidateFontTest( data[index] ) )
1891 tet_result(TET_FAIL);
1895 tet_result(TET_PASS);