2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/text/text-font-style.h>
22 #include <dali/integration-api/debug.h>
25 #include <dali-toolkit/internal/text/property-string-parser.h>
38 const std::string STYLE_KEY( "style" );
39 const std::string WEIGHT_KEY( "weight" );
40 const std::string WIDTH_KEY( "width" );
41 const std::string SLANT_KEY( "slant" );
43 #if defined(DEBUG_ENABLED)
44 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
49 void SetFontStyleProperty( ControllerPtr controller, const Property::Value& value, FontStyle::Type type )
53 const std::string style = value.Get< std::string >();
54 DALI_LOG_INFO( gLogFilter, Debug::General, "Text Control %p FONT_STYLE %s\n", controller.Get(), style.c_str() );
58 case FontStyle::DEFAULT:
60 // Stores the default font's style string to be recovered by the GetFontStyleProperty() function.
61 controller->SetDefaultFontStyle( style );
64 case FontStyle::INPUT:
66 // Stores the input font's style string to be recovered by the GetFontStyleProperty() function.
67 controller->SetInputFontStyle( style );
72 // Parses and applies the style.
74 ParsePropertyString( style, map );
79 Property::Value* weightValue = map.Find( WEIGHT_KEY );
81 FontWeight weight = TextAbstraction::FontWeight::NORMAL;
82 const bool weightDefined = weightValue != NULL;
85 const std::string weightStr = weightValue->Get<std::string>();
87 Scripting::GetEnumeration< FontWeight >( weightStr.c_str(),
88 FONT_WEIGHT_STRING_TABLE,
89 FONT_WEIGHT_STRING_TABLE_COUNT,
94 Property::Value* widthValue = map.Find( WIDTH_KEY );
96 FontWidth width = TextAbstraction::FontWidth::NORMAL;
97 const bool widthDefined = widthValue != NULL;
100 const std::string widthStr = widthValue->Get<std::string>();
102 Scripting::GetEnumeration< FontWidth >( widthStr.c_str(),
103 FONT_WIDTH_STRING_TABLE,
104 FONT_WIDTH_STRING_TABLE_COUNT,
109 Property::Value* slantValue = map.Find( SLANT_KEY );
111 FontSlant slant = TextAbstraction::FontSlant::NORMAL;
112 const bool slantDefined = slantValue != NULL;
115 const std::string slantStr = slantValue->Get<std::string>();
117 Scripting::GetEnumeration< FontSlant >( slantStr.c_str(),
118 FONT_SLANT_STRING_TABLE,
119 FONT_SLANT_STRING_TABLE_COUNT,
125 case FontStyle::DEFAULT:
127 // Sets the default font's style values.
128 if( weightDefined && ( controller->GetDefaultFontWeight() != weight ) )
130 controller->SetDefaultFontWeight( weight );
133 if( widthDefined && ( controller->GetDefaultFontWidth() != width ) )
135 controller->SetDefaultFontWidth( width );
138 if( slantDefined && ( controller->GetDefaultFontSlant() != slant ) )
140 controller->SetDefaultFontSlant( slant );
144 case FontStyle::INPUT:
146 // Sets the input font's style values.
147 if( weightDefined && ( controller->GetInputFontWeight() != weight ) )
149 controller->SetInputFontWeight( weight );
152 if( widthDefined && ( controller->GetInputFontWidth() != width ) )
154 controller->SetInputFontWidth( width );
157 if( slantDefined && ( controller->GetInputFontSlant() != slant ) )
159 controller->SetInputFontSlant( slant );
168 void GetFontStyleProperty( ControllerPtr controller, Property::Value& value, FontStyle::Type type )
174 case FontStyle::DEFAULT:
176 value = controller->GetDefaultFontStyle();
179 case FontStyle::INPUT:
181 value = controller->GetInputFontStyle();
188 FontWeight StringToWeight( const char* const weightStr )
190 FontWeight weight = TextAbstraction::FontWeight::NORMAL;
191 Scripting::GetEnumeration<FontWeight>( weightStr,
192 FONT_WEIGHT_STRING_TABLE,
193 FONT_WEIGHT_STRING_TABLE_COUNT,
199 FontWidth StringToWidth( const char* const widthStr )
201 FontWidth width = TextAbstraction::FontWidth::NORMAL;
202 Scripting::GetEnumeration<FontWidth>( widthStr,
203 FONT_WIDTH_STRING_TABLE,
204 FONT_WIDTH_STRING_TABLE_COUNT,
210 FontSlant StringToSlant( const char* const slantStr )
212 FontSlant slant = TextAbstraction::FontSlant::NORMAL;
213 Scripting::GetEnumeration<FontSlant>( slantStr,
214 FONT_SLANT_STRING_TABLE,
215 FONT_SLANT_STRING_TABLE_COUNT,
223 } // namespace Toolkit