Add MIN_LINE_SIZE property 95/233095/14
authorJoogab Yun <joogab.yun@samsung.com>
Tue, 12 May 2020 05:55:59 +0000 (14:55 +0900)
committerJoogab Yun <joogab.yun@samsung.com>
Thu, 14 May 2020 08:59:57 +0000 (17:59 +0900)
Users want to set the line size in multi-line.
We have a lineSpacing property which allows us to set the spacing of the lines.

However, the user wants to achieve a similar effect by setting the size of the line, not lineSpacing.

Change-Id: Ia96e1875e90454a3269d2ad853d3c4e20ce66ae9

automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp
dali-toolkit/devel-api/controls/text-controls/text-label-devel.h
dali-toolkit/internal/controls/text-controls/text-label-impl.cpp
dali-toolkit/internal/text/layouts/layout-engine.cpp
dali-toolkit/internal/text/layouts/layout-engine.h
dali-toolkit/internal/text/text-controller.cpp
dali-toolkit/internal/text/text-controller.h

index 9f9ce5f..2d6b092 100755 (executable)
@@ -637,6 +637,11 @@ int UtcDaliToolkitTextLabelSetPropertyP(void)
   label.SetProperty( Actor::Property::LAYOUT_DIRECTION, LayoutDirection::RIGHT_TO_LEFT );
   DALI_TEST_EQUALS( label.GetProperty< int >( Actor::Property::LAYOUT_DIRECTION ), static_cast< int >( LayoutDirection::RIGHT_TO_LEFT ), TEST_LOCATION );
 
   label.SetProperty( Actor::Property::LAYOUT_DIRECTION, LayoutDirection::RIGHT_TO_LEFT );
   DALI_TEST_EQUALS( label.GetProperty< int >( Actor::Property::LAYOUT_DIRECTION ), static_cast< int >( LayoutDirection::RIGHT_TO_LEFT ), TEST_LOCATION );
 
+  // Check the line size property
+  DALI_TEST_EQUALS( label.GetProperty<float>( DevelTextLabel::Property::MIN_LINE_SIZE ), 0.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
+  label.SetProperty( DevelTextLabel::Property::MIN_LINE_SIZE, 50.f );
+  DALI_TEST_EQUALS( label.GetProperty<float>( DevelTextLabel::Property::MIN_LINE_SIZE ), 50.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
+
   application.SendNotification();
   application.Render();
 
   application.SendNotification();
   application.Render();
 
index 72ad6f8..9190441 100755 (executable)
@@ -140,6 +140,13 @@ namespace Property
      */
     TEXT_FIT,
 
      */
     TEXT_FIT,
 
+    /**
+     * @brief Sets the height of the line in points.
+     * @details Name "lineSize", type Property::FLOAT.
+     * @note If the font size is larger than the line size, it works with the font size.
+     */
+    MIN_LINE_SIZE,
+
   };
 
 } // namespace Property
   };
 
 } // namespace Property
index c521817..2fddac3 100755 (executable)
@@ -140,7 +140,8 @@ DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit,     TextLabel, "verticalLineAlignment
 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit,     TextLabel, "textBackground",            MAP,     BACKGROUND                 )
 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit,     TextLabel, "ignoreSpacesAfterText",     BOOLEAN, IGNORE_SPACES_AFTER_TEXT   )
 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit,     TextLabel, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION )
 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit,     TextLabel, "textBackground",            MAP,     BACKGROUND                 )
 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit,     TextLabel, "ignoreSpacesAfterText",     BOOLEAN, IGNORE_SPACES_AFTER_TEXT   )
 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit,     TextLabel, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION )
-DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit,     TextLabel, "textFit",                   MAP,     TEXT_FIT                 )
+DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit,     TextLabel, "textFit",                   MAP,     TEXT_FIT                   )
+DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit,     TextLabel, "minLineSize",               FLOAT,   MIN_LINE_SIZE              )
 DALI_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT( Toolkit, TextLabel, "textColor",      Color::BLACK,     TEXT_COLOR     )
 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit,    TextLabel, "textColorRed",   TEXT_COLOR_RED,   TEXT_COLOR, 0  )
 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit,    TextLabel, "textColorGreen", TEXT_COLOR_GREEN, TEXT_COLOR, 1  )
 DALI_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT( Toolkit, TextLabel, "textColor",      Color::BLACK,     TEXT_COLOR     )
 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit,    TextLabel, "textColorRed",   TEXT_COLOR_RED,   TEXT_COLOR, 0  )
 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit,    TextLabel, "textColorGreen", TEXT_COLOR_GREEN, TEXT_COLOR, 1  )
