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-effects-style.h>
22 #include <dali-toolkit/internal/text/markup-processor-helper-functions.h>
23 #include <dali-toolkit/internal/text/property-string-parser.h>
36 const std::string COLOR_KEY( "color" );
37 const std::string OFFSET_KEY( "offset" );
38 const std::string HEIGHT_KEY( "height" );
39 const std::string ENABLE_KEY( "enable" );
40 const std::string TRUE_TOKEN( "true" );
41 const std::string FALSE_TOKEN( "false" );
44 bool ParseShadowProperties( const Property::Map& shadowPropertiesMap,
50 const unsigned int numberOfItems = shadowPropertiesMap.Count();
52 // Parses and applies the style.
53 for( unsigned int index = 0u; index < numberOfItems; ++index )
55 const KeyValuePair& valueGet = shadowPropertiesMap.GetKeyValue( index );
57 if( COLOR_KEY == valueGet.first.stringKey )
62 const std::string colorStr = valueGet.second.Get<std::string>();
64 Text::ColorStringToVector4( colorStr.c_str(), colorStr.size(), color );
66 else if( OFFSET_KEY == valueGet.first.stringKey )
71 const std::string offsetStr = valueGet.second.Get<std::string>();
73 StringToVector2( offsetStr.c_str(), offsetStr.size(), offset );
77 return 0u == numberOfItems;
80 bool ParseUnderlineProperties( const Property::Map& underlinePropertiesMap,
87 const unsigned int numberOfItems = underlinePropertiesMap.Count();
89 // Parses and applies the style.
90 for( unsigned int index = 0u; index < numberOfItems; ++index )
92 const KeyValuePair& valueGet = underlinePropertiesMap.GetKeyValue( index );
94 if( ENABLE_KEY == valueGet.first.stringKey )
97 const std::string enableStr = valueGet.second.Get<std::string>();
98 enabled = Text::TokenComparison( TRUE_TOKEN, enableStr.c_str(), enableStr.size() );
100 else if( COLOR_KEY == valueGet.first.stringKey )
105 const std::string colorStr = valueGet.second.Get<std::string>();
107 Text::ColorStringToVector4( colorStr.c_str(), colorStr.size(), color );
109 else if( HEIGHT_KEY == valueGet.first.stringKey )
112 heightDefined = true;
114 const std::string heightStr = valueGet.second.Get<std::string>();
116 height = StringToFloat( heightStr.c_str() );
120 return 0u == numberOfItems;
123 bool SetUnderlineProperties( ControllerPtr controller, const Property::Value& value, EffectStyle::Type type )
131 case EffectStyle::DEFAULT:
133 const Property::Map& propertiesMap = value.Get<Property::Map>();
135 bool enabled = false;
136 bool colorDefined = false;
138 bool heightDefined = false;
141 const bool empty = ParseUnderlineProperties( propertiesMap,
150 if( enabled != controller->IsUnderlineEnabled() )
152 controller->SetUnderlineEnabled( enabled );
156 // Sets the default underline values.
157 if( colorDefined && ( controller->GetUnderlineColor() != color ) )
159 controller->SetUnderlineColor( color );
163 if( heightDefined && ( fabsf( controller->GetUnderlineHeight() - height ) > Math::MACHINE_EPSILON_1000 ) )
165 controller->SetUnderlineHeight( height );
171 // Disable underline.
172 if( controller->IsUnderlineEnabled() )
174 controller->SetUnderlineEnabled( false );
180 case EffectStyle::INPUT:
182 const std::string& underlineProperties = value.Get<std::string>();
184 controller->SetInputUnderlineProperties( underlineProperties );
188 } // if( controller )
193 void GetUnderlineProperties( ControllerPtr controller, Property::Value& value, EffectStyle::Type type )
199 case EffectStyle::DEFAULT:
201 const bool enabled = controller->IsUnderlineEnabled();
202 const Vector4& color = controller->GetUnderlineColor();
203 const float height = controller->GetUnderlineHeight();
207 const std::string enabledStr = enabled ? TRUE_TOKEN : FALSE_TOKEN;
208 map.Insert( ENABLE_KEY, enabledStr );
210 std::string colorStr;
211 Vector4ToColorString( color, colorStr );
212 map.Insert( COLOR_KEY, colorStr );
214 std::string heightStr;
215 FloatToString( height, heightStr );
216 map.Insert( HEIGHT_KEY, heightStr );
221 case EffectStyle::INPUT:
223 value = controller->GetInputUnderlineProperties();
230 bool SetShadowProperties( ControllerPtr controller, const Property::Value& value, EffectStyle::Type type )
238 case EffectStyle::DEFAULT:
240 const Property::Map& propertiesMap = value.Get<Property::Map>();
242 bool colorDefined = false;
244 bool offsetDefined = false;
247 const bool empty = ParseShadowProperties( propertiesMap,
255 // Sets the default shadow values.
256 if( colorDefined && ( controller->GetShadowColor() != color ) )
258 controller->SetShadowColor( color );
262 if( offsetDefined && ( controller->GetShadowOffset() != offset ) )
264 controller->SetShadowOffset( offset );
271 if( Vector2::ZERO != controller->GetShadowOffset() )
273 controller->SetShadowOffset( Vector2::ZERO );
278 case EffectStyle::INPUT:
280 const std::string& shadowString = value.Get<std::string>();
282 controller->SetInputShadowProperties( shadowString );
286 } // if( controller )
291 void GetShadowProperties( ControllerPtr controller, Property::Value& value, EffectStyle::Type type )
297 case EffectStyle::DEFAULT:
299 const Vector4& color = controller->GetShadowColor();
300 const Vector2& offset = controller->GetShadowOffset();
304 std::string colorStr;
305 Vector4ToColorString( color, colorStr );
306 map.Insert( COLOR_KEY, colorStr );
308 std::string offsetStr;
309 Vector2ToString( offset, offsetStr );
310 map.Insert( OFFSET_KEY, offsetStr );
315 case EffectStyle::INPUT:
317 value = controller->GetInputShadowProperties();
324 bool SetEmbossProperties( ControllerPtr controller, const Property::Value& value, EffectStyle::Type type )
330 const std::string properties = value.Get< std::string >();
334 case EffectStyle::DEFAULT:
336 // Stores the default emboss's properties string to be recovered by the GetEmbossProperties() function.
337 controller->SetDefaultEmbossProperties( properties );
340 case EffectStyle::INPUT:
342 // Stores the input emboss's properties string to be recovered by the GetEmbossProperties() function.
343 controller->SetInputEmbossProperties( properties );
352 void GetEmbossProperties( ControllerPtr controller, Property::Value& value, EffectStyle::Type type )
358 case EffectStyle::DEFAULT:
360 value = controller->GetDefaultEmbossProperties();
363 case EffectStyle::INPUT:
365 value = controller->GetInputEmbossProperties();
372 bool SetOutlineProperties( ControllerPtr controller, const Property::Value& value, EffectStyle::Type type )
378 const std::string properties = value.Get< std::string >();
382 case EffectStyle::DEFAULT:
384 // Stores the default outline's properties string to be recovered by the GetOutlineProperties() function.
385 controller->SetDefaultOutlineProperties( properties );
388 case EffectStyle::INPUT:
390 // Stores the input outline's properties string to be recovered by the GetOutlineProperties() function.
391 controller->SetInputOutlineProperties( properties );
400 void GetOutlineProperties( ControllerPtr controller, Property::Value& value, EffectStyle::Type type )
406 case EffectStyle::DEFAULT:
408 value = controller->GetDefaultOutlineProperties();
411 case EffectStyle::INPUT:
413 value = controller->GetInputOutlineProperties();
422 } // namespace Toolkit