END_TEST;
}
+int UtcDaliTextGeometryGetCharacterBoundingRectangleLabel(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline("UtcDaliTextGeometryGetCharacterBoundingRectangleLabel");
+
+ TextLabel label = TextLabel::New();
+ DALI_TEST_CHECK(label);
+
+ application.GetScene().Add(label);
+
+ float lineSpacing = -20.f;
+
+ label.SetProperty(Actor::Property::SIZE, Vector2(450.0f, 300.f));
+ label.SetProperty(TextLabel::Property::POINT_SIZE, 10.f);
+ label.SetProperty(DevelTextLabel::Property::LINE_SPACING, lineSpacing);
+ label.SetProperty(TextLabel::Property::MULTI_LINE, true);
+ label.SetProperty(TextLabel::Property::TEXT, "Lorem ipsum dolor sit amet, \n consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
+
+ application.SendNotification();
+ application.Render();
+
+ Rect<> characterGeometry = TextGeometry::GetCharacterBoundingRectangle(label, 1);
+
+ std::cout << " characterGeometry "<< characterGeometry <<std::endl;
+
+ Rect<> expectedCharacterGeometry = {13.4844f, 16.0f, 18.7031f, 16.0f};
+ std::cout<< " expectedCharacterGeometry " << characterGeometry <<std::endl;
+
+ std:: cout << "if" << (characterGeometry == expectedCharacterGeometry) <<std::endl;
+ TestTextGeometryUtils::CheckRectGeometryResult(characterGeometry, expectedCharacterGeometry);
+
+ END_TEST;
+}
+
+int UtcDaliTextGeometryGetCharacterBoundingRectangleEditor(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline("UtcDaliTextGeometryGetCharacterBoundingRectangleEditor");
+
+ TextEditor editor = TextEditor::New();
+ DALI_TEST_CHECK(editor);
+
+ application.GetScene().Add(editor);
+
+ editor.SetProperty(Actor::Property::SIZE, Vector2(160.0f, 250.f));
+ editor.SetProperty(TextEditor::Property::POINT_SIZE, 10.f);
+ editor.SetProperty(TextEditor::Property::TEXT, "Lorem ipsum dolor sit amet, \n consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
+
+ application.SendNotification();
+ application.Render();
+
+ Rect<> characterGeometry = TextGeometry::GetCharacterBoundingRectangle(editor, 1);
+
+ Rect<> expectedCharacterGeometry = {13.4844f, 16.0f, 18.7031f, 16.0f};
+
+ TestTextGeometryUtils::CheckRectGeometryResult(characterGeometry, expectedCharacterGeometry);
+
+ END_TEST;
+}
+
+int UtcDaliTextGeometryGetCharacterBoundingRectangleField(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline("UtcDaliTextGeometryGetCharacterBoundingRectangleField");
+
+ TextField field = TextField::New();
+ DALI_TEST_CHECK(field);
+
+ application.GetScene().Add(field);
+
+ field.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
+ field.SetProperty(Actor::Property::SIZE, Vector2(450.0f, 350.f));
+ field.SetProperty(TextField::Property::POINT_SIZE, 10.f);
+ field.SetProperty(TextField::Property::TEXT, "مرحبا بالعالم");
+
+ application.SendNotification();
+ application.Render();
+
+ Rect<> characterGeometry = TextGeometry::GetCharacterBoundingRectangle(field, 0);
+
+ Rect<> expectedCharacterGeometry = {142.844f, 10.0f, 16.375f, 11.0f};
+
+ TestTextGeometryUtils::CheckRectGeometryResult(characterGeometry, expectedCharacterGeometry);
+
+ END_TEST;
+}
+// char tc
+
+int UtcDaliTextGeometryEmptyTextGetCharacterBoundingRectangleLabel(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline("UtcDaliTextGeometryEmptyTextGetCharacterBoundingRectangleLabel");
+
+ TextLabel label = TextLabel::New();
+ DALI_TEST_CHECK(label);
+
+ application.GetScene().Add(label);
+
+ label.SetProperty(Actor::Property::SIZE, Vector2(450.0f, 300.f));
+ label.SetProperty(TextLabel::Property::POINT_SIZE, 10.f);
+ label.SetProperty(TextLabel::Property::TEXT, "");
+
+ application.SendNotification();
+ application.Render();
+
+ Rect<> charGeometry = TextGeometry::GetCharacterBoundingRectangle(label, 0);
+
+ Rect<> expectedCharGeometry = {0.0f, 0.0f, 0.0f, 0.0f};
+
+ TestTextGeometryUtils::CheckRectGeometryResult(charGeometry, expectedCharGeometry);
+
+ END_TEST;
+}
+
+int UtcDaliTextGeometryLineSpacingPositiveGetCharacterBoundingRectangleLabel(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline("UtcDaliTextGeometryLineSpacingPositiveGetCharacterBoundingRectangleLabel");
+
+ TextLabel label = TextLabel::New();
+ DALI_TEST_CHECK(label);
+
+ application.GetScene().Add(label);
+
+ float lineSpacing = 20.f;
+ label.SetProperty(Actor::Property::SIZE, Vector2(450.0f, 300.f));
+ label.SetProperty(TextLabel::Property::POINT_SIZE, 10.f);
+ label.SetProperty(DevelTextLabel::Property::LINE_SPACING, lineSpacing);
+ label.SetProperty(TextLabel::Property::MULTI_LINE, true);
+ label.SetProperty(TextLabel::Property::TEXT, "Lorem ipsum dolor sit amet, \n consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
+
+ application.SendNotification();
+ application.Render();
+
+ Rect<> charGeometry = TextGeometry::GetCharacterBoundingRectangle(label, 1);
+
+ Rect<> expectedCharGeometry = {13.4844f, 16.0f, 18.7031f, 16.0f};
+
+ TestTextGeometryUtils::CheckRectGeometryResult(charGeometry, expectedCharGeometry);
+
+ END_TEST;
+}
+
+int UtcDaliTextGeometryWithVerticalLineAlignmentTopGetCharacterBoundingRectangleLabel(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline("UtcDaliTextGeometryWithVerticalLineAlignmentTopGetCharacterBoundingRectangleLabel");
+
+ TextLabel label = TextLabel::New();
+ DALI_TEST_CHECK(label);
+
+ application.GetScene().Add(label);
+
+ label.SetProperty(Actor::Property::SIZE, Vector2(450.0f, 300.f));
+ label.SetProperty(TextLabel::Property::POINT_SIZE, 10.f);
+ label.SetProperty(TextLabel::Property::MULTI_LINE, true);
+ label.SetProperty(Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "TOP");
+ label.SetProperty(TextLabel::Property::TEXT, "Lorem ipsum dolor sit amet, \n consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
+
+ application.SendNotification();
+ application.Render();
+
+ Rect<> charGeometry = TextGeometry::GetCharacterBoundingRectangle(label, 1);
+
+ Rect<> expectedCharGeometry = {13.4844f, 16.0f, 18.7031f, 16.0f};
+
+ TestTextGeometryUtils::CheckRectGeometryResult(charGeometry, expectedCharGeometry);
+
+ END_TEST;
+}
+
+int UtcDaliTextGeometryWithVerticalLineAlignmentBottomGetCharacterBoundingRectangleLabel(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline("UtcDaliTextGeometryWithVerticalLineAlignmentBottomGetCharacterBoundingRectangleLabel");
+
+ TextLabel label = TextLabel::New();
+ DALI_TEST_CHECK(label);
+
+ application.GetScene().Add(label);
+
+ label.SetProperty(Actor::Property::SIZE, Vector2(450.0f, 300.f));
+ label.SetProperty(TextLabel::Property::POINT_SIZE, 10.f);
+ label.SetProperty(TextLabel::Property::MULTI_LINE, true);
+ label.SetProperty(Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "BOTTOM");
+ label.SetProperty(TextLabel::Property::TEXT, "Lorem ipsum dolor sit amet, \n consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
+
+ application.SendNotification();
+ application.Render();
+
+ Rect<> charGeometry = TextGeometry::GetCharacterBoundingRectangle(label, 1);
+
+ Rect<> expectedCharGeometry = {13.4844f, 16.0f, 18.7031f, 16.0f};
+
+ TestTextGeometryUtils::CheckRectGeometryResult(charGeometry, expectedCharGeometry);
+
+ END_TEST;
+}
\ No newline at end of file
return GetImpl(field).GetLineBoundingRectangle(lineIndex);
}
+Rect<float> GetCharacterBoundingRectangle(TextLabel label, const uint32_t charIndex)
+{
+ return GetImpl(label).GetCharacterBoundingRectangle(charIndex);
+}
+
+Rect<float> GetCharacterBoundingRectangle(TextEditor editor, const uint32_t charIndex)
+{
+ return GetImpl(editor).GetCharacterBoundingRectangle(charIndex);
+}
+
+Rect<float> GetCharacterBoundingRectangle(TextField field, const uint32_t charIndex)
+{
+ return GetImpl(field).GetCharacterBoundingRectangle(charIndex);
+}
+
} //namespace TextGeometry
} // namespace Text
*/
DALI_TOOLKIT_API Rect<float> GetLineBoundingRectangle(TextField field, const uint32_t lineIndex);
+ /**
+ * @brief Get the character bounding rectangle.
+ * If the text is not yet rendered or the index > text.Count(); a rect of {0, 0, 0, 0} is returned.
+ *
+ * @param[in] label text model containing text info.
+ * @param[in] charIndex character index to which we want to calculate the geometry for.
+ * @return bounding rectangle.
+ */
+ DALI_TOOLKIT_API Rect<float> GetCharacterBoundingRectangle(TextLabel label, const uint32_t charIndex);
+
+ /**
+ * @brief Get the character bounding rectangle.
+ * If the text is not yet rendered or the index > text.Count(); a rect of {0, 0, 0, 0} is returned.
+ *
+ * @param[in] field text model containing text info.
+ * @param[in] charIndex character index to which we want to calculate the geometry for.
+ * @return bounding rectangle.
+ */
+ DALI_TOOLKIT_API Rect<float> GetCharacterBoundingRectangle(TextField field, const uint32_t charIndex);
+
+ /**
+ * @brief Get the character bounding rectangle.
+ * If the text is not yet rendered or the index > text.Count(); a rect of {0, 0, 0, 0} is returned.
+ *
+ * @param[in] editor text model containing text info.
+ * @param[in] charIndex character index to which we want to calculate the geometry for.
+ * @return bounding rectangle.
+ */
+ DALI_TOOLKIT_API Rect<float> GetCharacterBoundingRectangle(TextEditor editor, const uint32_t charIndex);
+
+
} // namespace TextGeometry
} // namespace Text
return mController->GetLineBoundingRectangle(lineIndex);
}
+Rect<float> TextEditor::GetCharacterBoundingRectangle(const uint32_t charIndex) const
+{
+ return mController->GetCharacterBoundingRectangle(charIndex);
+}
+
string TextEditor::GetSelectedText() const
{
string selectedText = "";
Rect<float> GetLineBoundingRectangle(const uint32_t lineIndex) const;
/**
+ * @brief Get the character bounding rectangle.
+ * If the text is not yet rendered or the index > text.Count(); a rect of {0, 0, 0, 0} is returned.
+ *
+ * @param[in] charIndex character index to which we want to calculate the geometry for.
+ * @return bounding rectangle.
+ */
+ Rect<float> GetCharacterBoundingRectangle(const uint32_t charIndex) const;
+
+ /**
* @copydoc Text::SelectableControlInterface::GetSelectedText()
*/
string GetSelectedText() const override;
return mController->GetLineBoundingRectangle(lineIndex);
}
+Rect<float> TextField::GetCharacterBoundingRectangle(const uint32_t charIndex) const
+{
+ return mController->GetCharacterBoundingRectangle(charIndex);
+}
+
std::string TextField::TextFieldAccessible::GetName() const
{
if(IsHiddenInput())
*/
Rect<float> GetLineBoundingRectangle(const uint32_t lineIndex) const;
+ /**
+ * @brief Get the character bounding rectangle.
+ * If the text is not yet rendered or the index > text.Count(); a rect of {0, 0, 0, 0} is returned.
+ *
+ * @param[in] charIndex character index to which we want to calculate the geometry for.
+ * @return bounding rectangle.
+ */
+ Rect<float> GetCharacterBoundingRectangle(const uint32_t charIndex) const;
+
private: // Implementation
/**
* @copydoc Dali::Toolkit::Text::Controller::(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
return mController->GetLineBoundingRectangle(lineIndex);
}
+Rect<float> TextLabel::GetCharacterBoundingRectangle(const uint32_t charIndex) const
+{
+ return mController->GetCharacterBoundingRectangle(charIndex);
+}
+
std::string TextLabel::TextLabelAccessible::GetNameRaw() const
{
return GetWholeText();
*/
Rect<float> GetLineBoundingRectangle(const uint32_t lineIndex) const;
+ /**
+ * @brief Get the character bounding rectangle.
+ * If the text is not yet rendered or the index > text.Count(); a rect of {0, 0, 0, 0} is returned.
+ *
+ * @param[in] charIndex character index to which we want to calculate the geometry for.
+ * @return bounding rectangle.
+ */
+ Rect<float> GetCharacterBoundingRectangle(const uint32_t charIndex) const;
+
private: // From Control
/**
* @copydoc Control::OnInitialize()
return GetLineBoundingRect(mImpl->mModel, lineIndex);
}
+Rect<float> Controller::GetCharacterBoundingRectangle(const uint32_t charIndex)
+{
+ return GetCharacterBoundingRect(mImpl->mModel, charIndex);
+}
+
Rect<> Controller::GetTextBoundingRectangle(CharacterIndex startIndex, CharacterIndex endIndex)
{
Vector<Vector2> sizeList;
Rect<float> GetLineBoundingRectangle(const uint32_t lineIndex);
/**
+ * @brief Get the char bounding rectangle.
+ * If the text is not yet rendered or the index > text.Count(); a rect of {0, 0, 0, 0} is returned.
+ *
+ * @param[in] charIndex character index to which we want to calculate the geometry for.
+ * @return bounding rectangle.
+ */
+ Rect<float> GetCharacterBoundingRectangle(const uint32_t charIndex);
+
+ /**
* @brief Gets the bounding box of a specific text range.
*
* @param[in] startIndex start index of the text requested to get bounding box to.
/**
* @brief Get the line width for the specified line run.
+ * The width in the geometry = glyph.advance, not glyph.width.
*
* @param[in] lineRun The line runs to get the width for.
* @return the width of the line.
return {lineX, lineY, lineWidth, lineHeight};
}
+float GetCharacterLeft(const GlyphInfo& glyph, const Vector2& characterPosition)
+{
+ return characterPosition.x - glyph.xBearing;
+}
+
+float GetCharacterTop(const float& yPosition)
+{
+ return (-1 * yPosition);
+}
+
+float GetCharacterHeight(const GlyphInfo& glyph)
+{
+ return glyph.height;
+}
+
+float GetCharacterWidth(const GlyphInfo& glyph)
+{
+ return glyph.advance;
+}
+
+Rect<> GetCharacterBoundingRect(ModelPtr textModel, const uint32_t charIndex)
+{
+ if(textModel->mVisualModel == nullptr)
+ {
+ return {0, 0, 0, 0};
+ }
+
+ VisualModelPtr& visualModel = textModel->mVisualModel;
+ LogicalModelPtr& logicalModel = textModel->mLogicalModel;
+
+ if(charIndex >= logicalModel->mText.Count() || visualModel->mLines.Empty())
+ {
+ return {0, 0, 0, 0};
+ }
+
+ const Vector<Vector2>& glyphPositions = visualModel->mGlyphPositions;
+ const Vector<GlyphInfo>& glyphs = visualModel->mGlyphs;
+ const Vector<LineRun>& lines = visualModel->mLines;
+
+ //For each character, the index of the first glyph.
+ const GlyphIndex glyphIndex = visualModel->mCharactersToGlyph[charIndex]; //took its glyphs
+
+ const Vector2& characterPosition = glyphPositions[glyphIndex];
+ const GlyphInfo& glyphInfo = glyphs[glyphIndex];
+
+ // GetLineOfCharacter function returns 0 if the lines are empty
+ const int lineIndex = visualModel->GetLineOfCharacter(charIndex);
+ const LineRun& lineRun = lines[lineIndex];
+
+ //Calculate the left: x position of the glyph + alignmentOffset of the line + mScrollPosition.x.
+ float characterX = lineRun.alignmentOffset + GetCharacterLeft(glyphInfo, characterPosition) + textModel->mScrollPosition.x;
+
+ //Calculate the Top(characterY): position.Y + previouse lines height + mScrollPosition.y.
+ bool isFirstLine = lineIndex == 0;
+
+ //If the line is the first line of the text; its top = 0.
+ float lineY = (isFirstLine ? 0 : GetLineTop(lines, lineRun));
+
+ float characterY = lineY + GetCharacterTop(characterPosition.y) + textModel->mScrollPosition.y;
+
+ //The rectangle contains the width and height:
+ float characterWidth = GetCharacterWidth(glyphInfo);
+ float characterHeight = GetCharacterHeight(glyphInfo);
+
+ return {characterX, characterY, characterWidth, characterHeight};
+}
+
} // namespace Text
} // namespace Toolkit
*/
float GetLineTop(const Vector<LineRun>& lines, const LineRun& lineRun);
+/**
+ * @brief Get the rendered size and position of a specific character in a rectangle.
+ * If the text is not yet rendered or the index > text.Count(); a rect of {0, 0, 0, 0} is returned.
+ * The Width of the character = glyph.advance
+ * The Height of the character = glyph.height
+ * The Left (X) of the character = characterPosition.x - glyph.xBearing; Regardless of the language direction RTL or LTR, the x point is the left x-point of the glyph.
+ * The Top (Y) of the character = characterPosition.y.
+ * @param[in] textModel text model containing text info.
+ * @param[in] charIndex character index to which we want to calculate the geometry for.
+ * @return Rect {x, y, width, height}.
+ */
+Rect<> GetCharacterBoundingRect(ModelPtr textModel, const uint32_t charIndex);
+
+/**
+ * @brief Get the left point of the character (x).
+ *
+ * @param[in] glyph the requested character glyph.
+ * @param[in] characterPosition the position of the requested character.
+ * @return x point of the character.
+ */
+float GetCharacterLeft(const GlyphInfo& glyph, const Vector2& characterPosition);
+
+/**
+ * @brief Get the top point of the character (y).
+ *
+ * @param[in] characterPosition the position of the requested character.
+ * @return y point of the character.
+ */
+float GetCharacterTop(const Vector2& characterPosition);
+
+/**
+ * @brief Get the height of the character.
+ *
+ * @param[in] glyph the requested character glyph.
+ * @return height of the character.
+ */
+float GetCharacterHeight(const GlyphInfo& glyph);
+
+/**
+ * @brief Get the left point of the character.
+ *
+ * @param[in] glyph the requested character glyph.
+ * @return width of the character.
+ */
+float GetCharacterWidth(const GlyphInfo& glyph);
+
} // namespace Text
} // namespace Toolkit