@@ -553,6 +554,19 @@ void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Pr
         }
         break;
       }
         }
         break;
       }
+      case Toolkit::DevelTextLabel::Property::MIN_LINE_SIZE:
+      {
+        if( impl.mController )
+        {
+          const float lineSize = value.Get<float>();
+
+          if( impl.mController->SetDefaultLineSize( lineSize ) )
+          {
+            impl.mTextUpdateNeeded = true;
+          }
+        }
+        break;
+      }
     }
 
     // Request relayout when text update is needed. It's necessary to call it
     }
 
     // Request relayout when text update is needed. It's necessary to call it
@@ -834,6 +848,14 @@ Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index inde
         value = map;
         break;
       }
         value = map;
         break;
       }
+      case Toolkit::DevelTextLabel::Property::MIN_LINE_SIZE:
+      {
+        if( impl.mController )
+        {
+          value = impl.mController->GetDefaultLineSize();
+        }
+        break;
+      }
     }
   }
 
     }
   }
 
index e91ebae..fb63d96 100755 (executable)
@@ -52,7 +52,8 @@ namespace
 const float MAX_FLOAT = std::numeric_limits<float>::max();
 const CharacterDirection LTR = false;
 const CharacterDirection RTL = !LTR;
 const float MAX_FLOAT = std::numeric_limits<float>::max();
 const CharacterDirection LTR = false;
 const CharacterDirection RTL = !LTR;
-const float LINE_SPACING= 0.f;
+const float LINE_SPACING = 0.f;
+const float MIN_LINE_SIZE = 0.f;
 
 inline bool isEmptyLineAtLast( const Vector<LineRun>& lines, const Vector<LineRun>::Iterator& line )
 {
 
 inline bool isEmptyLineAtLast( const Vector<LineRun>& lines, const Vector<LineRun>::Iterator& line )
 {
@@ -130,7 +131,8 @@ struct Engine::Impl
   Impl()
   : mLayout{ Layout::Engine::SINGLE_LINE_BOX },
     mCursorWidth{ 0.f },
   Impl()
   : mLayout{ Layout::Engine::SINGLE_LINE_BOX },
     mCursorWidth{ 0.f },
-    mDefaultLineSpacing{ LINE_SPACING }
+    mDefaultLineSpacing{ LINE_SPACING },
+    mDefaultLineSize{ MIN_LINE_SIZE }
   {
   }
 
   {
   }
 
@@ -162,8 +164,12 @@ struct Engine::Impl
     // Sets the minimum descender.
     lineLayout.descender = std::min( lineLayout.descender, fontMetrics.descender );
 
     // Sets the minimum descender.
     lineLayout.descender = std::min( lineLayout.descender, fontMetrics.descender );
 
-    // set the line spacing
-    lineLayout.lineSpacing = mDefaultLineSpacing;
+    // Sets the line size
+    lineLayout.lineSpacing = mDefaultLineSize - ( lineLayout.ascender + -lineLayout.descender );
+    lineLayout.lineSpacing = lineLayout.lineSpacing < 0.f ? 0.f : lineLayout.lineSpacing;
+
+    // Add the line spacing
+    lineLayout.lineSpacing += mDefaultLineSpacing;
   }
 
   /**
   }
 
   /**
@@ -921,8 +927,6 @@ struct Engine::Impl
     lineRun.glyphRun.numberOfGlyphs = layout.numberOfGlyphs;
     lineRun.characterRun.characterIndex = layout.characterIndex;
     lineRun.characterRun.numberOfCharacters = layout.numberOfCharacters;
     lineRun.glyphRun.numberOfGlyphs = layout.numberOfGlyphs;
     lineRun.characterRun.characterIndex = layout.characterIndex;
     lineRun.characterRun.numberOfCharacters = layout.numberOfCharacters;
-    lineRun.lineSpacing = mDefaultLineSpacing;
-
     lineRun.width = layout.length;
     lineRun.extraLength = std::ceil( layout.whiteSpaceLengthEndOfLine );
 
     lineRun.width = layout.length;
     lineRun.extraLength = std::ceil( layout.whiteSpaceLengthEndOfLine );
 
@@ -935,6 +939,12 @@ struct Engine::Impl
     lineRun.direction = layout.direction;
     lineRun.ellipsis = false;
 
     lineRun.direction = layout.direction;
     lineRun.ellipsis = false;
 
+    lineRun.lineSpacing = mDefaultLineSize - ( lineRun.ascender + -lineRun.descender );
+    lineRun.lineSpacing = lineRun.lineSpacing < 0.f ? 0.f : lineRun.lineSpacing;
+
+    lineRun.lineSpacing += mDefaultLineSpacing;
+
+
     // Update the actual size.
     if( lineRun.width > layoutSize.width )
     {
     // Update the actual size.
     if( lineRun.width > layoutSize.width )
     {
@@ -986,7 +996,11 @@ struct Engine::Impl
     lineRun.alignmentOffset = 0.f;
     lineRun.direction = LTR;
     lineRun.ellipsis = false;
     lineRun.alignmentOffset = 0.f;
     lineRun.direction = LTR;
     lineRun.ellipsis = false;
-    lineRun.lineSpacing = mDefaultLineSpacing;
+
+    lineRun.lineSpacing = mDefaultLineSize - ( lineRun.ascender + -lineRun.descender );
+    lineRun.lineSpacing = lineRun.lineSpacing < 0.f ? 0.f : lineRun.lineSpacing;
+
+    lineRun.lineSpacing += mDefaultLineSpacing;
 
     layoutSize.height += ( lineRun.ascender + -lineRun.descender ) + lineRun.lineSpacing;
   }
 
     layoutSize.height += ( lineRun.ascender + -lineRun.descender ) + lineRun.lineSpacing;
   }
@@ -1551,6 +1565,7 @@ struct Engine::Impl
   Type mLayout;
   float mCursorWidth;
   float mDefaultLineSpacing;
   Type mLayout;
   float mCursorWidth;
   float mDefaultLineSpacing;
+  float mDefaultLineSize;
 
   IntrusivePtr<Metrics> mMetrics;
 };
 
   IntrusivePtr<Metrics> mMetrics;
 };
@@ -1632,6 +1647,16 @@ float Engine::GetDefaultLineSpacing() const
   return mImpl->mDefaultLineSpacing;
 }
 
   return mImpl->mDefaultLineSpacing;
 }
 
+void Engine::SetDefaultLineSize( float lineSize )
+{
+  mImpl->mDefaultLineSize = lineSize;
+}
+
+float Engine::GetDefaultLineSize() const
+{
+  return mImpl->mDefaultLineSize;
+}
+
 } // namespace Layout
 
 } // namespace Text
 } // namespace Layout
 
 } // namespace Text
index af693da..5641c47 100755 (executable)
@@ -152,6 +152,20 @@ public:
    */
   float GetDefaultLineSpacing() const;
 
    */
   float GetDefaultLineSpacing() const;
 
+  /**
+   * @brief Sets the default line size.
+   *
+   * @param[in] lineSize The line size.
+   */
+  void SetDefaultLineSize( float lineSize );
+
+  /**
+   * @brief Retrieves the default line size.
+   *
+   * @return The line size.
+   */
+  float GetDefaultLineSize() const;
+
 private:
 
   // Undefined
 private:
 
   // Undefined
index b4624dc..cfac37f 100755 (executable)
@@ -1462,6 +1462,22 @@ float Controller::GetDefaultLineSpacing() const
   return mImpl->mLayoutEngine.GetDefaultLineSpacing();
 }
 
   return mImpl->mLayoutEngine.GetDefaultLineSpacing();
 }
 
