Add ENABLE_FONT_SIZE_SCALE property to text components
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-TextLabel.cpp
index be0e5b1..621c634 100644 (file)
@@ -30,6 +30,7 @@
 #include <dali-toolkit/devel-api/text/bitmap-font.h>
 #include <dali-toolkit/devel-api/text/rendering-backend.h>
 #include <dali-toolkit/devel-api/text/text-utils-devel.h>
+#include "test-text-geometry-utils.h"
 
 using namespace Dali;
 using namespace Toolkit;
@@ -73,6 +74,7 @@ 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 char* const PROPERTY_NAME_FONT_SIZE_SCALE = "fontSizeScale";
+const char* const PROPERTY_NAME_ENABLE_FONT_SIZE_SCALE = "enableFontSizeScale";
 
 const char* const PROPERTY_NAME_ELLIPSIS_POSITION = "ellipsisPosition";
 
@@ -82,6 +84,8 @@ const unsigned int EMOJI_FONT_SIZE = 3840u; // 60 * 64
 static bool gAnchorClickedCallBackCalled;
 static bool gAnchorClickedCallBackNotCalled;
 
+static bool gTextFitChangedCallBackCalled;
+
 struct CallbackFunctor
 {
   CallbackFunctor(bool* callbackFlag)
@@ -108,6 +112,12 @@ static void TestAnchorClickedCallback(TextLabel control, const char* href, unsig
   }
 }
 
+static void TestTextFitChangedCallback(TextLabel control)
+{
+  tet_infoline(" TestTextFitChangedCallback");
+  gTextFitChangedCallBackCalled = true;
+}
+
 bool DaliTestCheckMaps( const Property::Map& mapGet, const Property::Map& mapSet, const std::vector<std::string>& indexConversionTable = std::vector<std::string>() )
 {
   const Property::Map::SizeType size = mapGet.Count();
@@ -343,6 +353,7 @@ int UtcDaliToolkitTextLabelGetPropertyP(void)
   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_ELLIPSIS ) == TextLabel::Property::ELLIPSIS );
   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_AUTO_SCROLL_LOOP_DELAY ) == TextLabel::Property::AUTO_SCROLL_LOOP_DELAY );
   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_FONT_SIZE_SCALE ) == DevelTextLabel::Property::FONT_SIZE_SCALE );
+  DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_ENABLE_FONT_SIZE_SCALE ) == DevelTextLabel::Property::ENABLE_FONT_SIZE_SCALE );
   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_ELLIPSIS_POSITION ) == DevelTextLabel::Property::ELLIPSIS_POSITION );
 
   END_TEST;
@@ -399,6 +410,10 @@ int UtcDaliToolkitTextLabelSetPropertyP(void)
   DALI_TEST_EQUALS( label.GetProperty<float>( DevelTextLabel::Property::FONT_SIZE_SCALE ), 2.5f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
   label.SetProperty( DevelTextLabel::Property::FONT_SIZE_SCALE, 1.0f );
 
+  label.SetProperty( DevelTextLabel::Property::ENABLE_FONT_SIZE_SCALE, false );
+  DALI_TEST_EQUALS( label.GetProperty<bool>( DevelTextLabel::Property::ENABLE_FONT_SIZE_SCALE ), false, TEST_LOCATION );
+  label.SetProperty( DevelTextLabel::Property::ENABLE_FONT_SIZE_SCALE, true );
+
   // Reset font style.
   fontStyleMapSet.Clear();
   fontStyleMapSet.Insert( "weight", "normal" );
@@ -1663,6 +1678,13 @@ int UtcDaliToolkitTextlabelTextFit(void)
   label.SetProperty( Actor::Property::SIZE, size );
   label.SetProperty( TextLabel::Property::TEXT, "Hello world" );
 
+   // connect to the text git changed signal.
+  ConnectionTracker* testTracker = new ConnectionTracker();
+  DevelTextLabel::TextFitChangedSignal(label).Connect(&TestTextFitChangedCallback);
+  bool textFitChangedSignal = false;
+  label.ConnectSignal(testTracker, "textFitChanged", CallbackFunctor(&textFitChangedSignal));
+  gTextFitChangedCallBackCalled = false;
+
   // check point size
   Property::Map textFitMapSet;
   textFitMapSet["enable"] = true;
@@ -1682,6 +1704,9 @@ int UtcDaliToolkitTextlabelTextFit(void)
   const Vector3 EXPECTED_NATURAL_SIZE( 450.0f, 96.0f, 0.0f );
   DALI_TEST_EQUALS( EXPECTED_NATURAL_SIZE, label.GetNaturalSize(), TEST_LOCATION );
 
+  DALI_TEST_CHECK(gTextFitChangedCallBackCalled);
+  DALI_TEST_CHECK(textFitChangedSignal);
+
   // check pixel size
   textFitMapSet.Clear();
   textFitMapSet["enable"] = true;
@@ -1999,6 +2024,106 @@ int utcDaliTextLabelGetHeightForWidthChangeLineCountWhenTextChanged(void)
   END_TEST;
 }
 
