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::NONE;
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::NONE;
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::NONE;
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 ||
129 ( weightDefined && ( controller->GetDefaultFontWeight() != weight ) ) )
131 controller->SetDefaultFontWeight( weight );
135 ( widthDefined && ( controller->GetDefaultFontWidth() != width ) ) )
137 controller->SetDefaultFontWidth( width );
141 ( slantDefined && ( controller->GetDefaultFontSlant() != slant ) ) )
143 controller->SetDefaultFontSlant( slant );
147 case FontStyle::INPUT:
149 // Sets the input font's style values.
150 if( !weightDefined ||
151 ( weightDefined && ( controller->GetInputFontWeight() != weight ) ) )
153 controller->SetInputFontWeight( weight );
157 ( widthDefined && ( controller->GetInputFontWidth() != width ) ) )
159 controller->SetInputFontWidth( width );
163 ( slantDefined && ( controller->GetInputFontSlant() != slant ) ) )
165 controller->SetInputFontSlant( slant );
175 case FontStyle::DEFAULT:
177 controller->SetDefaultFontWeight( TextAbstraction::FontWeight::NONE );
178 controller->SetDefaultFontWidth( TextAbstraction::FontWidth::NONE );
179 controller->SetDefaultFontSlant( TextAbstraction::FontSlant::NONE );
182 case FontStyle::INPUT:
184 controller->SetInputFontWeight( TextAbstraction::FontWeight::NONE );
185 controller->SetInputFontWidth( TextAbstraction::FontWidth::NONE );
186 controller->SetInputFontSlant( TextAbstraction::FontSlant::NONE );
194 void GetFontStyleProperty( ControllerPtr controller, Property::Value& value, FontStyle::Type type )
200 case FontStyle::DEFAULT:
202 value = controller->GetDefaultFontStyle();
205 case FontStyle::INPUT:
207 value = controller->GetInputFontStyle();
214 FontWeight StringToWeight( const char* const weightStr )
216 FontWeight weight = TextAbstraction::FontWeight::NORMAL;
217 Scripting::GetEnumeration<FontWeight>( weightStr,
218 FONT_WEIGHT_STRING_TABLE,
219 FONT_WEIGHT_STRING_TABLE_COUNT,
225 FontWidth StringToWidth( const char* const widthStr )
227 FontWidth width = TextAbstraction::FontWidth::NORMAL;
228 Scripting::GetEnumeration<FontWidth>( widthStr,
229 FONT_WIDTH_STRING_TABLE,
230 FONT_WIDTH_STRING_TABLE_COUNT,
236 FontSlant StringToSlant( const char* const slantStr )
238 FontSlant slant = TextAbstraction::FontSlant::NORMAL;
239 Scripting::GetEnumeration<FontSlant>( slantStr,
240 FONT_SLANT_STRING_TABLE,
241 FONT_SLANT_STRING_TABLE_COUNT,
249 } // namespace Toolkit