Bitmap Font support for TextLabel.
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-TextLabel.cpp
index 67dc221..96fcb63 100755 (executable)
@@ -24,6 +24,8 @@
 #include <dali-toolkit/devel-api/controls/text-controls/text-label-devel.h>
 #include <dali-toolkit/devel-api/controls/text-controls/text-style-properties-devel.h>
 #include <dali-toolkit/devel-api/text/text-enumerations-devel.h>
+#include <dali/devel-api/text-abstraction/bitmap-font.h>
+#include <dali-toolkit/devel-api/text/bitmap-font.h>
 
 using namespace Dali;
 using namespace Toolkit;
@@ -67,7 +69,6 @@ const char* const PROPERTY_NAME_PIXEL_SIZE = "pixelSize";
 const char* const PROPERTY_NAME_ELLIPSIS = "ellipsis";
 const char* const PROPERTY_NAME_AUTO_SCROLL_LOOP_DELAY = "autoScrollLoopDelay";
 
-const int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
 const std::string DEFAULT_FONT_DIR( "/resources/fonts" );
 const unsigned int EMOJI_FONT_SIZE = 3840u; // 60 * 64
 
@@ -373,9 +374,9 @@ int UtcDaliToolkitTextLabelSetPropertyP(void)
   Property::Map underlineMapSet;
   Property::Map underlineMapGet;
 
-  underlineMapSet.Insert( "enable", "false" );
-  underlineMapSet.Insert( "color", "blue" );
-  underlineMapSet.Insert( "height", "0" );
+  underlineMapSet.Insert( "enable", false );
+  underlineMapSet.Insert( "color", Color::BLUE );
+  underlineMapSet.Insert( "height", 0 );
 
   underlineMapGet = label.GetProperty<Property::Map>( TextLabel::Property::UNDERLINE );
   DALI_TEST_EQUALS( underlineMapGet.Count(), underlineMapSet.Count(), TEST_LOCATION );
@@ -466,9 +467,9 @@ int UtcDaliToolkitTextLabelSetPropertyP(void)
 
   // Check the underline property
   underlineMapSet.Clear();
-  underlineMapSet.Insert( "enable", "true" );
-  underlineMapSet.Insert( "color", "red" );
-  underlineMapSet.Insert( "height", "1" );
+  underlineMapSet.Insert( "enable", true );
+  underlineMapSet.Insert( "color", Color::RED );
+  underlineMapSet.Insert( "height", 1 );
 
   label.SetProperty( TextLabel::Property::UNDERLINE, underlineMapSet );
 
@@ -480,9 +481,9 @@ int UtcDaliToolkitTextLabelSetPropertyP(void)
   DALI_TEST_EQUALS( DaliTestCheckMaps( underlineMapGet, underlineMapSet ), true, TEST_LOCATION );
 
   underlineMapSet.Clear();
-  underlineMapSet.Insert( Toolkit::DevelText::Underline::Property::ENABLE, "true" );
-  underlineMapSet.Insert( Toolkit::DevelText::Underline::Property::COLOR, "green" );
-  underlineMapSet.Insert( Toolkit::DevelText::Underline::Property::HEIGHT, "2" );
+  underlineMapSet.Insert( Toolkit::DevelText::Underline::Property::ENABLE, true );
+  underlineMapSet.Insert( Toolkit::DevelText::Underline::Property::COLOR, Color::GREEN );
+  underlineMapSet.Insert( Toolkit::DevelText::Underline::Property::HEIGHT, 2 );
 
   label.SetProperty( TextLabel::Property::UNDERLINE, underlineMapSet );
 
@@ -497,9 +498,9 @@ int UtcDaliToolkitTextLabelSetPropertyP(void)
   underlineMapSet.Clear();
 
   Property::Map underlineDisabledMapGet;
-  underlineDisabledMapGet.Insert( "enable", "false" );
-  underlineDisabledMapGet.Insert( "color", "green" );
-  underlineDisabledMapGet.Insert( "height", "2" );
+  underlineDisabledMapGet.Insert( "enable", false );
+  underlineDisabledMapGet.Insert( "color", Color::GREEN );
+  underlineDisabledMapGet.Insert( "height", 2 );
 
   label.SetProperty( TextLabel::Property::UNDERLINE, underlineMapSet );
 
@@ -647,8 +648,8 @@ int UtcDaliToolkitTextlabelAtlasRenderP(void)
   label.SetProperty( TextLabel::Property::MULTI_LINE, true );
 
   Property::Map underlineMap;
-  underlineMap.Insert( "enable", "true" );
-  underlineMap.Insert( "color", "red" );
+  underlineMap.Insert( "enable", true );
+  underlineMap.Insert( "color", Color::RED );
   label.SetProperty( TextLabel::Property::UNDERLINE, underlineMap );
 
   Property::Map shadowMap;
@@ -1174,7 +1175,7 @@ int UtcDaliToolkitTextlabelTextWrapMode(void)
   application.Render();
 
   lineCount =  label.GetProperty<int>( TextLabel::Property::LINE_COUNT );
