X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Ftext-font-style.cpp;h=927f27781437a55ac83696bba142345be8a97989;hp=681ffc77e74a6ea0ea2c8696032f6a26798e3691;hb=528aa3699cd51dab5115bca1aaebb65d4bc67c15;hpb=0e5a634c6f20855c76a6e2f63049db37fcbad965 diff --git a/dali-toolkit/internal/text/text-font-style.cpp b/dali-toolkit/internal/text/text-font-style.cpp index 681ffc7..927f277 100644 --- a/dali-toolkit/internal/text/text-font-style.cpp +++ b/dali-toolkit/internal/text/text-font-style.cpp @@ -22,8 +22,8 @@ #include // INTERNAL INCLUDES -#include -#include +#include +#include namespace Dali { @@ -40,67 +40,63 @@ const std::string STYLE_KEY( "style" ); const std::string WEIGHT_KEY( "weight" ); const std::string WIDTH_KEY( "width" ); const std::string SLANT_KEY( "slant" ); -const std::string EMPTY_STRING( "" ); +const std::string FAMILY_KEY( "family" ); +const std::string TYPE_KEY( "type" ); -#if defined(DEBUG_ENABLED) -Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS"); -#endif +const std::string SYSTEM_TOKEN( "system" ); } // namespace -/** - * @brief Creates a map with pairs 'key,value' with the font's style parameters. - * - * @param[in] node Data structure with the font's style parameters. - * @param[out] map A map with the font's style parameters. - * - */ -void CreateFontStyleMap( const TreeNode* const node, Property::Map& map ) +void SetFontFamilyProperty( ControllerPtr controller, const Property::Value& value ) { - switch( node->GetType() ) + if( controller ) { - case TreeNode::IS_NULL: - case TreeNode::OBJECT: - case TreeNode::ARRAY: // FALL THROUGH + const std::string fontFamilyValue = value.Get(); + + if( fontFamilyValue.empty() ) { - break; + // Resets the default's font family name. + controller->SetDefaultFontFamily( "" ); + return; } - case TreeNode::STRING: + + Property::Map map; + ParsePropertyString( fontFamilyValue, map ); + + if( map.Empty() ) { - map.Insert( node->GetName(), Property::Value( node->GetString() ) ); - break; + // There is no map. The font has been passed as a font's family name with no format. + controller->SetDefaultFontFamily( fontFamilyValue ); } - case TreeNode::INTEGER: - case TreeNode::FLOAT: - case TreeNode::BOOLEAN: // FALL THROUGH + else { - break; - } - } + /// Family key + Property::Value* familyValue = map.Find( FAMILY_KEY ); - for( TreeNode::ConstIterator it = node->CBegin(), endIt = node->CEnd(); it != endIt; ++it ) - { - const TreeNode::KeyNodePair& pair = *it; - CreateFontStyleMap( &pair.second, map ); - } -} + std::string fontFamilyName; + if( NULL != familyValue ) + { + fontFamilyName = familyValue->Get(); + } -/** - * @brief Parses the font's style string. - * - * @param[in] style The font's style string. - * @param[out] map A map with the font's style parameters. - * - */ -void ParseFontStyleString( const std::string& style, Property::Map& map ) -{ - Toolkit::JsonParser parser = Toolkit::JsonParser::New(); + /// Type key + Property::Value* typeValue = map.Find( TYPE_KEY ); - if( parser.Parse( style ) ) - { - const TreeNode* const node = parser.GetRoot(); + std::string typeStr; + if( NULL != typeValue ) + { + typeStr = typeValue->Get(); + } - CreateFontStyleMap( node, map ); + if( TokenComparison( SYSTEM_TOKEN, typeStr.c_str(), typeStr.size() ) ) + { + controller->UpdateAfterFontChange( fontFamilyName ); + } + else + { + controller->SetDefaultFontFamily( fontFamilyName ); + } + } } } @@ -108,35 +104,27 @@ void SetFontStyleProperty( ControllerPtr controller, const Property::Value& valu { if( controller ) { - 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() ); + Property::Map map; + if( Property::STRING == value.GetType() ) + { + const std::string& fontStyleProperties = value.Get(); - switch( type ) + ParsePropertyString( fontStyleProperties, map ); + controller->FontStyleSetByString( true ); + + } + else { - 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; - } + map = value.Get(); + controller->FontStyleSetByString( false ); } - // Parses and applies the style. - Property::Map map; - ParseFontStyleString( style, map ); - if( !map.Empty() ) { /// Weight key Property::Value* weightValue = map.Find( WEIGHT_KEY ); - FontWeight weight = TextAbstraction::FontWeight::NORMAL; + FontWeight weight = TextAbstraction::FontWeight::NONE; const bool weightDefined = weightValue != NULL; if( weightDefined ) { @@ -151,7 +139,7 @@ void SetFontStyleProperty( ControllerPtr controller, const Property::Value& valu /// Width key Property::Value* widthValue = map.Find( WIDTH_KEY ); - FontWidth width = TextAbstraction::FontWidth::NORMAL; + FontWidth width = TextAbstraction::FontWidth::NONE; const bool widthDefined = widthValue != NULL; if( widthDefined ) { @@ -166,7 +154,7 @@ void SetFontStyleProperty( ControllerPtr controller, const Property::Value& valu /// Slant key Property::Value* slantValue = map.Find( SLANT_KEY ); - FontSlant slant = TextAbstraction::FontSlant::NORMAL; + FontSlant slant = TextAbstraction::FontSlant::NONE; const bool slantDefined = slantValue != NULL; if( slantDefined ) { @@ -183,17 +171,20 @@ void SetFontStyleProperty( ControllerPtr controller, const Property::Value& valu case FontStyle::DEFAULT: { // Sets the default font's style values. - if( weightDefined && ( controller->GetDefaultFontWeight() != weight ) ) + if( !weightDefined || + ( weightDefined && ( controller->GetDefaultFontWeight() != weight ) ) ) { controller->SetDefaultFontWeight( weight ); } - if( widthDefined && ( controller->GetDefaultFontWidth() != width ) ) + if( !widthDefined || + ( widthDefined && ( controller->GetDefaultFontWidth() != width ) ) ) { controller->SetDefaultFontWidth( width ); } - if( slantDefined && ( controller->GetDefaultFontSlant() != slant ) ) + if( !slantDefined || + ( slantDefined && ( controller->GetDefaultFontSlant() != slant ) ) ) { controller->SetDefaultFontSlant( slant ); } @@ -202,45 +193,254 @@ void SetFontStyleProperty( ControllerPtr controller, const Property::Value& valu case FontStyle::INPUT: { // Sets the input font's style values. - if( weightDefined && ( controller->GetInputFontWeight() != weight ) ) + if( !weightDefined || + ( weightDefined && ( controller->GetInputFontWeight() != weight ) ) ) { controller->SetInputFontWeight( weight ); } - if( widthDefined && ( controller->GetInputFontWidth() != width ) ) + if( !widthDefined || + ( widthDefined && ( controller->GetInputFontWidth() != width ) ) ) { controller->SetInputFontWidth( width ); } - if( slantDefined && ( controller->GetInputFontSlant() != slant ) ) + if( !slantDefined || + ( slantDefined && ( controller->GetInputFontSlant() != slant ) ) ) { controller->SetInputFontSlant( slant ); } break; } - } - } - } + case FontStyle::PLACEHOLDER: + { + // Sets the placeholder text font's style values. + if( !weightDefined || + ( weightDefined && ( controller->GetPlaceholderTextFontWeight() != weight ) ) ) + { + controller->SetPlaceholderTextFontWeight( weight ); + } + + if( !widthDefined || + ( widthDefined && ( controller->GetPlaceholderTextFontWidth() != width ) ) ) + { + controller->SetPlaceholderTextFontWidth( width ); + } + + if( !slantDefined || + ( slantDefined && ( controller->GetPlaceholderTextFontSlant() != slant ) ) ) + { + controller->SetPlaceholderTextFontSlant( slant ); + } + break; + } + } // switch + } // map not empty + else + { + switch( type ) + { + case FontStyle::DEFAULT: + { + controller->SetDefaultFontWeight( TextAbstraction::FontWeight::NONE ); + controller->SetDefaultFontWidth( TextAbstraction::FontWidth::NONE ); + controller->SetDefaultFontSlant( TextAbstraction::FontSlant::NONE ); + break; + } + case FontStyle::INPUT: + { + controller->SetInputFontWeight( TextAbstraction::FontWeight::NONE ); + controller->SetInputFontWidth( TextAbstraction::FontWidth::NONE ); + controller->SetInputFontSlant( TextAbstraction::FontSlant::NONE ); + break; + } + case FontStyle::PLACEHOLDER: + { + controller->SetPlaceholderTextFontWeight( TextAbstraction::FontWeight::NONE ); + controller->SetPlaceholderTextFontWidth( TextAbstraction::FontWidth::NONE ); + controller->SetPlaceholderTextFontSlant( TextAbstraction::FontSlant::NONE ); + break; + } + } // switch + } // map.Empty() + } // controller } void GetFontStyleProperty( ControllerPtr controller, Property::Value& value, FontStyle::Type type ) { if( controller ) { + const bool isSetbyString = controller->IsFontStyleSetByString(); + + bool weightDefined = false; + bool widthDefined = false; + bool slantDefined = false; + FontWeight weight = TextAbstraction::FontWeight::NONE; + FontWidth width = TextAbstraction::FontWidth::NONE; + FontSlant slant = TextAbstraction::FontSlant::NONE; + switch( type ) { case FontStyle::DEFAULT: { - value = controller->GetDefaultFontStyle(); + weightDefined = controller->IsDefaultFontWeightDefined(); + widthDefined = controller->IsDefaultFontWidthDefined(); + slantDefined = controller->IsDefaultFontSlantDefined(); + + if( weightDefined ) + { + weight = controller->GetDefaultFontWeight(); + } + + if( widthDefined ) + { + width = controller->GetDefaultFontWidth(); + } + + if( slantDefined ) + { + slant = controller->GetDefaultFontSlant(); + } break; } case FontStyle::INPUT: { - value = controller->GetInputFontStyle(); + weightDefined = controller->IsInputFontWeightDefined(); + widthDefined = controller->IsInputFontWidthDefined(); + slantDefined = controller->IsInputFontSlantDefined(); + + if( weightDefined ) + { + weight = controller->GetInputFontWeight(); + } + + if( widthDefined ) + { + width = controller->GetInputFontWidth(); + } + + if( slantDefined ) + { + slant = controller->GetInputFontSlant(); + } + break; + } + case FontStyle::PLACEHOLDER: + { + // The type is FontStyle::PLACEHOLDER + weightDefined = controller->IsPlaceholderTextFontWeightDefined(); + widthDefined = controller->IsPlaceholderTextFontWidthDefined(); + slantDefined = controller->IsPlaceholderTextFontSlantDefined(); + + if( weightDefined ) + { + weight = controller->GetPlaceholderTextFontWeight(); + } + + if( widthDefined ) + { + width = controller->GetPlaceholderTextFontWidth(); + } + + if( slantDefined ) + { + slant = controller->GetPlaceholderTextFontSlant(); + } break; } } - } + + if( !isSetbyString ) + { + Property::Map map; + + if( weightDefined ) + { + if( TextAbstraction::FontWeight::NONE != weight ) + { + const std::string weightStr( GetEnumerationName( weight, + FONT_WEIGHT_STRING_TABLE, + FONT_WEIGHT_STRING_TABLE_COUNT ) ); + + map.Insert( WEIGHT_KEY, weightStr ); + } + } + + if( widthDefined ) + { + if( TextAbstraction::FontWidth::NONE != width ) + { + const std::string widthStr( GetEnumerationName( width, + FONT_WIDTH_STRING_TABLE, + FONT_WIDTH_STRING_TABLE_COUNT ) ); + + map.Insert( WIDTH_KEY, widthStr ); + } + } + + if( slantDefined ) + { + if( TextAbstraction::FontSlant::NONE != slant ) + { + const std::string slantStr( GetEnumerationName( slant, + FONT_SLANT_STRING_TABLE, + FONT_SLANT_STRING_TABLE_COUNT ) ); + + map.Insert( SLANT_KEY, slantStr ); + } + } + + value = map; + } // SetbyMAP + else + { + std::string fontStyleProperties = "{"; + + if( weightDefined ) + { + if( TextAbstraction::FontWeight::NONE != weight ) + { + const std::string weightStr( GetEnumerationName( weight, + FONT_WEIGHT_STRING_TABLE, + FONT_WEIGHT_STRING_TABLE_COUNT ) ); + + fontStyleProperties += "\"weight\":\"" + weightStr + "\","; + } + } + + if( widthDefined ) + { + if( TextAbstraction::FontWidth::NONE != width ) + { + const std::string widthStr( GetEnumerationName( width, + FONT_WIDTH_STRING_TABLE, + FONT_WIDTH_STRING_TABLE_COUNT ) ); + fontStyleProperties += "\"width\":\"" + widthStr + "\","; + } + } + + if( slantDefined ) + { + if( TextAbstraction::FontSlant::NONE != slant ) + { + const std::string slantStr( GetEnumerationName( slant, + FONT_SLANT_STRING_TABLE, + FONT_SLANT_STRING_TABLE_COUNT ) ); + + fontStyleProperties += "\"slant\":\"" + slantStr + "\""; + } + } + + // If last character is comma, it will be removed. + if((*fontStyleProperties.rbegin()) == ',' ) + { + fontStyleProperties = fontStyleProperties.substr( 0, fontStyleProperties.size()-1 ); + } + fontStyleProperties += "}"; + + value = fontStyleProperties; + } // SetbyString + }// controller } FontWeight StringToWeight( const char* const weightStr )