From 9f41a0812c57d92f166e0ecbb8bf3c8801834b89 Mon Sep 17 00:00:00 2001 From: abdullah Date: Wed, 23 Feb 2022 11:01:49 +0200 Subject: [PATCH] Fix issue in Selection with negative line spacing this will fix the selection highlighting height & grape handles position. Editor.SetProperty(TextEditor::Property::TEXT, "AB\nCD"); Editor.SetProperty(TextEditor::Property::LINE_SPACING, -20); Change-Id: I08dad34722584ff7d3815cd4f8a7b577be6d81cf --- .../src/dali-toolkit/utc-Dali-TextEditor.cpp | 39 ++++++++++++++++++++++ .../internal/text/cursor-helper-functions.cpp | 8 +++-- .../text/text-selection-handle-controller.cpp | 20 +++++++++-- 3 files changed, 63 insertions(+), 4 deletions(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp index 537207c..0c3ab82 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp @@ -4516,6 +4516,45 @@ int UtcDaliTextEditorLineSpacing(void) END_TEST; } +int UtcDaliTextEditorSelectionWithLineSpacing(void) +{ + //Only for test coverage + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextEditorSelectionWithLineSpacing "); + + TextEditor textEditor = TextEditor::New(); + textEditor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.f)); + application.GetScene().Add(textEditor); + application.SendNotification(); + application.Render(); + + textEditor.SetProperty(TextEditor::Property::TEXT, "Line #1\nLine #2\nLine #3"); + textEditor.SetProperty(DevelTextEditor::Property::LINE_SPACING, -20); + + application.SendNotification(); + application.Render(); + + DevelTextEditor::SelectWholeText(textEditor); + + application.SendNotification(); + application.Render(); + + DevelTextEditor::SelectNone(textEditor); + textEditor.SetProperty(DevelTextEditor::Property::LINE_SPACING, 20); + + application.SendNotification(); + application.Render(); + + DevelTextEditor::SelectWholeText(textEditor); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(textEditor.GetProperty(DevelTextEditor::Property::LINE_SPACING), 20.0f, TEST_LOCATION); + + END_TEST; +} + int UtcDaliTextEditorMinLineSize(void) { ToolkitTestApplication application; diff --git a/dali-toolkit/internal/text/cursor-helper-functions.cpp b/dali-toolkit/internal/text/cursor-helper-functions.cpp index c70d530..9137a2f 100644 --- a/dali-toolkit/internal/text/cursor-helper-functions.cpp +++ b/dali-toolkit/internal/text/cursor-helper-functions.cpp @@ -504,7 +504,9 @@ void GetCursorPosition(GetCursorPositionParameters& parameters, cursorInfo.lineOffset = CalculateLineOffset(parameters.visualModel->mLines, newLineIndex); - cursorInfo.lineHeight = GetLineHeight(newLine); + // The line height is the addition of the line ascender and the line descender. + // However, the line descender has a negative value, hence the subtraction also line spacing should not be included in cursor height. + cursorInfo.lineHeight = newLine.ascender - newLine.descender; index = 0u; const Length totalNumberOfCharacters = parameters.logicalModel->mText.Count(); @@ -560,7 +562,9 @@ void GetCursorPosition(GetCursorPositionParameters& parameters, cursorInfo.lineOffset = CalculateLineOffset(parameters.visualModel->mLines, lineIndex); - cursorInfo.lineHeight = GetLineHeight(line); + // The line height is the addition of the line ascender and the line descender. + // However, the line descender has a negative value, hence the subtraction also line spacing should not be included in cursor height. + cursorInfo.lineHeight = line.ascender - line.descender; // Calculate the primary cursor. diff --git a/dali-toolkit/internal/text/text-selection-handle-controller.cpp b/dali-toolkit/internal/text/text-selection-handle-controller.cpp index 8e43a87..a36f81f 100644 --- a/dali-toolkit/internal/text/text-selection-handle-controller.cpp +++ b/dali-toolkit/internal/text/text-selection-handle-controller.cpp @@ -148,7 +148,9 @@ void SelectionHandleController::Reposition(Controller::Impl& impl) lineRun += firstLineIndex; - selectionBoxInfo->lineHeight = GetLineHeight(*lineRun); + // The line height is the addition of the line ascender and the line descender. + // However, the line descender has a negative value, hence the subtraction also line spacing should not be included in selection height. + selectionBoxInfo->lineHeight = lineRun->ascender - lineRun->descender; GlyphIndex lastGlyphOfLine = lineRun->glyphRun.glyphIndex + lineRun->glyphRun.numberOfGlyphs - 1u; @@ -260,6 +262,8 @@ void SelectionHandleController::Reposition(Controller::Impl& impl) ++lineIndex; if(lineIndex < firstLineIndex + numberOfLines) { + float currentLineSpacing = lineRun->lineSpacing; + // Retrieve the next line. ++lineRun; @@ -279,7 +283,19 @@ void SelectionHandleController::Reposition(Controller::Impl& impl) // Update the line's vertical offset. selectionBoxInfo->lineOffset = currentLineOffset + currentLineHeight; - selectionBoxInfo->lineHeight = GetLineHeight(*lineRun); + if(currentLineSpacing < 0) + { + selectionBoxInfo->lineOffset += currentLineSpacing; + } + + // The line height is the addition of the line ascender and the line descender. + // However, the line descender has a negative value, hence the subtraction also line spacing should not be included in selection height. + selectionBoxInfo->lineHeight = lineRun->ascender - lineRun->descender; + + if(lineRun->lineSpacing > 0) + { + selectionBoxInfo->lineHeight += lineRun->lineSpacing; + } } } } -- 2.7.4