-  DALI_TEST_EQUALS( lineCount, 4, TEST_LOCATION );
+  DALI_TEST_EQUALS( lineCount, 2, TEST_LOCATION );
 
   label.SetProperty( TextLabel::Property::LINE_WRAP_MODE, "CHARACTER" );
   DALI_TEST_EQUALS( label.GetProperty< int >( TextLabel::Property::LINE_WRAP_MODE ), static_cast< int >( Text::LineWrap::CHARACTER ), TEST_LOCATION );
@@ -1189,7 +1190,7 @@ int UtcDaliToolkitTextlabelTextWrapMode(void)
   application.Render();
 
   lineCount =  label.GetProperty<int>( TextLabel::Property::LINE_COUNT );
-  DALI_TEST_EQUALS( lineCount, 4, TEST_LOCATION );
+  DALI_TEST_EQUALS( lineCount, 2, TEST_LOCATION );
 
   label.SetProperty( TextLabel::Property::LINE_WRAP_MODE, Text::LineWrap::CHARACTER );
   DALI_TEST_EQUALS( label.GetProperty< int >( TextLabel::Property::LINE_WRAP_MODE ), static_cast< int >( Text::LineWrap::CHARACTER ), TEST_LOCATION );
@@ -1198,7 +1199,7 @@ int UtcDaliToolkitTextlabelTextWrapMode(void)
   application.Render();
 
   lineCount =  label.GetProperty<int>( TextLabel::Property::LINE_COUNT );
-  DALI_TEST_EQUALS( lineCount, 3, TEST_LOCATION );
+  DALI_TEST_EQUALS( lineCount, 2, TEST_LOCATION );
 
   tet_infoline( "Ensure invalid string does not change wrapping mode" );
   label.SetProperty( TextLabel::Property::LINE_WRAP_MODE, "InvalidWrapMode" );
@@ -1420,3 +1421,50 @@ int UtcDaliToolkitTextlabelVerticalLineAlignment(void)
 
   END_TEST;
 }
+
+int UtcDaliToolkitTextLabelBitmapFont(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" UtcDaliToolkitTextLabelBitmapFont");
+
+  DevelText::BitmapFontDescription fontDescription;
+  fontDescription.name = "Digits";
+  fontDescription.underlinePosition = 0.f;
+  fontDescription.underlineThickness = 0.f;
+
+  fontDescription.glyphs.push_back( { TEST_RESOURCE_DIR "/fonts/bitmap/u0030.png", ":", 34.f, 0.f } );
+  fontDescription.glyphs.push_back( { TEST_RESOURCE_DIR "/fonts/bitmap/u0031.png", "0", 34.f, 0.f } );
+  fontDescription.glyphs.push_back( { TEST_RESOURCE_DIR "/fonts/bitmap/u0032.png", "1", 34.f, 0.f } );
+  fontDescription.glyphs.push_back( { TEST_RESOURCE_DIR "/fonts/bitmap/u0033.png", "2", 34.f, 0.f } );
+  fontDescription.glyphs.push_back( { TEST_RESOURCE_DIR "/fonts/bitmap/u0034.png", "3", 34.f, 0.f } );
+  fontDescription.glyphs.push_back( { TEST_RESOURCE_DIR "/fonts/bitmap/u0035.png", "4", 34.f, 0.f } );
+  fontDescription.glyphs.push_back( { TEST_RESOURCE_DIR "/fonts/bitmap/u0036.png", "5", 34.f, 0.f } );
+  fontDescription.glyphs.push_back( { TEST_RESOURCE_DIR "/fonts/bitmap/u0037.png", "6", 34.f, 0.f } );
+  fontDescription.glyphs.push_back( { TEST_RESOURCE_DIR "/fonts/bitmap/u0038.png", "7", 34.f, 0.f } );
+  fontDescription.glyphs.push_back( { TEST_RESOURCE_DIR "/fonts/bitmap/u0039.png", "8", 34.f, 0.f } );
+  fontDescription.glyphs.push_back( { TEST_RESOURCE_DIR "/fonts/bitmap/u003a.png", "9", 34.f, 0.f } );
+
+  TextAbstraction::BitmapFont bitmapFont;
+  DevelText::CreateBitmapFont( fontDescription, bitmapFont );
+
+  TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
+  fontClient.GetFontId( bitmapFont );
+
+  TextLabel label = TextLabel::New();
+
+  label.SetProperty( TextLabel::Property::TEXT, "0123456789:" );
+  label.SetProperty( TextLabel::Property::FONT_FAMILY, "Digits" );
+
+  // The text has been laid out with the bitmap font if the natural size is the sum of all the width (322) and 34 height.
+  DALI_TEST_EQUALS( label.GetNaturalSize(), Vector3(322.f, 34.f, 0.f), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
+
+  Stage::GetCurrent().Add( label );
+
+  application.SendNotification();
+  application.Render();
+
+  // The text has been rendered if the height of the text-label is the height of the line.
+  DALI_TEST_EQUALS( label.GetCurrentSize().height, 34.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
+
+  END_TEST;
+}