RelativeLineHeight is providing the ability to set relative line size.
Ex:
0.5 means half of the line size.
2 means double the line size.
Change-Id: Ic81b3ab0349b17de2339eb4b24002d0d4bb049dc
END_TEST;
}
+int UtcDaliToolkitTextEditorRelativeLineHeight(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline(" UtcDaliToolkitTextEditorRelativeLineHeight");
+
+ TextEditor editor = TextEditor::New();
+ editor.SetProperty(Actor::Property::SIZE, Vector2(200.0f, 300.f));
+ editor.SetProperty(TextEditor::Property::POINT_SIZE, 10);
+ editor.SetProperty(TextEditor::Property::TEXT, "Hello\nWorld");
+
+ application.GetScene().Add(editor);
+ application.SendNotification();
+ application.Render();
+
+ Vector3 naturalSize = editor.GetNaturalSize();
+
+ editor.SetProperty(DevelTextEditor::Property::RELATIVE_LINE_SIZE, 0.5f);
+
+ application.SendNotification();
+ application.Render();
+
+ Vector3 relativeNaturalSize = editor.GetNaturalSize();
+
+ DALI_TEST_EQUALS(naturalSize.y, relativeNaturalSize.y * 2, TEST_LOCATION);
+
+ editor.SetProperty(DevelTextEditor::Property::RELATIVE_LINE_SIZE, 2.0f);
+
+ application.SendNotification();
+ application.Render();
+
+ relativeNaturalSize = editor.GetNaturalSize();
+
+ DALI_TEST_EQUALS(naturalSize.y * 2, relativeNaturalSize.y, TEST_LOCATION);
+ END_TEST;
+}
+
int UtcDaliTextEditorCharacterSpacing(void)
{
ToolkitTestApplication application;
END_TEST;
}
+int UtcDaliToolkitTextLabelRelativeLineHeight(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline(" UtcDaliToolkitTextLabelRelativeLineHeight");
+
+ TextLabel label = TextLabel::New();
+ label.SetProperty(Actor::Property::SIZE, Vector2(200.0f, 300.f));
+ label.SetProperty(TextLabel::Property::POINT_SIZE, 10);
+ label.SetProperty(TextLabel::Property::TEXT, "Hello\nWorld");
+
+ application.GetScene().Add(label);
+ application.SendNotification();
+ application.Render();
+
+ Vector3 naturalSize = label.GetNaturalSize();
+
+ label.SetProperty(DevelTextLabel::Property::RELATIVE_LINE_SIZE, 0.5f);
+
+ application.SendNotification();
+ application.Render();
+
+ Vector3 relativeNaturalSize = label.GetNaturalSize();
+
+ DALI_TEST_EQUALS(naturalSize.y, relativeNaturalSize.y * 2, TEST_LOCATION);
+
+ label.SetProperty(DevelTextLabel::Property::RELATIVE_LINE_SIZE, 2.0f);
+
+ application.SendNotification();
+ application.Render();
+
+ relativeNaturalSize = label.GetNaturalSize();
+
+ DALI_TEST_EQUALS(naturalSize.y * 2, relativeNaturalSize.y, TEST_LOCATION);
+ END_TEST;
+}
+
int UtcDaliTextLabelCharacterSpacing(void)
{
ToolkitTestApplication application;
* The default value is 0.f which does nothing.
*/
CHARACTER_SPACING,
+
+ /**
+ * @brief the relative height of the line (a factor that will be multiplied by text height).
+ * @details Name "relativeLineSize", type Property::FLOAT.
+ * @note If the value is less than 1, the lines could to be overlapped.
+ */
+ RELATIVE_LINE_SIZE,
};
} // namespace Property
* The default value is 0.f which does nothing.
*/
CHARACTER_SPACING,
+
+ /**
+ * @brief the relative height of the line (a factor that will be multiplied by text height).
+ * @details Name "relativeLineSize", type Property::FLOAT.
+ * @note If the value is less than 1, the lines could to be overlapped.
+ */
+ RELATIVE_LINE_SIZE,
};
} // namespace Property
DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "strikethrough", MAP, STRIKETHROUGH )
DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputStrikethrough", MAP, INPUT_STRIKETHROUGH )
DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "characterSpacing", FLOAT, CHARACTER_SPACING )
+DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "relativeLineSize", FLOAT, RELATIVE_LINE_SIZE )
DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "textChanged", SIGNAL_TEXT_CHANGED )
DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
impl.mRenderer.Reset();
break;
}
+ case Toolkit::DevelTextEditor::Property::RELATIVE_LINE_SIZE:
+ {
+ const float relativeLineSize = value.Get<float>();
+ DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor %p RELATIVE_LINE_SIZE %f\n", impl.mController.Get(), relativeLineSize);
+
+ impl.mController->SetRelativeLineSize(relativeLineSize);
+ impl.mRenderer.Reset();
+ break;
+ }
}
}
value = impl.mController->GetCharacterSpacing();
break;
}
+ case Toolkit::DevelTextEditor::Property::RELATIVE_LINE_SIZE:
+ {
+ value = impl.mController->GetRelativeLineSize();
+ break;
+ }
} //switch
return value;
}
DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextLabel, "ellipsisPosition", INTEGER, ELLIPSIS_POSITION )
DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextLabel, "strikethrough", MAP, STRIKETHROUGH )
DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextLabel, "characterSpacing", FLOAT, CHARACTER_SPACING )
+DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextLabel, "relativeLineSize", FLOAT, RELATIVE_LINE_SIZE )
DALI_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT(Toolkit, TextLabel, "textColor", Color::BLACK, TEXT_COLOR )
DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit, TextLabel, "textColorRed", TEXT_COLOR_RED, TEXT_COLOR, 0)
impl.mController->SetCharacterSpacing(characterSpacing);
break;
}
+ case Toolkit::DevelTextLabel::Property::RELATIVE_LINE_SIZE:
+ {
+ const float relativeLineSize = value.Get<float>();
+ DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextLabel %p RELATIVE_LINE_SIZE %f\n", impl.mController.Get(), relativeLineSize);
+
+ impl.mController->SetRelativeLineSize(relativeLineSize);
+ break;
+ }
}
// Request relayout when text update is needed. It's necessary to call it
value = impl.mController->GetCharacterSpacing();
break;
}
+ case Toolkit::DevelTextLabel::Property::RELATIVE_LINE_SIZE:
+ {
+ value = impl.mController->GetRelativeLineSize();
+ break;
+ }
}
}
Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_LAYOUT");
#endif
-const float MAX_FLOAT = std::numeric_limits<float>::max();
-const CharacterDirection LTR = false;
-const CharacterDirection RTL = !LTR;
-const float LINE_SPACING = 0.f;
-const float MIN_LINE_SIZE = 0.f;
-const Character HYPHEN_UNICODE = 0x002D;
+const float MAX_FLOAT = std::numeric_limits<float>::max();
+const CharacterDirection LTR = false;
+const CharacterDirection RTL = !LTR;
+const float LINE_SPACING = 0.f;
+const float MIN_LINE_SIZE = 0.f;
+const Character HYPHEN_UNICODE = 0x002D;
+const float RELATIVE_LINE_SIZE = 1.f;
inline bool isEmptyLineAtLast(const Vector<LineRun>& lines, const Vector<LineRun>::Iterator& line)
{
: mLayout{Layout::Engine::SINGLE_LINE_BOX},
mCursorWidth{0.f},
mDefaultLineSpacing{LINE_SPACING},
- mDefaultLineSize{MIN_LINE_SIZE}
+ mDefaultLineSize{MIN_LINE_SIZE},
+ mRelativeLineSize{RELATIVE_LINE_SIZE}
{
}
/**
+ * @brief get the line spacing.
+ *
+ * @param[in] textSize The text size.
+ * @return the line spacing value.
+ */
+ float GetLineSpacing(float textSize)
+ {
+ float lineSpacing;
+ float relTextSize;
+
+ // Sets the line size
+ lineSpacing = mDefaultLineSize - textSize;
+ lineSpacing = lineSpacing < 0.f ? 0.f : lineSpacing;
+
+ // Add the line spacing
+ lineSpacing += mDefaultLineSpacing;
+
+ //subtract line spcaing if relativeLineSize < 1 & larger than min height
+ relTextSize = textSize * mRelativeLineSize;
+ if(relTextSize > mDefaultLineSize)
+ {
+ if(mRelativeLineSize < 1)
+ {
+ //subtract the difference (always will be positive)
+ lineSpacing -= (textSize - relTextSize);
+ }
+ else
+ {
+ //reverse the addition in the top.
+ if(mDefaultLineSize > textSize)
+ {
+ lineSpacing -= mDefaultLineSize - textSize;
+ }
+
+ //add difference instead
+ lineSpacing += relTextSize - textSize;
+ }
+ }
+
+ return lineSpacing;
+ }
+
+ /**
* @brief Updates the line ascender and descender with the metrics of a new font.
*
* @param[in] glyphMetrics The metrics of the new font.
// Sets the minimum descender.
lineLayout.descender = std::min(lineLayout.descender, fontMetrics.descender);
- // Sets the line size
- lineLayout.lineSpacing = mDefaultLineSize - (lineLayout.ascender + -lineLayout.descender);
- lineLayout.lineSpacing = lineLayout.lineSpacing < 0.f ? 0.f : lineLayout.lineSpacing;
-
- // Add the line spacing
- lineLayout.lineSpacing += mDefaultLineSpacing;
+ lineLayout.lineSpacing = GetLineSpacing(lineLayout.ascender + -lineLayout.descender);
}
/**
lineRun.direction = layout.direction;
lineRun.ellipsis = false;
- lineRun.lineSpacing = mDefaultLineSize - (lineRun.ascender + -lineRun.descender);
- lineRun.lineSpacing = lineRun.lineSpacing < 0.f ? 0.f : lineRun.lineSpacing;
-
- lineRun.lineSpacing += mDefaultLineSpacing;
+ lineRun.lineSpacing = GetLineSpacing(lineRun.ascender + -lineRun.descender);
// Update the actual size.
if(lineRun.width > layoutSize.width)
lineRun.direction = LTR;
lineRun.ellipsis = false;
- lineRun.lineSpacing = mDefaultLineSize - (lineRun.ascender + -lineRun.descender);
- lineRun.lineSpacing = lineRun.lineSpacing < 0.f ? 0.f : lineRun.lineSpacing;
-
- lineRun.lineSpacing += mDefaultLineSpacing;
+ lineRun.lineSpacing = GetLineSpacing(lineRun.ascender + -lineRun.descender);
layoutSize.height += GetLineHeight(lineRun);
}
}
// Updates the vertical pen's position.
- penY += -layout.descender + layout.lineSpacing + mDefaultLineSpacing;
- // If there is a defaultLineSize, updates the pen's position.
- if(mDefaultLineSize > 0.f)
- {
- float lineSpacing = mDefaultLineSize - (layout.ascender + -layout.descender);
- lineSpacing = lineSpacing < 0.f ? 0.f : lineSpacing;
- penY += lineSpacing;
- }
+ penY += -layout.descender + layout.lineSpacing + GetLineSpacing(layout.ascender + -layout.descender);
// Increase the glyph index.
index = nextIndex;
float mDefaultLineSize;
IntrusivePtr<Metrics> mMetrics;
+ float mRelativeLineSize;
};
Engine::Engine()
return mImpl->mDefaultLineSize;
}
+void Engine::SetRelativeLineSize(float relativeLineSize)
+{
+ mImpl->mRelativeLineSize = relativeLineSize;
+}
+
+float Engine::GetRelativeLineSize() const
+{
+ return mImpl->mRelativeLineSize;
+}
+
} // namespace Layout
} // namespace Text
#define DALI_TOOLKIT_TEXT_LAYOUT_ENGINE_H
/*
- * 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.
*/
float GetDefaultLineSize() const;
+ /**
+ * @brief Sets relative line size to the original line size.
+ *
+ * @param[in] relativeLineSize The relative line size.
+ */
+ void SetRelativeLineSize(float relativeLineSize);
+
+ /**
+ * @brief Retrieves the relative line size.
+ *
+ * @return The relative line size.
+ */
+ float GetRelativeLineSize() const;
+
private:
// Undefined
Engine(const Engine& handle);
return false;
}
+bool Controller::Impl::SetRelativeLineSize(float relativeLineSize)
+{
+ if(std::fabs(relativeLineSize - GetRelativeLineSize()) > Math::MACHINE_EPSILON_1000)
+ {
+ mLayoutEngine.SetRelativeLineSize(relativeLineSize);
+
+ RelayoutAllCharacters();
+ return true;
+ }
+ return false;
+}
+
+float Controller::Impl::GetRelativeLineSize()
+{
+ return mLayoutEngine.GetRelativeLineSize();
+}
+
string Controller::Impl::GetSelectedText()
{
string text;
bool SetDefaultLineSize(float lineSize);
/**
+ * @copydoc Controller::SetRelativeLineSize
+ */
+ bool SetRelativeLineSize(float relativeLineSize);
+
+ /**
+ * @copydoc Controller::GetRelativeLineSize
+ */
+ float GetRelativeLineSize();
+
+ /**
* @copydoc Text::Controller::GetPrimaryCursorPosition()
*/
CharacterIndex GetPrimaryCursorPosition() const;
return mImpl->mLayoutEngine.GetDefaultLineSize();
}
+bool Controller::SetRelativeLineSize(float relativeLineSize)
+{
+ return mImpl->SetRelativeLineSize(relativeLineSize);
+}
+
+float Controller::GetRelativeLineSize() const
+{
+ return mImpl->GetRelativeLineSize();
+}
+
void Controller::SetInputColor(const Vector4& color)
{
InputProperties::SetInputColor(*this, color);
float GetDefaultLineSize() const;
/**
+ * @brief Sets the relative line size to the original line size.
+ *
+ * @param[in] relativeLineSize The relativeline size.
+ *
+ * @return True if relativeLineSize has been updated, false otherwise
+ */
+ bool SetRelativeLineSize(float lineSize);
+
+ /**
+ * @brief Retrieves the relative line size.
+ *
+ * @return The relative line size.
+ */
+ float GetRelativeLineSize() const;
+
+ /**
* @brief Sets the input text's color.
*
* @param[in] color The input text's color.