X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit-internal%2Futc-Dali-Text-MultiLanguage.cpp;h=db59db38d57fc6870968aba558d349129c2956d6;hp=4b89f259809803eaf09f22bea106a4e2a0d756a6;hb=3e30971f9884dc48e80ef82de4ef85fc9dba1229;hpb=2d1ba388f9a941d273e95d729b9662cc1cdad822 diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-MultiLanguage.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-MultiLanguage.cpp index 4b89f25..db59db3 100644 --- a/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-MultiLanguage.cpp +++ b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-MultiLanguage.cpp @@ -16,45 +16,147 @@ */ #include - #include +#include + +#include #include -#include -#include #include +#include +#include +#include +#include #include #include - using namespace Dali; using namespace Toolkit; using namespace Text; // Tests the following functions with different scripts. +// +// void MergeFontDescriptions( const Vector& fontDescriptions, +// Vector& fontIds, +// Vector& isDefaultFont, +// const TextAbstraction::FontDescription& defaultFontDescription, +// TextAbstraction::PointSize26Dot6 defaultPointSize, +// CharacterIndex startIndex, +// Length numberOfCharacters ); +// +// Script GetScript( Length index, +// Vector::ConstIterator& scriptRunIt, +// const Vector::ConstIterator& scriptRunEndIt ); +// // Constructor, destructor and MultilanguageSupport::Get() -// void MultilanguageSupport::SetScripts( const Vector& text, const Vector& lineBreakInfo, Vector& scripts ); -// void MultilanguageSupport::ValidateFonts( const Vector& text, const Vector& scripts, Vector& fonts ); +// +// void MultilanguageSupport::SetScripts( const Vector& text, +// CharacterIndex startIndex, +// Length numberOfCharacters, +// Vector& scripts ); +// +// void MultilanguageSupport::ValidateFonts( const Vector& text, +// const Vector& scripts, +// const Vector& fontDescriptions, +// FontId defaultFontId, +// CharacterIndex startIndex, +// Length numberOfCharacters, +// Vector& fonts ); ////////////////////////////////////////////////////////// namespace { +const std::string DEFAULT_FONT_DIR( "/resources/fonts" ); +const unsigned int EMOJI_FONT_SIZE = 3968u; +const unsigned int NON_DEFAULT_FONT_SIZE = 40u; + +struct MergeFontDescriptionsData +{ + std::string description; ///< Description of the experiment. + Vector fontDescriptionRuns; ///< The font description runs. + TextAbstraction::FontDescription defaultFontDescription; ///< The default font description. + TextAbstraction::PointSize26Dot6 defaultPointSize; ///< The default point size. + unsigned int startIndex; ///< The start index. + unsigned int numberOfCharacters; ///< The number of characters. + Vector expectedFontIds; ///< The expected font ids. + Vector expectedIsDefault; ///< The expected font ids. +}; + struct ScriptsData { - std::string description; ///< Description of the experiment. - std::string text; ///< Input text. - Vector scriptRuns; ///< Expected script runs. + std::string description; ///< Description of the experiment. + std::string text; ///< Input text. + unsigned int index; ///< The index of the first character to update the script. + unsigned int numberOfCharacters; ///< The numbers of characters to update the script. + Vector scriptRuns; ///< Expected script runs. }; struct ValidateFontsData { - std::string description; ///< Description of the experiment. - std::string text; ///< Input text. + std::string description; ///< Description of the experiment. + std::string text; ///< Input text. + std::string defaultFont; ///< The default font. + unsigned int defaultFontSize; ///< The default font size. + unsigned int index; ///< The index of the first character to update the script. + unsigned int numberOfCharacters; ///< The numbers of characters to update the script. + Vector fontDescriptionRuns; ///< The font description runs. + Vector fontRuns; ///< The expected font runs. }; ////////////////////////////////////////////////////////// +bool MergeFontDescriptionsTest( const MergeFontDescriptionsData& data ) +{ + Vector fontIds; + fontIds.Resize( data.startIndex + data.numberOfCharacters, 0u ); + Vector isDefaultFont; + isDefaultFont.Resize( data.startIndex + data.numberOfCharacters, true ); + + MergeFontDescriptions( data.fontDescriptionRuns, + fontIds, + isDefaultFont, + data.defaultFontDescription, + data.defaultPointSize, + data.startIndex, + data.numberOfCharacters ); + + if( fontIds.Count() != data.expectedFontIds.Count() ) + { + std::cout << data.description << " Different number of font ids : " << fontIds.Count() << ", expected : " << data.expectedFontIds.Count() << std::endl; + return false; + } + + for( unsigned int index = 0u; index < fontIds.Count(); ++index ) + { + if( fontIds[index] != data.expectedFontIds[index] ) + { + std::cout << data.description << " Different font id at index : " << index << ", font id : " << fontIds[index] << ", expected : " << data.expectedFontIds[index] << std::endl; + std::cout << " font ids : "; + for( unsigned int i=0;i lineBreakInfo; - lineBreakInfo.Resize( numberOfCharacters ); - - SetLineBreakInfo( utf32, lineBreakInfo ); - - // 3) Set the script info. + // 2) Set the script info. Vector scripts; multilanguageSupport.SetScripts( utf32, - lineBreakInfo, + 0u, + numberOfCharacters, scripts ); + if( ( 0u != data.index ) || + ( numberOfCharacters != data.numberOfCharacters ) ) + { + // 3) Clear the scripts. + ClearCharacterRuns( data.index, + data.index + data.numberOfCharacters - 1u, + scripts ); + + multilanguageSupport.SetScripts( utf32, + data.index, + data.numberOfCharacters, + scripts ); + } + // 4) Compare the results. + tet_printf( "Testing %s\n", data.description.c_str() ); if( scripts.Count() != data.scriptRuns.Count() ) { - tet_infoline("ScriptsTest: different number of scripts."); + tet_printf("ScriptsTest FAIL: different number of scripts. %d, should be %d\n", scripts.Count(), data.scriptRuns.Count() ); return false; } @@ -95,19 +207,19 @@ bool ScriptsTest( const ScriptsData& data ) if( scriptRun1.characterRun.characterIndex != scriptRun2.characterRun.characterIndex ) { - tet_infoline("ScriptsTest: different character index."); + tet_printf("ScriptsTest FAIL: different character index. %d, should be %d\n", scriptRun1.characterRun.characterIndex, scriptRun2.characterRun.characterIndex ); return false; } if( scriptRun1.characterRun.numberOfCharacters != scriptRun2.characterRun.numberOfCharacters ) { - tet_infoline("ScriptsTest: different number of characters."); + tet_printf("ScriptsTest FAIL: different number of characters. %d, should be %d\n", scriptRun1.characterRun.numberOfCharacters, scriptRun2.characterRun.numberOfCharacters ); return false; } if( scriptRun1.script != scriptRun2.script ) { - tet_infoline("ScriptsTest: different script."); + tet_printf("ScriptsTest FAIL: different script. %s, should be %s\n", TextAbstraction::ScriptName[scriptRun1.script], TextAbstraction::ScriptName[scriptRun2.script] ); return false; } } @@ -118,6 +230,7 @@ bool ScriptsTest( const ScriptsData& data ) bool ValidateFontTest( const ValidateFontsData& data ) { MultilanguageSupport multilanguageSupport = MultilanguageSupport::Get(); + TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get(); // 1) Convert to utf32 Vector utf32; @@ -128,29 +241,371 @@ bool ValidateFontTest( const ValidateFontsData& data ) &utf32[0u] ); utf32.Resize( numberOfCharacters ); - // 2) Set the line break info. - Vector lineBreakInfo; - lineBreakInfo.Resize( numberOfCharacters ); - - SetLineBreakInfo( utf32, lineBreakInfo ); - - // 3) Set the script info. + // 2) Set the script info. Vector scripts; multilanguageSupport.SetScripts( utf32, - lineBreakInfo, + 0u, + numberOfCharacters, scripts ); - Vector fonts; - // 4) Validate the fonts + char* pathNamePtr = get_current_dir_name(); + const std::string pathName( pathNamePtr ); + free( pathNamePtr ); + + // Get the default font id. + const FontId defaultFontId = fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + data.defaultFont, + data.defaultFontSize ); + + Vector fontRuns; + + // 3) Validate the fonts. multilanguageSupport.ValidateFonts( utf32, scripts, - fonts ); + data.fontDescriptionRuns, + defaultFontId, + 0u, + numberOfCharacters, + fontRuns ); + + if( ( 0u != data.index ) || + ( numberOfCharacters != data.numberOfCharacters ) ) + { + // 4) Clear the fonts. + ClearCharacterRuns( data.index, + data.index + data.numberOfCharacters - 1u, + fontRuns ); + + multilanguageSupport.ValidateFonts( utf32, + scripts, + data.fontDescriptionRuns, + defaultFontId, + data.index, + data.numberOfCharacters, + fontRuns ); + } + + // 5) Compare the results. + if( data.fontRuns.Count() != fontRuns.Count() ) + { + std::cout << " Different number of font runs : " << fontRuns.Count() << ", expected : " << data.fontRuns.Count() << std::endl; + return false; + } + + + for( unsigned int index = 0; index < data.fontRuns.Count(); ++index ) + { + const FontRun& run = fontRuns[index]; + const FontRun& expectedRun = data.fontRuns[index]; + + if( run.characterRun.characterIndex != expectedRun.characterRun.characterIndex ) + { + std::cout << " character run : " << index << ", index : " << run.characterRun.characterIndex << ", expected : " << expectedRun.characterRun.characterIndex << std::endl; + return false; + } + if( run.characterRun.numberOfCharacters != expectedRun.characterRun.numberOfCharacters ) + { + std::cout << " character run : " << index << ", num chars : " << run.characterRun.numberOfCharacters << ", expected : " << expectedRun.characterRun.numberOfCharacters << std::endl; + return false; + } + if( run.fontId != expectedRun.fontId ) + { + std::cout << " character run : " << index << ", font : " << run.fontId << ", expected : " << expectedRun.fontId << std::endl; + return false; + } + } return true; } } // namespace +int UtcDaliTextGetScript(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextGetScript"); + + Script script = TextAbstraction::LATIN; + + // Text with no scripts. + Vector scriptRuns; + Vector::ConstIterator scriptRunIt = scriptRuns.Begin(); + script = GetScript( 0u, + scriptRunIt, + scriptRuns.End() ); + + DALI_TEST_CHECK( TextAbstraction::UNKNOWN == script ); + + const unsigned int numberOfCharacters = 7u; + // Add scripts. + ScriptRun scriptRun01 = + { + { + 0u, + 2u, + }, + TextAbstraction::LATIN + }; + ScriptRun scriptRun02 = + { + { + 2u, + 2u, + }, + TextAbstraction::HEBREW + }; + ScriptRun scriptRun03 = + { + { + 4u, + 2u, + }, + TextAbstraction::ARABIC + }; + scriptRuns.PushBack( scriptRun01 ); + scriptRuns.PushBack( scriptRun02 ); + scriptRuns.PushBack( scriptRun03 ); + + // Expected results + TextAbstraction::Script expectedScripts[]= + { + TextAbstraction::LATIN, + TextAbstraction::LATIN, + TextAbstraction::HEBREW, + TextAbstraction::HEBREW, + TextAbstraction::ARABIC, + TextAbstraction::ARABIC, + TextAbstraction::UNKNOWN + }; + + scriptRunIt = scriptRuns.Begin(); + for( unsigned int index = 0u; index < numberOfCharacters; ++index ) + { + script = GetScript( index, + scriptRunIt, + scriptRuns.End() ); + + DALI_TEST_CHECK( expectedScripts[index] == script ); + } + DALI_TEST_CHECK( scriptRunIt == scriptRuns.End() ); + + tet_result(TET_PASS); + END_TEST; +} + +int UtcDaliTextMergeFontDescriptions(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextMergeFontDescriptions"); + + // Load some fonts. + + char* pathNamePtr = get_current_dir_name(); + const std::string pathName( pathNamePtr ); + free( pathNamePtr ); + + TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get(); + fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSans.ttf" ); + fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf" ); + fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", NON_DEFAULT_FONT_SIZE ); + fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf" ); + fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Italic.ttf" ); + + // To test the font width as GetFontId() with the font file path can't cache the width property. + TextAbstraction::FontDescription widthDescription; + widthDescription.path = ""; + widthDescription.family = "DejaVu Serif"; + widthDescription.weight = TextAbstraction::FontWeight::NORMAL; + widthDescription.width = TextAbstraction::FontWidth::EXPANDED; + widthDescription.slant = TextAbstraction::FontSlant::NORMAL; + fontClient.GetFontId( widthDescription ); + + // Test. + + TextAbstraction::FontDescription defaultFontDescription01; + Vector fontDescriptionRuns01; + Vector expectedFontIds01; + Vector expectedIsFontDefault01; + + TextAbstraction::FontDescription defaultFontDescription02; + Vector fontDescriptionRuns02; + Vector expectedFontIds02; + expectedFontIds02.PushBack( 0u ); + expectedFontIds02.PushBack( 0u ); + Vector expectedIsFontDefault02; + expectedIsFontDefault02.PushBack( true ); + expectedIsFontDefault02.PushBack( true ); + + TextAbstraction::FontDescription defaultFontDescription03; + defaultFontDescription03.family = "DejaVu Serif"; + Vector fontDescriptionRuns03; + + FontDescriptionRun fontDescription0301 = + { + { + 0u, + 2u + }, + const_cast( "DejaVu Sans" ), + 11u, + TextAbstraction::FontWeight::NORMAL, + TextAbstraction::FontWidth::NORMAL, + TextAbstraction::FontSlant::NORMAL, + TextAbstraction::FontClient::DEFAULT_POINT_SIZE, + true, + false, + false, + false, + false + }; + FontDescriptionRun fontDescription0302 = + { + { + 2u, + 2u + }, + NULL, + 0u, + TextAbstraction::FontWeight::NORMAL, + TextAbstraction::FontWidth::NORMAL, + TextAbstraction::FontSlant::ITALIC, + TextAbstraction::FontClient::DEFAULT_POINT_SIZE, + false, + false, + false, + true, + false + }; + FontDescriptionRun fontDescription0303 = + { + { + 4u, + 2u + }, + NULL, + 0u, + TextAbstraction::FontWeight::BOLD, + TextAbstraction::FontWidth::NORMAL, + TextAbstraction::FontSlant::NORMAL, + TextAbstraction::FontClient::DEFAULT_POINT_SIZE, + false, + true, + false, + false, + false + }; + FontDescriptionRun fontDescription0304 = + { + { + 6u, + 2u + }, + NULL, + 0u, + TextAbstraction::FontWeight::NORMAL, + TextAbstraction::FontWidth::NORMAL, + TextAbstraction::FontSlant::NORMAL, + NON_DEFAULT_FONT_SIZE, + false, + false, + false, + false, + true + }; + FontDescriptionRun fontDescription0305 = + { + { + 8u, + 2u + }, + NULL, + 0u, + TextAbstraction::FontWeight::NORMAL, + TextAbstraction::FontWidth::EXPANDED, + TextAbstraction::FontSlant::NORMAL, + TextAbstraction::FontClient::DEFAULT_POINT_SIZE, + false, + false, + true, + false, + false + }; + + fontDescriptionRuns03.PushBack( fontDescription0301 ); + fontDescriptionRuns03.PushBack( fontDescription0302 ); + fontDescriptionRuns03.PushBack( fontDescription0303 ); + fontDescriptionRuns03.PushBack( fontDescription0304 ); + fontDescriptionRuns03.PushBack( fontDescription0305 ); + + Vector expectedFontIds03; + expectedFontIds03.PushBack( 1u ); + expectedFontIds03.PushBack( 1u ); + expectedFontIds03.PushBack( 5u ); + expectedFontIds03.PushBack( 5u ); + expectedFontIds03.PushBack( 4u ); + expectedFontIds03.PushBack( 4u ); + expectedFontIds03.PushBack( 3u ); + expectedFontIds03.PushBack( 3u ); + expectedFontIds03.PushBack( 6u ); + expectedFontIds03.PushBack( 6u ); + Vector expectedIsFontDefault03; + expectedIsFontDefault03.PushBack( false ); + expectedIsFontDefault03.PushBack( false ); + expectedIsFontDefault03.PushBack( false ); + expectedIsFontDefault03.PushBack( false ); + expectedIsFontDefault03.PushBack( false ); + expectedIsFontDefault03.PushBack( false ); + expectedIsFontDefault03.PushBack( false ); + expectedIsFontDefault03.PushBack( false ); + expectedIsFontDefault03.PushBack( false ); + expectedIsFontDefault03.PushBack( false ); + + const MergeFontDescriptionsData data[] = + { + { + "void text.", + fontDescriptionRuns01, + defaultFontDescription01, + TextAbstraction::FontClient::DEFAULT_POINT_SIZE, + 0u, + 0u, + expectedFontIds01, + expectedIsFontDefault01 + }, + { + "No description runs.", + fontDescriptionRuns02, + defaultFontDescription02, + TextAbstraction::FontClient::DEFAULT_POINT_SIZE, + 0u, + 2u, + expectedFontIds02, + expectedIsFontDefault02 + }, + { + "Some description runs.", + fontDescriptionRuns03, + defaultFontDescription03, + TextAbstraction::FontClient::DEFAULT_POINT_SIZE, + 0u, + 10u, + expectedFontIds03, + expectedIsFontDefault03 + } + }; + const unsigned int numberOfTests = 3u; + + for( unsigned int index = 0u; index < numberOfTests; ++index ) + { + if( !MergeFontDescriptionsTest( data[index] ) ) + { + tet_result(TET_FAIL); + } + } + + tet_result(TET_PASS); + END_TEST; +} + int UtcDaliTextMultiLanguageConstructor(void) { ToolkitTestApplication application; @@ -184,56 +639,1060 @@ int UtcDaliTextMultiLanguageSetScripts(void) Vector scriptRuns01; ScriptRun scriptRun0100 = { - 0u, - 11u, + { + 0u, + 11u, + }, TextAbstraction::LATIN }; scriptRuns01.PushBack( scriptRun0100 ); - const ScriptsData data[] = + // Mix of LTR '\n'and RTL + Vector scriptRuns02; + ScriptRun scriptRun0200 = { { - "void text", - "", - scriptRuns00, + 0u, + 12u, }, + TextAbstraction::LATIN + }; + ScriptRun scriptRun0201 = + { { - "Easy latin script", - "Hello world", - scriptRuns01, + 12u, + 13u, }, + TextAbstraction::ARABIC }; - const unsigned int numberOfTests = 2u; + scriptRuns02.PushBack( scriptRun0200 ); + scriptRuns02.PushBack( scriptRun0201 ); - for( unsigned int index = 0u; index < numberOfTests; ++index ) + // Mix of RTL '\n'and LTR + Vector scriptRuns03; + ScriptRun scriptRun0300 = { - if( !ScriptsTest( data[index] ) ) { - tet_result(TET_FAIL); - } - } + 0u, + 14u, + }, + TextAbstraction::ARABIC + }; + ScriptRun scriptRun0301 = + { + { + 14u, + 11u, + }, + TextAbstraction::LATIN + }; + scriptRuns03.PushBack( scriptRun0300 ); + scriptRuns03.PushBack( scriptRun0301 ); - tet_result(TET_PASS); - END_TEST; -} + // White spaces. At the beginning of the text. + Vector scriptRuns04; + ScriptRun scriptRun0400 = + { + { + 0u, + 16u, + }, + TextAbstraction::LATIN + }; + scriptRuns04.PushBack( scriptRun0400 ); -int UtcDaliTextMultiLanguageValidateFonts01(void) -{ - ToolkitTestApplication application; - tet_infoline(" UtcDaliTextMultiLanguageValidateFonts"); + // White spaces. At the end of the text. + Vector scriptRuns05; + ScriptRun scriptRun0500 = + { + { + 0u, + 16u, + }, + TextAbstraction::LATIN + }; + scriptRuns05.PushBack( scriptRun0500 ); - const ValidateFontsData data[] = + // White spaces. At the middle of the text. + Vector scriptRuns06; + ScriptRun scriptRun0600 = { { - "void text", - "", + 0u, + 16u, }, + TextAbstraction::LATIN + }; + scriptRuns06.PushBack( scriptRun0600 ); + + // White spaces between different scripts. + Vector scriptRuns07; + ScriptRun scriptRun0700 = + { { - "Easy latin script", - "Hello world", + 0u, + 8u, + }, + TextAbstraction::LATIN + }; + ScriptRun scriptRun0701 = + { + { + 8u, + 5u, + }, + TextAbstraction::HANGUL + }; + scriptRuns07.PushBack( scriptRun0700 ); + scriptRuns07.PushBack( scriptRun0701 ); + + // White spaces between different scripts and differetn directions. Starting LTR. + Vector scriptRuns08; + ScriptRun scriptRun0800 = + { + { + 0u, + 18u, + }, + TextAbstraction::LATIN + }; + ScriptRun scriptRun0801 = + { + { + 18u, + 14u, + }, + TextAbstraction::ARABIC + }; + ScriptRun scriptRun0802 = + { + { + 32u, + 18u, + }, + TextAbstraction::HANGUL + }; + scriptRuns08.PushBack( scriptRun0800 ); + scriptRuns08.PushBack( scriptRun0801 ); + scriptRuns08.PushBack( scriptRun0802 ); + + // White spaces between different scripts and differetn directions. Starting RTL. + Vector scriptRuns09; + ScriptRun scriptRun0900 = + { + { + 0u, + 21u, + }, + TextAbstraction::ARABIC + }; + ScriptRun scriptRun0901 = + { + { + 21u, + 16u, + }, + TextAbstraction::LATIN + }; + ScriptRun scriptRun0902 = + { + { + 37u, + 10u, + }, + TextAbstraction::HANGUL + }; + ScriptRun scriptRun0903 = + { + { + 47u, + 20u, + }, + TextAbstraction::ARABIC + }; + scriptRuns09.PushBack( scriptRun0900 ); + scriptRuns09.PushBack( scriptRun0901 ); + scriptRuns09.PushBack( scriptRun0902 ); + scriptRuns09.PushBack( scriptRun0903 ); + + // Paragraphs with different directions. + Vector scriptRuns10; + ScriptRun scriptRun1000 = + { + { + 0u, + 20u, + }, + TextAbstraction::ARABIC + }; + ScriptRun scriptRun1001 = + { + { + 20u, + 12u, + }, + TextAbstraction::HEBREW + }; + ScriptRun scriptRun1002 = + { + { + 32u, + 17u, + }, + TextAbstraction::ARABIC + }; + ScriptRun scriptRun1003 = + { + { + 49u, + 18u, + }, + TextAbstraction::LATIN + }; + ScriptRun scriptRun1004 = + { + { + 67u, + 14u, + }, + TextAbstraction::HANGUL + }; + ScriptRun scriptRun1005 = + { + { + 81u, + 19u, + }, + TextAbstraction::ARABIC + }; + ScriptRun scriptRun1006 = + { + { + 100u, + 13u, + }, + TextAbstraction::LATIN + }; + ScriptRun scriptRun1007 = + { + { + 113u, + 16u, + }, + TextAbstraction::HEBREW + }; + ScriptRun scriptRun1008 = + { + { + 129u, + 20u, + }, + TextAbstraction::LATIN + }; + ScriptRun scriptRun1009 = + { + { + 149u, + 14u, + }, + TextAbstraction::ARABIC + }; + ScriptRun scriptRun1010 = + { + { + 163u, + 18u, + }, + TextAbstraction::HANGUL + }; + ScriptRun scriptRun1011 = + { + { + 181u, + 17u, + }, + TextAbstraction::HANGUL + }; + scriptRuns10.PushBack( scriptRun1000 ); + scriptRuns10.PushBack( scriptRun1001 ); + scriptRuns10.PushBack( scriptRun1002 ); + scriptRuns10.PushBack( scriptRun1003 ); + scriptRuns10.PushBack( scriptRun1004 ); + scriptRuns10.PushBack( scriptRun1005 ); + scriptRuns10.PushBack( scriptRun1006 ); + scriptRuns10.PushBack( scriptRun1007 ); + scriptRuns10.PushBack( scriptRun1008 ); + scriptRuns10.PushBack( scriptRun1009 ); + scriptRuns10.PushBack( scriptRun1010 ); + scriptRuns10.PushBack( scriptRun1011 ); + + // Paragraphs with no scripts mixed with paragraphs with scripts. + Vector scriptRuns11; + ScriptRun scriptRun1100 = + { + { + 0u, + 3u, + }, + TextAbstraction::LATIN + }; + ScriptRun scriptRun1101 = + { + { + 3u, + 3u, + }, + TextAbstraction::LATIN + }; + ScriptRun scriptRun1102 = + { + { + 6u, + 19u, + }, + TextAbstraction::LATIN + }; + ScriptRun scriptRun1103 = + { + { + 25u, + 3u, + }, + TextAbstraction::LATIN + }; + ScriptRun scriptRun1104 = + { + { + 28u, + 3u, + }, + TextAbstraction::LATIN + }; + ScriptRun scriptRun1105 = + { + { + 31u, + 15u, + }, + TextAbstraction::HEBREW + }; + ScriptRun scriptRun1106 = + { + { + 46u, + 2u, + }, + TextAbstraction::LATIN + }; + ScriptRun scriptRun1107 = + { + { + 48u, + 2u, + }, + TextAbstraction::LATIN + }; + ScriptRun scriptRun1108 = + { + { + 50u, + 2u, + }, + TextAbstraction::LATIN + }; + scriptRuns11.PushBack( scriptRun1100 ); + scriptRuns11.PushBack( scriptRun1101 ); + scriptRuns11.PushBack( scriptRun1102 ); + scriptRuns11.PushBack( scriptRun1103 ); + scriptRuns11.PushBack( scriptRun1104 ); + scriptRuns11.PushBack( scriptRun1105 ); + scriptRuns11.PushBack( scriptRun1106 ); + scriptRuns11.PushBack( scriptRun1107 ); + scriptRuns11.PushBack( scriptRun1108 ); + + // Paragraphs with no scripts. + Vector scriptRuns12; + ScriptRun scriptRun1200 = + { + { + 0u, + 3u, + }, + TextAbstraction::LATIN + }; + ScriptRun scriptRun1201 = + { + { + 3u, + 3u, + }, + TextAbstraction::LATIN + }; + ScriptRun scriptRun1202 = + { + { + 6u, + 3u, + }, + TextAbstraction::LATIN + }; + ScriptRun scriptRun1203 = + { + { + 9u, + 2u, + }, + TextAbstraction::LATIN + }; + scriptRuns12.PushBack( scriptRun1200 ); + scriptRuns12.PushBack( scriptRun1201 ); + scriptRuns12.PushBack( scriptRun1202 ); + scriptRuns12.PushBack( scriptRun1203 ); + + Vector scriptRuns13; + ScriptRun scriptRun1301 = + { + { + 0u, + 4u, + }, + TextAbstraction::LATIN // An unknown script is transformed to LATIN + }; + scriptRuns13.PushBack( scriptRun1301 ); + + const ScriptsData data[] = + { + { + "void text", + "", + 0u, + 0u, + scriptRuns00, + }, + { + "Easy latin script", + "Hello world", + 0u, + 11u, + scriptRuns01, + }, + { + "Mix of LTR '\\n'and RTL", + "Hello world\nمرحبا بالعالم", + 0u, + 25u, + scriptRuns02, + }, + { + "Update mix of LTR '\\n'and RTL. Update LTR", + "Hello world\nمرحبا بالعالم", + 0u, + 12u, + scriptRuns02, + }, + { + "Update mix of LTR '\\n'and RTL. Update RTL", + "Hello world\nمرحبا بالعالم", + 12u, + 13u, + scriptRuns02, + }, + { + "Mix of RTL '\\n'and LTR", + "مرحبا بالعالم\nHello world", + 0u, + 25u, + scriptRuns03, + }, + { + "Update mix of RTL '\\n'and LTR. Update RTL", + "مرحبا بالعالم\nHello world", + 0u, + 14u, + scriptRuns03, + }, + { + "Update mix of RTL '\\n'and LTR. Update LTR", + "مرحبا بالعالم\nHello world", + 14u, + 11u, + scriptRuns03, + }, + { + "White spaces. At the beginning of the text.", + " Hello world.", + 0u, + 16u, + scriptRuns04, + }, + { + "White spaces. At the end of the text.", + "Hello world. ", + 0u, + 16u, + scriptRuns05, + }, + { + "White spaces. At the middle of the text.", + "Hello world.", + 0u, + 16u, + scriptRuns06, + }, + { + "White spaces between different scripts.", + " Hel 세계 ", + 0u, + 13u, + scriptRuns07, + }, + { + "White spaces between different scripts and differetn directions. Starting LTR.", + " Hello world مرحبا بالعالم 안녕하세요 세계 ", + 0u, + 50u, + scriptRuns08, + }, + { + "White spaces between different scripts and differetn directions. Starting RTL.", + " مرحبا بالعالم Hello world 안녕하세요 세계 مرحبا بالعالم ", + 0u, + 67u, + scriptRuns09 + }, + { + "Paragraphs with different directions.", + " مرحبا بالعالم שלום עולם مرحبا بالعالم \n " + " Hello world 안녕하세요 세계 \n " + " مرحبا بالعالم Hello world שלום עולם \n " + " Hello world مرحبا بالعالم 안녕하세요 세계 \n " + " 안녕하세요 세계 ", + 0u, + 198u, + scriptRuns10 + }, + { + "Update paragraphs with different directions. Update initial paragraphs.", + " مرحبا بالعالم שלום עולם مرحبا بالعالم \n " + " Hello world 안녕하세요 세계 \n " + " مرحبا بالعالم Hello world שלום עולם \n " + " Hello world مرحبا بالعالم 안녕하세요 세계 \n " + " 안녕하세요 세계 ", + 0u, + 81u, + scriptRuns10 + }, + { + "Update paragraphs with different directions. Update middle paragraphs.", + " مرحبا بالعالم שלום עולם مرحبا بالعالم \n " + " Hello world 안녕하세요 세계 \n " + " مرحبا بالعالم Hello world שלום עולם \n " + " Hello world مرحبا بالعالم 안녕하세요 세계 \n " + " 안녕하세요 세계 ", + 49u, + 80u, + scriptRuns10 + }, + { + "Update paragraphs with different directions. Update final paragraphs.", + " مرحبا بالعالم שלום עולם مرحبا بالعالم \n " + " Hello world 안녕하세요 세계 \n " + " مرحبا بالعالم Hello world שלום עולם \n " + " Hello world مرحبا بالعالم 안녕하세요 세계 \n " + " 안녕하세요 세계 ", + 129u, + 69u, + scriptRuns10 + }, + { + "Paragraphs with no scripts mixed with paragraphs with scripts.", + " \n \n Hello world \n \n \n שלום עולם \n \n \n ", + 0u, + 52u, + scriptRuns11 + }, + { + "Paragraphs with no scripts.", + " \n \n \n ", + 0u, + 11u, + scriptRuns12 + }, + { + "Update paragraphs with no scripts. Update initial paragraphs.", + " \n \n \n ", + 0u, + 3u, + scriptRuns12 + }, + { + "Update paragraphs with no scripts. Update middle paragraphs.", + " \n \n \n ", + 3u, + 6u, + scriptRuns12 + }, + { + "Update paragraphs with no scripts. Update final paragraphs.", + " \n \n \n ", + 9u, + 2u, + scriptRuns12 + }, + { + "Unknown scripts.", + "ᚩᚯᚱᚸ", // Runic script not currentlu supported. + 0u, + 4u, + scriptRuns13 + } + }; + const unsigned int numberOfTests = 24u; + + for( unsigned int index = 0u; index < numberOfTests; ++index ) + { + if( !ScriptsTest( data[index] ) ) + { + tet_result(TET_FAIL); + } + } + + tet_result(TET_PASS); + END_TEST; +} + +int UtcDaliTextMultiLanguageValidateFonts01(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextMultiLanguageValidateFonts"); + + TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get(); + + char* pathNamePtr = get_current_dir_name(); + const std::string pathName( pathNamePtr ); + free( pathNamePtr ); + + const PointSize26Dot6 pointSize01 = static_cast( 21.f * 64.f ); + const PointSize26Dot6 pointSize02 = static_cast( 35.f * 64.f ); + + // Load some fonts. + fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansArabicRegular.ttf" ); + fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansHebrewRegular.ttf" ); + fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenColorEmoji.ttf", EMOJI_FONT_SIZE ); + fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansRegular.ttf", pointSize01 ); + fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansRegular.ttf", pointSize02 ); + fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansHebrewRegular.ttf", pointSize01 ); + fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansHebrewRegular.ttf", pointSize02 ); + + // Font id 1 --> TizenSansArabicRegular.ttf + // Font id 2 --> TizenSansHebrewRegular.ttf + // Font id 3 --> TizenColorEmoji.ttf + // Font id 4 --> TizenSansRegular.ttf, size 8 + // Font id 5 --> TizenSansRegular.ttf, size 16 + // Font id 6 --> TizenSansHebrewRegular.ttf, size 8 + // Font id 7 --> TizenSansHebrewRegular.ttf, size 16 + // Font id 8 --> (default) + + Vector fontRuns01; + Vector fontDescriptions01; + + FontRun fontRun0201 = + { + { + 0u, + 11u + }, + 8u + }; + Vector fontRuns02; + fontRuns02.PushBack( fontRun0201 ); + + FontDescriptionRun fontDescription0201 = + { + { + 0u, + 11u + }, + const_cast( "TizenSans" ), + 9u, + TextAbstraction::FontWeight::NORMAL, + TextAbstraction::FontWidth::NORMAL, + TextAbstraction::FontSlant::NORMAL, + 0u, + true, + false, + false, + false, + false + }; + Vector fontDescriptions02; + fontDescriptions02.PushBack( fontDescription0201 ); + + FontRun fontRun0301 = + { + { + 0u, + 12u + }, + 8u + }; + FontRun fontRun0302 = + { + { + 12u, + 12u + }, + 8u + }; + FontRun fontRun0303 = + { + { + 24u, + 4u + }, + 8u + }; + Vector fontRuns03; + fontRuns03.PushBack( fontRun0301 ); + fontRuns03.PushBack( fontRun0302 ); + fontRuns03.PushBack( fontRun0303 ); + + Vector fontDescriptions03; + + FontRun fontRun0701 = + { + { + 0u, + 4u + }, + 2u + }; + FontRun fontRun0702 = + { + { + 4u, + 1u + }, + 8u + }; + FontRun fontRun0703 = + { + { + 5u, + 4u + }, + 2u + }; + Vector fontRuns07; + fontRuns07.PushBack( fontRun0701 ); + fontRuns07.PushBack( fontRun0702 ); + fontRuns07.PushBack( fontRun0703 ); + + FontDescriptionRun fontDescription0701 = + { + { + 0u, + 4u + }, + const_cast( "TizenSansHebrew" ), + 15u, + TextAbstraction::FontWeight::NORMAL, + TextAbstraction::FontWidth::NORMAL, + TextAbstraction::FontSlant::NORMAL, + 0u, + true, + false, + false, + false, + false + }; + FontDescriptionRun fontDescription0702 = + { + { + 5u, + 4u + }, + const_cast( "TizenSansHebrew" ), + 15u, + TextAbstraction::FontWeight::NORMAL, + TextAbstraction::FontWidth::NORMAL, + TextAbstraction::FontSlant::NORMAL, + 0u, + true, + false, + false, + false, + false + }; + Vector fontDescriptions07; + fontDescriptions07.PushBack( fontDescription0701 ); + fontDescriptions07.PushBack( fontDescription0702 ); + + FontRun fontRun0801 = + { + { + 0u, + 9u + }, + 2u + }; + Vector fontRuns08; + fontRuns08.PushBack( fontRun0801 ); + + Vector fontDescriptions08; + + FontRun fontRun0901 = + { + { + 0u, + 4u + }, + 3u + }; + Vector fontRuns09; + fontRuns09.PushBack( fontRun0901 ); + + Vector fontDescriptions09; + FontDescriptionRun fontDescription0901 = + { + { + 0u, + 4u + }, + const_cast( "TizenColorEmoji" ), + 15u, + TextAbstraction::FontWeight::NORMAL, + TextAbstraction::FontWidth::NORMAL, + TextAbstraction::FontSlant::NORMAL, + EMOJI_FONT_SIZE, + true, + false, + false, + false, + true + }; + fontDescriptions09.PushBack( fontDescription0901 ); + + FontRun fontRun1001 = + { + { + 0u, + 13u + }, + 4u + }; + FontRun fontRun1002 = + { + { + 13u, + 9u + }, + 6u + }; + FontRun fontRun1003 = + { + { + 22u, + 15u + }, + 5u + }; + FontRun fontRun1004 = + { + { + 37u, + 9u + }, + 7u + }; + Vector fontRuns10; + fontRuns10.PushBack( fontRun1001 ); + fontRuns10.PushBack( fontRun1002 ); + fontRuns10.PushBack( fontRun1003 ); + fontRuns10.PushBack( fontRun1004 ); + + FontDescriptionRun fontDescription1001 = + { + { + 0u, + 13u + }, + const_cast( "TizenSans" ), + 9u, + TextAbstraction::FontWeight::NORMAL, + TextAbstraction::FontWidth::NORMAL, + TextAbstraction::FontSlant::NORMAL, + pointSize01, + true, + false, + false, + false, + true + }; + FontDescriptionRun fontDescription1002 = + { + { + 13u, + 9u + }, + const_cast( "TizenSansHebrew" ), + 15u, + TextAbstraction::FontWeight::NORMAL, + TextAbstraction::FontWidth::NORMAL, + TextAbstraction::FontSlant::NORMAL, + pointSize01, + true, + false, + false, + false, + true + }; + FontDescriptionRun fontDescription1003 = + { + { + 22u, + 15u + }, + const_cast( "TizenSans" ), + 9u, + TextAbstraction::FontWeight::NORMAL, + TextAbstraction::FontWidth::NORMAL, + TextAbstraction::FontSlant::NORMAL, + pointSize02, + true, + false, + false, + false, + true + }; + FontDescriptionRun fontDescription1004 = + { + { + 37u, + 9u + }, + const_cast( "TizenSansHebrew" ), + 15u, + TextAbstraction::FontWeight::NORMAL, + TextAbstraction::FontWidth::NORMAL, + TextAbstraction::FontSlant::NORMAL, + pointSize02, + true, + false, + false, + false, + true + }; + Vector fontDescriptions10; + fontDescriptions10.PushBack( fontDescription1001 ); + fontDescriptions10.PushBack( fontDescription1002 ); + fontDescriptions10.PushBack( fontDescription1003 ); + fontDescriptions10.PushBack( fontDescription1004 ); + + const ValidateFontsData data[] = + { + { + "void text.", + "", + "/tizen/TizenSansRegular.ttf", + TextAbstraction::FontClient::DEFAULT_POINT_SIZE, + 0u, + 0u, + fontDescriptions01, + fontRuns01 + }, + { + "Easy latin script.", + "Hello world", + "/tizen/TizenSansRegular.ttf", + TextAbstraction::FontClient::DEFAULT_POINT_SIZE, + 0u, + 11u, + fontDescriptions02, + fontRuns02 + }, + { + "Different paragraphs.", + "Hello world\nhello world\ndemo", + "/tizen/TizenSansRegular.ttf", + TextAbstraction::FontClient::DEFAULT_POINT_SIZE, + 0u, + 28u, + fontDescriptions03, + fontRuns03 + }, + { + "Different paragraphs. Update the initial paragraph.", + "Hello world\nhello world\ndemo", + "/tizen/TizenSansRegular.ttf", + TextAbstraction::FontClient::DEFAULT_POINT_SIZE, + 0u, + 12u, + fontDescriptions03, + fontRuns03 + }, + { + "Different paragraphs. Update the middle paragraph.", + "Hello world\nhello world\ndemo", + "/tizen/TizenSansRegular.ttf", + TextAbstraction::FontClient::DEFAULT_POINT_SIZE, + 12u, + 12u, + fontDescriptions03, + fontRuns03 + }, + { + "Different paragraphs. Update the final paragraph.", + "Hello world\nhello world\ndemo", + "/tizen/TizenSansRegular.ttf", + TextAbstraction::FontClient::DEFAULT_POINT_SIZE, + 24u, + 4u, + fontDescriptions03, + fontRuns03 + }, + { + "Hebrew text. Default font: latin", + "שלום עולם", + "/tizen/TizenSansRegular.ttf", + TextAbstraction::FontClient::DEFAULT_POINT_SIZE, + 0u, + 9u, + fontDescriptions07, + fontRuns07 + }, + { + "Hebrew text. Default font: hebrew", + "שלום עולם", + "/tizen/TizenSansHebrewRegular.ttf", + TextAbstraction::FontClient::DEFAULT_POINT_SIZE, + 0u, + 9u, + fontDescriptions08, + fontRuns08 + }, + { + "Emojis", + "\xF0\x9F\x98\x81\xF0\x9F\x98\x82\xF0\x9F\x98\x83\xF0\x9F\x98\x84", + "/tizen/TizenColorEmoji.ttf", + EMOJI_FONT_SIZE, + 0u, + 4u, + fontDescriptions09, + fontRuns09 + }, + { + "Mix text. Default font: latin. Different font sizes", + "Hello world, שלום עולם, hello world, שלום עולם", + "/tizen/TizenSansRegular.ttf", + TextAbstraction::FontClient::DEFAULT_POINT_SIZE, + 0u, + 46u, + fontDescriptions10, + fontRuns10 }, }; - const unsigned int numberOfTests = 2u; + const unsigned int numberOfTests = 10u; for( unsigned int index = 0u; index < numberOfTests; ++index ) {