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=6a573373417e554486c06696e61566be4df755c6;hp=190a3f346c321f0e30bd6336af0815f6f54cab8a;hb=b1fd7c9ac268691ba02ca0b358b82a6f76d31edb;hpb=a632f8445619b331bc1cf1ae95b14d84a024a281 diff --git a/dali-toolkit/internal/text/text-font-style.cpp b/dali-toolkit/internal/text/text-font-style.cpp index 190a3f3..6a57337 100644 --- a/dali-toolkit/internal/text/text-font-style.cpp +++ b/dali-toolkit/internal/text/text-font-style.cpp @@ -23,6 +23,7 @@ // INTERNAL INCLUDES #include +#include namespace Dali { @@ -39,6 +40,10 @@ 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 FAMILY_KEY( "family" ); +const std::string TYPE_KEY( "type" ); + +const std::string SYSTEM_TOKEN( "system" ); #if defined(DEBUG_ENABLED) Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS"); @@ -46,32 +51,74 @@ Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_C } // namespace -void SetFontStyleProperty( ControllerPtr controller, const Property::Value& value, FontStyle::Type type ) +void SetFontFamilyProperty( ControllerPtr controller, const Property::Value& value ) { 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() ); + const std::string fontFamilyValue = value.Get(); + + if( fontFamilyValue.empty() ) + { + // Resets the default's font family name. + controller->SetDefaultFontFamily( "" ); + return; + } - switch( type ) + Property::Map map; + ParsePropertyString( fontFamilyValue, map ); + + if( map.Empty() ) + { + // There is no map. The font has been passed as a font's family name with no format. + controller->SetDefaultFontFamily( fontFamilyValue ); + } + else { - case FontStyle::DEFAULT: + /// Family key + Property::Value* familyValue = map.Find( FAMILY_KEY ); + + std::string fontFamilyName; + if( NULL != familyValue ) + { + fontFamilyName = familyValue->Get(); + } + + /// Type key + Property::Value* typeValue = map.Find( TYPE_KEY ); + + std::string typeStr; + if( NULL != typeValue ) { - // Stores the default font's style string to be recovered by the GetFontStyleProperty() function. - controller->SetDefaultFontStyle( style ); - break; + typeStr = typeValue->Get(); } - case FontStyle::INPUT: + + if( TokenComparison( SYSTEM_TOKEN, typeStr.c_str(), typeStr.size() ) ) + { + controller->UpdateAfterFontChange( fontFamilyName ); + } + else { - // Stores the input font's style string to be recovered by the GetFontStyleProperty() function. - controller->SetInputFontStyle( style ); - break; + controller->SetDefaultFontFamily( fontFamilyName ); } } + } +} - // Parses and applies the style. +void SetFontStyleProperty( ControllerPtr controller, const Property::Value& value, FontStyle::Type type ) +{ + if( controller ) + { Property::Map map; - ParsePropertyString( style, map ); + if( Property::STRING == value.GetType() ) + { + const std::string& fontStyleProperties = value.Get(); + + ParsePropertyString( fontStyleProperties, map ); + } + else + { + map = value.Get(); + } if( !map.Empty() ) { @@ -166,7 +213,7 @@ void SetFontStyleProperty( ControllerPtr controller, const Property::Value& valu } break; } - } + } // switch } // map not empty else { @@ -186,28 +233,106 @@ 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 + { + weightDefined = controller->IsInputFontWeightDefined(); + widthDefined = controller->IsInputFontWidthDefined(); + slantDefined = controller->IsInputFontSlantDefined(); + + if( weightDefined ) + { + weight = controller->GetInputFontWeight(); + } + + if( widthDefined ) + { + width = controller->GetInputFontWidth(); + } + + if( slantDefined ) + { + slant = controller->GetInputFontSlant(); + } + } + + 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 ) { - case FontStyle::DEFAULT: + if( TextAbstraction::FontWidth::NONE != width ) { - value = controller->GetDefaultFontStyle(); - break; + const std::string widthStr( GetEnumerationName( width, + FONT_WIDTH_STRING_TABLE, + FONT_WIDTH_STRING_TABLE_COUNT ) ); + + map.Insert( WIDTH_KEY, widthStr ); } - case FontStyle::INPUT: + } + + if( slantDefined ) + { + if( TextAbstraction::FontSlant::NONE != slant ) { - value = controller->GetInputFontStyle(); - break; + const std::string slantStr( GetEnumerationName( slant, + FONT_SLANT_STRING_TABLE, + FONT_SLANT_STRING_TABLE_COUNT ) ); + + map.Insert( SLANT_KEY, slantStr ); } } + + value = map; } }