From 297612cc09fbe560a454742a52bfb3ed03a2655f Mon Sep 17 00:00:00 2001 From: abdullah Date: Mon, 3 Jan 2022 16:20:42 +0200 Subject: [PATCH] Fix text written below cursor bug *********************************************************** Description: When we use different font sizes with min line size, text in the new line gets written below the cursor position. Please use the code below to generate the issue. *********************************************************** using namespace Dali; using namespace Dali::Toolkit; class SimpleApp : public ConnectionTracker { public: SimpleApp(Application &application) : mApplication(application) { mApplication.InitSignal().Connect(this, &SimpleApp::Create); } void Create(Application &application) { Window window = application.GetWindow(); window.SetBackgroundColor(Vector4(0.04f, 0.345f, 0.392f, 1.0f)); mEditor = TextEditor::New(); mEditor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); mEditor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); mEditor.SetProperty(Actor::Property::POSITION, Vector3(0.f, 0.0f, 0.f)); mEditor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 100.0f)); mEditor.SetProperty( TextField::Property::TEXT, "Hello Span\n S \n" );//issue here with the y position after the new line mEditor.SetProperty(TextEditor::Property::ENABLE_MARKUP, true); mEditor.SetProperty(TextEditor::Property::POINT_SIZE, 15.0f); mEditor.SetBackgroundColor(Color::WHITE); mEditor.SetProperty(DevelTextEditor::Property::MIN_LINE_SIZE, 50.f); window.Add(mEditor); } bool OnButtonClicked(Button button) { if (button == mButton) { Vector3 originalSize = mEditor.GetNaturalSize(); } return true; } private: Application &mApplication; TextEditor mEditor; PushButton mButton; TextField mField; }; int DALI_EXPORT_API main(int argc, char **argv) { Application application = Application::New(&argc, &argv); SimpleApp test(application); application.MainLoop(); return 0; } *********************************************************** Change-Id: I2868f923e38d9ecc14bf738959f24be015b754fd --- .../utc-Dali-TextEditor-internal.cpp | 169 +++++++++++++-------- dali-toolkit/internal/text/text-view.cpp | 6 +- 2 files changed, 107 insertions(+), 68 deletions(-) mode change 100755 => 100644 automated-tests/src/dali-toolkit-internal/utc-Dali-TextEditor-internal.cpp diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-TextEditor-internal.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-TextEditor-internal.cpp old mode 100755 new mode 100644 index 0b18d11..e588998 --- a/automated-tests/src/dali-toolkit-internal/utc-Dali-TextEditor-internal.cpp +++ b/automated-tests/src/dali-toolkit-internal/utc-Dali-TextEditor-internal.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,16 +15,16 @@ * */ -#include #include +#include #include #include -#include #include -#include +#include #include +#include using namespace Dali; using namespace Toolkit; @@ -33,20 +33,20 @@ using namespace Text; int UtcDaliTextEditorSelectText(void) { ToolkitTestApplication application; - tet_infoline( "UtcDaliTextEditorSelectText" ); + tet_infoline("UtcDaliTextEditorSelectText"); // Create a text editor TextEditor textEditor = TextEditor::New(); - textEditor.SetProperty( Actor::Property::SIZE, Vector2( 400.f, 60.f ) ); - textEditor.SetProperty( TextEditor::Property::TEXT, "Hello World" ); + textEditor.SetProperty(Actor::Property::SIZE, Vector2(400.f, 60.f)); + textEditor.SetProperty(TextEditor::Property::TEXT, "Hello World"); // Add the text editor to the stage - application.GetScene().Add( textEditor ); + application.GetScene().Add(textEditor); application.SendNotification(); application.Render(); - Toolkit::Internal::TextEditor& textEditorImpl = GetImpl( textEditor ); + Toolkit::Internal::TextEditor& textEditorImpl = GetImpl(textEditor); application.SendNotification(); application.Render(); @@ -58,7 +58,7 @@ int UtcDaliTextEditorSelectText(void) application.Render(); std::string selectedText = textEditorImpl.GetSelectedText(); - DALI_TEST_CHECK( selectedText == "Hello World" ); + DALI_TEST_CHECK(selectedText == "Hello World"); // Select None textEditorImpl.SelectNone(); @@ -67,7 +67,7 @@ int UtcDaliTextEditorSelectText(void) application.Render(); selectedText = textEditorImpl.GetSelectedText(); - DALI_TEST_CHECK( selectedText == "" ); + DALI_TEST_CHECK(selectedText == ""); END_TEST; } @@ -79,33 +79,33 @@ int UtcDaliTextEditorMarkupUnderline(void) TextEditor textEditor = TextEditor::New(); - application.GetScene().Add( textEditor ); + application.GetScene().Add(textEditor); - textEditor.SetProperty( TextEditor::Property::TEXT, "ABCEFGH" ); - textEditor.SetProperty( TextEditor ::Property::ENABLE_MARKUP, true ); + textEditor.SetProperty(TextEditor::Property::TEXT, "ABCEFGH"); + textEditor.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true); application.SendNotification(); application.Render(); uint32_t expectedNumberOfUnderlinedGlyphs = 5u; - Toolkit::Internal::TextEditor& textEditorImpl = GetImpl( textEditor ); - const Text::Length numberOfUnderlineRuns = textEditorImpl.GetTextController()->GetTextModel()->GetNumberOfUnderlineRuns(); + Toolkit::Internal::TextEditor& textEditorImpl = GetImpl(textEditor); + const Text::Length numberOfUnderlineRuns = textEditorImpl.GetTextController()->GetTextModel()->GetNumberOfUnderlineRuns(); - DALI_TEST_EQUALS( numberOfUnderlineRuns, expectedNumberOfUnderlinedGlyphs, TEST_LOCATION ); + DALI_TEST_EQUALS(numberOfUnderlineRuns, expectedNumberOfUnderlinedGlyphs, TEST_LOCATION); Vector underlineRuns; underlineRuns.Resize(numberOfUnderlineRuns); textEditorImpl.GetTextController()->GetTextModel()->GetUnderlineRuns(underlineRuns.Begin(), 0u, numberOfUnderlineRuns); //ABC are underlined - DALI_TEST_EQUALS( underlineRuns[0u].glyphIndex, 0u, TEST_LOCATION); - DALI_TEST_EQUALS( underlineRuns[1u].glyphIndex, 1u, TEST_LOCATION); - DALI_TEST_EQUALS( underlineRuns[2u].glyphIndex, 2u, TEST_LOCATION); + DALI_TEST_EQUALS(underlineRuns[0u].glyphIndex, 0u, TEST_LOCATION); + DALI_TEST_EQUALS(underlineRuns[1u].glyphIndex, 1u, TEST_LOCATION); + DALI_TEST_EQUALS(underlineRuns[2u].glyphIndex, 2u, TEST_LOCATION); //GH are underlined - DALI_TEST_EQUALS( underlineRuns[3u].glyphIndex, 5u, TEST_LOCATION); - DALI_TEST_EQUALS( underlineRuns[4u].glyphIndex, 6u, TEST_LOCATION); + DALI_TEST_EQUALS(underlineRuns[3u].glyphIndex, 5u, TEST_LOCATION); + DALI_TEST_EQUALS(underlineRuns[4u].glyphIndex, 6u, TEST_LOCATION); END_TEST; } @@ -118,27 +118,26 @@ int UtcDaliTextEditorFontPointSizeLargerThanAtlas(void) // Create a text editor TextEditor textEditor = TextEditor::New(); //Set size to avoid automatic eliding - textEditor.SetProperty( Actor::Property::SIZE, Vector2(1025, 1025)); + textEditor.SetProperty(Actor::Property::SIZE, Vector2(1025, 1025)); //Set very large font-size using point-size - textEditor.SetProperty( TextEditor::Property::POINT_SIZE, 1000); + textEditor.SetProperty(TextEditor::Property::POINT_SIZE, 1000); //Specify font-family - textEditor.SetProperty( TextEditor::Property::FONT_FAMILY, "DejaVu Sans"); + textEditor.SetProperty(TextEditor::Property::FONT_FAMILY, "DejaVu Sans"); //Set text to check if appear or not textEditor.SetProperty(TextEditor::Property::TEXT, "A"); - application.GetScene().Add( textEditor ); + application.GetScene().Add(textEditor); application.SendNotification(); application.Render(); //Check if Glyph is added to AtlasGlyphManger or not int countAtlas = AtlasGlyphManager::Get().GetMetrics().mAtlasMetrics.mAtlasCount; - DALI_TEST_EQUALS( countAtlas, 1, TEST_LOCATION ); + DALI_TEST_EQUALS(countAtlas, 1, TEST_LOCATION); END_TEST; } - int UtcDaliTextEditorFontPointSizeLargerThanAtlasPlaceholderCase(void) { ToolkitTestApplication application; @@ -146,25 +145,25 @@ int UtcDaliTextEditorFontPointSizeLargerThanAtlasPlaceholderCase(void) //Set Map of placeholder: text, font-family and point-size Property::Map placeholderMapSet; - placeholderMapSet["text"] = "A"; + placeholderMapSet["text"] = "A"; placeholderMapSet["fontFamily"] = "DejaVu Sans"; - placeholderMapSet["pixelSize"] = 1000.0f; + placeholderMapSet["pixelSize"] = 1000.0f; // Create a text editor TextEditor textEditor = TextEditor::New(); //Set size to avoid automatic eliding - textEditor.SetProperty( Actor::Property::SIZE, Vector2(1025, 1025)); + textEditor.SetProperty(Actor::Property::SIZE, Vector2(1025, 1025)); //Set placeholder - textEditor.SetProperty( TextEditor::Property::PLACEHOLDER, placeholderMapSet) ; + textEditor.SetProperty(TextEditor::Property::PLACEHOLDER, placeholderMapSet); - application.GetScene().Add( textEditor ); + application.GetScene().Add(textEditor); application.SendNotification(); application.Render(); //Check if Glyph is added to AtlasGlyphManger or not int countAtlas = AtlasGlyphManager::Get().GetMetrics().mAtlasMetrics.mAtlasCount; - DALI_TEST_EQUALS( countAtlas, 1, TEST_LOCATION ); + DALI_TEST_EQUALS(countAtlas, 1, TEST_LOCATION); END_TEST; } @@ -175,27 +174,27 @@ int UtcDaliTextEditorBackgroundTag(void) tet_infoline("UtcDaliTextEditorBackgroundTag\n"); TextEditor editor = TextEditor::New(); - DALI_TEST_CHECK( editor ); + DALI_TEST_CHECK(editor); - editor.SetProperty( TextEditor ::Property::ENABLE_MARKUP, true ); - editor.SetProperty( TextEditor::Property::TEXT, "He World" ); - application.GetScene().Add( editor ); + editor.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true); + editor.SetProperty(TextEditor::Property::TEXT, "He World"); + application.GetScene().Add(editor); application.SendNotification(); application.Render(); - Toolkit::Internal::TextEditor& editorImpl = GetImpl( editor ); - const ColorIndex* const backgroundColorIndicesBuffer = editorImpl.GetTextController()->GetTextModel()->GetBackgroundColorIndices(); + Toolkit::Internal::TextEditor& editorImpl = GetImpl(editor); + const ColorIndex* const backgroundColorIndicesBuffer = editorImpl.GetTextController()->GetTextModel()->GetBackgroundColorIndices(); - DALI_TEST_CHECK( backgroundColorIndicesBuffer ); + DALI_TEST_CHECK(backgroundColorIndicesBuffer); //default color - DALI_TEST_EQUALS( backgroundColorIndicesBuffer[0], 0u, TEST_LOCATION); + DALI_TEST_EQUALS(backgroundColorIndicesBuffer[0], 0u, TEST_LOCATION); //red color - DALI_TEST_EQUALS( backgroundColorIndicesBuffer[1], 1u, TEST_LOCATION); + DALI_TEST_EQUALS(backgroundColorIndicesBuffer[1], 1u, TEST_LOCATION); //yellow color - DALI_TEST_EQUALS( backgroundColorIndicesBuffer[7], 2u, TEST_LOCATION); + DALI_TEST_EQUALS(backgroundColorIndicesBuffer[7], 2u, TEST_LOCATION); END_TEST; } @@ -206,17 +205,17 @@ int UtcDaliTextEditorTextWithSpan(void) tet_infoline("UtcDaliTextEditorTextWithSpan\n"); TextEditor editor = TextEditor::New(); - DALI_TEST_CHECK( editor ); + DALI_TEST_CHECK(editor); - editor.SetProperty( TextEditor ::Property::ENABLE_MARKUP, true ); - editor.SetProperty( TextEditor::Property::TEXT, "Hello Span" ); - application.GetScene().Add( editor ); + editor.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true); + editor.SetProperty(TextEditor::Property::TEXT, "Hello Span"); + application.GetScene().Add(editor); application.SendNotification(); application.Render(); Vector3 originalSize = editor.GetNaturalSize(); - editor.SetProperty( TextEditor::Property::TEXT, "Hello Span" ); + editor.SetProperty(TextEditor::Property::TEXT, "Hello Span"); application.SendNotification(); application.Render(); @@ -225,41 +224,40 @@ int UtcDaliTextEditorTextWithSpan(void) DALI_TEST_GREATER(spanSize.width, originalSize.width, TEST_LOCATION); - Toolkit::Internal::TextEditor& editorImpl = GetImpl( editor ); - const ColorIndex* const colorIndicesBuffer1 = editorImpl.GetTextController()->GetTextModel()->GetColorIndices(); + Toolkit::Internal::TextEditor& editorImpl = GetImpl(editor); + const ColorIndex* const colorIndicesBuffer1 = editorImpl.GetTextController()->GetTextModel()->GetColorIndices(); - DALI_TEST_CHECK( colorIndicesBuffer1 ); + DALI_TEST_CHECK(colorIndicesBuffer1); //default color - DALI_TEST_EQUALS( colorIndicesBuffer1[0], 0u, TEST_LOCATION); + DALI_TEST_EQUALS(colorIndicesBuffer1[0], 0u, TEST_LOCATION); //span color - DALI_TEST_EQUALS( colorIndicesBuffer1[1], 1u, TEST_LOCATION); + DALI_TEST_EQUALS(colorIndicesBuffer1[1], 1u, TEST_LOCATION); //default color - DALI_TEST_EQUALS( colorIndicesBuffer1[6], 0u, TEST_LOCATION); - + DALI_TEST_EQUALS(colorIndicesBuffer1[6], 0u, TEST_LOCATION); - editor.SetProperty( TextEditor::Property::TEXT, "Hello Span" ); + editor.SetProperty(TextEditor::Property::TEXT, "Hello Span"); application.SendNotification(); application.Render(); const ColorIndex* const colorIndicesBuffer2 = editorImpl.GetTextController()->GetTextModel()->GetColorIndices(); - DALI_TEST_CHECK( colorIndicesBuffer2 ); + DALI_TEST_CHECK(colorIndicesBuffer2); //default color - DALI_TEST_EQUALS( colorIndicesBuffer2[0], 0u, TEST_LOCATION); + DALI_TEST_EQUALS(colorIndicesBuffer2[0], 0u, TEST_LOCATION); //default color - DALI_TEST_EQUALS( colorIndicesBuffer2[1], 0u, TEST_LOCATION); + DALI_TEST_EQUALS(colorIndicesBuffer2[1], 0u, TEST_LOCATION); //span color - DALI_TEST_EQUALS( colorIndicesBuffer2[6], 1u, TEST_LOCATION); + DALI_TEST_EQUALS(colorIndicesBuffer2[6], 1u, TEST_LOCATION); //default color - DALI_TEST_EQUALS( colorIndicesBuffer2[7], 0u, TEST_LOCATION); + DALI_TEST_EQUALS(colorIndicesBuffer2[7], 0u, TEST_LOCATION); END_TEST; } @@ -279,9 +277,9 @@ int UtcDaliTextEditorControlBackgroundColor(void) application.SendNotification(); application.Render(); - Toolkit::Internal::TextEditor& editorImpl = GetImpl(editor); - ControllerPtr controller = editorImpl.GetTextController(); - Controller::Impl& controllerImpl = Controller::Impl::GetImplementation(*controller.Get()); + Toolkit::Internal::TextEditor& editorImpl = GetImpl(editor); + ControllerPtr controller = editorImpl.GetTextController(); + Controller::Impl& controllerImpl = Controller::Impl::GetImplementation(*controller.Get()); // Default color is transparent controllerImpl.mEditableControlInterface->GetControlBackgroundColor(backgroundColor); @@ -298,3 +296,44 @@ int UtcDaliTextEditorControlBackgroundColor(void) END_TEST; } + +int UtcDaliTextEditorTextPositionWithMinLineAndBigFont(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextEditorTextPositionWithMinLine "); + + TextEditor textEditor = TextEditor::New(); + + textEditor.SetProperty(TextEditor::Property::TEXT, "H\ni"); + textEditor.SetProperty(DevelTextEditor::Property::MIN_LINE_SIZE, 50); + textEditor.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true); + + application.GetScene().Add(textEditor); + + application.SendNotification(); + application.Render(); + + Toolkit::Internal::TextEditor& textEditorImpl = GetImpl(textEditor); + Text::ViewInterface& view = textEditorImpl.GetTextController()->GetView(); + + Length numberOfGlyphs = view.GetNumberOfGlyphs(); + + DALI_TEST_EQUALS(numberOfGlyphs, 3u, Math::MACHINE_EPSILON_1000, TEST_LOCATION); + + Vector glyphs; + glyphs.Resize(numberOfGlyphs); + + Vector positions; + positions.Resize(numberOfGlyphs); + + float alignmentOffset = 0u; + numberOfGlyphs = view.GetGlyphs(glyphs.Begin(), + positions.Begin(), + alignmentOffset, + 0u, + numberOfGlyphs); + + DALI_TEST_EQUALS(positions[2].y, 165.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION); + + END_TEST; +} \ No newline at end of file diff --git a/dali-toolkit/internal/text/text-view.cpp b/dali-toolkit/internal/text/text-view.cpp index a5a6b3b..ab90d50 100644 --- a/dali-toolkit/internal/text/text-view.cpp +++ b/dali-toolkit/internal/text/text-view.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -213,7 +213,7 @@ Length View::GetGlyphs(GlyphInfo* glyphs, if(lastGlyphIndexOfLine == index) { - penY += -line->descender; + penY += -line->descender + line->lineSpacing; // Get the next line. ++lineIndex; @@ -225,7 +225,7 @@ Length View::GetGlyphs(GlyphInfo* glyphs, lastGlyphIndexOfLine = (line->isSplitToTwoHalves ? line->glyphRunSecondHalf.glyphIndex + line->glyphRunSecondHalf.numberOfGlyphs : line->glyphRun.glyphIndex + line->glyphRun.numberOfGlyphs) - 1u; - penY += line->ascender + line->lineSpacing; + penY += line->ascender; } } } -- 2.7.4