+int utcDaliTextLabelGeometryRTL(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" utcDaliTextLabelGeometryRTL");
+
+  TextLabel label = TextLabel::New();
+  DALI_TEST_CHECK( label );
+
+  application.GetScene().Add( label );
+
+  label.SetProperty( TextLabel::Property::POINT_SIZE, 7.f );
+  label.SetProperty( Actor::Property::SIZE, Vector2( 150.f, 100.f ) );
+  label.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+  label.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+  label.SetProperty( TextLabel::Property::ENABLE_MARKUP, true );
+  label.SetProperty( TextLabel::Property::MULTI_LINE, true);
+  label.SetProperty( TextLabel::Property::TEXT, "line1 \nline2\nline 3\nالاخيرالسطر" );
+
+  // Avoid a crash when core load gl resources.
+  application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
+
+  // Render and notify
+  application.SendNotification();
+  application.Render();
+
+  unsigned int expectedCount = 4;
+  unsigned int startIndex = 3;
+  unsigned int endIndex = 24;
+
+  Vector<Vector2> positionsList = DevelTextLabel::GetTextPosition(label, startIndex, endIndex);
+  Vector<Vector2> sizeList = DevelTextLabel::GetTextSize(label, startIndex, endIndex);
+
+  DALI_TEST_EQUALS(positionsList.Size(), expectedCount, TEST_LOCATION);
+  DALI_TEST_EQUALS(sizeList.Size(), expectedCount, TEST_LOCATION);
+
+  Vector<Vector2> expectedSizes;
+  Vector<Vector2> expectedPositions;
+
+  expectedPositions.PushBack(Vector2(24, 0));
+  expectedSizes.PushBack(Vector2(33, 25));
+
+  expectedPositions.PushBack(Vector2(-1, 25));
+  expectedSizes.PushBack(Vector2(52, 25));
+
+  expectedPositions.PushBack(Vector2(-1, 50));
+  expectedSizes.PushBack(Vector2(59, 25));
+
+  expectedPositions.PushBack(Vector2(73, 75));
+  expectedSizes.PushBack(Vector2(37, 25));
+
+  TestTextGeometryUtils::CheckGeometryResult(positionsList, sizeList, expectedPositions, expectedSizes);
+
+  END_TEST;
+}
+
+int utcDaliTextLabelGeometryGlyphMiddle(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" utcDaliTextLabelGeometryGlyphMiddle");
+
+  TextLabel label = TextLabel::New();
+  DALI_TEST_CHECK( label );
+
+  application.GetScene().Add( label );
+
+  label.SetProperty( TextLabel::Property::POINT_SIZE, 7.f );
+  label.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
+  label.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+  label.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+  label.SetProperty( TextLabel::Property::ENABLE_MARKUP, true );
+  label.SetProperty( TextLabel::Property::TEXT, "لا تحتوي على لا" );
+
+  // Avoid a crash when core load gl resources.
+  application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
+
+  // Render and notify
+  application.SendNotification();
+  application.Render();
+
+  unsigned int expectedCount = 1;
+  unsigned int startIndex = 1;
+  unsigned int endIndex = 13;
+
+  Vector<Vector2> positionsList = DevelTextLabel::GetTextPosition(label, startIndex, endIndex);
+  Vector<Vector2> sizeList = DevelTextLabel::GetTextSize(label, startIndex, endIndex);
+
+  DALI_TEST_EQUALS(positionsList.Size(), expectedCount, TEST_LOCATION);
+  DALI_TEST_EQUALS(sizeList.Size(), expectedCount, TEST_LOCATION);
+
+  Vector<Vector2> expectedSizes;
+  Vector<Vector2> expectedPositions;
+
+  expectedPositions.PushBack(Vector2(12, 0));
+  expectedSizes.PushBack(Vector2(118, 25));
+
+  TestTextGeometryUtils::CheckGeometryResult(positionsList, sizeList, expectedPositions, expectedSizes);
+
+  END_TEST;
+}
+
 int UtcDaliToolkitTextlabelEllipsisPositionProperty(void)
 {
   ToolkitTestApplication application;
@@ -2058,4 +2183,4 @@ int UtcDaliToolkitTextlabelEllipsisPositionProperty(void)
 
 
   END_TEST;
-}
\ No newline at end of file
+}