+bool Controller::SetDefaultLineSize( float lineSize )
+{
+  if( std::fabs( lineSize - mImpl->mLayoutEngine.GetDefaultLineSize() ) > Math::MACHINE_EPSILON_1000 )
+  {
+    mImpl->mLayoutEngine.SetDefaultLineSize(lineSize);
+    mImpl->mRecalculateNaturalSize = true;
+    return true;
+  }
+  return false;
+}
+
+float Controller::GetDefaultLineSize() const
+{
+  return mImpl->mLayoutEngine.GetDefaultLineSize();
+}
+
 void Controller::SetInputColor( const Vector4& color )
 {
   if( NULL != mImpl->mEventData )
 void Controller::SetInputColor( const Vector4& color )
 {
   if( NULL != mImpl->mEventData )
index 6a986f5..c7a549e 100755 (executable)
@@ -1055,6 +1055,22 @@ public: // Default style & Input style
   float GetDefaultLineSpacing() const;
 
   /**
   float GetDefaultLineSpacing() const;
 
   /**
+   * @brief Sets the default line size.
+   *
+   * @param[in] lineSize The line size.
+   *
+   * @return True if lineSize has been updated, false otherwise
+   */
+  bool SetDefaultLineSize( float lineSize );
+
+  /**
+   * @brief Retrieves the default line size.
+   *
+   * @return The line size.
+   */
+  float GetDefaultLineSize() const;
+
+  /**
    * @brief Sets the input text's color.
    *
    * @param[in] color The input text's color.
    * @brief Sets the input text's color.
    *
    * @param[in] color The input text's color.