From: Victor Cebollada Date: Wed, 27 Jul 2016 13:13:04 +0000 (+0100) Subject: Retrieve the input font's style. X-Git-Tag: dali_1.2.1~5^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=636b271317c1d8a5c83acf632bfe18259917c5a0 Retrieve the input font's style. * Removes the font's style string from the InputStyle struct. This string is useless as it stores only the string style set through the property system. This string does not contain the valid font's style if the style changes as a consequence of moving the cursor. Change-Id: I41d05f3686d949e1b50233df7f6d05fc2583af92 Signed-off-by: Victor Cebollada --- diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp index 2300b50..dfc5c86 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp @@ -314,11 +314,19 @@ int UtcDaliTextEditorSetPropertyP(void) // Check font properties. editor.SetProperty( TextEditor::Property::FONT_FAMILY, "Setting font family" ); DALI_TEST_EQUALS( editor.GetProperty( TextEditor::Property::FONT_FAMILY ), std::string("Setting font family"), TEST_LOCATION ); - editor.SetProperty( TextEditor::Property::FONT_STYLE, "Setting font style" ); - DALI_TEST_EQUALS( editor.GetProperty( TextEditor::Property::FONT_STYLE ), std::string("Setting font style"), TEST_LOCATION ); + editor.SetProperty( TextEditor::Property::FONT_STYLE, "{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}" ); + DALI_TEST_EQUALS( editor.GetProperty( TextEditor::Property::FONT_STYLE ), std::string("{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}"), TEST_LOCATION ); 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 ); + // Reset font style. + editor.SetProperty( TextEditor::Property::FONT_STYLE, "{\"weight\":\"normal\",\"slant\":\"oblique\"}" ); + DALI_TEST_EQUALS( editor.GetProperty( TextEditor::Property::FONT_STYLE ), std::string("{\"weight\":\"normal\",\"slant\":\"oblique\"}"), TEST_LOCATION ); + editor.SetProperty( TextEditor::Property::FONT_STYLE, "{\"slant\":\"roman\"}" ); + DALI_TEST_EQUALS( editor.GetProperty( TextEditor::Property::FONT_STYLE ), std::string("{\"slant\":\"normal\"}"), TEST_LOCATION ); + editor.SetProperty( TextEditor::Property::FONT_STYLE, "" ); + DALI_TEST_EQUALS( editor.GetProperty( TextEditor::Property::FONT_STYLE ), std::string(""), TEST_LOCATION ); + // Check that the Alignment properties can be correctly set editor.SetProperty( TextEditor::Property::HORIZONTAL_ALIGNMENT, "END" ); DALI_TEST_EQUALS( editor.GetProperty( TextEditor::Property::HORIZONTAL_ALIGNMENT ), "END", TEST_LOCATION ); @@ -379,11 +387,19 @@ int UtcDaliTextEditorSetPropertyP(void) // Check input font properties. editor.SetProperty( TextEditor::Property::INPUT_FONT_FAMILY, "Setting input font family" ); DALI_TEST_EQUALS( editor.GetProperty( TextEditor::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION ); - editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, "Setting input font style" ); - DALI_TEST_EQUALS( editor.GetProperty( TextEditor::Property::INPUT_FONT_STYLE ), "Setting input font style", TEST_LOCATION ); + editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, "{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}" ); + DALI_TEST_EQUALS( editor.GetProperty( TextEditor::Property::INPUT_FONT_STYLE ), "{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}", TEST_LOCATION ); editor.SetProperty( TextEditor::Property::INPUT_POINT_SIZE, 12.f ); DALI_TEST_EQUALS( editor.GetProperty( TextEditor::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); + // Reset input font style. + editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, "{\"weight\":\"normal\",\"slant\":\"oblique\"}" ); + DALI_TEST_EQUALS( editor.GetProperty( TextEditor::Property::INPUT_FONT_STYLE ), std::string("{\"weight\":\"normal\",\"slant\":\"oblique\"}"), TEST_LOCATION ); + editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, "{\"slant\":\"roman\"}" ); + DALI_TEST_EQUALS( editor.GetProperty( TextEditor::Property::INPUT_FONT_STYLE ), std::string("{\"slant\":\"normal\"}"), TEST_LOCATION ); + editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, "" ); + DALI_TEST_EQUALS( editor.GetProperty( TextEditor::Property::INPUT_FONT_STYLE ), std::string(""), TEST_LOCATION ); + // Check the line spacing property DALI_TEST_EQUALS( editor.GetProperty( TextEditor::Property::LINE_SPACING ), 0.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); editor.SetProperty( TextEditor::Property::LINE_SPACING, 10.f ); diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp index 911a06e..cd3985a 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp @@ -456,11 +456,19 @@ int UtcDaliTextFieldSetPropertyP(void) // Check font properties. field.SetProperty( TextField::Property::FONT_FAMILY, "Setting font family" ); DALI_TEST_EQUALS( field.GetProperty( TextField::Property::FONT_FAMILY ), std::string("Setting font family"), TEST_LOCATION ); - field.SetProperty( TextField::Property::FONT_STYLE, "Setting font style" ); - DALI_TEST_EQUALS( field.GetProperty( TextField::Property::FONT_STYLE ), std::string("Setting font style"), TEST_LOCATION ); + field.SetProperty( TextField::Property::FONT_STYLE, "{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}" ); + DALI_TEST_EQUALS( field.GetProperty( TextField::Property::FONT_STYLE ), std::string("{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}"), TEST_LOCATION ); 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 ); + // Reset font style. + field.SetProperty( TextField::Property::FONT_STYLE, "{\"weight\":\"normal\",\"slant\":\"oblique\"}" ); + DALI_TEST_EQUALS( field.GetProperty( TextField::Property::FONT_STYLE ), std::string("{\"weight\":\"normal\",\"slant\":\"oblique\"}"), TEST_LOCATION ); + field.SetProperty( TextField::Property::FONT_STYLE, "{\"slant\":\"roman\"}" ); + DALI_TEST_EQUALS( field.GetProperty( TextField::Property::FONT_STYLE ), std::string("{\"slant\":\"normal\"}"), TEST_LOCATION ); + field.SetProperty( TextField::Property::FONT_STYLE, "" ); + DALI_TEST_EQUALS( field.GetProperty( TextField::Property::FONT_STYLE ), std::string(""), TEST_LOCATION ); + // Check that the MAX_LENGTH property can be correctly set const int maxNumberOfCharacters = 20; field.SetProperty( TextField::Property::MAX_LENGTH, maxNumberOfCharacters ); @@ -545,11 +553,19 @@ int UtcDaliTextFieldSetPropertyP(void) // Check input font properties. field.SetProperty( TextField::Property::INPUT_FONT_FAMILY, "Setting input font family" ); DALI_TEST_EQUALS( field.GetProperty( TextField::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION ); - field.SetProperty( TextField::Property::INPUT_FONT_STYLE, "Setting input font style" ); - DALI_TEST_EQUALS( field.GetProperty( TextField::Property::INPUT_FONT_STYLE ), "Setting input font style", TEST_LOCATION ); + field.SetProperty( TextField::Property::INPUT_FONT_STYLE, "{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}" ); + DALI_TEST_EQUALS( field.GetProperty( TextField::Property::INPUT_FONT_STYLE ), "{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}", TEST_LOCATION ); field.SetProperty( TextField::Property::INPUT_POINT_SIZE, 12.f ); DALI_TEST_EQUALS( field.GetProperty( TextField::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); + // Reset input font style. + field.SetProperty( TextField::Property::INPUT_FONT_STYLE, "{\"weight\":\"normal\",\"slant\":\"oblique\"}" ); + DALI_TEST_EQUALS( field.GetProperty( TextField::Property::INPUT_FONT_STYLE ), std::string("{\"weight\":\"normal\",\"slant\":\"oblique\"}"), TEST_LOCATION ); + field.SetProperty( TextField::Property::INPUT_FONT_STYLE, "{\"slant\":\"roman\"}" ); + DALI_TEST_EQUALS( field.GetProperty( TextField::Property::INPUT_FONT_STYLE ), std::string("{\"slant\":\"normal\"}"), TEST_LOCATION ); + field.SetProperty( TextField::Property::INPUT_FONT_STYLE, "" ); + DALI_TEST_EQUALS( field.GetProperty( TextField::Property::INPUT_FONT_STYLE ), std::string(""), TEST_LOCATION ); + // Check the underline property field.SetProperty( TextField::Property::UNDERLINE, "Underline properties" ); DALI_TEST_EQUALS( field.GetProperty( TextField::Property::UNDERLINE ), std::string("Underline properties"), TEST_LOCATION ); @@ -1269,10 +1285,10 @@ int utcDaliTextFieldEvent08(void) END_TEST; } -int utcDaliTextFieldStyleWhilstSelected09(void) +int utcDaliTextFieldStyleWhilstSelected(void) { ToolkitTestApplication application; - tet_infoline(" utcDaliTextFieldEvent09"); + tet_infoline(" utcDaliTextFieldStyleWhilstSelected"); // Change font and styles whilst text is selected whilst word selected diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp index 2f71832..39778f7 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 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. @@ -193,11 +193,19 @@ int UtcDaliToolkitTextLabelSetPropertyP(void) // Check font properties. label.SetProperty( TextLabel::Property::FONT_FAMILY, "Setting font family" ); DALI_TEST_EQUALS( label.GetProperty( TextLabel::Property::FONT_FAMILY ), std::string("Setting font family"), TEST_LOCATION ); - label.SetProperty( TextLabel::Property::FONT_STYLE, "Setting font style" ); - DALI_TEST_EQUALS( label.GetProperty( TextLabel::Property::FONT_STYLE ), std::string("Setting font style"), TEST_LOCATION ); + label.SetProperty( TextLabel::Property::FONT_STYLE, "{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}" ); + DALI_TEST_EQUALS( label.GetProperty( TextLabel::Property::FONT_STYLE ), std::string("{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}"), TEST_LOCATION ); 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 ); + // Reset font style. + label.SetProperty( TextLabel::Property::FONT_STYLE, "{\"weight\":\"normal\",\"slant\":\"oblique\"}" ); + DALI_TEST_EQUALS( label.GetProperty( TextLabel::Property::FONT_STYLE ), std::string("{\"weight\":\"normal\",\"slant\":\"oblique\"}"), TEST_LOCATION ); + label.SetProperty( TextLabel::Property::FONT_STYLE, "{\"slant\":\"roman\"}" ); + DALI_TEST_EQUALS( label.GetProperty( TextLabel::Property::FONT_STYLE ), std::string("{\"slant\":\"normal\"}"), TEST_LOCATION ); + label.SetProperty( TextLabel::Property::FONT_STYLE, "" ); + DALI_TEST_EQUALS( label.GetProperty( TextLabel::Property::FONT_STYLE ), std::string(""), TEST_LOCATION ); + // Toggle multi-line label.SetProperty( TextLabel::Property::MULTI_LINE, true ); DALI_TEST_EQUALS( label.GetProperty( TextLabel::Property::MULTI_LINE ), true, TEST_LOCATION ); diff --git a/dali-toolkit/internal/text/input-style.h b/dali-toolkit/internal/text/input-style.h index 30ce38c..63add2d 100644 --- a/dali-toolkit/internal/text/input-style.h +++ b/dali-toolkit/internal/text/input-style.h @@ -2,7 +2,7 @@ #define __DALI_TOOLKIT_TEXT_INPUT_STYLE_H__ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 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. @@ -40,7 +40,6 @@ struct InputStyle { InputStyle() : textColor( Color::BLACK ), - fontStyle(), familyName(), weight( TextAbstraction::FontWeight::NORMAL ), width( TextAbstraction::FontWidth::NORMAL ), @@ -64,7 +63,6 @@ struct InputStyle {}; Vector4 textColor; ///< The text's color. - std::string fontStyle; ///< The font's style string. std::string familyName; ///< The font's family name. FontWeight weight; ///< The font's weight. FontWidth width; ///< The font's width. diff --git a/dali-toolkit/internal/text/text-controller-impl.h b/dali-toolkit/internal/text/text-controller-impl.h index 8e9ab39..b220be6 100644 --- a/dali-toolkit/internal/text/text-controller-impl.h +++ b/dali-toolkit/internal/text/text-controller-impl.h @@ -2,7 +2,7 @@ #define __DALI_TOOLKIT_TEXT_CONTROLLER_IMPL_H__ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 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. @@ -166,7 +166,6 @@ struct FontDefaults { FontDefaults() : mFontDescription(), - mFontStyle(), mDefaultPointSize( 0.f ), mFontId( 0u ), familyDefined( false ), @@ -192,7 +191,6 @@ struct FontDefaults } TextAbstraction::FontDescription mFontDescription; ///< The default font's description. - std::string mFontStyle; ///< The font's style string set through the property system. float mDefaultPointSize; ///< The default font's point size. FontId mFontId; ///< The font's id of the default font. bool familyDefined:1; ///< Whether the default font's family name is defined. diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index f6544cb..dbbf523 100644 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 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. @@ -446,26 +446,6 @@ const std::string& Controller::GetDefaultFontFamily() const return EMPTY_STRING; } -void Controller::SetDefaultFontStyle( const std::string& style ) -{ - if( NULL == mImpl->mFontDefaults ) - { - mImpl->mFontDefaults = new FontDefaults(); - } - - mImpl->mFontDefaults->mFontStyle = style; -} - -const std::string& Controller::GetDefaultFontStyle() const -{ - if( NULL != mImpl->mFontDefaults ) - { - return mImpl->mFontDefaults->mFontStyle; - } - - return EMPTY_STRING; -} - void Controller::SetDefaultFontWeight( FontWeight weight ) { if( NULL == mImpl->mFontDefaults ) @@ -482,6 +462,11 @@ void Controller::SetDefaultFontWeight( FontWeight weight ) mImpl->RequestRelayout(); } +bool Controller::IsDefaultFontWeightDefined() const +{ + return mImpl->mFontDefaults->weightDefined; +} + FontWeight Controller::GetDefaultFontWeight() const { if( NULL != mImpl->mFontDefaults ) @@ -508,6 +493,11 @@ void Controller::SetDefaultFontWidth( FontWidth width ) mImpl->RequestRelayout(); } +bool Controller::IsDefaultFontWidthDefined() const +{ + return mImpl->mFontDefaults->widthDefined; +} + FontWidth Controller::GetDefaultFontWidth() const { if( NULL != mImpl->mFontDefaults ) @@ -534,6 +524,11 @@ void Controller::SetDefaultFontSlant( FontSlant slant ) mImpl->RequestRelayout(); } +bool Controller::IsDefaultFontSlantDefined() const +{ + return mImpl->mFontDefaults->slantDefined; +} + FontSlant Controller::GetDefaultFontSlant() const { if( NULL != mImpl->mFontDefaults ) @@ -955,25 +950,6 @@ const std::string& Controller::GetInputFontFamily() const return GetDefaultFontFamily(); } -void Controller::SetInputFontStyle( const std::string& fontStyle ) -{ - if( NULL != mImpl->mEventData ) - { - mImpl->mEventData->mInputStyle.fontStyle = fontStyle; - } -} - -const std::string& Controller::GetInputFontStyle() const -{ - if( NULL != mImpl->mEventData ) - { - return mImpl->mEventData->mInputStyle.fontStyle; - } - - // Return the default font's style if there is no EventData. - return GetDefaultFontStyle(); -} - void Controller::SetInputFontWeight( FontWeight weight ) { if( NULL != mImpl->mEventData ) @@ -1018,6 +994,18 @@ void Controller::SetInputFontWeight( FontWeight weight ) } } +bool Controller::IsInputFontWeightDefined() const +{ + bool defined = false; + + if( NULL != mImpl->mEventData ) + { + defined = mImpl->mEventData->mInputStyle.weightDefined; + } + + return defined; +} + FontWeight Controller::GetInputFontWeight() const { if( NULL != mImpl->mEventData ) @@ -1072,6 +1060,18 @@ void Controller::SetInputFontWidth( FontWidth width ) } } +bool Controller::IsInputFontWidthDefined() const +{ + bool defined = false; + + if( NULL != mImpl->mEventData ) + { + defined = mImpl->mEventData->mInputStyle.widthDefined; + } + + return defined; +} + FontWidth Controller::GetInputFontWidth() const { if( NULL != mImpl->mEventData ) @@ -1126,6 +1126,18 @@ void Controller::SetInputFontSlant( FontSlant slant ) } } +bool Controller::IsInputFontSlantDefined() const +{ + bool defined = false; + + if( NULL != mImpl->mEventData ) + { + defined = mImpl->mEventData->mInputStyle.slantDefined; + } + + return defined; +} + FontSlant Controller::GetInputFontSlant() const { if( NULL != mImpl->mEventData ) diff --git a/dali-toolkit/internal/text/text-controller.h b/dali-toolkit/internal/text/text-controller.h index ad5c09a..7b1e2ba 100644 --- a/dali-toolkit/internal/text/text-controller.h +++ b/dali-toolkit/internal/text/text-controller.h @@ -2,7 +2,7 @@ #define __DALI_TOOLKIT_TEXT_CONTROLLER_H__ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 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. @@ -305,22 +305,6 @@ public: const std::string& GetDefaultFontFamily() const; /** - * @brief Sets the font's style string. - * - * @note The style set may be changed by the underlying font system. The string is stored to be recovered. - * - * @param[in] style The font's style string. - */ - void SetDefaultFontStyle( const std::string& style ); - - /** - * @brief Retrieves the font's style. - * - * @return The font's style. - */ - const std::string& GetDefaultFontStyle() const; - - /** * @brief Sets the default font weight. * * @param[in] weight The font weight. @@ -328,6 +312,11 @@ public: void SetDefaultFontWeight( FontWeight weight ); /** + * @brief Whether the font's weight has been defined. + */ + bool IsDefaultFontWeightDefined() const; + + /** * @brief Retrieves the default font weight. * * @return The default font weight. @@ -342,6 +331,11 @@ public: void SetDefaultFontWidth( FontWidth width ); /** + * @brief Whether the font's width has been defined. + */ + bool IsDefaultFontWidthDefined() const; + + /** * @brief Retrieves the default font width. * * @return The default font width. @@ -356,6 +350,11 @@ public: void SetDefaultFontSlant( FontSlant slant ); /** + * @brief Whether the font's slant has been defined. + */ + bool IsDefaultFontSlantDefined() const; + + /** * @brief Retrieves the default font slant. * * @return The default font slant. @@ -587,20 +586,6 @@ public: const std::string& GetInputFontFamily() const; /** - * @brief Sets the input text's font style. - * - * @param[in] fontStyle The input text's font style. - */ - void SetInputFontStyle( const std::string& fontStyle ); - - /** - * @brief Retrieves the input text's font style. - * - * @return The input text's font style. - */ - const std::string& GetInputFontStyle() const; - - /** * @brief Sets the input font's weight. * * @param[in] weight The input font's weight. @@ -608,6 +593,11 @@ public: void SetInputFontWeight( FontWeight weight ); /** + * @return Whether the font's weight has been defined. + */ + bool IsInputFontWeightDefined() const; + + /** * @brief Retrieves the input font's weight. * * @return The input font's weight. @@ -622,6 +612,11 @@ public: void SetInputFontWidth( FontWidth width ); /** + * @return Whether the font's width has been defined. + */ + bool IsInputFontWidthDefined() const; + + /** * @brief Retrieves the input font's width. * * @return The input font's width. @@ -636,6 +631,11 @@ public: void SetInputFontSlant( FontSlant slant ); /** + * @return Whether the font's slant has been defined. + */ + bool IsInputFontSlantDefined() const; + + /** * @brief Retrieves the input font's slant. * * @return The input font's slant. diff --git a/dali-toolkit/internal/text/text-font-style.cpp b/dali-toolkit/internal/text/text-font-style.cpp index 190a3f3..6fff87e 100644 --- a/dali-toolkit/internal/text/text-font-style.cpp +++ b/dali-toolkit/internal/text/text-font-style.cpp @@ -53,22 +53,6 @@ void SetFontStyleProperty( ControllerPtr controller, const Property::Value& valu const std::string style = value.Get< std::string >(); DALI_LOG_INFO( gLogFilter, Debug::General, "Text Control %p FONT_STYLE %s\n", controller.Get(), style.c_str() ); - switch( type ) - { - case FontStyle::DEFAULT: - { - // Stores the default font's style string to be recovered by the GetFontStyleProperty() function. - controller->SetDefaultFontStyle( style ); - break; - } - case FontStyle::INPUT: - { - // Stores the input font's style string to be recovered by the GetFontStyleProperty() function. - controller->SetInputFontStyle( style ); - break; - } - } - // Parses and applies the style. Property::Map map; ParsePropertyString( style, map ); @@ -166,7 +150,7 @@ void SetFontStyleProperty( ControllerPtr controller, const Property::Value& valu } break; } - } + } // switch } // map not empty else { @@ -186,27 +170,136 @@ void SetFontStyleProperty( ControllerPtr controller, const Property::Value& valu controller->SetInputFontSlant( TextAbstraction::FontSlant::NONE ); break; } - } - } - } + } // switch + } // map.Empty() + } // controller } void GetFontStyleProperty( ControllerPtr controller, Property::Value& value, FontStyle::Type type ) { if( controller ) { - switch( type ) + const bool isDefaultStyle = FontStyle::DEFAULT == type; + + bool weightDefined = false; + bool widthDefined = false; + bool slantDefined = false; + FontWeight weight = TextAbstraction::FontWeight::NONE; + FontWidth width = TextAbstraction::FontWidth::NONE; + FontSlant slant = TextAbstraction::FontSlant::NONE; + + if( isDefaultStyle ) + { + weightDefined = controller->IsDefaultFontWeightDefined(); + widthDefined = controller->IsDefaultFontWidthDefined(); + slantDefined = controller->IsDefaultFontSlantDefined(); + + if( weightDefined ) + { + weight = controller->GetDefaultFontWeight(); + } + + if( widthDefined ) + { + width = controller->GetDefaultFontWidth(); + } + + if( slantDefined ) + { + slant = controller->GetDefaultFontSlant(); + } + } + else { - case FontStyle::DEFAULT: + weightDefined = controller->IsInputFontWeightDefined(); + widthDefined = controller->IsInputFontWidthDefined(); + slantDefined = controller->IsInputFontSlantDefined(); + + if( weightDefined ) { - value = controller->GetDefaultFontStyle(); - break; + weight = controller->GetInputFontWeight(); } - case FontStyle::INPUT: + + if( widthDefined ) { - value = controller->GetInputFontStyle(); - break; + width = controller->GetInputFontWidth(); } + + if( slantDefined ) + { + slant = controller->GetInputFontSlant(); + } + } + + if( weightDefined || widthDefined || slantDefined ) + { + std::string styleString("{"); + if( weightDefined ) + { + if( TextAbstraction::FontWeight::NONE != weight ) + { + const std::string weightStr( GetEnumerationName( weight, + FONT_WEIGHT_STRING_TABLE, + FONT_WEIGHT_STRING_TABLE_COUNT ) ); + + styleString += "\"weight\":\"" + weightStr + "\""; + } + else + { + weightDefined = false; + } + } + + if( widthDefined ) + { + if( TextAbstraction::FontWidth::NONE != width ) + { + const std::string widthStr( GetEnumerationName( width, + FONT_WIDTH_STRING_TABLE, + FONT_WIDTH_STRING_TABLE_COUNT ) ); + + if( weightDefined ) + { + styleString += ","; + } + styleString += "\"width\":\"" + widthStr + "\""; + } + else + { + widthDefined = false; + } + } + + if( slantDefined ) + { + if( TextAbstraction::FontSlant::NONE != slant ) + { + const std::string slantStr( GetEnumerationName( slant, + FONT_SLANT_STRING_TABLE, + FONT_SLANT_STRING_TABLE_COUNT ) ); + + if( weightDefined || widthDefined ) + { + styleString += ","; + } + styleString += "\"slant\":\"" + slantStr + "\""; + } + else + { + slantDefined = false; + } + } + + if( weightDefined || widthDefined || slantDefined ) + { + styleString += "}"; + } + else + { + styleString.clear(); + } + + value = styleString; } } }