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=6fff87e9e61832665cd1b2e438ef2d9fd5f92339;hb=6bc33c55ece7fc30d8229f35e6e9f8b807a9a437;hpb=59d3e8a364401fb6631aa3954f48ed5781b8b9c4 diff --git a/dali-toolkit/internal/text/text-font-style.cpp b/dali-toolkit/internal/text/text-font-style.cpp index 6fff87e..927f277 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,23 +40,84 @@ 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" ); -#if defined(DEBUG_ENABLED) -Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS"); -#endif +const std::string SYSTEM_TOKEN( "system" ); } // 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; + } + + 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 + { + /// 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 ) + { + typeStr = typeValue->Get(); + } + + if( TokenComparison( SYSTEM_TOKEN, typeStr.c_str(), typeStr.size() ) ) + { + controller->UpdateAfterFontChange( fontFamilyName ); + } + else + { + 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 ); + controller->FontStyleSetByString( true ); + + } + else + { + map = value.Get(); + controller->FontStyleSetByString( false ); + } if( !map.Empty() ) { @@ -150,6 +212,28 @@ void SetFontStyleProperty( ControllerPtr controller, const Property::Value& valu } 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 @@ -170,6 +254,13 @@ void SetFontStyleProperty( ControllerPtr controller, const Property::Value& valu 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 @@ -179,7 +270,7 @@ void GetFontStyleProperty( ControllerPtr controller, Property::Value& value, Fon { if( controller ) { - const bool isDefaultStyle = FontStyle::DEFAULT == type; + const bool isSetbyString = controller->IsFontStyleSetByString(); bool weightDefined = false; bool widthDefined = false; @@ -188,65 +279,132 @@ void GetFontStyleProperty( ControllerPtr controller, Property::Value& value, Fon FontWidth width = TextAbstraction::FontWidth::NONE; FontSlant slant = TextAbstraction::FontSlant::NONE; - if( isDefaultStyle ) + switch( type ) { - weightDefined = controller->IsDefaultFontWeightDefined(); - widthDefined = controller->IsDefaultFontWidthDefined(); - slantDefined = controller->IsDefaultFontSlantDefined(); - - if( weightDefined ) + case FontStyle::DEFAULT: { - weight = controller->GetDefaultFontWeight(); - } + weightDefined = controller->IsDefaultFontWeightDefined(); + widthDefined = controller->IsDefaultFontWidthDefined(); + slantDefined = controller->IsDefaultFontSlantDefined(); - if( widthDefined ) - { - width = controller->GetDefaultFontWidth(); + if( weightDefined ) + { + weight = controller->GetDefaultFontWeight(); + } + + if( widthDefined ) + { + width = controller->GetDefaultFontWidth(); + } + + if( slantDefined ) + { + slant = controller->GetDefaultFontSlant(); + } + break; } + case FontStyle::INPUT: + { + weightDefined = controller->IsInputFontWeightDefined(); + widthDefined = controller->IsInputFontWidthDefined(); + slantDefined = controller->IsInputFontSlantDefined(); - if( slantDefined ) + if( weightDefined ) + { + weight = controller->GetInputFontWeight(); + } + + if( widthDefined ) + { + width = controller->GetInputFontWidth(); + } + + if( slantDefined ) + { + slant = controller->GetInputFontSlant(); + } + break; + } + case FontStyle::PLACEHOLDER: { - slant = controller->GetDefaultFontSlant(); + // 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; } } - else + + if( !isSetbyString ) { - weightDefined = controller->IsInputFontWeightDefined(); - widthDefined = controller->IsInputFontWidthDefined(); - slantDefined = controller->IsInputFontSlantDefined(); + Property::Map map; if( weightDefined ) { - weight = controller->GetInputFontWeight(); + 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 ) { - width = controller->GetInputFontWidth(); + 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 ) { - slant = controller->GetInputFontSlant(); + 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 ); + } } - } - if( weightDefined || widthDefined || slantDefined ) + value = map; + } // SetbyMAP + else { - std::string styleString("{"); + 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 ) ); + FONT_WEIGHT_STRING_TABLE, + FONT_WEIGHT_STRING_TABLE_COUNT ) ); - styleString += "\"weight\":\"" + weightStr + "\""; - } - else - { - weightDefined = false; + fontStyleProperties += "\"weight\":\"" + weightStr + "\","; } } @@ -257,16 +415,7 @@ void GetFontStyleProperty( ControllerPtr controller, Property::Value& value, Fon const std::string widthStr( GetEnumerationName( width, FONT_WIDTH_STRING_TABLE, FONT_WIDTH_STRING_TABLE_COUNT ) ); - - if( weightDefined ) - { - styleString += ","; - } - styleString += "\"width\":\"" + widthStr + "\""; - } - else - { - widthDefined = false; + fontStyleProperties += "\"width\":\"" + widthStr + "\","; } } @@ -278,30 +427,20 @@ void GetFontStyleProperty( ControllerPtr controller, Property::Value& value, Fon FONT_SLANT_STRING_TABLE, FONT_SLANT_STRING_TABLE_COUNT ) ); - if( weightDefined || widthDefined ) - { - styleString += ","; - } - styleString += "\"slant\":\"" + slantStr + "\""; - } - else - { - slantDefined = false; + fontStyleProperties += "\"slant\":\"" + slantStr + "\""; } } - if( weightDefined || widthDefined || slantDefined ) - { - styleString += "}"; - } - else + // If last character is comma, it will be removed. + if((*fontStyleProperties.rbegin()) == ',' ) { - styleString.clear(); + fontStyleProperties = fontStyleProperties.substr( 0, fontStyleProperties.size()-1 ); } + fontStyleProperties += "}"; - value = styleString; - } - } + value = fontStyleProperties; + } // SetbyString + }// controller } FontWeight StringToWeight( const char* const weightStr )