2 * Copyright (c) 2015 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 // CharacterIndex characterIndex,
42 // TextAbstraction::FontDescription& fontDescription,
43 // TextAbstraction::PointSize26Dot6& fontPointSize,
44 // bool& isDefaultFont );
46 // Script GetScript( Length index,
47 // Vector<ScriptRun>::ConstIterator& scriptRunIt,
48 // const Vector<ScriptRun>::ConstIterator& scriptRunEndIt );
50 // Constructor, destructor and MultilanguageSupport::Get()
52 // void MultilanguageSupport::SetScripts( const Vector<Character>& text,
53 // CharacterIndex startIndex,
54 // Length numberOfCharacters,
55 // Vector<ScriptRun>& scripts );
57 // void MultilanguageSupport::ValidateFonts( const Vector<Character>& text,
58 // const Vector<ScriptRun>& scripts,
59 // const Vector<FontDescriptionRun>& fontDescriptions,
60 // const TextAbstraction::FontDescription& defaultFontDescription,
61 // TextAbstraction::PointSize26Dot6 defaultFontPointSize,
62 // CharacterIndex startIndex,
63 // Length numberOfCharacters,
64 // Vector<FontRun>& fonts );
66 //////////////////////////////////////////////////////////
71 const std::string DEFAULT_FONT_DIR( "/resources/fonts" );
72 const unsigned int EMOJI_FONT_SIZE = 3968u;
73 const unsigned int NON_DEFAULT_FONT_SIZE = 40u;
75 struct MergeFontDescriptionsData
77 std::string description; ///< Description of the experiment.
78 Vector<FontDescriptionRun> fontDescriptionRuns; ///< The font description runs.
79 TextAbstraction::FontDescription defaultFontDescription; ///< The default font description.
80 TextAbstraction::PointSize26Dot6 defaultPointSize; ///< The default point size.
81 unsigned int startIndex; ///< The start index.
82 unsigned int numberOfCharacters; ///< The number of characters.
83 Vector<FontId> expectedFontIds; ///< The expected font ids.
84 Vector<bool> expectedIsDefault; ///< The expected font ids.
89 std::string description; ///< Description of the experiment.
90 std::string text; ///< Input text.
91 unsigned int index; ///< The index of the first character to update the script.
92 unsigned int numberOfCharacters; ///< The numbers of characters to update the script.
93 Vector<ScriptRun> scriptRuns; ///< Expected script runs.
96 struct ValidateFontsData
98 std::string description; ///< Description of the experiment.
99 std::string text; ///< Input text.
100 std::string defaultFont; ///< The default font.
101 unsigned int defaultFontSize; ///< The default font size.
102 unsigned int index; ///< The index of the first character to update the script.
103 unsigned int numberOfCharacters; ///< The numbers of characters to update the script.
104 Vector<FontDescriptionRun> fontDescriptionRuns; ///< The font description runs.
105 Vector<FontRun> fontRuns; ///< The expected font runs.
108 //////////////////////////////////////////////////////////
109 void PrintFontDescription( FontId id )
111 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
113 TextAbstraction::FontDescription description;
114 fontClient.GetDescription( id, description );
116 const TextAbstraction::PointSize26Dot6 pointSize = fontClient.GetPointSize( id );
118 std::cout << std::endl << " font description for font id : " << id << std::endl;
119 std::cout << " font family : [" << description.family << "]" << std::endl;
120 std::cout << " font width : [" << TextAbstraction::FontWidth::Name[description.width] << "]" << std::endl;
121 std::cout << " font weight : [" << TextAbstraction::FontWeight::Name[description.weight] << "]" << std::endl;
122 std::cout << " font slant : [" << TextAbstraction::FontSlant::Name[description.slant] << "]" << std::endl;
123 std::cout << " font size : " << pointSize << std::endl;
126 bool MergeFontDescriptionsTest( const MergeFontDescriptionsData& data )
128 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
130 Vector<FontId> fontIds;
131 fontIds.Resize( data.startIndex + data.numberOfCharacters, 0u );
132 Vector<bool> isDefaultFont;
133 isDefaultFont.Resize( data.startIndex + data.numberOfCharacters, true );
135 for( unsigned int index = data.startIndex; index < data.startIndex + data.numberOfCharacters; ++index )
137 TextAbstraction::FontDescription fontDescription;
138 TextAbstraction::PointSize26Dot6 fontPointSize = TextAbstraction::FontClient::DEFAULT_POINT_SIZE;
140 MergeFontDescriptions( data.fontDescriptionRuns,
141 data.defaultFontDescription,
142 data.defaultPointSize,
146 isDefaultFont[index] );
148 if( !isDefaultFont[index] )
150 fontIds[index] = fontClient.GetFontId( fontDescription, fontPointSize );
154 if( fontIds.Count() != data.expectedFontIds.Count() )
156 std::cout << data.description << " Different number of font ids : " << fontIds.Count() << ", expected : " << data.expectedFontIds.Count() << std::endl;
160 for( unsigned int index = 0u; index < fontIds.Count(); ++index )
162 if( fontIds[index] != data.expectedFontIds[index] )
164 std::cout << data.description << " Different font id at index : " << index << ", font id : " << fontIds[index] << ", expected : " << data.expectedFontIds[index] << std::endl;
165 std::cout << " font ids : ";
166 for( unsigned int i=0;i<fontIds.Count();++i)
168 std::cout << fontIds[i] << " ";
170 std::cout << std::endl;
171 std::cout << " expected font ids : ";
172 for( unsigned int i=0;i<data.expectedFontIds.Count();++i)
174 std::cout << data.expectedFontIds[i] << " ";
176 std::cout << std::endl;
180 if( isDefaultFont[index] != data.expectedIsDefault[index] )
182 std::cout << data.description << " Different 'is font default' at index : " << index << ", is font default : " << isDefaultFont[index] << ", expected : " << data.expectedIsDefault[index] << std::endl;
190 bool ScriptsTest( const ScriptsData& data )
192 MultilanguageSupport multilanguageSupport = MultilanguageSupport::Get();
194 // 1) Convert to utf32
195 Vector<Character> utf32;
196 utf32.Resize( data.text.size() );
198 const uint32_t numberOfCharacters = Utf8ToUtf32( reinterpret_cast<const uint8_t* const>( data.text.c_str() ),
201 utf32.Resize( numberOfCharacters );
203 // 2) Set the script info.
204 Vector<ScriptRun> scripts;
205 multilanguageSupport.SetScripts( utf32,
210 if( ( 0u != data.index ) ||
211 ( numberOfCharacters != data.numberOfCharacters ) )
213 // 3) Clear the scripts.
214 ClearCharacterRuns( data.index,
215 data.index + data.numberOfCharacters - 1u,
218 multilanguageSupport.SetScripts( utf32,
220 data.numberOfCharacters,
224 // 4) Compare the results.
226 tet_printf( "Testing %s\n", data.description.c_str() );
227 if( scripts.Count() != data.scriptRuns.Count() )
229 tet_printf("ScriptsTest FAIL: different number of scripts. %d, should be %d\n", scripts.Count(), data.scriptRuns.Count() );
230 for( Vector<ScriptRun>::ConstIterator it = scripts.Begin(); it != scripts.End(); ++it)
232 const ScriptRun& run = *it;
234 std::cout << " index : " << run.characterRun.characterIndex << ", num chars : " << run.characterRun.numberOfCharacters << ", script : [" << TextAbstraction::ScriptName[run.script] << "]" << std::endl;
239 for( unsigned int index = 0u; index < scripts.Count(); ++index )
241 const ScriptRun& scriptRun1 = scripts[index];
242 const ScriptRun& scriptRun2 = data.scriptRuns[index];
244 if( scriptRun1.characterRun.characterIndex != scriptRun2.characterRun.characterIndex )
246 tet_printf("ScriptsTest FAIL: different character index. %d, should be %d\n", scriptRun1.characterRun.characterIndex, scriptRun2.characterRun.characterIndex );
250 if( scriptRun1.characterRun.numberOfCharacters != scriptRun2.characterRun.numberOfCharacters )
252 tet_printf("ScriptsTest FAIL: different number of characters. %d, should be %d\n", scriptRun1.characterRun.numberOfCharacters, scriptRun2.characterRun.numberOfCharacters );
256 if( scriptRun1.script != scriptRun2.script )
258 tet_printf("ScriptsTest FAIL: different script. %s, should be %s\n", TextAbstraction::ScriptName[scriptRun1.script], TextAbstraction::ScriptName[scriptRun2.script] );
266 bool ValidateFontTest( const ValidateFontsData& data )
268 MultilanguageSupport multilanguageSupport = MultilanguageSupport::Get();
269 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
271 // 1) Convert to utf32
272 Vector<Character> utf32;
273 utf32.Resize( data.text.size() );
275 const uint32_t numberOfCharacters = Utf8ToUtf32( reinterpret_cast<const uint8_t* const>( data.text.c_str() ),
278 utf32.Resize( numberOfCharacters );
280 // 2) Set the script info.
281 Vector<ScriptRun> scripts;
282 multilanguageSupport.SetScripts( utf32,
287 char* pathNamePtr = get_current_dir_name();
288 const std::string pathName( pathNamePtr );
291 // Get the default font id.
292 const FontId defaultFontId = fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + data.defaultFont,
293 data.defaultFontSize );
294 TextAbstraction::FontDescription defaultFontDescription;
295 fontClient.GetDescription( defaultFontId, defaultFontDescription );
297 const TextAbstraction::PointSize26Dot6 defaultPointSize = fontClient.GetPointSize( defaultFontId );
299 Vector<FontRun> fontRuns;
301 // 3) Validate the fonts.
302 multilanguageSupport.ValidateFonts( utf32,
304 data.fontDescriptionRuns,
305 defaultFontDescription,
311 if( ( 0u != data.index ) ||
312 ( numberOfCharacters != data.numberOfCharacters ) )
314 // 4) Clear the fonts.
315 ClearCharacterRuns( data.index,
316 data.index + data.numberOfCharacters - 1u,
319 multilanguageSupport.ValidateFonts( utf32,
321 data.fontDescriptionRuns,
322 defaultFontDescription,
325 data.numberOfCharacters,
329 // 5) Compare the results.
330 if( data.fontRuns.Count() != fontRuns.Count() )
332 std::cout << " Different number of font runs : " << fontRuns.Count() << ", expected : " << data.fontRuns.Count() << std::endl;
337 for( unsigned int index = 0; index < data.fontRuns.Count(); ++index )
339 const FontRun& run = fontRuns[index];
340 const FontRun& expectedRun = data.fontRuns[index];
342 if( run.characterRun.characterIndex != expectedRun.characterRun.characterIndex )
344 std::cout << " character run : " << index << ", index : " << run.characterRun.characterIndex << ", expected : " << expectedRun.characterRun.characterIndex << std::endl;
347 if( run.characterRun.numberOfCharacters != expectedRun.characterRun.numberOfCharacters )
349 std::cout << " character run : " << index << ", num chars : " << run.characterRun.numberOfCharacters << ", expected : " << expectedRun.characterRun.numberOfCharacters << std::endl;
352 if( run.fontId != expectedRun.fontId )
354 std::cout << " character run : " << index << ", font : " << run.fontId << ", expected : " << expectedRun.fontId << std::endl;
364 int UtcDaliTextGetScript(void)
366 ToolkitTestApplication application;
367 tet_infoline(" UtcDaliTextGetScript");
369 Script script = TextAbstraction::LATIN;
371 // Text with no scripts.
372 Vector<ScriptRun> scriptRuns;
373 Vector<ScriptRun>::ConstIterator scriptRunIt = scriptRuns.Begin();
374 script = GetScript( 0u,
378 DALI_TEST_CHECK( TextAbstraction::UNKNOWN == script );
380 const unsigned int numberOfCharacters = 7u;
382 ScriptRun scriptRun01 =
388 TextAbstraction::LATIN
390 ScriptRun scriptRun02 =
396 TextAbstraction::HEBREW
398 ScriptRun scriptRun03 =
404 TextAbstraction::ARABIC
406 scriptRuns.PushBack( scriptRun01 );
407 scriptRuns.PushBack( scriptRun02 );
408 scriptRuns.PushBack( scriptRun03 );
411 TextAbstraction::Script expectedScripts[]=
413 TextAbstraction::LATIN,
414 TextAbstraction::LATIN,
415 TextAbstraction::HEBREW,
416 TextAbstraction::HEBREW,
417 TextAbstraction::ARABIC,
418 TextAbstraction::ARABIC,
419 TextAbstraction::UNKNOWN
422 scriptRunIt = scriptRuns.Begin();
423 for( unsigned int index = 0u; index < numberOfCharacters; ++index )
425 script = GetScript( index,
429 DALI_TEST_CHECK( expectedScripts[index] == script );
431 DALI_TEST_CHECK( scriptRunIt == scriptRuns.End() );
433 tet_result(TET_PASS);
437 int UtcDaliTextMergeFontDescriptions(void)
439 ToolkitTestApplication application;
440 tet_infoline(" UtcDaliTextMergeFontDescriptions");
444 char* pathNamePtr = get_current_dir_name();
445 const std::string pathName( pathNamePtr );
448 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
449 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSans.ttf" );
450 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf" );
451 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", NON_DEFAULT_FONT_SIZE );
452 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf" );
453 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Italic.ttf" );
455 // To test the font width as GetFontId() with the font file path can't cache the width property.
456 TextAbstraction::FontDescription widthDescription;
457 widthDescription.path = "";
458 widthDescription.family = "DejaVu Serif";
459 widthDescription.weight = TextAbstraction::FontWeight::NORMAL;
460 widthDescription.width = TextAbstraction::FontWidth::EXPANDED;
461 widthDescription.slant = TextAbstraction::FontSlant::NORMAL;
462 fontClient.GetFontId( widthDescription );
466 TextAbstraction::FontDescription defaultFontDescription01;
467 Vector<FontDescriptionRun> fontDescriptionRuns01;
468 Vector<FontId> expectedFontIds01;
469 Vector<bool> expectedIsFontDefault01;
471 TextAbstraction::FontDescription defaultFontDescription02;
472 Vector<FontDescriptionRun> fontDescriptionRuns02;
473 Vector<FontId> expectedFontIds02;
474 expectedFontIds02.PushBack( 0u );
475 expectedFontIds02.PushBack( 0u );
476 Vector<bool> expectedIsFontDefault02;
477 expectedIsFontDefault02.PushBack( true );
478 expectedIsFontDefault02.PushBack( true );
480 TextAbstraction::FontDescription defaultFontDescription03;
481 defaultFontDescription03.family = "DejaVu Serif";
482 Vector<FontDescriptionRun> fontDescriptionRuns03;
484 FontDescriptionRun fontDescription0301 =
490 const_cast<char*>( "DejaVu Sans" ),
492 TextAbstraction::FontWeight::NONE,
493 TextAbstraction::FontWidth::NONE,
494 TextAbstraction::FontSlant::NONE,
495 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
502 FontDescriptionRun fontDescription0302 =
510 TextAbstraction::FontWeight::NONE,
511 TextAbstraction::FontWidth::NONE,
512 TextAbstraction::FontSlant::ITALIC,
513 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
520 FontDescriptionRun fontDescription0303 =
528 TextAbstraction::FontWeight::BOLD,
529 TextAbstraction::FontWidth::NONE,
530 TextAbstraction::FontSlant::NONE,
531 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
538 FontDescriptionRun fontDescription0304 =
546 TextAbstraction::FontWeight::NONE,
547 TextAbstraction::FontWidth::NONE,
548 TextAbstraction::FontSlant::NONE,
549 NON_DEFAULT_FONT_SIZE,
556 FontDescriptionRun fontDescription0305 =
564 TextAbstraction::FontWeight::NONE,
565 TextAbstraction::FontWidth::EXPANDED,
566 TextAbstraction::FontSlant::NONE,
567 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
575 fontDescriptionRuns03.PushBack( fontDescription0301 );
576 fontDescriptionRuns03.PushBack( fontDescription0302 );
577 fontDescriptionRuns03.PushBack( fontDescription0303 );
578 fontDescriptionRuns03.PushBack( fontDescription0304 );
579 fontDescriptionRuns03.PushBack( fontDescription0305 );
581 Vector<FontId> expectedFontIds03;
582 expectedFontIds03.PushBack( 1u );
583 expectedFontIds03.PushBack( 1u );
584 expectedFontIds03.PushBack( 5u );
585 expectedFontIds03.PushBack( 5u );
586 expectedFontIds03.PushBack( 4u );
587 expectedFontIds03.PushBack( 4u );
588 expectedFontIds03.PushBack( 3u );
589 expectedFontIds03.PushBack( 3u );
590 expectedFontIds03.PushBack( 6u );
591 expectedFontIds03.PushBack( 6u );
592 Vector<bool> expectedIsFontDefault03;
593 expectedIsFontDefault03.PushBack( false );
594 expectedIsFontDefault03.PushBack( false );
595 expectedIsFontDefault03.PushBack( false );
596 expectedIsFontDefault03.PushBack( false );
597 expectedIsFontDefault03.PushBack( false );
598 expectedIsFontDefault03.PushBack( false );
599 expectedIsFontDefault03.PushBack( false );
600 expectedIsFontDefault03.PushBack( false );
601 expectedIsFontDefault03.PushBack( false );
602 expectedIsFontDefault03.PushBack( false );
604 const MergeFontDescriptionsData data[] =
608 fontDescriptionRuns01,
609 defaultFontDescription01,
610 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
614 expectedIsFontDefault01
617 "No description runs.",
618 fontDescriptionRuns02,
619 defaultFontDescription02,
620 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
624 expectedIsFontDefault02
627 "Some description runs.",
628 fontDescriptionRuns03,
629 defaultFontDescription03,
630 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
634 expectedIsFontDefault03
637 const unsigned int numberOfTests = 3u;
639 for( unsigned int index = 0u; index < numberOfTests; ++index )
641 if( !MergeFontDescriptionsTest( data[index] ) )
643 tet_result(TET_FAIL);
647 tet_result(TET_PASS);
651 int UtcDaliTextMultiLanguageConstructor(void)
653 ToolkitTestApplication application;
654 tet_infoline(" UtcDaliTextMultiLanguageConstructor");
656 MultilanguageSupport multilanguageSupport;
657 DALI_TEST_CHECK( !multilanguageSupport );
659 MultilanguageSupport multilanguageSupport1 = MultilanguageSupport::Get();
660 DALI_TEST_CHECK( multilanguageSupport1 );
662 // To increase coverage.
663 MultilanguageSupport multilanguageSupport2 = MultilanguageSupport::Get();
664 DALI_TEST_CHECK( multilanguageSupport2 );
666 DALI_TEST_CHECK( multilanguageSupport1 == multilanguageSupport2 );
668 tet_result(TET_PASS);
672 int UtcDaliTextMultiLanguageSetScripts(void)
674 ToolkitTestApplication application;
675 tet_infoline(" UtcDaliTextMultiLanguageSetScripts" );
678 Vector<ScriptRun> scriptRuns00;
681 Vector<ScriptRun> scriptRuns01;
682 ScriptRun scriptRun0100 =
688 TextAbstraction::LATIN
690 scriptRuns01.PushBack( scriptRun0100 );
692 // Mix of LTR '\n'and RTL
693 Vector<ScriptRun> scriptRuns02;
694 ScriptRun scriptRun0200 =
700 TextAbstraction::LATIN
702 ScriptRun scriptRun0201 =
708 TextAbstraction::ARABIC
710 scriptRuns02.PushBack( scriptRun0200 );
711 scriptRuns02.PushBack( scriptRun0201 );
713 // Mix of RTL '\n'and LTR
714 Vector<ScriptRun> scriptRuns03;
715 ScriptRun scriptRun0300 =
721 TextAbstraction::ARABIC
723 ScriptRun scriptRun0301 =
729 TextAbstraction::LATIN
731 scriptRuns03.PushBack( scriptRun0300 );
732 scriptRuns03.PushBack( scriptRun0301 );
734 // White spaces. At the beginning of the text.
735 Vector<ScriptRun> scriptRuns04;
736 ScriptRun scriptRun0400 =
742 TextAbstraction::LATIN
744 scriptRuns04.PushBack( scriptRun0400 );
746 // White spaces. At the end of the text.
747 Vector<ScriptRun> scriptRuns05;
748 ScriptRun scriptRun0500 =
754 TextAbstraction::LATIN
756 scriptRuns05.PushBack( scriptRun0500 );
758 // White spaces. At the middle of the text.
759 Vector<ScriptRun> scriptRuns06;
760 ScriptRun scriptRun0600 =
766 TextAbstraction::LATIN
768 scriptRuns06.PushBack( scriptRun0600 );
770 // White spaces between different scripts.
771 Vector<ScriptRun> scriptRuns07;
772 ScriptRun scriptRun0700 =
778 TextAbstraction::LATIN
780 ScriptRun scriptRun0701 =
786 TextAbstraction::HANGUL
788 scriptRuns07.PushBack( scriptRun0700 );
789 scriptRuns07.PushBack( scriptRun0701 );
791 // White spaces between different scripts and differetn directions. Starting LTR.
792 Vector<ScriptRun> scriptRuns08;
793 ScriptRun scriptRun0800 =
799 TextAbstraction::LATIN
801 ScriptRun scriptRun0801 =
807 TextAbstraction::ARABIC
809 ScriptRun scriptRun0802 =
815 TextAbstraction::HANGUL
817 scriptRuns08.PushBack( scriptRun0800 );
818 scriptRuns08.PushBack( scriptRun0801 );
819 scriptRuns08.PushBack( scriptRun0802 );
821 // White spaces between different scripts and differetn directions. Starting RTL.
822 Vector<ScriptRun> scriptRuns09;
823 ScriptRun scriptRun0900 =
829 TextAbstraction::ARABIC
831 ScriptRun scriptRun0901 =
837 TextAbstraction::LATIN
839 ScriptRun scriptRun0902 =
845 TextAbstraction::HANGUL
847 ScriptRun scriptRun0903 =
853 TextAbstraction::ARABIC
855 scriptRuns09.PushBack( scriptRun0900 );
856 scriptRuns09.PushBack( scriptRun0901 );
857 scriptRuns09.PushBack( scriptRun0902 );
858 scriptRuns09.PushBack( scriptRun0903 );
860 // Paragraphs with different directions.
861 Vector<ScriptRun> scriptRuns10;
862 ScriptRun scriptRun1000 =
868 TextAbstraction::ARABIC
870 ScriptRun scriptRun1001 =
876 TextAbstraction::HEBREW
878 ScriptRun scriptRun1002 =
884 TextAbstraction::ARABIC
886 ScriptRun scriptRun1003 =
892 TextAbstraction::LATIN
894 ScriptRun scriptRun1004 =
900 TextAbstraction::HANGUL
902 ScriptRun scriptRun1005 =
908 TextAbstraction::ARABIC
910 ScriptRun scriptRun1006 =
916 TextAbstraction::LATIN
918 ScriptRun scriptRun1007 =
924 TextAbstraction::HEBREW
926 ScriptRun scriptRun1008 =
932 TextAbstraction::LATIN
934 ScriptRun scriptRun1009 =
940 TextAbstraction::ARABIC
942 ScriptRun scriptRun1010 =
948 TextAbstraction::HANGUL
950 ScriptRun scriptRun1011 =
956 TextAbstraction::HANGUL
958 scriptRuns10.PushBack( scriptRun1000 );
959 scriptRuns10.PushBack( scriptRun1001 );
960 scriptRuns10.PushBack( scriptRun1002 );
961 scriptRuns10.PushBack( scriptRun1003 );
962 scriptRuns10.PushBack( scriptRun1004 );
963 scriptRuns10.PushBack( scriptRun1005 );
964 scriptRuns10.PushBack( scriptRun1006 );
965 scriptRuns10.PushBack( scriptRun1007 );
966 scriptRuns10.PushBack( scriptRun1008 );
967 scriptRuns10.PushBack( scriptRun1009 );
968 scriptRuns10.PushBack( scriptRun1010 );
969 scriptRuns10.PushBack( scriptRun1011 );
971 // Paragraphs with no scripts mixed with paragraphs with scripts.
972 Vector<ScriptRun> scriptRuns11;
973 ScriptRun scriptRun1100 =
979 TextAbstraction::LATIN
981 ScriptRun scriptRun1101 =
987 TextAbstraction::LATIN
989 ScriptRun scriptRun1102 =
995 TextAbstraction::LATIN
997 ScriptRun scriptRun1103 =
1003 TextAbstraction::LATIN
1005 ScriptRun scriptRun1104 =
1011 TextAbstraction::LATIN
1013 ScriptRun scriptRun1105 =
1019 TextAbstraction::HEBREW
1021 ScriptRun scriptRun1106 =
1027 TextAbstraction::LATIN
1029 ScriptRun scriptRun1107 =
1035 TextAbstraction::LATIN
1037 ScriptRun scriptRun1108 =
1043 TextAbstraction::LATIN
1045 scriptRuns11.PushBack( scriptRun1100 );
1046 scriptRuns11.PushBack( scriptRun1101 );
1047 scriptRuns11.PushBack( scriptRun1102 );
1048 scriptRuns11.PushBack( scriptRun1103 );
1049 scriptRuns11.PushBack( scriptRun1104 );
1050 scriptRuns11.PushBack( scriptRun1105 );
1051 scriptRuns11.PushBack( scriptRun1106 );
1052 scriptRuns11.PushBack( scriptRun1107 );
1053 scriptRuns11.PushBack( scriptRun1108 );
1055 // Paragraphs with no scripts.
1056 Vector<ScriptRun> scriptRuns12;
1057 ScriptRun scriptRun1200 =
1063 TextAbstraction::LATIN
1065 ScriptRun scriptRun1201 =
1071 TextAbstraction::LATIN
1073 ScriptRun scriptRun1202 =
1079 TextAbstraction::LATIN
1081 ScriptRun scriptRun1203 =
1087 TextAbstraction::LATIN
1089 scriptRuns12.PushBack( scriptRun1200 );
1090 scriptRuns12.PushBack( scriptRun1201 );
1091 scriptRuns12.PushBack( scriptRun1202 );
1092 scriptRuns12.PushBack( scriptRun1203 );
1094 Vector<ScriptRun> scriptRuns13;
1095 ScriptRun scriptRun1301 =
1101 TextAbstraction::LATIN // An unknown script is transformed to LATIN
1103 scriptRuns13.PushBack( scriptRun1301 );
1105 const ScriptsData data[] =
1115 "Easy latin script",
1122 "Mix of LTR '\\n'and RTL",
1123 "Hello world\nمرحبا بالعالم",
1129 "Update mix of LTR '\\n'and RTL. Update LTR",
1130 "Hello world\nمرحبا بالعالم",
1136 "Update mix of LTR '\\n'and RTL. Update RTL",
1137 "Hello world\nمرحبا بالعالم",
1143 "Mix of RTL '\\n'and LTR",
1144 "مرحبا بالعالم\nHello world",
1150 "Update mix of RTL '\\n'and LTR. Update RTL",
1151 "مرحبا بالعالم\nHello world",
1157 "Update mix of RTL '\\n'and LTR. Update LTR",
1158 "مرحبا بالعالم\nHello world",
1164 "White spaces. At the beginning of the text.",
1171 "White spaces. At the end of the text.",
1178 "White spaces. At the middle of the text.",
1185 "White spaces between different scripts.",
1192 "White spaces between different scripts and differetn directions. Starting LTR.",
1193 " Hello world مرحبا بالعالم 안녕하세요 세계 ",
1199 "White spaces between different scripts and differetn directions. Starting RTL.",
1200 " مرحبا بالعالم Hello world 안녕하세요 세계 مرحبا بالعالم ",
1206 "Paragraphs with different directions.",
1207 " مرحبا بالعالم שלום עולם مرحبا بالعالم \n "
1208 " Hello world 안녕하세요 세계 \n "
1209 " مرحبا بالعالم Hello world שלום עולם \n "
1210 " Hello world مرحبا بالعالم 안녕하세요 세계 \n "
1217 "Update paragraphs with different directions. Update initial paragraphs.",
1218 " مرحبا بالعالم שלום עולם مرحبا بالعالم \n "
1219 " Hello world 안녕하세요 세계 \n "
1220 " مرحبا بالعالم Hello world שלום עולם \n "
1221 " Hello world مرحبا بالعالم 안녕하세요 세계 \n "
1228 "Update paragraphs with different directions. Update middle paragraphs.",
1229 " مرحبا بالعالم שלום עולם مرحبا بالعالم \n "
1230 " Hello world 안녕하세요 세계 \n "
1231 " مرحبا بالعالم Hello world שלום עולם \n "
1232 " Hello world مرحبا بالعالم 안녕하세요 세계 \n "
1239 "Update paragraphs with different directions. Update final paragraphs.",
1240 " مرحبا بالعالم שלום עולם مرحبا بالعالم \n "
1241 " Hello world 안녕하세요 세계 \n "
1242 " مرحبا بالعالم Hello world שלום עולם \n "
1243 " Hello world مرحبا بالعالم 안녕하세요 세계 \n "
1250 "Paragraphs with no scripts mixed with paragraphs with scripts.",
1251 " \n \n Hello world \n \n \n שלום עולם \n \n \n ",
1257 "Paragraphs with no scripts.",
1264 "Update paragraphs with no scripts. Update initial paragraphs.",
1271 "Update paragraphs with no scripts. Update middle paragraphs.",
1278 "Update paragraphs with no scripts. Update final paragraphs.",
1286 "ᚩᚯᚱᚸ", // Runic script not currentlu supported.
1292 const unsigned int numberOfTests = 24u;
1294 for( unsigned int index = 0u; index < numberOfTests; ++index )
1296 if( !ScriptsTest( data[index] ) )
1298 tet_result(TET_FAIL);
1302 tet_result(TET_PASS);
1306 int UtcDaliTextMultiLanguageValidateFonts01(void)
1308 ToolkitTestApplication application;
1309 tet_infoline(" UtcDaliTextMultiLanguageValidateFonts");
1311 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1313 char* pathNamePtr = get_current_dir_name();
1314 const std::string pathName( pathNamePtr );
1315 free( pathNamePtr );
1317 const PointSize26Dot6 pointSize01 = static_cast<PointSize26Dot6>( 21.f * 64.f );
1318 const PointSize26Dot6 pointSize02 = static_cast<PointSize26Dot6>( 35.f * 64.f );
1321 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansArabicRegular.ttf" );
1322 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansHebrewRegular.ttf" );
1323 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenColorEmoji.ttf", EMOJI_FONT_SIZE );
1324 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansRegular.ttf", pointSize01 );
1325 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansRegular.ttf", pointSize02 );
1326 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansHebrewRegular.ttf", pointSize01 );
1327 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansHebrewRegular.ttf", pointSize02 );
1329 // Font id 1 --> TizenSansArabicRegular.ttf
1330 // Font id 2 --> TizenSansHebrewRegular.ttf
1331 // Font id 3 --> TizenColorEmoji.ttf
1332 // Font id 4 --> TizenSansRegular.ttf, size 8
1333 // Font id 5 --> TizenSansRegular.ttf, size 16
1334 // Font id 6 --> TizenSansHebrewRegular.ttf, size 8
1335 // Font id 7 --> TizenSansHebrewRegular.ttf, size 16
1336 // Font id 8 --> (default)
1338 Vector<FontRun> fontRuns01;
1339 Vector<FontDescriptionRun> fontDescriptions01;
1341 FontRun fontRun0201 =
1349 Vector<FontRun> fontRuns02;
1350 fontRuns02.PushBack( fontRun0201 );
1352 FontDescriptionRun fontDescription0201 =
1358 const_cast<char*>( "TizenSans" ),
1360 TextAbstraction::FontWeight::NORMAL,
1361 TextAbstraction::FontWidth::NORMAL,
1362 TextAbstraction::FontSlant::NORMAL,
1370 Vector<FontDescriptionRun> fontDescriptions02;
1371 fontDescriptions02.PushBack( fontDescription0201 );
1373 FontRun fontRun0301 =
1381 FontRun fontRun0302 =
1389 FontRun fontRun0303 =
1397 Vector<FontRun> fontRuns03;
1398 fontRuns03.PushBack( fontRun0301 );
1399 fontRuns03.PushBack( fontRun0302 );
1400 fontRuns03.PushBack( fontRun0303 );
1402 Vector<FontDescriptionRun> fontDescriptions03;
1404 FontRun fontRun0701 =
1412 FontRun fontRun0702 =
1420 FontRun fontRun0703 =
1428 Vector<FontRun> fontRuns07;
1429 fontRuns07.PushBack( fontRun0701 );
1430 fontRuns07.PushBack( fontRun0702 );
1431 fontRuns07.PushBack( fontRun0703 );
1433 FontDescriptionRun fontDescription0701 =
1439 const_cast<char*>( "TizenSansHebrew" ),
1441 TextAbstraction::FontWeight::NORMAL,
1442 TextAbstraction::FontWidth::NORMAL,
1443 TextAbstraction::FontSlant::NORMAL,
1451 FontDescriptionRun fontDescription0702 =
1457 const_cast<char*>( "TizenSansHebrew" ),
1459 TextAbstraction::FontWeight::NORMAL,
1460 TextAbstraction::FontWidth::NORMAL,
1461 TextAbstraction::FontSlant::NORMAL,
1469 Vector<FontDescriptionRun> fontDescriptions07;
1470 fontDescriptions07.PushBack( fontDescription0701 );
1471 fontDescriptions07.PushBack( fontDescription0702 );
1473 FontRun fontRun0801 =
1481 Vector<FontRun> fontRuns08;
1482 fontRuns08.PushBack( fontRun0801 );
1484 Vector<FontDescriptionRun> fontDescriptions08;
1486 FontRun fontRun0901 =
1494 Vector<FontRun> fontRuns09;
1495 fontRuns09.PushBack( fontRun0901 );
1497 Vector<FontDescriptionRun> fontDescriptions09;
1498 FontDescriptionRun fontDescription0901 =
1504 const_cast<char*>( "TizenColorEmoji" ),
1506 TextAbstraction::FontWeight::NORMAL,
1507 TextAbstraction::FontWidth::NORMAL,
1508 TextAbstraction::FontSlant::NORMAL,
1516 fontDescriptions09.PushBack( fontDescription0901 );
1518 FontRun fontRun1001 =
1526 FontRun fontRun1002 =
1534 FontRun fontRun1003 =
1542 FontRun fontRun1004 =
1550 Vector<FontRun> fontRuns10;
1551 fontRuns10.PushBack( fontRun1001 );
1552 fontRuns10.PushBack( fontRun1002 );
1553 fontRuns10.PushBack( fontRun1003 );
1554 fontRuns10.PushBack( fontRun1004 );
1556 FontDescriptionRun fontDescription1001 =
1562 const_cast<char*>( "TizenSans" ),
1564 TextAbstraction::FontWeight::NORMAL,
1565 TextAbstraction::FontWidth::NORMAL,
1566 TextAbstraction::FontSlant::NORMAL,
1574 FontDescriptionRun fontDescription1002 =
1580 const_cast<char*>( "TizenSansHebrew" ),
1582 TextAbstraction::FontWeight::NORMAL,
1583 TextAbstraction::FontWidth::NORMAL,
1584 TextAbstraction::FontSlant::NORMAL,
1592 FontDescriptionRun fontDescription1003 =
1598 const_cast<char*>( "TizenSans" ),
1600 TextAbstraction::FontWeight::NORMAL,
1601 TextAbstraction::FontWidth::NORMAL,
1602 TextAbstraction::FontSlant::NORMAL,
1610 FontDescriptionRun fontDescription1004 =
1616 const_cast<char*>( "TizenSansHebrew" ),
1618 TextAbstraction::FontWeight::NORMAL,
1619 TextAbstraction::FontWidth::NORMAL,
1620 TextAbstraction::FontSlant::NORMAL,
1628 Vector<FontDescriptionRun> fontDescriptions10;
1629 fontDescriptions10.PushBack( fontDescription1001 );
1630 fontDescriptions10.PushBack( fontDescription1002 );
1631 fontDescriptions10.PushBack( fontDescription1003 );
1632 fontDescriptions10.PushBack( fontDescription1004 );
1634 const ValidateFontsData data[] =
1639 "/tizen/TizenSansRegular.ttf",
1640 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
1647 "Easy latin script.",
1649 "/tizen/TizenSansRegular.ttf",
1650 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
1657 "Different paragraphs.",
1658 "Hello world\nhello world\ndemo",
1659 "/tizen/TizenSansRegular.ttf",
1660 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
1667 "Different paragraphs. Update the initial paragraph.",
1668 "Hello world\nhello world\ndemo",
1669 "/tizen/TizenSansRegular.ttf",
1670 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
1677 "Different paragraphs. Update the middle paragraph.",
1678 "Hello world\nhello world\ndemo",
1679 "/tizen/TizenSansRegular.ttf",
1680 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
1687 "Different paragraphs. Update the final paragraph.",
1688 "Hello world\nhello world\ndemo",
1689 "/tizen/TizenSansRegular.ttf",
1690 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
1697 "Hebrew text. Default font: latin",
1699 "/tizen/TizenSansRegular.ttf",
1700 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
1707 "Hebrew text. Default font: hebrew",
1709 "/tizen/TizenSansHebrewRegular.ttf",
1710 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
1718 "\xF0\x9F\x98\x81\xF0\x9F\x98\x82\xF0\x9F\x98\x83\xF0\x9F\x98\x84",
1719 "/tizen/TizenColorEmoji.ttf",
1727 "Mix text. Default font: latin. Different font sizes",
1728 "Hello world, שלום עולם, hello world, שלום עולם",
1729 "/tizen/TizenSansRegular.ttf",
1730 TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
1737 const unsigned int numberOfTests = 10u;
1739 for( unsigned int index = 0u; index < numberOfTests; ++index )
1741 if( !ValidateFontTest( data[index] ) )
1743 tet_result(TET_FAIL);
1747 tet_result(TET_PASS);