From c312165228ec840a5d407be8b3762aa05bd9ba2e Mon Sep 17 00:00:00 2001 From: Youngbok Shin Date: Fri, 27 Nov 2020 16:53:10 +0900 Subject: [PATCH] fix ellipsis not working issue when the given width is too narrow This patch fix the issue when the given width is too narrow for adding an ellipsis glyph. Change-Id: Ifdea96eb42041c5d603acfd36874b3704a5cb7f9 --- .../dali-toolkit-internal/utc-Dali-Text-ViewModel.cpp | 18 ++++++++++++++++++ dali-toolkit/internal/text/rendering/view-model.cpp | 9 +++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-ViewModel.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-ViewModel.cpp index f243f08..fc4f9ac 100755 --- a/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-ViewModel.cpp +++ b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-ViewModel.cpp @@ -572,6 +572,24 @@ int UtcDaliTextViewModelElideText01(void) DALI_TEST_CHECK( NULL != glyphs ); DALI_TEST_CHECK( NULL != layouts ); + // When the ellipsis is enabled, at least a glyph has to be rendered. + // Even if the given width is too narrow for rendering an ellipsis glyph. + controller->SetText( "…" ); + Vector3 sizeEllipsis = controller->GetNaturalSize(); + controller->SetText( "A" ); + Vector3 sizeA = controller->GetNaturalSize(); + float testWidth = sizeA.width < sizeEllipsis.width ? sizeA.width : sizeEllipsis.width - 1.0; + + controller->SetText( "AB" ); + Vector3 sizeAB = controller->GetNaturalSize(); + + controller->Relayout( Size(testWidth, sizeAB.height) ); + + // Elide the glyphs. + model->ElideGlyphs(); + DALI_TEST_EQUALS( 1u, model->GetNumberOfGlyphs(), TEST_LOCATION ); + DALI_TEST_EQUALS( 1u, model->GetNumberOfLines(), TEST_LOCATION ); + tet_result(TET_PASS); END_TEST; } diff --git a/dali-toolkit/internal/text/rendering/view-model.cpp b/dali-toolkit/internal/text/rendering/view-model.cpp index 3046f45..0e8dc61 100755 --- a/dali-toolkit/internal/text/rendering/view-model.cpp +++ b/dali-toolkit/internal/text/rendering/view-model.cpp @@ -335,7 +335,8 @@ void ViewModel::ElideGlyphs() // Calculate the width of the ellipsis glyph and check if it fits. const float ellipsisGlyphWidth = ellipsisGlyph.width + ellipsisGlyph.xBearing; - if( ellipsisGlyphWidth < removedGlypsWidth ) + // If it is the last glyph to remove, add the ellipsis glyph without checking its width. + if( ( ellipsisGlyphWidth < removedGlypsWidth ) || ( index == 0u ) ) { GlyphInfo& glyphInfo = *( elidedGlyphsBuffer + index ); Vector2& position = *( elidedPositionsBuffer + index ); @@ -347,7 +348,11 @@ void ViewModel::ElideGlyphs() // Change the 'x' and 'y' position of the ellipsis glyph. if( position.x > firstPenX ) { - position.x = firstPenX + removedGlypsWidth - ellipsisGlyphWidth; + position.x = firstPenX; + if (ellipsisGlyphWidth < removedGlypsWidth) + { + position.x += removedGlypsWidth - ellipsisGlyphWidth; + } } position.x += ellipsisGlyph.xBearing; -- 2.7.4