From 10fff2207a4c6251f4ed35e2fff7be598d8002d1 Mon Sep 17 00:00:00 2001 From: Victor Cebollada Date: Tue, 4 Oct 2016 14:11:06 +0100 Subject: [PATCH] Text - Ellipsis improvement. * Elide all the characters if the control's height is not big enough. * Fix the vertical alignment. Change-Id: Ib7f8cc710b554952da357321e88058bbb3c7b0ab Signed-off-by: Victor Cebollada --- .../dali-toolkit-internal/utc-Dali-Text-Layout.cpp | 78 +++++++++++++++++++++- .../src/dali-toolkit/utc-Dali-TextLabel.cpp | 32 +++++++++ .../internal/text/layouts/layout-engine.cpp | 5 +- dali-toolkit/internal/text/text-view.cpp | 18 +++++ 4 files changed, 130 insertions(+), 3 deletions(-) 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 36ab916..4d42843 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 @@ -3247,7 +3247,7 @@ int UtcDaliTextLayoutEllipsis02(void) }; Size textArea( 100.f, 50.f ); - Size layoutSize( 100.f, 60.f ); + Size layoutSize( 100.f, 40.f ); LayoutTextData data = { @@ -3545,7 +3545,7 @@ int UtcDaliTextLayoutEllipsis04(void) }; Size textArea( 100.f, 50.f ); - Size layoutSize( 100.f, 60.f ); + Size layoutSize( 100.f, 40.f ); LayoutTextData data = { @@ -3575,6 +3575,80 @@ int UtcDaliTextLayoutEllipsis04(void) END_TEST; } +int UtcDaliTextLayoutEllipsis05(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextLayoutEllipsis05"); + + const std::string fontLatin( "TizenSans" ); + + // Set a known font description + FontDescriptionRun fontDescriptionRun01; + fontDescriptionRun01.characterRun.characterIndex = 0u; + fontDescriptionRun01.characterRun.numberOfCharacters = 51u; + fontDescriptionRun01.familyLength = fontLatin.size(); + fontDescriptionRun01.familyName = new char[fontDescriptionRun01.familyLength]; + memcpy( fontDescriptionRun01.familyName, fontLatin.c_str(), fontDescriptionRun01.familyLength ); + fontDescriptionRun01.familyDefined = true; + fontDescriptionRun01.weightDefined = false; + fontDescriptionRun01.widthDefined = false; + fontDescriptionRun01.slantDefined = false; + fontDescriptionRun01.sizeDefined = false; + + Vector fontDescriptionRuns; + fontDescriptionRuns.PushBack( fontDescriptionRun01 ); + + struct LineRun line01 = + { + { 0u, 11u }, + { 0u, 11u }, + 80.f, + 15.f, + -5.f, + 0.f, + 0.f, + false, + true + }; + Vector lines; + lines.PushBack( line01 ); + + float positions[] = + { + 1.f, -12.f + }; + + Size textArea( 100.f, 19.f ); + Size layoutSize( 100.f, 20.f ); + + LayoutTextData data = + { + "Not enough height.", + "Hello world", + textArea, + 1u, + fontDescriptionRuns.Begin(), + layoutSize, + 1u, + positions, + 1u, + lines.Begin(), + LayoutEngine::MULTI_LINE_BOX, + 0u, + 11u, + true, + true + }; + + if( !LayoutTextTest( data ) ) + { + tet_result(TET_FAIL); + } + + tet_result(TET_PASS); + END_TEST; +} + int UtcDaliTextReorderLayout01(void) { ToolkitTestApplication application; diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp index 39778f7..5f9a710 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp @@ -413,3 +413,35 @@ int UtcDaliToolkitTextlabelScrollingP(void) END_TEST; } + +int UtcDaliToolkitTextlabelEllipsis(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliToolkitTextlabelEllipsis"); + + TextLabel label = TextLabel::New("Hello world"); + DALI_TEST_CHECK( label ); + + // Avoid a crash when core load gl resources. + application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); + + Stage::GetCurrent().Add( label ); + + // Turn on all the effects + label.SetAnchorPoint( AnchorPoint::CENTER ); + label.SetParentOrigin( ParentOrigin::CENTER ); + label.SetSize( 360.0f, 10.f ); + + try + { + // Render the text. + application.SendNotification(); + application.Render(); + } + catch( ... ) + { + tet_result(TET_FAIL); + } + + END_TEST; +} diff --git a/dali-toolkit/internal/text/layouts/layout-engine.cpp b/dali-toolkit/internal/text/layouts/layout-engine.cpp index cd51c8d..717c752 100644 --- a/dali-toolkit/internal/text/layouts/layout-engine.cpp +++ b/dali-toolkit/internal/text/layouts/layout-engine.cpp @@ -596,7 +596,10 @@ struct LayoutEngine::Impl lineRun->ellipsis = true; layoutSize.width = layoutParameters.boundingBox.width; - layoutSize.height += ( lineRun->ascender + -lineRun->descender ); + if( layoutSize.height < Math::MACHINE_EPSILON_1000 ) + { + layoutSize.height += ( lineRun->ascender + -lineRun->descender ); + } SetGlyphPositions( layoutParameters.glyphsBuffer + lineRun->glyphRun.glyphIndex, ellipsisLayout.numberOfGlyphs, diff --git a/dali-toolkit/internal/text/text-view.cpp b/dali-toolkit/internal/text/text-view.cpp index be6ac8f..7333428 100644 --- a/dali-toolkit/internal/text/text-view.cpp +++ b/dali-toolkit/internal/text/text-view.cpp @@ -190,6 +190,24 @@ Length View::GetGlyphs( GlyphInfo* glyphs, if( lastLine.ellipsis ) { + if( ( 1u == numberOfLines ) && + ( lastLine.ascender - lastLine.descender > mImpl->mVisualModel->mControlSize.height ) ) + { + // Get the first glyph which is going to be replaced and the ellipsis glyph. + GlyphInfo& glyphInfo = *glyphs; + const GlyphInfo& ellipsisGlyph = mImpl->mFontClient.GetEllipsisGlyph( mImpl->mFontClient.GetPointSize( glyphInfo.fontId ) ); + + // Change the 'x' and 'y' position of the ellipsis glyph. + Vector2& position = *glyphPositions; + position.x = ellipsisGlyph.xBearing; + position.y = mImpl->mVisualModel->mControlSize.height - ellipsisGlyph.yBearing; + + // Replace the glyph by the ellipsis glyph. + glyphInfo = ellipsisGlyph; + + return 1u; + } + // firstPenX, penY and firstPenSet are used to position the ellipsis glyph if needed. float firstPenX = 0.f; // Used if rtl text is elided. float penY = 0.f; -- 2.7.4