Text - Ellipsis improvement. 77/90877/2
authorVictor Cebollada <v.cebollada@samsung.com>
Tue, 4 Oct 2016 13:11:06 +0000 (14:11 +0100)
committerVictor Cebollada <v.cebollada@samsung.com>
Tue, 4 Oct 2016 14:39:53 +0000 (15:39 +0100)
* 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 <v.cebollada@samsung.com>
automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Layout.cpp
automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp
dali-toolkit/internal/text/layouts/layout-engine.cpp
dali-toolkit/internal/text/text-view.cpp

index 36ab916..4d42843 100644 (file)
@@ -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<FontDescriptionRun> fontDescriptionRuns;
+  fontDescriptionRuns.PushBack( fontDescriptionRun01 );
+
+  struct LineRun line01 =
+  {
+    { 0u, 11u },
+    { 0u, 11u },
+    80.f,
+    15.f,
+    -5.f,
+    0.f,
+    0.f,
+    false,
+    true
+  };
+  Vector<LineRun> 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;
index 39778f7..5f9a710 100644 (file)
@@ -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;
+}
index cd51c8d..717c752 100644 (file)
@@ -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,
index be6ac8f..7333428 100644 (file)
@@ -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;