From dd0935960c1acaf63d2b4f560b39236b871135b7 Mon Sep 17 00:00:00 2001 From: Joogab Yun Date: Tue, 12 May 2020 14:55:59 +0900 Subject: [PATCH] Add MIN_LINE_SIZE property 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 --- .../src/dali-toolkit/utc-Dali-TextLabel.cpp | 5 +++ .../controls/text-controls/text-label-devel.h | 7 ++++ .../controls/text-controls/text-label-impl.cpp | 24 ++++++++++++- .../internal/text/layouts/layout-engine.cpp | 39 ++++++++++++++++++---- dali-toolkit/internal/text/layouts/layout-engine.h | 14 ++++++++ dali-toolkit/internal/text/text-controller.cpp | 16 +++++++++ dali-toolkit/internal/text/text-controller.h | 16 +++++++++ 7 files changed, 113 insertions(+), 8 deletions(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp index 9f9ce5f..2d6b092 100755 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp @@ -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 ); + // Check the line size property + DALI_TEST_EQUALS( label.GetProperty( 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( DevelTextLabel::Property::MIN_LINE_SIZE ), 50.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); + application.SendNotification(); application.Render(); diff --git a/dali-toolkit/devel-api/controls/text-controls/text-label-devel.h b/dali-toolkit/devel-api/controls/text-controls/text-label-devel.h index 72ad6f8..9190441 100755 --- a/dali-toolkit/devel-api/controls/text-controls/text-label-devel.h +++ b/dali-toolkit/devel-api/controls/text-controls/text-label-devel.h @@ -140,6 +140,13 @@ namespace Property */ 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 diff --git a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp index c521817..2fddac3 100755 --- a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp @@ -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, "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 ) @@ -553,6 +554,19 @@ void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Pr } break; } + case Toolkit::DevelTextLabel::Property::MIN_LINE_SIZE: + { + if( impl.mController ) + { + const float lineSize = value.Get(); + + if( impl.mController->SetDefaultLineSize( lineSize ) ) + { + impl.mTextUpdateNeeded = true; + } + } + break; + } } // 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; } + case Toolkit::DevelTextLabel::Property::MIN_LINE_SIZE: + { + if( impl.mController ) + { + value = impl.mController->GetDefaultLineSize(); + } + break; + } } } diff --git a/dali-toolkit/internal/text/layouts/layout-engine.cpp b/dali-toolkit/internal/text/layouts/layout-engine.cpp index e91ebae..fb63d96 100755 --- a/dali-toolkit/internal/text/layouts/layout-engine.cpp +++ b/dali-toolkit/internal/text/layouts/layout-engine.cpp @@ -52,7 +52,8 @@ namespace const float MAX_FLOAT = std::numeric_limits::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& lines, const Vector::Iterator& line ) { @@ -130,7 +131,8 @@ struct Engine::Impl 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 ); - // 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.lineSpacing = mDefaultLineSpacing; - 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.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 ) { @@ -986,7 +996,11 @@ struct Engine::Impl 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; } @@ -1551,6 +1565,7 @@ struct Engine::Impl Type mLayout; float mCursorWidth; float mDefaultLineSpacing; + float mDefaultLineSize; IntrusivePtr mMetrics; }; @@ -1632,6 +1647,16 @@ float Engine::GetDefaultLineSpacing() const return mImpl->mDefaultLineSpacing; } +void Engine::SetDefaultLineSize( float lineSize ) +{ + mImpl->mDefaultLineSize = lineSize; +} + +float Engine::GetDefaultLineSize() const +{ + return mImpl->mDefaultLineSize; +} + } // namespace Layout } // namespace Text diff --git a/dali-toolkit/internal/text/layouts/layout-engine.h b/dali-toolkit/internal/text/layouts/layout-engine.h index af693da..5641c47 100755 --- a/dali-toolkit/internal/text/layouts/layout-engine.h +++ b/dali-toolkit/internal/text/layouts/layout-engine.h @@ -152,6 +152,20 @@ public: */ 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 diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index b4624dc..cfac37f 100755 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -1462,6 +1462,22 @@ float Controller::GetDefaultLineSpacing() const 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 ) diff --git a/dali-toolkit/internal/text/text-controller.h b/dali-toolkit/internal/text/text-controller.h index 6a986f5..c7a549e 100755 --- a/dali-toolkit/internal/text/text-controller.h +++ b/dali-toolkit/internal/text/text-controller.h @@ -1055,6 +1055,22 @@ public: // Default style & Input style 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. -- 2.7.4