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" );
43 bool SetUnderlineProperties( ControllerPtr controller, const Property::Value& value, EffectStyle::Type type )
49 const std::string properties = value.Get<std::string>();
51 // Parses and applies the style.
53 ParsePropertyString( properties, map );
58 Property::Value* enableValue = map.Find( ENABLE_KEY );
61 const bool enabledDefined = enableValue != NULL;
64 const std::string enableStr = enableValue->Get<std::string>();
65 enabled = TokenComparison( TRUE_TOKEN, enableStr.c_str(), enableStr.size() );
69 Property::Value* colorValue = map.Find( COLOR_KEY );
72 const bool colorDefined = colorValue != NULL;
75 const std::string colorStr = colorValue->Get<std::string>();
77 ColorStringToVector4( colorStr.c_str(), colorStr.size(), color );
81 Property::Value* heightValue = map.Find( HEIGHT_KEY );
84 const bool heightDefined = heightValue != NULL;
87 const std::string heightStr = heightValue->Get<std::string>();
89 height = StringToFloat( heightStr.c_str() );
94 case EffectStyle::DEFAULT:
96 if( enabled != controller->IsUnderlineEnabled() )
98 controller->SetUnderlineEnabled( enabled );
101 // Sets the default underline values.
102 if( colorDefined && ( controller->GetUnderlineColor() != color ) )
104 controller->SetUnderlineColor( color );
108 if( heightDefined && fabsf( controller->GetUnderlineHeight() - height ) > Math::MACHINE_EPSILON_1000 )
110 controller->SetUnderlineHeight( height );
115 case EffectStyle::INPUT:
117 // Sets the input underline values.
118 // TODO: to be implemented.
127 case EffectStyle::DEFAULT:
129 // Disable underline.
130 if( controller->IsUnderlineEnabled() )
132 controller->SetUnderlineEnabled( false );
137 case EffectStyle::INPUT:
139 // Sets the input underline values.
140 // TODO: to be implemented.
141 controller->SetInputUnderlineProperties( properties );
151 void GetUnderlineProperties( ControllerPtr controller, Property::Value& value, EffectStyle::Type type )
157 case EffectStyle::DEFAULT:
159 const bool enabled = controller->IsUnderlineEnabled();
160 const Vector4& color = controller->GetUnderlineColor();
161 const float height = controller->GetUnderlineHeight();
163 std::string underlineProperties = "{\"enable\":";
164 const std::string enabledStr = enabled ? "true" : "false";
165 underlineProperties += "\"" + enabledStr + "\",";
167 std::string colorStr;
168 Vector4ToColorString( color, colorStr );
169 underlineProperties += "\"color\":\"" + colorStr + "\",";
171 std::string heightStr;
172 FloatToString( height, heightStr );
173 underlineProperties += "\"height\":\"" + heightStr + "\"}";
175 value = underlineProperties;
178 case EffectStyle::INPUT:
180 value = controller->GetInputUnderlineProperties();
187 bool SetShadowProperties( ControllerPtr controller, const Property::Value& value, EffectStyle::Type type )
193 const std::string properties = value.Get< std::string >();
195 // Parses and applies the style.
197 ParsePropertyString( properties, map );
202 Property::Value* colorValue = map.Find( COLOR_KEY );
205 const bool colorDefined = colorValue != NULL;
208 const std::string colorStr = colorValue->Get<std::string>();
210 ColorStringToVector4( colorStr.c_str(), colorStr.size(), color );
214 Property::Value* offsetValue = map.Find( OFFSET_KEY );
217 const bool offsetDefined = offsetValue != NULL;
220 const std::string offsetStr = offsetValue->Get<std::string>();
222 StringToVector2( offsetStr.c_str(), offsetStr.size(), offset );
227 case EffectStyle::DEFAULT:
229 // Sets the default shadow values.
230 if( colorDefined && ( controller->GetShadowColor() != color ) )
232 controller->SetShadowColor( color );
236 if( offsetDefined && ( controller->GetShadowOffset() != offset ) )
238 controller->SetShadowOffset( offset );
243 case EffectStyle::INPUT:
245 // Sets the input shadow values.
246 // TODO: to be implemented.
255 case EffectStyle::DEFAULT:
258 if( Vector2::ZERO != controller->GetShadowOffset() )
260 controller->SetShadowOffset( Vector2::ZERO );
264 case EffectStyle::INPUT:
266 // Sets the input shadow values.
267 // TODO: to be implemented.
268 controller->SetInputShadowProperties( properties );
278 void GetShadowProperties( ControllerPtr controller, Property::Value& value, EffectStyle::Type type )
284 case EffectStyle::DEFAULT:
286 const Vector4& color = controller->GetShadowColor();
287 const Vector2& offset = controller->GetShadowOffset();
289 std::string shadowProperties = "{";
291 std::string colorStr;
292 Vector4ToColorString( color, colorStr );
293 shadowProperties += "\"color\":\"" + colorStr + "\",";
295 std::string offsetStr;
296 Vector2ToString( offset, offsetStr );
297 shadowProperties += "\"offset\":\"" + offsetStr + "\"}";
299 value = shadowProperties;
302 case EffectStyle::INPUT:
304 value = controller->GetInputShadowProperties();
311 bool SetEmbossProperties( ControllerPtr controller, const Property::Value& value, EffectStyle::Type type )
317 const std::string properties = value.Get< std::string >();
321 case EffectStyle::DEFAULT:
323 // Stores the default emboss's properties string to be recovered by the GetEmbossProperties() function.
324 controller->SetDefaultEmbossProperties( properties );
327 case EffectStyle::INPUT:
329 // Stores the input emboss's properties string to be recovered by the GetEmbossProperties() function.
330 controller->SetInputEmbossProperties( properties );
339 void GetEmbossProperties( ControllerPtr controller, Property::Value& value, EffectStyle::Type type )
345 case EffectStyle::DEFAULT:
347 value = controller->GetDefaultEmbossProperties();
350 case EffectStyle::INPUT:
352 value = controller->GetInputEmbossProperties();
359 bool SetOutlineProperties( ControllerPtr controller, const Property::Value& value, EffectStyle::Type type )
365 const std::string properties = value.Get< std::string >();
369 case EffectStyle::DEFAULT:
371 // Stores the default outline's properties string to be recovered by the GetOutlineProperties() function.
372 controller->SetDefaultOutlineProperties( properties );
375 case EffectStyle::INPUT:
377 // Stores the input outline's properties string to be recovered by the GetOutlineProperties() function.
378 controller->SetInputOutlineProperties( properties );
387 void GetOutlineProperties( ControllerPtr controller, Property::Value& value, EffectStyle::Type type )
393 case EffectStyle::DEFAULT:
395 value = controller->GetDefaultOutlineProperties();
398 case EffectStyle::INPUT:
400 value = controller->GetInputOutlineProperties();
409 } // namespace Toolkit