Merge "Fix issue in Selection with negative line spacing" into devel/master
authorBowon Ryu <bowon.ryu@samsung.com>
Thu, 3 Mar 2022 09:53:03 +0000 (09:53 +0000)
committerGerrit Code Review <gerrit@review>
Thu, 3 Mar 2022 09:53:03 +0000 (09:53 +0000)
automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp
dali-toolkit/internal/text/cursor-helper-functions.cpp
dali-toolkit/internal/text/text-selection-handle-controller.cpp

index 537207c..0c3ab82 100644 (file)
@@ -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<float>(DevelTextEditor::Property::LINE_SPACING), 20.0f, TEST_LOCATION);
+
+  END_TEST;
+}
+
 int UtcDaliTextEditorMinLineSize(void)
 {
   ToolkitTestApplication application;
index c70d530..9137a2f 100644 (file)
@@ -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.
 
index 8e43a87..a36f81f 100644 (file)
@@ -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;
+        }
       }
     }
   }