// INTERNAL INCLUDES
#include <dali-toolkit/internal/text/property-string-parser.h>
+#include <dali-toolkit/internal/text/markup-processor-helper-functions.h>
namespace Dali
{
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");
} // 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<std::string>();
- switch( type )
+ if( fontFamilyValue.empty() )
{
- case FontStyle::DEFAULT:
+ // 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<std::string>();
+ }
+
+ /// Type key
+ Property::Value* typeValue = map.Find( TYPE_KEY );
+
+ std::string typeStr;
+ if( NULL != typeValue )
+ {
+ typeStr = typeValue->Get<std::string>();
+ }
+
+ if( TokenComparison( SYSTEM_TOKEN, typeStr.c_str(), typeStr.size() ) )
{
- // Stores the default font's style string to be recovered by the GetFontStyleProperty() function.
- controller->SetDefaultFontStyle( style );
- break;
+ controller->UpdateAfterFontChange( fontFamilyName );
}
- case FontStyle::INPUT:
+ 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<std::string>();
+
+ ParsePropertyString( fontStyleProperties, map );
+ }
+ else
+ {
+ map = value.Get<Property::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 )
{
/// 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 )
{
/// 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 )
{
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 );
}
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;
}
- }
- }
- }
+ } // 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;
+ }
+ } // 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 )
{
- case FontStyle::DEFAULT:
+ 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 )
{
- value = controller->GetDefaultFontStyle();
- break;
+ weight = controller->GetInputFontWeight();
}
- case FontStyle::INPUT:
+
+ if( widthDefined )
+ {
+ width = controller->GetInputFontWidth();
+ }
+
+ if( slantDefined )
{
- value = controller->GetInputFontStyle();
- break;
+ 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 )
+ {
+ 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;
}
}