From 115fa45194f9091fe6d593491d1cd6a95eee1c95 Mon Sep 17 00:00:00 2001 From: Youngbok Shin Date: Wed, 16 Sep 2020 14:22:58 +0900 Subject: [PATCH] added FONT_SIZE_SCALE("fontSizeScale") DevelProperty into TextLabel, TextField and TextEditor The FONT_SIZE_SCALE property is added for scaling up/down a given font size. A font size will be multiplied with a FONT_SIZE_SCALE value before querying fonts. The FONT_SIZE_SCALE property will be disabled if TEXT_FIT is enabled in TextLabel. Change-Id: I4de48af34d14f077e8005a0a1b06ccc34835f83e --- .../src/dali-toolkit/utc-Dali-TextEditor.cpp | 39 ++++++++++++++++++++++ .../src/dali-toolkit/utc-Dali-TextField.cpp | 38 +++++++++++++++++++++ .../src/dali-toolkit/utc-Dali-TextLabel.cpp | 38 +++++++++++++++++++++ .../controls/text-controls/text-editor-devel.h | 12 +++++++ .../controls/text-controls/text-field-devel.h | 12 +++++++ .../controls/text-controls/text-label-devel.h | 12 +++++++ .../controls/text-controls/text-editor-impl.cpp | 17 ++++++++++ .../controls/text-controls/text-field-impl.cpp | 17 ++++++++++ .../controls/text-controls/text-label-impl.cpp | 17 ++++++++++ .../internal/text/text-controller-impl.cpp | 10 +++--- dali-toolkit/internal/text/text-controller-impl.h | 9 +++-- .../text/text-controller-input-font-handler.cpp | 2 +- dali-toolkit/internal/text/text-controller.cpp | 32 +++++++++++++++++- dali-toolkit/internal/text/text-controller.h | 14 ++++++++ 14 files changed, 259 insertions(+), 10 deletions(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp index 49e630d..8fb86da 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp @@ -102,6 +102,7 @@ const char* const PROPERTY_NAME_ENABLE_SHIFT_SELECTION = "enableSh const char* const PROPERTY_NAME_ENABLE_GRAB_HANDLE = "enableGrabHandle"; const char* const PROPERTY_NAME_MATCH_SYSTEM_LANGUAGE_DIRECTION = "matchSystemLanguageDirection"; const char* const PROPERTY_NAME_MAX_LENGTH = "maxLength"; +const char* const PROPERTY_NAME_FONT_SIZE_SCALE = "fontSizeScale"; const Vector4 PLACEHOLDER_TEXT_COLOR( 0.8f, 0.8f, 0.8f, 0.8f ); @@ -487,6 +488,7 @@ int UtcDaliTextEditorGetPropertyP(void) DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_LINE_COUNT) == TextEditor::Property::LINE_COUNT ); DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_SELECTION ) == TextEditor::Property::ENABLE_SELECTION ); DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER ) == TextEditor::Property::PLACEHOLDER ); + DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_FONT_SIZE_SCALE ) == DevelTextEditor::Property::FONT_SIZE_SCALE ); DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER_TEXT ) == DevelTextEditor::Property::PLACEHOLDER_TEXT ); DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER_TEXT_COLOR ) == DevelTextEditor::Property::PLACEHOLDER_TEXT_COLOR ); DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_SHIFT_SELECTION ) == DevelTextEditor::Property::ENABLE_SHIFT_SELECTION ); @@ -494,6 +496,7 @@ int UtcDaliTextEditorGetPropertyP(void) DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_MATCH_SYSTEM_LANGUAGE_DIRECTION ) == DevelTextEditor::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION ); DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_MAX_LENGTH ) == DevelTextEditor::Property::MAX_LENGTH ); + END_TEST; } @@ -558,6 +561,10 @@ int UtcDaliTextEditorSetPropertyP(void) editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f ); DALI_TEST_EQUALS( editor.GetProperty( TextEditor::Property::POINT_SIZE ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); + editor.SetProperty( DevelTextEditor::Property::FONT_SIZE_SCALE, 2.5f ); + DALI_TEST_EQUALS( editor.GetProperty( DevelTextEditor::Property::FONT_SIZE_SCALE ), 2.5f, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); + editor.SetProperty( DevelTextEditor::Property::FONT_SIZE_SCALE, 1.0f ); + // Reset font style. fontStyleMapSet.Clear(); fontStyleMapSet.Insert( "weight", "normal" ); @@ -3131,3 +3138,35 @@ int UtcDaliTextEditorScrolling(void) END_TEST; } + +int UtcDaliToolkitTextEditorFontSizeScale(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliToolkitTextEditorFontSizeScale"); + + TextEditor textEditor = TextEditor::New(); + textEditor.SetProperty( TextEditor::Property::POINT_SIZE, 30.f ); + textEditor.SetProperty( TextEditor::Property::TEXT, "Test" ); + Vector3 nonScaledSize = textEditor.GetNaturalSize(); + + TextEditor textEditorScaled = TextEditor::New(); + textEditorScaled.SetProperty( TextEditor::Property::POINT_SIZE, 15.f ); + textEditorScaled.SetProperty( Toolkit::DevelTextEditor::Property::FONT_SIZE_SCALE, 2.f ); + textEditorScaled.SetProperty( TextEditor::Property::TEXT, "Test" ); + Vector3 scaledSize = textEditorScaled.GetNaturalSize(); + + DALI_TEST_EQUALS( nonScaledSize, scaledSize, TEST_LOCATION ); + + textEditor.SetProperty( TextEditor::Property::PIXEL_SIZE, 30.f ); + textEditor.SetProperty( TextEditor::Property::TEXT, "Test" ); + nonScaledSize = textEditor.GetNaturalSize(); + + textEditorScaled.SetProperty( TextEditor::Property::PIXEL_SIZE, 15.f ); + textEditorScaled.SetProperty( Toolkit::DevelTextEditor::Property::FONT_SIZE_SCALE, 2.f ); + textEditorScaled.SetProperty( TextEditor::Property::TEXT, "Test" ); + scaledSize = textEditorScaled.GetNaturalSize(); + + DALI_TEST_EQUALS( nonScaledSize, scaledSize, TEST_LOCATION ); + + END_TEST; +} diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp index 2dd61c2..b3b4412 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp @@ -104,6 +104,7 @@ const char* const PROPERTY_NAME_ENABLE_GRAB_HANDLE = "enableGr const char* const PROPERTY_NAME_MATCH_SYSTEM_LANGUAGE_DIRECTION = "matchSystemLanguageDirection"; const char* const PROPERTY_NAME_ENABLE_GRAB_HANDLE_POPUP = "enableGrabHandlePopup"; const char* const PROPERTY_NAME_BACKGROUND = "textBackground"; +const char* const PROPERTY_NAME_FONT_SIZE_SCALE = "fontSizeScale"; const Vector4 PLACEHOLDER_TEXT_COLOR( 0.8f, 0.8f, 0.8f, 0.8f ); const Dali::Vector4 LIGHT_BLUE( 0.75f, 0.96f, 1.f, 1.f ); // The text highlight color. @@ -503,6 +504,7 @@ int UtcDaliTextFieldGetPropertyP(void) DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ENABLE_SELECTION ) == TextField::Property::ENABLE_SELECTION ); DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER ) == TextField::Property::PLACEHOLDER ); DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ELLIPSIS ) == TextField::Property::ELLIPSIS ); + DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_FONT_SIZE_SCALE ) == DevelTextField::Property::FONT_SIZE_SCALE ); DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ENABLE_SHIFT_SELECTION ) == DevelTextField::Property::ENABLE_SHIFT_SELECTION ); DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ENABLE_GRAB_HANDLE ) == DevelTextField::Property::ENABLE_GRAB_HANDLE ); DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_MATCH_SYSTEM_LANGUAGE_DIRECTION ) == DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION ); @@ -579,6 +581,10 @@ int UtcDaliTextFieldSetPropertyP(void) field.SetProperty( TextField::Property::POINT_SIZE, 10.f ); DALI_TEST_EQUALS( field.GetProperty( TextField::Property::POINT_SIZE ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); + field.SetProperty( DevelTextField::Property::FONT_SIZE_SCALE, 2.5f ); + DALI_TEST_EQUALS( field.GetProperty( DevelTextField::Property::FONT_SIZE_SCALE ), 2.5f, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); + field.SetProperty( DevelTextField::Property::FONT_SIZE_SCALE, 1.0f ); + // Reset font style. fontStyleMapSet.Clear(); fontStyleMapSet.Insert( "weight", "normal" ); @@ -3050,3 +3056,35 @@ int UtcDaliTextFieldEnableEditing(void) END_TEST; } + +int UtcDaliToolkitTextFieldFontSizeScale(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliToolkitTextFieldFontSizeScale"); + + TextField textField = TextField::New(); + textField.SetProperty( TextField::Property::POINT_SIZE, 30.f ); + textField.SetProperty( TextField::Property::TEXT, "Test" ); + Vector3 nonScaledSize = textField.GetNaturalSize(); + + TextField textFieldScaled = TextField::New(); + textFieldScaled.SetProperty( TextField::Property::POINT_SIZE, 15.f ); + textFieldScaled.SetProperty( Toolkit::DevelTextField::Property::FONT_SIZE_SCALE, 2.f ); + textFieldScaled.SetProperty( TextField::Property::TEXT, "Test" ); + Vector3 scaledSize = textFieldScaled.GetNaturalSize(); + + DALI_TEST_EQUALS( nonScaledSize, scaledSize, TEST_LOCATION ); + + textField.SetProperty( TextField::Property::PIXEL_SIZE, 30.f ); + textField.SetProperty( TextField::Property::TEXT, "Test" ); + nonScaledSize = textField.GetNaturalSize(); + + textFieldScaled.SetProperty( TextField::Property::PIXEL_SIZE, 15.f ); + textFieldScaled.SetProperty( Toolkit::DevelTextField::Property::FONT_SIZE_SCALE, 2.f ); + textFieldScaled.SetProperty( TextField::Property::TEXT, "Test" ); + scaledSize = textFieldScaled.GetNaturalSize(); + + DALI_TEST_EQUALS( nonScaledSize, scaledSize, TEST_LOCATION ); + + END_TEST; +} diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp index f9128fd..57862f4 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp @@ -72,6 +72,7 @@ const char* const PROPERTY_NAME_BACKGROUND = "textBackground"; const char* const PROPERTY_NAME_PIXEL_SIZE = "pixelSize"; const char* const PROPERTY_NAME_ELLIPSIS = "ellipsis"; const char* const PROPERTY_NAME_AUTO_SCROLL_LOOP_DELAY = "autoScrollLoopDelay"; +const char* const PROPERTY_NAME_FONT_SIZE_SCALE = "fontSizeScale"; const std::string DEFAULT_FONT_DIR( "/resources/fonts" ); const unsigned int EMOJI_FONT_SIZE = 3840u; // 60 * 64 @@ -310,6 +311,7 @@ int UtcDaliToolkitTextLabelGetPropertyP(void) DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_PIXEL_SIZE ) == TextLabel::Property::PIXEL_SIZE ); DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_ELLIPSIS ) == TextLabel::Property::ELLIPSIS ); DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_AUTO_SCROLL_LOOP_DELAY ) == TextLabel::Property::AUTO_SCROLL_LOOP_DELAY ); + DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_FONT_SIZE_SCALE ) == DevelTextLabel::Property::FONT_SIZE_SCALE ); END_TEST; } @@ -361,6 +363,10 @@ int UtcDaliToolkitTextLabelSetPropertyP(void) label.SetProperty( TextLabel::Property::POINT_SIZE, 10.f ); DALI_TEST_EQUALS( label.GetProperty( TextLabel::Property::POINT_SIZE ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); + label.SetProperty( DevelTextLabel::Property::FONT_SIZE_SCALE, 2.5f ); + DALI_TEST_EQUALS( label.GetProperty( DevelTextLabel::Property::FONT_SIZE_SCALE ), 2.5f, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); + label.SetProperty( DevelTextLabel::Property::FONT_SIZE_SCALE, 1.0f ); + // Reset font style. fontStyleMapSet.Clear(); fontStyleMapSet.Insert( "weight", "normal" ); @@ -1689,3 +1695,35 @@ int UtcDaliToolkitTextlabelLastCharacterIndex(void) END_TEST; } + +int UtcDaliToolkitTextlabelFontSizeScale(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliToolkitTextlabelFontSizeScale"); + + TextLabel label = TextLabel::New(); + label.SetProperty( TextLabel::Property::POINT_SIZE, 30.f ); + label.SetProperty( TextLabel::Property::TEXT, "Test" ); + Vector3 nonScaledSize = label.GetNaturalSize(); + + TextLabel labelScaled = TextLabel::New(); + labelScaled.SetProperty( TextLabel::Property::POINT_SIZE, 15.f ); + labelScaled.SetProperty( Toolkit::DevelTextLabel::Property::FONT_SIZE_SCALE, 2.f ); + labelScaled.SetProperty( TextLabel::Property::TEXT, "Test" ); + Vector3 scaledSize = labelScaled.GetNaturalSize(); + + DALI_TEST_EQUALS( nonScaledSize, scaledSize, TEST_LOCATION ); + + label.SetProperty( TextLabel::Property::PIXEL_SIZE, 30.f ); + label.SetProperty( TextLabel::Property::TEXT, "Test" ); + nonScaledSize = label.GetNaturalSize(); + + labelScaled.SetProperty( TextLabel::Property::PIXEL_SIZE, 15.f ); + labelScaled.SetProperty( Toolkit::DevelTextLabel::Property::FONT_SIZE_SCALE, 2.f ); + labelScaled.SetProperty( TextLabel::Property::TEXT, "Test" ); + scaledSize = labelScaled.GetNaturalSize(); + + DALI_TEST_EQUALS( nonScaledSize, scaledSize, TEST_LOCATION ); + + END_TEST; +} diff --git a/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h b/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h index 6cb473c..9a5bff1 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h +++ b/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h @@ -163,6 +163,18 @@ enum Type * @note This property is read-only. */ SELECTED_TEXT, + + /** + * @brief The font size scale. + * @details name "fontSizeScale", type Property::FLOAT. + * @note The default value is 1.0 which does nothing. + * The given font size scale value is used for multiplying the specified font size before querying fonts. + * + * e.g. The rendering results of both cases are same. + * - fontSize: 15pt, fontSizeScale: 1.0 + * - fontSize: 10pt, fontSizeScale: 1.5 + */ + FONT_SIZE_SCALE, }; } // namespace Property diff --git a/dali-toolkit/devel-api/controls/text-controls/text-field-devel.h b/dali-toolkit/devel-api/controls/text-controls/text-field-devel.h index cec1709..f13b2cb 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-field-devel.h +++ b/dali-toolkit/devel-api/controls/text-controls/text-field-devel.h @@ -149,6 +149,18 @@ enum */ ENABLE_EDITING, + /** + * @brief The font size scale. + * @details name "fontSizeScale", type Property::FLOAT. + * @note The default value is 1.0 which does nothing. + * The given font size scale value is used for multiplying the specified font size before querying fonts. + * + * e.g. The rendering results of both cases are same. + * - fontSize: 15pt, fontSizeScale: 1.0 + * - fontSize: 10pt, fontSizeScale: 1.5 + */ + FONT_SIZE_SCALE + }; } // namespace Property diff --git a/dali-toolkit/devel-api/controls/text-controls/text-label-devel.h b/dali-toolkit/devel-api/controls/text-controls/text-label-devel.h index a315536..9b3e4db 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-label-devel.h +++ b/dali-toolkit/devel-api/controls/text-controls/text-label-devel.h @@ -142,6 +142,18 @@ enum Type * @details Name "renderingBackend", type Property::INT. */ RENDERING_BACKEND, + + /** + * @brief The font size scale for scaling the specified font size up or down. + * @details name "fontSizeScale", type Property::FLOAT. + * @note The default value is 1.0 which does nothing. + * The given font size scale value is used for multiplying the specified font size before querying fonts. + * + * e.g. The rendering results of both cases are same. + * - fontSize: 15pt, fontSizeScale: 1.0 + * - fontSize: 10pt, fontSizeScale: 1.5 + */ + FONT_SIZE_SCALE, }; } // namespace Property diff --git a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp index dc82c36..113a1f5 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp @@ -147,6 +147,7 @@ DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "horizontalScrollPosition DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "verticalScrollPosition", INTEGER, VERTICAL_SCROLL_POSITION ) DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableEditing", BOOLEAN, ENABLE_EDITING ) DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextEditor, "selectedText", STRING, SELECTED_TEXT ) +DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "fontSizeScale", FLOAT, FONT_SIZE_SCALE ) DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "textChanged", SIGNAL_TEXT_CHANGED ) DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED ) @@ -744,6 +745,17 @@ void TextEditor::SetProperty( BaseObject* object, Property::Index index, const P } break; } + case Toolkit::DevelTextEditor::Property::FONT_SIZE_SCALE: + { + const float scale = value.Get< float >(); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p FONT_SIZE_SCALE %f\n", impl.mController.Get(), scale ); + + if( !Equals( impl.mController->GetFontSizeScale(), scale ) ) + { + impl.mController->SetFontSizeScale( scale ); + } + break; + } } // switch } // texteditor } @@ -1090,6 +1102,11 @@ Property::Value TextEditor::GetProperty( BaseObject* object, Property::Index ind value = impl.GetVerticalScrollPosition(); break; } + case Toolkit::DevelTextEditor::Property::FONT_SIZE_SCALE: + { + value = impl.mController->GetFontSizeScale(); + break; + } } //switch } diff --git a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp index 312a54e..1bf65ca 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp @@ -138,6 +138,7 @@ DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "renderingBackend", DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "selectedTextStart", INTEGER, SELECTED_TEXT_START ) DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "selectedTextEnd", INTEGER, SELECTED_TEXT_END ) DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableEditing", BOOLEAN, ENABLE_EDITING ) +DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "fontSizeScale", FLOAT, FONT_SIZE_SCALE ) DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED ) DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED ) @@ -733,6 +734,17 @@ void TextField::SetProperty( BaseObject* object, Property::Index index, const Pr impl.SetEditable( editable ); break; } + case Toolkit::DevelTextField::Property::FONT_SIZE_SCALE: + { + const float scale = value.Get< float >(); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_SIZE_SCALE %f\n", impl.mController.Get(), scale ); + + if( !Equals( impl.mController->GetFontSizeScale(), scale ) ) + { + impl.mController->SetFontSizeScale( scale ); + } + break; + } } // switch } // textfield } @@ -1073,6 +1085,11 @@ Property::Value TextField::GetProperty( BaseObject* object, Property::Index inde value = impl.IsEditable(); break; } + case Toolkit::DevelTextField::Property::FONT_SIZE_SCALE: + { + value = impl.mController->GetFontSizeScale(); + break; + } } //switch } diff --git a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp index 3ecb376..1c03203 100755 --- a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp @@ -134,6 +134,7 @@ DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "matchSystemLanguageDi DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "textFit", MAP, TEXT_FIT ) DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "minLineSize", FLOAT, MIN_LINE_SIZE ) DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "renderingBackend", INTEGER, RENDERING_BACKEND ) +DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "fontSizeScale", FLOAT, FONT_SIZE_SCALE ) 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 ) DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorGreen", TEXT_COLOR_GREEN, TEXT_COLOR, 1 ) @@ -466,6 +467,17 @@ void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Pr impl.mTextUpdateNeeded = impl.mController->SetDefaultLineSize( lineSize ) || impl.mTextUpdateNeeded; break; } + case Toolkit::DevelTextLabel::Property::FONT_SIZE_SCALE: + { + const float scale = value.Get< float >(); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p FONT_SIZE_SCALE %f\n", impl.mController.Get(), scale ); + + if( !Equals( impl.mController->GetFontSizeScale(), scale ) ) + { + impl.mController->SetFontSizeScale( scale ); + } + break; + } } // Request relayout when text update is needed. It's necessary to call it @@ -694,6 +706,11 @@ Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index inde value = impl.mController->GetDefaultLineSize(); break; } + case Toolkit::DevelTextLabel::Property::FONT_SIZE_SCALE: + { + value = impl.mController->GetFontSizeScale(); + break; + } } } diff --git a/dali-toolkit/internal/text/text-controller-impl.cpp b/dali-toolkit/internal/text/text-controller-impl.cpp index b0aa82e..32bf7ab 100644 --- a/dali-toolkit/internal/text/text-controller-impl.cpp +++ b/dali-toolkit/internal/text/text-controller-impl.cpp @@ -959,7 +959,7 @@ bool Controller::Impl::UpdateModel( OperationsMask operationsRequired ) // Get the default font's description. TextAbstraction::FontDescription defaultFontDescription; - TextAbstraction::PointSize26Dot6 defaultPointSize = TextAbstraction::FontClient::DEFAULT_POINT_SIZE; + TextAbstraction::PointSize26Dot6 defaultPointSize = TextAbstraction::FontClient::DEFAULT_POINT_SIZE * mFontSizeScale; if( IsShowingPlaceholderText() && mEventData && ( NULL != mEventData->mPlaceholderFont ) ) { @@ -967,7 +967,7 @@ bool Controller::Impl::UpdateModel( OperationsMask operationsRequired ) defaultFontDescription = mEventData->mPlaceholderFont->mFontDescription; if( mEventData->mPlaceholderFont->sizeDefined ) { - defaultPointSize = mEventData->mPlaceholderFont->mDefaultPointSize * 64u; + defaultPointSize = mEventData->mPlaceholderFont->mDefaultPointSize * mFontSizeScale * 64u; } } else if( NULL != mFontDefaults ) @@ -981,7 +981,7 @@ bool Controller::Impl::UpdateModel( OperationsMask operationsRequired ) } else { - defaultPointSize = mFontDefaults->mDefaultPointSize * 64u; + defaultPointSize = mFontDefaults->mDefaultPointSize * mFontSizeScale * 64u; } } @@ -1332,11 +1332,11 @@ float Controller::Impl::GetDefaultFontLineHeight() if( NULL == mFontDefaults ) { TextAbstraction::FontDescription fontDescription; - defaultFontId = mFontClient.GetFontId( fontDescription ); + defaultFontId = mFontClient.GetFontId( fontDescription, TextAbstraction::FontClient::DEFAULT_POINT_SIZE * mFontSizeScale ); } else { - defaultFontId = mFontDefaults->GetFontId( mFontClient ); + defaultFontId = mFontDefaults->GetFontId( mFontClient, mFontDefaults->mDefaultPointSize * mFontSizeScale ); } Text::FontMetrics fontMetrics; diff --git a/dali-toolkit/internal/text/text-controller-impl.h b/dali-toolkit/internal/text/text-controller-impl.h index 61714e6..1c6702c 100755 --- a/dali-toolkit/internal/text/text-controller-impl.h +++ b/dali-toolkit/internal/text/text-controller-impl.h @@ -43,6 +43,7 @@ namespace Text const float DEFAULT_TEXTFIT_MIN = 10.f; const float DEFAULT_TEXTFIT_MAX = 100.f; const float DEFAULT_TEXTFIT_STEP = 1.f; +const float DEFAULT_FONT_SIZE_SCALE = 1.f; //Forward declarations struct CursorInfo; @@ -206,11 +207,11 @@ struct FontDefaults fontClient.GetDefaultPlatformFontDescription( mFontDescription ); } - FontId GetFontId( TextAbstraction::FontClient& fontClient ) + FontId GetFontId( TextAbstraction::FontClient& fontClient, float fontPointSize ) { if( !mFontId ) { - const PointSize26Dot6 pointSize = static_cast( mDefaultPointSize * 64.f ); + const PointSize26Dot6 pointSize = static_cast( fontPointSize * 64.f ); mFontId = fontClient.GetFontId( mFontDescription, pointSize ); } @@ -349,7 +350,8 @@ struct Controller::Impl mTextFitMinSize( DEFAULT_TEXTFIT_MIN ), mTextFitMaxSize( DEFAULT_TEXTFIT_MAX ), mTextFitStepSize( DEFAULT_TEXTFIT_STEP ), - mTextFitEnabled( false ) + mTextFitEnabled( false ), + mFontSizeScale( DEFAULT_FONT_SIZE_SCALE ) { mModel = Model::New(); @@ -828,6 +830,7 @@ public: float mTextFitMaxSize; ///< Maximum Font Size for text fit. Default 100 float mTextFitStepSize; ///< Step Size for font intervalse. Default 1 bool mTextFitEnabled : 1; ///< Whether the text's fit is enabled. + float mFontSizeScale; ///< Scale value for Font Size. Default 1.0 private: friend ControllerImplEventHandler; diff --git a/dali-toolkit/internal/text/text-controller-input-font-handler.cpp b/dali-toolkit/internal/text/text-controller-input-font-handler.cpp index 21bd604..3eb74a1 100644 --- a/dali-toolkit/internal/text/text-controller-input-font-handler.cpp +++ b/dali-toolkit/internal/text/text-controller-input-font-handler.cpp @@ -397,7 +397,7 @@ void Controller::InputFontHandler::SetInputFontPointSize(Controller& controller, startOfSelectedText, lengthOfSelectedText ); - fontDescriptionRun.size = static_cast( size * 64.f ); + fontDescriptionRun.size = static_cast( size * controller.mImpl->mFontSizeScale * 64.f ); fontDescriptionRun.sizeDefined = true; controller.mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText; diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index aed8d32..d00330e 100644 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -989,6 +989,36 @@ FontSlant Controller::GetPlaceholderTextFontSlant() const return PlaceholderHandler::GetPlaceholderTextFontSlant(*this); } +void Controller::SetFontSizeScale( float scale ) +{ + mImpl->mFontSizeScale = scale; + + if( mImpl->mEventData ) + { + // Update the cursor position if it's in editing mode + if( EventData::IsEditingState( mImpl->mEventData->mState ) ) + { + mImpl->mEventData->mDecoratorUpdated = true; + mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font size is updated. + } + } + + // Clear the font-specific data + ClearFontData(); + + mImpl->RequestRelayout(); +} + +float Controller::GetFontSizeScale() const +{ + if( nullptr != mImpl->mFontDefaults ) + { + return mImpl->mFontSizeScale; + } + + return 1.f; +} + void Controller::SetDefaultFontSize( float fontSize, FontSizeType type ) { if( NULL == mImpl->mFontDefaults ) @@ -2511,7 +2541,7 @@ void Controller::InsertText( const std::string& text, Controller::InsertType typ if( addFontSizeRun ) { - fontDescriptionRun.size = static_cast( mImpl->mEventData->mInputStyle.size * 64.f ); + fontDescriptionRun.size = static_cast( mImpl->mEventData->mInputStyle.size * mImpl->mFontSizeScale * 64.f ); fontDescriptionRun.sizeDefined = true; } diff --git a/dali-toolkit/internal/text/text-controller.h b/dali-toolkit/internal/text/text-controller.h index d627324..4e6f99b 100644 --- a/dali-toolkit/internal/text/text-controller.h +++ b/dali-toolkit/internal/text/text-controller.h @@ -860,6 +860,20 @@ public: // Default style & Input style float GetDefaultFontSize( FontSizeType type ) const; /** + * @brief Set the font size scale. + * + * @param[in] scale The font size scale + */ + void SetFontSizeScale( float scale ); + + /** + * @brief Get the font size scale. + * + * @return The font size scale. + */ + float GetFontSizeScale() const; + + /** * @brief Sets the Placeholder text font size. * @param[in] fontSize The placeholder text font size * @param[in] type The font size type is point size or pixel size -- 2.7.4