From cd5b6f3ff9138207df66d93e95a750fa9f56c70b Mon Sep 17 00:00:00 2001 From: ssabah Date: Wed, 20 Apr 2022 12:03:48 +0300 Subject: [PATCH 1/1] Resolved incorrect size when call GetTextSize(TextLabel) for one glyph GetTextSize(TextLabel) for one glyph return zero size with ellipsis end. But it works fine with GetTextSize(TextEditor). To check it: =========================================================== Window window = application.GetWindow(); window.SetBackgroundColor(Color::WHITE); textLabel = TextLabel::New(); textLabel.SetProperty(TextLabel::Property::POINT_SIZE, 7.f); textLabel.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f)); textLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); textLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); textLabel.SetProperty(TextLabel::Property::TEXT, "H"); window.Add(textLabel); ... Vector sizesList = DevelTextLabel::GetTextSize(textLabel, 0u, 0u); =========================================================== Change-Id: I38f6177c46f7485663412d55d95a5ffc318341f9 --- .../src/dali-toolkit/utc-Dali-TextEditor.cpp | 49 ++++++++++++++++++++- .../src/dali-toolkit/utc-Dali-TextLabel.cpp | 51 ++++++++++++++++++++-- dali-toolkit/internal/text/text-geometry.cpp | 2 +- dali-toolkit/internal/text/text-view.cpp | 3 +- 4 files changed, 97 insertions(+), 8 deletions(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp index 476da78..c3a08ed 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp @@ -4860,7 +4860,7 @@ int utcDaliTextEditorGeometryEllipsisEnd(void) expectedSizes.PushBack(Vector2(59, 25)); expectedPositions.PushBack(Vector2(-1, 25)); - expectedSizes.PushBack(Vector2(25, 25)); + expectedSizes.PushBack(Vector2(38, 25)); TestTextGeometryUtils::CheckGeometryResult(positionsList, sizeList, expectedPositions, expectedSizes); @@ -4966,6 +4966,51 @@ int utcDaliTextEditorGeometryGlyphMiddle(void) END_TEST; } +int utcDaliTextEditorGeometryOneGlyph(void) +{ + ToolkitTestApplication application; + tet_infoline(" utcDaliTextEditorGeometryOneGlyph "); + + TextEditor label = TextEditor::New(); + DALI_TEST_CHECK(label); + + application.GetScene().Add(label); + + label.SetProperty(TextEditor::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(TextEditor::Property::ENABLE_MARKUP, true); + label.SetProperty(TextEditor::Property::TEXT, "H"); + + // 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 = 0; + unsigned int endIndex = 0; + + Vector positionsList = DevelTextEditor::GetTextPosition(label, startIndex, endIndex); + Vector sizeList = DevelTextEditor::GetTextSize(label, startIndex, endIndex); + + DALI_TEST_EQUALS(positionsList.Size(), expectedCount, TEST_LOCATION); + DALI_TEST_EQUALS(sizeList.Size(), expectedCount, TEST_LOCATION); + + Vector expectedSizes; + Vector expectedPositions; + + expectedPositions.PushBack(Vector2(-2, 0)); + expectedSizes.PushBack(Vector2(16, 25)); + + TestTextGeometryUtils::CheckGeometryResult(positionsList, sizeList, expectedPositions, expectedSizes); + + END_TEST; +} + int utcDaliTextEditorSelectionClearedSignal(void) { ToolkitTestApplication application; @@ -5840,7 +5885,7 @@ int UtcDaliToolkitTextEditorMarkupRelativeLineHeight(void) //no effect of relative line size for paragraph with single line DALI_TEST_EQUALS(naturalSize.y, relativeSingleNaturalSize.y, Math::MACHINE_EPSILON_1000, TEST_LOCATION); - DALI_TEST_EQUALS(lineSize*8.5f, relativeMultiNaturalSize.y, Math::MACHINE_EPSILON_1000, TEST_LOCATION); + DALI_TEST_EQUALS(lineSize * 8.5f, relativeMultiNaturalSize.y, Math::MACHINE_EPSILON_1000, TEST_LOCATION); END_TEST; } diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp index 30aaade..c810939 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp @@ -2525,8 +2525,53 @@ int utcDaliTextLabelGeometryGlyphMiddle(void) Vector expectedSizes; Vector expectedPositions; - expectedPositions.PushBack(Vector2(12, 0)); - expectedSizes.PushBack(Vector2(118, 25)); + expectedPositions.PushBack(Vector2(6, 0)); + expectedSizes.PushBack(Vector2(124, 25)); + + TestTextGeometryUtils::CheckGeometryResult(positionsList, sizeList, expectedPositions, expectedSizes); + + END_TEST; +} + +int utcDaliTextLabelGeometryOneGlyph(void) +{ + ToolkitTestApplication application; + tet_infoline(" utcDaliTextLabelGeometryOneGlyph "); + + 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, "H"); + + // 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 = 0; + unsigned int endIndex = 0; + + Vector positionsList = DevelTextLabel::GetTextPosition(label, startIndex, endIndex); + Vector sizeList = DevelTextLabel::GetTextSize(label, startIndex, endIndex); + + DALI_TEST_EQUALS(positionsList.Size(), expectedCount, TEST_LOCATION); + DALI_TEST_EQUALS(sizeList.Size(), expectedCount, TEST_LOCATION); + + Vector expectedSizes; + Vector expectedPositions; + + expectedPositions.PushBack(Vector2(-2, 0)); + expectedSizes.PushBack(Vector2(16, 25)); TestTextGeometryUtils::CheckGeometryResult(positionsList, sizeList, expectedPositions, expectedSizes); @@ -2679,7 +2724,7 @@ int UtcDaliToolkitTextLabelMarkupRelativeLineHeight(void) //no effect of relative line size for paragraph with single line DALI_TEST_EQUALS(naturalSize.y, relativeSingleNaturalSize.y, Math::MACHINE_EPSILON_1000, TEST_LOCATION); - DALI_TEST_EQUALS(lineSize*8.5f, relativeMultiNaturalSize.y, Math::MACHINE_EPSILON_1000, TEST_LOCATION); + DALI_TEST_EQUALS(lineSize * 8.5f, relativeMultiNaturalSize.y, Math::MACHINE_EPSILON_1000, TEST_LOCATION); END_TEST; } diff --git a/dali-toolkit/internal/text/text-geometry.cpp b/dali-toolkit/internal/text/text-geometry.cpp index bde5517..6c90665 100644 --- a/dali-toolkit/internal/text/text-geometry.cpp +++ b/dali-toolkit/internal/text/text-geometry.cpp @@ -160,7 +160,7 @@ void GetTextGeometry(ModelPtr textModel, CharacterIndex startIndex, CharacterInd } else { - if((ellipsisPosition == DevelText::EllipsisPosition::END) && (index >= endIndexOfGlyphs)) + if((ellipsisPosition == DevelText::EllipsisPosition::END) && (index > endIndexOfGlyphs)) { //skip remaining elided glyphs break; diff --git a/dali-toolkit/internal/text/text-view.cpp b/dali-toolkit/internal/text/text-view.cpp index 697dc04..9c067de 100644 --- a/dali-toolkit/internal/text/text-view.cpp +++ b/dali-toolkit/internal/text/text-view.cpp @@ -114,7 +114,6 @@ Length View::GetGlyphs(GlyphInfo* glyphs, float calculatedAdvance = 0.f; const Character* textBuffer = mImpl->mLogicalModel->mText.Begin(); - if(mImpl->mVisualModel) { // Get the character-spacing runs. @@ -125,7 +124,7 @@ Length View::GetGlyphs(GlyphInfo* glyphs, //Reset indices of ElidedGlyphs mImpl->mVisualModel->SetStartIndexOfElidedGlyphs(0u); - mImpl->mVisualModel->SetEndIndexOfElidedGlyphs(numberOfGlyphs); + mImpl->mVisualModel->SetEndIndexOfElidedGlyphs(numberOfGlyphs - 1u); // Initialization is the last index of Glyphs mImpl->mVisualModel->SetFirstMiddleIndexOfElidedGlyphs(0u); mImpl->mVisualModel->SetSecondMiddleIndexOfElidedGlyphs(0u); -- 2.7.4