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() );
56 // Parses and applies the style.
58 ParsePropertyString( style, map );
63 Property::Value* weightValue = map.Find( WEIGHT_KEY );
65 FontWeight weight = TextAbstraction::FontWeight::NONE;
66 const bool weightDefined = weightValue != NULL;
69 const std::string weightStr = weightValue->Get<std::string>();
71 Scripting::GetEnumeration< FontWeight >( weightStr.c_str(),
72 FONT_WEIGHT_STRING_TABLE,
73 FONT_WEIGHT_STRING_TABLE_COUNT,
78 Property::Value* widthValue = map.Find( WIDTH_KEY );
80 FontWidth width = TextAbstraction::FontWidth::NONE;
81 const bool widthDefined = widthValue != NULL;
84 const std::string widthStr = widthValue->Get<std::string>();
86 Scripting::GetEnumeration< FontWidth >( widthStr.c_str(),
87 FONT_WIDTH_STRING_TABLE,
88 FONT_WIDTH_STRING_TABLE_COUNT,
93 Property::Value* slantValue = map.Find( SLANT_KEY );
95 FontSlant slant = TextAbstraction::FontSlant::NONE;
96 const bool slantDefined = slantValue != NULL;
99 const std::string slantStr = slantValue->Get<std::string>();
101 Scripting::GetEnumeration< FontSlant >( slantStr.c_str(),
102 FONT_SLANT_STRING_TABLE,
103 FONT_SLANT_STRING_TABLE_COUNT,
109 case FontStyle::DEFAULT:
111 // Sets the default font's style values.
112 if( !weightDefined ||
113 ( weightDefined && ( controller->GetDefaultFontWeight() != weight ) ) )
115 controller->SetDefaultFontWeight( weight );
119 ( widthDefined && ( controller->GetDefaultFontWidth() != width ) ) )
121 controller->SetDefaultFontWidth( width );
125 ( slantDefined && ( controller->GetDefaultFontSlant() != slant ) ) )
127 controller->SetDefaultFontSlant( slant );
131 case FontStyle::INPUT:
133 // Sets the input font's style values.
134 if( !weightDefined ||
135 ( weightDefined && ( controller->GetInputFontWeight() != weight ) ) )
137 controller->SetInputFontWeight( weight );
141 ( widthDefined && ( controller->GetInputFontWidth() != width ) ) )
143 controller->SetInputFontWidth( width );
147 ( slantDefined && ( controller->GetInputFontSlant() != slant ) ) )
149 controller->SetInputFontSlant( slant );
159 case FontStyle::DEFAULT:
161 controller->SetDefaultFontWeight( TextAbstraction::FontWeight::NONE );
162 controller->SetDefaultFontWidth( TextAbstraction::FontWidth::NONE );
163 controller->SetDefaultFontSlant( TextAbstraction::FontSlant::NONE );
166 case FontStyle::INPUT:
168 controller->SetInputFontWeight( TextAbstraction::FontWeight::NONE );
169 controller->SetInputFontWidth( TextAbstraction::FontWidth::NONE );
170 controller->SetInputFontSlant( TextAbstraction::FontSlant::NONE );
178 void GetFontStyleProperty( ControllerPtr controller, Property::Value& value, FontStyle::Type type )
182 const bool isDefaultStyle = FontStyle::DEFAULT == type;
184 bool weightDefined = false;
185 bool widthDefined = false;
186 bool slantDefined = false;
187 FontWeight weight = TextAbstraction::FontWeight::NONE;
188 FontWidth width = TextAbstraction::FontWidth::NONE;
189 FontSlant slant = TextAbstraction::FontSlant::NONE;
193 weightDefined = controller->IsDefaultFontWeightDefined();
194 widthDefined = controller->IsDefaultFontWidthDefined();
195 slantDefined = controller->IsDefaultFontSlantDefined();
199 weight = controller->GetDefaultFontWeight();
204 width = controller->GetDefaultFontWidth();
209 slant = controller->GetDefaultFontSlant();
214 weightDefined = controller->IsInputFontWeightDefined();
215 widthDefined = controller->IsInputFontWidthDefined();
216 slantDefined = controller->IsInputFontSlantDefined();
220 weight = controller->GetInputFontWeight();
225 width = controller->GetInputFontWidth();
230 slant = controller->GetInputFontSlant();
234 if( weightDefined || widthDefined || slantDefined )
236 std::string styleString("{");
239 if( TextAbstraction::FontWeight::NONE != weight )
241 const std::string weightStr( GetEnumerationName( weight,
242 FONT_WEIGHT_STRING_TABLE,
243 FONT_WEIGHT_STRING_TABLE_COUNT ) );
245 styleString += "\"weight\":\"" + weightStr + "\"";
249 weightDefined = false;
255 if( TextAbstraction::FontWidth::NONE != width )
257 const std::string widthStr( GetEnumerationName( width,
258 FONT_WIDTH_STRING_TABLE,
259 FONT_WIDTH_STRING_TABLE_COUNT ) );
265 styleString += "\"width\":\"" + widthStr + "\"";
269 widthDefined = false;
275 if( TextAbstraction::FontSlant::NONE != slant )
277 const std::string slantStr( GetEnumerationName( slant,
278 FONT_SLANT_STRING_TABLE,
279 FONT_SLANT_STRING_TABLE_COUNT ) );
281 if( weightDefined || widthDefined )
285 styleString += "\"slant\":\"" + slantStr + "\"";
289 slantDefined = false;
293 if( weightDefined || widthDefined || slantDefined )
307 FontWeight StringToWeight( const char* const weightStr )
309 FontWeight weight = TextAbstraction::FontWeight::NORMAL;
310 Scripting::GetEnumeration<FontWeight>( weightStr,
311 FONT_WEIGHT_STRING_TABLE,
312 FONT_WEIGHT_STRING_TABLE_COUNT,
318 FontWidth StringToWidth( const char* const widthStr )
320 FontWidth width = TextAbstraction::FontWidth::NORMAL;
321 Scripting::GetEnumeration<FontWidth>( widthStr,
322 FONT_WIDTH_STRING_TABLE,
323 FONT_WIDTH_STRING_TABLE_COUNT,
329 FontSlant StringToSlant( const char* const slantStr )
331 FontSlant slant = TextAbstraction::FontSlant::NORMAL;
332 Scripting::GetEnumeration<FontSlant>( slantStr,
333 FONT_SLANT_STRING_TABLE,
334 FONT_SLANT_STRING_TABLE_COUNT,
342 } // namespace Toolkit