From: Bowon Ryu Date: Fri, 4 Mar 2022 03:02:45 +0000 (+0000) Subject: Merge "fix issue with text size with negative line spacing" into devel/master X-Git-Tag: dali_2.1.13~13 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=85cc4dec9417a45d031bc8bc968e82df3339159e;hp=-c Merge "fix issue with text size with negative line spacing" into devel/master --- 85cc4dec9417a45d031bc8bc968e82df3339159e diff --combined automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp index f8b2799,7c391b5..06ef3fb --- a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp @@@ -5765,42 -5765,6 +5765,42 @@@ int UtcDaliToolkitTextEditorUnderlineTy END_TEST; } +int UtcDaliToolkitTextEditorRelativeLineHeight(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliToolkitTextEditorRelativeLineHeight"); + + TextEditor editor = TextEditor::New(); + editor.SetProperty(Actor::Property::SIZE, Vector2(200.0f, 300.f)); + editor.SetProperty(TextEditor::Property::POINT_SIZE, 10); + editor.SetProperty(TextEditor::Property::TEXT, "Hello\nWorld"); + + application.GetScene().Add(editor); + application.SendNotification(); + application.Render(); + + Vector3 naturalSize = editor.GetNaturalSize(); + + editor.SetProperty(DevelTextEditor::Property::RELATIVE_LINE_SIZE, 0.5f); + + application.SendNotification(); + application.Render(); + + Vector3 relativeNaturalSize = editor.GetNaturalSize(); + + DALI_TEST_EQUALS(naturalSize.y, relativeNaturalSize.y * 2, TEST_LOCATION); + + editor.SetProperty(DevelTextEditor::Property::RELATIVE_LINE_SIZE, 2.0f); + + application.SendNotification(); + application.Render(); + + relativeNaturalSize = editor.GetNaturalSize(); + + DALI_TEST_EQUALS(naturalSize.y * 2, relativeNaturalSize.y, TEST_LOCATION); + END_TEST; +} + int UtcDaliTextEditorCharacterSpacing(void) { ToolkitTestApplication application; @@@ -5824,6 -5788,39 +5824,39 @@@ END_TEST; } + int UtcDaliTextEditorTextSizeNegativeLineSpacing(void) + { + ToolkitTestApplication application; + tet_infoline("UtcDaliTextEditorTextSizeNegativeLineSpacing"); + + TextEditor editor = TextEditor::New(); + + float lineSpacing = -20.f; + + editor.SetProperty(Actor::Property::SIZE, Vector2(450.0f, 300.f)); + editor.SetProperty(TextEditor::Property::POINT_SIZE, 10.f); + editor.SetProperty(DevelTextEditor::Property::LINE_SPACING, lineSpacing); + editor.SetProperty(TextEditor::Property::TEXT, "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."); + + application.GetScene().Add(editor); + application.SendNotification(); + application.Render(); + + Vector positionsList = DevelTextEditor::GetTextPosition(editor, 0, 123); + Vector sizeList = DevelTextEditor::GetTextSize(editor, 0, 123); + + Vector2 lastLinePos = positionsList[positionsList.Size() - 1]; + Vector2 lastLineSize = sizeList[sizeList.Size() - 1]; + + DALI_TEST_EQUALS(sizeList[0].y * (sizeList.Size() - 1), lastLinePos.y, Math::MACHINE_EPSILON_1000, TEST_LOCATION); + DALI_TEST_EQUALS(sizeList[0].y - lineSpacing, lastLineSize.y, Math::MACHINE_EPSILON_1000, TEST_LOCATION); + + application.SendNotification(); + application.Render(); + + END_TEST; + } + int UtcDaliToolkitTexteditorParagraphTag(void) { ToolkitTestApplication application; diff --combined automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp index dc3cac4,b4d943d..4eaee42 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp @@@ -2632,42 -2632,6 +2632,42 @@@ int UtcDaliToolkitTextLabelStrikethroug END_TEST; } +int UtcDaliToolkitTextLabelRelativeLineHeight(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliToolkitTextLabelRelativeLineHeight"); + + TextLabel label = TextLabel::New(); + label.SetProperty(Actor::Property::SIZE, Vector2(200.0f, 300.f)); + label.SetProperty(TextLabel::Property::POINT_SIZE, 10); + label.SetProperty(TextLabel::Property::TEXT, "Hello\nWorld"); + + application.GetScene().Add(label); + application.SendNotification(); + application.Render(); + + Vector3 naturalSize = label.GetNaturalSize(); + + label.SetProperty(DevelTextLabel::Property::RELATIVE_LINE_SIZE, 0.5f); + + application.SendNotification(); + application.Render(); + + Vector3 relativeNaturalSize = label.GetNaturalSize(); + + DALI_TEST_EQUALS(naturalSize.y, relativeNaturalSize.y * 2, TEST_LOCATION); + + label.SetProperty(DevelTextLabel::Property::RELATIVE_LINE_SIZE, 2.0f); + + application.SendNotification(); + application.Render(); + + relativeNaturalSize = label.GetNaturalSize(); + + DALI_TEST_EQUALS(naturalSize.y * 2, relativeNaturalSize.y, TEST_LOCATION); + END_TEST; +} + int UtcDaliTextLabelCharacterSpacing(void) { ToolkitTestApplication application; @@@ -2691,6 -2655,40 +2691,40 @@@ END_TEST; } + int UtcDaliTextTextLabelSizeNegativeLineSpacing(void) + { + ToolkitTestApplication application; + tet_infoline("UtcDaliTextTextLabelSizeNegativeLineSpacing"); + + TextLabel label = TextLabel::New(); + + float lineSpacing = -20.f; + + label.SetProperty(Actor::Property::SIZE, Vector2(450.0f, 300.f)); + label.SetProperty(TextLabel::Property::POINT_SIZE, 10.f); + label.SetProperty(DevelTextLabel::Property::LINE_SPACING, lineSpacing); + label.SetProperty(TextLabel::Property::MULTI_LINE, true); + label.SetProperty(TextLabel::Property::TEXT, "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."); + + application.GetScene().Add(label); + application.SendNotification(); + application.Render(); + + Vector positionsList = DevelTextLabel::GetTextPosition(label, 0, 123); + Vector sizeList = DevelTextLabel::GetTextSize(label, 0, 123); + + Vector2 lastLinePos = positionsList[positionsList.Size() - 1]; + Vector2 lastLineSize = sizeList[sizeList.Size() - 1]; + + DALI_TEST_EQUALS(sizeList[0].y * (sizeList.Size() - 1), lastLinePos.y, Math::MACHINE_EPSILON_1000, TEST_LOCATION); + DALI_TEST_EQUALS(sizeList[0].y - lineSpacing, lastLineSize.y, Math::MACHINE_EPSILON_1000, TEST_LOCATION); + + application.SendNotification(); + application.Render(); + + END_TEST; + } + int UtcDaliToolkitTextlabelParagraphTag(void) { ToolkitTestApplication application; diff --combined dali-toolkit/internal/text/layouts/layout-engine.cpp index 8c8ea94,a85f5f6..53030e2 --- a/dali-toolkit/internal/text/layouts/layout-engine.cpp +++ b/dali-toolkit/internal/text/layouts/layout-engine.cpp @@@ -37,11 -37,18 +37,18 @@@ namespace Toolki { namespace Text { - float GetLineHeight(const LineRun lineRun) + float GetLineHeight(const LineRun lineRun, bool isLastLine) { // The line height is the addition of the line ascender, the line descender and the line spacing. // However, the line descender has a negative value, hence the subtraction. - return lineRun.ascender - lineRun.descender + lineRun.lineSpacing; + // In case this is the only/last line then line spacing should be ignored. + float lineHeight = lineRun.ascender - lineRun.descender; + + if(!isLastLine || lineRun.lineSpacing > 0) + { + lineHeight += lineRun.lineSpacing; + } + return lineHeight; } namespace Layout @@@ -52,13 -59,12 +59,13 @@@ namespac Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_LAYOUT"); #endif -const float MAX_FLOAT = std::numeric_limits::max(); -const CharacterDirection LTR = false; -const CharacterDirection RTL = !LTR; -const float LINE_SPACING = 0.f; -const float MIN_LINE_SIZE = 0.f; -const Character HYPHEN_UNICODE = 0x002D; +const float MAX_FLOAT = std::numeric_limits::max(); +const CharacterDirection LTR = false; +const CharacterDirection RTL = !LTR; +const float LINE_SPACING = 0.f; +const float MIN_LINE_SIZE = 0.f; +const Character HYPHEN_UNICODE = 0x002D; +const float RELATIVE_LINE_SIZE = 1.f; inline bool isEmptyLineAtLast(const Vector& lines, const Vector::Iterator& line) { @@@ -156,55 -162,11 +163,55 @@@ struct Engine::Imp : mLayout{Layout::Engine::SINGLE_LINE_BOX}, mCursorWidth{0.f}, mDefaultLineSpacing{LINE_SPACING}, - mDefaultLineSize{MIN_LINE_SIZE} + mDefaultLineSize{MIN_LINE_SIZE}, + mRelativeLineSize{RELATIVE_LINE_SIZE} { } /** + * @brief get the line spacing. + * + * @param[in] textSize The text size. + * @return the line spacing value. + */ + float GetLineSpacing(float textSize) + { + float lineSpacing; + float relTextSize; + + // Sets the line size + lineSpacing = mDefaultLineSize - textSize; + lineSpacing = lineSpacing < 0.f ? 0.f : lineSpacing; + + // Add the line spacing + lineSpacing += mDefaultLineSpacing; + + //subtract line spcaing if relativeLineSize < 1 & larger than min height + relTextSize = textSize * mRelativeLineSize; + if(relTextSize > mDefaultLineSize) + { + if(mRelativeLineSize < 1) + { + //subtract the difference (always will be positive) + lineSpacing -= (textSize - relTextSize); + } + else + { + //reverse the addition in the top. + if(mDefaultLineSize > textSize) + { + lineSpacing -= mDefaultLineSize - textSize; + } + + //add difference instead + lineSpacing += relTextSize - textSize; + } + } + + return lineSpacing; + } + + /** * @brief Updates the line ascender and descender with the metrics of a new font. * * @param[in] glyphMetrics The metrics of the new font. @@@ -232,7 -194,12 +239,7 @@@ // Sets the minimum descender. lineLayout.descender = std::min(lineLayout.descender, fontMetrics.descender); - // 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; + lineLayout.lineSpacing = GetLineSpacing(lineLayout.ascender + -lineLayout.descender); } /** @@@ -1297,7 -1264,7 +1304,7 @@@ layoutSize.width = layoutParameters.boundingBox.width; if(layoutSize.height < Math::MACHINE_EPSILON_1000) { - layoutSize.height += GetLineHeight(*lineRun); + layoutSize.height += GetLineHeight(*lineRun, true); } const Vector& bidirectionalLinesInfo = layoutParameters.textModel->mLogicalModel->mBidirectionalLineInfo; @@@ -1393,7 -1360,10 +1400,7 @@@ 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; + lineRun.lineSpacing = GetLineSpacing(lineRun.ascender + -lineRun.descender); // Update the actual size. if(lineRun.width > layoutSize.width) @@@ -1401,7 -1371,7 +1408,7 @@@ layoutSize.width = lineRun.width; } - layoutSize.height += GetLineHeight(lineRun); + layoutSize.height += GetLineHeight(lineRun, isLastLine); } /** @@@ -1447,9 -1417,12 +1454,9 @@@ lineRun.direction = LTR; lineRun.ellipsis = false; - lineRun.lineSpacing = mDefaultLineSize - (lineRun.ascender + -lineRun.descender); - lineRun.lineSpacing = lineRun.lineSpacing < 0.f ? 0.f : lineRun.lineSpacing; - - lineRun.lineSpacing += mDefaultLineSpacing; + lineRun.lineSpacing = GetLineSpacing(lineRun.ascender + -lineRun.descender); - layoutSize.height += GetLineHeight(lineRun); + layoutSize.height += GetLineHeight(lineRun, true); } /** @@@ -1466,14 -1439,15 +1473,15 @@@ it != endIt; ++it) { - const LineRun& line = *it; + const LineRun& line = *it; + bool isLastLine = (it + 1 == endIt); if(line.width > layoutSize.width) { layoutSize.width = line.width; } - layoutSize.height += GetLineHeight(line); + layoutSize.height += GetLineHeight(line, isLastLine); } } @@@ -1845,7 -1819,14 +1853,7 @@@ } // Updates the vertical pen's position. - penY += -layout.descender + layout.lineSpacing + mDefaultLineSpacing; - // If there is a defaultLineSize, updates the pen's position. - if(mDefaultLineSize > 0.f) - { - float lineSpacing = mDefaultLineSize - (layout.ascender + -layout.descender); - lineSpacing = lineSpacing < 0.f ? 0.f : lineSpacing; - penY += lineSpacing; - } + penY += -layout.descender + layout.lineSpacing + GetLineSpacing(layout.ascender + -layout.descender); // Increase the glyph index. index = nextIndex; @@@ -2104,7 -2085,6 +2112,7 @@@ float mDefaultLineSize; IntrusivePtr mMetrics; + float mRelativeLineSize; }; Engine::Engine() @@@ -2196,16 -2176,6 +2204,16 @@@ float Engine::GetDefaultLineSize() cons return mImpl->mDefaultLineSize; } +void Engine::SetRelativeLineSize(float relativeLineSize) +{ + mImpl->mRelativeLineSize = relativeLineSize; +} + +float Engine::GetRelativeLineSize() const +{ + return mImpl->mRelativeLineSize; +} + } // namespace Layout } // namespace Text