From ef26ad3f7e7de375b10d1f17052a78915eae2976 Mon Sep 17 00:00:00 2001 From: "minho.sun" Date: Mon, 13 Aug 2018 18:52:28 +0900 Subject: [PATCH] Added IGNORE_SPACES_AFTER_TEXT property Currently, DALi doesn't make text to ellipsis when there are spaces after text. "AAA " can't be ellipsis. "AAA A" can be ellipsis. User wants to choose whether ignoring spaces after text or not. So, added devel text property for this which is named IGNORE_SPACES_AFTER_TEXT. Change-Id: Ibad9f70b1f8012dc4e04914e4f98072fc8741ad9 Signed-off-by: minho.sun --- .../dali-toolkit-test-utils/toolkit-text-utils.cpp | 3 ++- .../src/dali-toolkit-internal/utc-Dali-Text-Layout.cpp | 6 ++++-- automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp | 15 +++++++++++++++ .../devel-api/controls/text-controls/text-label-devel.h | 7 +++++++ .../internal/controls/text-controls/text-label-impl.cpp | 11 +++++++++++ dali-toolkit/internal/text/layouts/layout-engine.cpp | 10 +++++++++- dali-toolkit/internal/text/layouts/layout-parameters.h | 9 ++++++--- dali-toolkit/internal/text/text-controller.cpp | 13 ++++++++++++- dali-toolkit/internal/text/text-controller.h | 12 ++++++++++++ dali-toolkit/internal/text/text-model.cpp | 3 ++- dali-toolkit/internal/text/text-model.h | 17 +++++++++-------- .../styles/1920x1080/dali-toolkit-default-theme.json | 3 ++- 12 files changed, 91 insertions(+), 18 deletions(-) diff --git a/automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/toolkit-text-utils.cpp b/automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/toolkit-text-utils.cpp index b977ec3..24ff3f7 100755 --- a/automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/toolkit-text-utils.cpp +++ b/automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/toolkit-text-utils.cpp @@ -284,7 +284,8 @@ void CreateTextModel( const std::string& text, numberOfGlyphs, Text::HorizontalAlignment::BEGIN, Text::LineWrap::WORD, - outlineWidth ); + outlineWidth, + true ); Vector& lines = visualModel->mLines; diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Layout.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Layout.cpp index 86edead..dfe1397 100644 --- a/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Layout.cpp +++ b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Layout.cpp @@ -172,7 +172,8 @@ bool LayoutTextTest( const LayoutTextData& data ) totalNumberOfGlyphs, Text::HorizontalAlignment::BEGIN, Text::LineWrap::WORD, - outlineWidth ); + outlineWidth, + true ); layoutParameters.isLastNewParagraph = isLastNewParagraph; @@ -390,7 +391,8 @@ bool ReLayoutRightToLeftLinesTest( const ReLayoutRightToLeftLinesData& data ) visualModel->mGlyphs.Count(), Text::HorizontalAlignment::BEGIN, Text::LineWrap::WORD, - outlineWidth ); + outlineWidth, + true ); layoutParameters.numberOfBidirectionalInfoRuns = logicalModel->mBidirectionalLineInfo.Count(); layoutParameters.lineBidirectionalInfoRunsBuffer = logicalModel->mBidirectionalLineInfo.Begin(); diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp index b134179..f19cb12 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp @@ -1047,6 +1047,21 @@ int UtcDaliToolkitTextlabelEllipsis(void) tet_result(TET_FAIL); } + label.SetProperty( TextLabel::Property::TEXT, "Hello world " ); + label.SetProperty( DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT, false ); + label.SetSize( 400.0f, 10.f ); + + try + { + // Render the text. + application.SendNotification(); + application.Render(); + } + catch( ... ) + { + tet_result(TET_FAIL); + } + END_TEST; } 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 939c08d..0b16273 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-label-devel.h +++ b/dali-toolkit/devel-api/controls/text-controls/text-label-devel.h @@ -94,6 +94,13 @@ namespace Property * | color | VECTOR4 | No | The color of the background (the default value is Color::CYAN) | */ BACKGROUND, + + /** + * @brief Ignore spaces after text. + * @details Name "ignoreSpacesAfterText", type (Property::BOLEAN), Read/Write + * @note The default value is true + */ + IGNORE_SPACES_AFTER_TEXT, }; } // 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 7c6ef25..bb40d00 100644 --- a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp @@ -131,6 +131,7 @@ DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineWrapMode", DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "textDirection", INTEGER, TEXT_DIRECTION ) DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "verticalLineAlignment", INTEGER, VERTICAL_LINE_ALIGNMENT ) DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "textBackground", MAP, BACKGROUND ) +DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "ignoreSpacesAfterText", BOOLEAN, IGNORE_SPACES_AFTER_TEXT ) 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 ) @@ -533,6 +534,11 @@ void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Pr } break; } + case Toolkit::DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT: + { + impl.mController->SetIgnoreSpacesAfterText(value.Get< bool >()); + break; + } } // Request relayout when text update is needed. It's necessary to call it @@ -831,6 +837,11 @@ Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index inde GetBackgroundProperties( impl.mController, value, Text::EffectStyle::DEFAULT ); break; } + case Toolkit::DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT: + { + value = impl.mController->IsIgnoreSpacesAfterText(); + break; + } } } diff --git a/dali-toolkit/internal/text/layouts/layout-engine.cpp b/dali-toolkit/internal/text/layouts/layout-engine.cpp index af257ff..4f9a47c 100644 --- a/dali-toolkit/internal/text/layouts/layout-engine.cpp +++ b/dali-toolkit/internal/text/layouts/layout-engine.cpp @@ -397,11 +397,19 @@ struct Engine::Impl tmpLineLayout.wsLengthEndOfLine = 0.f; } + // If calculation is end but wsLengthEndOfLine is exist, it means end of text is space. + // Merge remained length. + if ( !parameters.ignoreSpaceAfterText && glyphIndex == lastGlyphOfParagraphPlusOne-1 && tmpLineLayout.wsLengthEndOfLine > 0 ) + { + tmpLineLayout.length += tmpLineLayout.wsLengthEndOfLine; + tmpLineLayout.wsLengthEndOfLine = 0u; + } + // Save the current extra width to compare with the next one mPreviousCharacterExtraWidth = tmpExtraWidth; // Check if the accumulated length fits in the width of the box. - if( ( completelyFill || isMultiline ) && !isWhiteSpace && + if( ( completelyFill || isMultiline ) && !(parameters.ignoreSpaceAfterText && isWhiteSpace) && ( tmpExtraBearing + lineLayout.length + lineLayout.wsLengthEndOfLine + tmpLineLayout.length + tmpExtraWidth > parameters.boundingBox.width ) ) { // Current word does not fit in the box's width. diff --git a/dali-toolkit/internal/text/layouts/layout-parameters.h b/dali-toolkit/internal/text/layouts/layout-parameters.h index 7f3e169..5a77d86 100644 --- a/dali-toolkit/internal/text/layouts/layout-parameters.h +++ b/dali-toolkit/internal/text/layouts/layout-parameters.h @@ -74,7 +74,8 @@ struct Parameters Length totalNumberOfGlyphs, Text::HorizontalAlignment::Type horizontalAlignment, Text::LineWrap::Mode lineWrapMode, - float outlineWidth ) + float outlineWidth, + bool ignoreSpaceAfterText ) : boundingBox( boundingBox ), textBuffer( textBuffer ), lineBreakInfoBuffer( lineBreakInfoBuffer ), @@ -94,8 +95,9 @@ struct Parameters startLineIndex( 0u ), estimatedNumberOfLines( 0u ), lineWrapMode( lineWrapMode ), + outlineWidth( outlineWidth ), isLastNewParagraph( false ), - outlineWidth( outlineWidth ) + ignoreSpaceAfterText( ignoreSpaceAfterText ) {} Vector2 boundingBox; ///< The size of the box containing the text. @@ -117,8 +119,9 @@ struct Parameters LineIndex startLineIndex; ///< The line index where to insert the new lines. Length estimatedNumberOfLines; ///< The estimated number of lines. Text::LineWrap::Mode lineWrapMode; ///< The line wrap mode for moving to next line. - bool isLastNewParagraph; ///< Whether the last character is a new paragraph character. float outlineWidth; ///< The outline width. + bool isLastNewParagraph:1; ///< Whether the last character is a new paragraph character. + bool ignoreSpaceAfterText:1; ///< Whether ignoring spaces after text or not. Default is true. }; } // namespace Layout diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index 4ce4b5a..227760f 100755 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -407,6 +407,16 @@ VerticalAlignment::Type Controller::GetVerticalAlignment() const return mImpl->mModel->mVerticalAlignment; } +bool Controller::IsIgnoreSpacesAfterText() const +{ + return mImpl->mModel->mIgnoreSpacesAfterText; +} + +void Controller::SetIgnoreSpacesAfterText( bool ignore ) +{ + mImpl->mModel->mIgnoreSpacesAfterText = ignore; +} + void Controller::SetLineWrapMode( Text::LineWrap::Mode lineWrapMode ) { if( lineWrapMode != mImpl->mModel->mLineWrapMode ) @@ -3533,7 +3543,8 @@ bool Controller::DoRelayout( const Size& size, totalNumberOfGlyphs, mImpl->mModel->mHorizontalAlignment, mImpl->mModel->mLineWrapMode, - outlineWidth ); + outlineWidth, + mImpl->mModel->mIgnoreSpacesAfterText ); // Resize the vector of positions to have the same size than the vector of glyphs. Vector& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions; diff --git a/dali-toolkit/internal/text/text-controller.h b/dali-toolkit/internal/text/text-controller.h index 92677f2..25bb13b 100755 --- a/dali-toolkit/internal/text/text-controller.h +++ b/dali-toolkit/internal/text/text-controller.h @@ -1231,6 +1231,18 @@ public: // Queries & retrieves. */ void SetVerticalLineAlignment( Toolkit::DevelText::VerticalLineAlignment::Type alignment ); + /** + * @brief Retrieves ignoreSpaceAfterText value from model + * @return The value of ignoreSpaceAfterText + */ + bool IsIgnoreSpacesAfterText() const; + + /** + * @brief Sets ignoreSpaceAfterText value to model + * @param[in] ignore The value of ignoreSpacesAfterText for the text + */ + void SetIgnoreSpacesAfterText( bool ignore ); + public: // Relayout. /** diff --git a/dali-toolkit/internal/text/text-model.cpp b/dali-toolkit/internal/text/text-model.cpp index 84b0428..65494e5 100755 --- a/dali-toolkit/internal/text/text-model.cpp +++ b/dali-toolkit/internal/text/text-model.cpp @@ -187,7 +187,8 @@ Model::Model() mVerticalLineAlignment( DevelText::VerticalLineAlignment::TOP ), mLineWrapMode( Text::LineWrap::WORD ), mAlignmentOffset( 0.0f ), - mElideEnabled( false ) + mElideEnabled( false ), + mIgnoreSpacesAfterText( true ) { mLogicalModel = LogicalModel::New(); mVisualModel = VisualModel::New(); diff --git a/dali-toolkit/internal/text/text-model.h b/dali-toolkit/internal/text/text-model.h index cb8d77c..1ea725c 100755 --- a/dali-toolkit/internal/text/text-model.h +++ b/dali-toolkit/internal/text/text-model.h @@ -230,14 +230,15 @@ public: * 0,0 means that the top-left corner of the layout matches the top-left corner of the UI control. * Typically this will have a negative value with scrolling occurs. */ - Vector2 mScrollPosition; ///< The text is offset by this position when scrolling. - Vector2 mScrollPositionLast; ///< The last offset value of mScrollPosition - HorizontalAlignment::Type mHorizontalAlignment; ///< The layout's horizontal alignment. - VerticalAlignment::Type mVerticalAlignment; ///< The layout's vertical alignment. - DevelText::VerticalLineAlignment::Type mVerticalLineAlignment; ///< The layout's vertical line alignment. - Text::LineWrap::Mode mLineWrapMode; ///< The text wrap mode - float mAlignmentOffset; ///< The alignment offset. - bool mElideEnabled:1; ///< Whether the text's elide is enabled. + Vector2 mScrollPosition; ///< The text is offset by this position when scrolling. + Vector2 mScrollPositionLast; ///< The last offset value of mScrollPosition + HorizontalAlignment::Type mHorizontalAlignment; ///< The layout's horizontal alignment. + VerticalAlignment::Type mVerticalAlignment; ///< The layout's vertical alignment. + DevelText::VerticalLineAlignment::Type mVerticalLineAlignment; ///< The layout's vertical line alignment. + Text::LineWrap::Mode mLineWrapMode; ///< The text wrap mode + float mAlignmentOffset; ///< The alignment offset. + bool mElideEnabled:1; ///< Whether the text's elide is enabled. + bool mIgnoreSpacesAfterText:1; ///< Whether ignoring spaces after text or not. Default is true. }; } // namespace Text diff --git a/dali-toolkit/styles/1920x1080/dali-toolkit-default-theme.json b/dali-toolkit/styles/1920x1080/dali-toolkit-default-theme.json index fa8c6f8..43bd4e5 100644 --- a/dali-toolkit/styles/1920x1080/dali-toolkit-default-theme.json +++ b/dali-toolkit/styles/1920x1080/dali-toolkit-default-theme.json @@ -66,7 +66,8 @@ "enableAutoScroll":false, "autoScrollLoopCount":2, "autoScrollGap":50, - "autoScrollSpeed":80 + "autoScrollSpeed":80, + "ignoreSpacesAfterText":false }, "TextLabelFontSize0": -- 2.7.4