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>
26 #include <dali-toolkit/internal/text/markup-processor-helper-functions.h>
39 const std::string STYLE_KEY( "style" );
40 const std::string WEIGHT_KEY( "weight" );
41 const std::string WIDTH_KEY( "width" );
42 const std::string SLANT_KEY( "slant" );
43 const std::string FAMILY_KEY( "family" );
44 const std::string TYPE_KEY( "type" );
46 const std::string SYSTEM_TOKEN( "system" );
48 #if defined(DEBUG_ENABLED)
49 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
54 void SetFontFamilyProperty( ControllerPtr controller, const Property::Value& value )
58 const std::string fontFamilyValue = value.Get<std::string>();
60 if( fontFamilyValue.empty() )
62 // Resets the default's font family name.
63 controller->SetDefaultFontFamily( "" );
68 ParsePropertyString( fontFamilyValue, map );
72 // There is no map. The font has been passed as a font's family name with no format.
73 controller->SetDefaultFontFamily( fontFamilyValue );
78 Property::Value* familyValue = map.Find( FAMILY_KEY );
80 std::string fontFamilyName;
81 if( NULL != familyValue )
83 fontFamilyName = familyValue->Get<std::string>();
87 Property::Value* typeValue = map.Find( TYPE_KEY );
90 if( NULL != typeValue )
92 typeStr = typeValue->Get<std::string>();
95 if( TokenComparison( SYSTEM_TOKEN, typeStr.c_str(), typeStr.size() ) )
97 controller->UpdateAfterFontChange( fontFamilyName );
101 controller->SetDefaultFontFamily( fontFamilyName );
107 void SetFontStyleProperty( ControllerPtr controller, const Property::Value& value, FontStyle::Type type )
112 if( Property::STRING == value.GetType() )
114 const std::string& fontStyleProperties = value.Get<std::string>();
116 ParsePropertyString( fontStyleProperties, map );
120 map = value.Get<Property::Map>();
126 Property::Value* weightValue = map.Find( WEIGHT_KEY );
128 FontWeight weight = TextAbstraction::FontWeight::NONE;
129 const bool weightDefined = weightValue != NULL;
132 const std::string weightStr = weightValue->Get<std::string>();
134 Scripting::GetEnumeration< FontWeight >( weightStr.c_str(),
135 FONT_WEIGHT_STRING_TABLE,
136 FONT_WEIGHT_STRING_TABLE_COUNT,
141 Property::Value* widthValue = map.Find( WIDTH_KEY );
143 FontWidth width = TextAbstraction::FontWidth::NONE;
144 const bool widthDefined = widthValue != NULL;
147 const std::string widthStr = widthValue->Get<std::string>();
149 Scripting::GetEnumeration< FontWidth >( widthStr.c_str(),
150 FONT_WIDTH_STRING_TABLE,
151 FONT_WIDTH_STRING_TABLE_COUNT,
156 Property::Value* slantValue = map.Find( SLANT_KEY );
158 FontSlant slant = TextAbstraction::FontSlant::NONE;
159 const bool slantDefined = slantValue != NULL;
162 const std::string slantStr = slantValue->Get<std::string>();
164 Scripting::GetEnumeration< FontSlant >( slantStr.c_str(),
165 FONT_SLANT_STRING_TABLE,
166 FONT_SLANT_STRING_TABLE_COUNT,
172 case FontStyle::DEFAULT:
174 // Sets the default font's style values.
175 if( !weightDefined ||
176 ( weightDefined && ( controller->GetDefaultFontWeight() != weight ) ) )
178 controller->SetDefaultFontWeight( weight );
182 ( widthDefined && ( controller->GetDefaultFontWidth() != width ) ) )
184 controller->SetDefaultFontWidth( width );
188 ( slantDefined && ( controller->GetDefaultFontSlant() != slant ) ) )
190 controller->SetDefaultFontSlant( slant );
194 case FontStyle::INPUT:
196 // Sets the input font's style values.
197 if( !weightDefined ||
198 ( weightDefined && ( controller->GetInputFontWeight() != weight ) ) )
200 controller->SetInputFontWeight( weight );
204 ( widthDefined && ( controller->GetInputFontWidth() != width ) ) )
206 controller->SetInputFontWidth( width );
210 ( slantDefined && ( controller->GetInputFontSlant() != slant ) ) )
212 controller->SetInputFontSlant( slant );
222 case FontStyle::DEFAULT:
224 controller->SetDefaultFontWeight( TextAbstraction::FontWeight::NONE );
225 controller->SetDefaultFontWidth( TextAbstraction::FontWidth::NONE );
226 controller->SetDefaultFontSlant( TextAbstraction::FontSlant::NONE );
229 case FontStyle::INPUT:
231 controller->SetInputFontWeight( TextAbstraction::FontWeight::NONE );
232 controller->SetInputFontWidth( TextAbstraction::FontWidth::NONE );
233 controller->SetInputFontSlant( TextAbstraction::FontSlant::NONE );
241 void GetFontStyleProperty( ControllerPtr controller, Property::Value& value, FontStyle::Type type )
245 const bool isDefaultStyle = FontStyle::DEFAULT == type;
247 bool weightDefined = false;
248 bool widthDefined = false;
249 bool slantDefined = false;
250 FontWeight weight = TextAbstraction::FontWeight::NONE;
251 FontWidth width = TextAbstraction::FontWidth::NONE;
252 FontSlant slant = TextAbstraction::FontSlant::NONE;
256 weightDefined = controller->IsDefaultFontWeightDefined();
257 widthDefined = controller->IsDefaultFontWidthDefined();
258 slantDefined = controller->IsDefaultFontSlantDefined();
262 weight = controller->GetDefaultFontWeight();
267 width = controller->GetDefaultFontWidth();
272 slant = controller->GetDefaultFontSlant();
277 weightDefined = controller->IsInputFontWeightDefined();
278 widthDefined = controller->IsInputFontWidthDefined();
279 slantDefined = controller->IsInputFontSlantDefined();
283 weight = controller->GetInputFontWeight();
288 width = controller->GetInputFontWidth();
293 slant = controller->GetInputFontSlant();
301 if( TextAbstraction::FontWeight::NONE != weight )
303 const std::string weightStr( GetEnumerationName( weight,
304 FONT_WEIGHT_STRING_TABLE,
305 FONT_WEIGHT_STRING_TABLE_COUNT ) );
307 map.Insert( WEIGHT_KEY, weightStr );
313 if( TextAbstraction::FontWidth::NONE != width )
315 const std::string widthStr( GetEnumerationName( width,
316 FONT_WIDTH_STRING_TABLE,
317 FONT_WIDTH_STRING_TABLE_COUNT ) );
319 map.Insert( WIDTH_KEY, widthStr );
325 if( TextAbstraction::FontSlant::NONE != slant )
327 const std::string slantStr( GetEnumerationName( slant,
328 FONT_SLANT_STRING_TABLE,
329 FONT_SLANT_STRING_TABLE_COUNT ) );
331 map.Insert( SLANT_KEY, slantStr );
339 FontWeight StringToWeight( const char* const weightStr )
341 FontWeight weight = TextAbstraction::FontWeight::NORMAL;
342 Scripting::GetEnumeration<FontWeight>( weightStr,
343 FONT_WEIGHT_STRING_TABLE,
344 FONT_WEIGHT_STRING_TABLE_COUNT,
350 FontWidth StringToWidth( const char* const widthStr )
352 FontWidth width = TextAbstraction::FontWidth::NORMAL;
353 Scripting::GetEnumeration<FontWidth>( widthStr,
354 FONT_WIDTH_STRING_TABLE,
355 FONT_WIDTH_STRING_TABLE_COUNT,
361 FontSlant StringToSlant( const char* const slantStr )
363 FontSlant slant = TextAbstraction::FontSlant::NORMAL;
364 Scripting::GetEnumeration<FontSlant>( slantStr,
365 FONT_SLANT_STRING_TABLE,
366 FONT_SLANT_STRING_TABLE_COUNT,
374 } // namespace Toolkit