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 THICKNESS_KEY( "thickness" );
41 bool SetUnderlineProperties( ControllerPtr controller, const Property::Value& value, EffectStyle::Type type )
47 const std::string properties = value.Get< std::string >();
51 case EffectStyle::DEFAULT:
53 // Stores the default underline's properties string to be recovered by the GetUnderlineProperties() function.
54 controller->SetDefaultUnderlineProperties( properties );
57 case EffectStyle::INPUT:
59 // Stores the input underline's properties string to be recovered by the GetUnderlineProperties() function.
60 controller->SetInputUnderlineProperties( properties );
65 // Parses and applies the style.
67 ParsePropertyString( properties, map );
72 Property::Value* colorValue = map.Find( COLOR_KEY );
75 const bool colorDefined = colorValue != NULL;
78 const std::string colorStr = colorValue->Get<std::string>();
80 ColorStringToVector4( colorStr.c_str(), colorStr.size(), color );
84 Property::Value* thicknessValue = map.Find( THICKNESS_KEY );
86 float thickness = 0.f;
87 const bool thicknessDefined = thicknessValue != NULL;
88 if( thicknessDefined )
90 const std::string thicknessStr = thicknessValue->Get<std::string>();
92 thickness = StringToFloat( thicknessStr.c_str() );
97 case EffectStyle::DEFAULT:
99 if( !controller->IsUnderlineEnabled() )
101 controller->SetUnderlineEnabled( true );
104 // Sets the default underline values.
105 if( colorDefined && ( controller->GetUnderlineColor() != color ) )
107 controller->SetUnderlineColor( color );
111 if( thicknessDefined && fabsf( controller->GetUnderlineHeight() - thickness ) > Math::MACHINE_EPSILON_1000 )
113 controller->SetUnderlineHeight( thickness );
118 case EffectStyle::INPUT:
120 // Sets the input underline values.
121 // TODO: to be implemented.
128 // Disable underline.
129 if( controller->IsUnderlineEnabled() )
131 controller->SetUnderlineEnabled( false );
140 void GetUnderlineProperties( ControllerPtr controller, Property::Value& value, EffectStyle::Type type )
146 case EffectStyle::DEFAULT:
148 value = controller->GetDefaultUnderlineProperties();
151 case EffectStyle::INPUT:
153 value = controller->GetInputUnderlineProperties();
160 bool SetShadowProperties( ControllerPtr controller, const Property::Value& value, EffectStyle::Type type )
166 const std::string properties = value.Get< std::string >();
170 case EffectStyle::DEFAULT:
172 // Stores the default shadow's properties string to be recovered by the GetShadowProperties() function.
173 controller->SetDefaultShadowProperties( properties );
176 case EffectStyle::INPUT:
178 // Stores the input shadow's properties string to be recovered by the GetShadowProperties() function.
179 controller->SetInputShadowProperties( properties );
184 // Parses and applies the style.
186 ParsePropertyString( properties, map );
191 Property::Value* colorValue = map.Find( COLOR_KEY );
194 const bool colorDefined = colorValue != NULL;
197 const std::string colorStr = colorValue->Get<std::string>();
199 ColorStringToVector4( colorStr.c_str(), colorStr.size(), color );
203 Property::Value* offsetValue = map.Find( OFFSET_KEY );
206 const bool offsetDefined = offsetValue != NULL;
209 const std::string offsetStr = offsetValue->Get<std::string>();
211 StringOffsetToVector2( offsetStr, offset );
216 case EffectStyle::DEFAULT:
218 // Sets the default shadow values.
219 if( colorDefined && ( controller->GetShadowColor() != color ) )
221 controller->SetShadowColor( color );
225 if( offsetDefined && ( controller->GetShadowOffset() != offset ) )
227 controller->SetShadowOffset( offset );
232 case EffectStyle::INPUT:
234 // Sets the input shadow values.
235 // TODO: to be implemented.
245 void GetShadowProperties( ControllerPtr controller, Property::Value& value, EffectStyle::Type type )
251 case EffectStyle::DEFAULT:
253 value = controller->GetDefaultShadowProperties();
256 case EffectStyle::INPUT:
258 value = controller->GetInputShadowProperties();
265 bool SetEmbossProperties( ControllerPtr controller, const Property::Value& value, EffectStyle::Type type )
271 const std::string properties = value.Get< std::string >();
275 case EffectStyle::DEFAULT:
277 // Stores the default emboss's properties string to be recovered by the GetEmbossProperties() function.
278 controller->SetDefaultEmbossProperties( properties );
281 case EffectStyle::INPUT:
283 // Stores the input emboss's properties string to be recovered by the GetEmbossProperties() function.
284 controller->SetInputEmbossProperties( properties );
293 void GetEmbossProperties( ControllerPtr controller, Property::Value& value, EffectStyle::Type type )
299 case EffectStyle::DEFAULT:
301 value = controller->GetDefaultEmbossProperties();
304 case EffectStyle::INPUT:
306 value = controller->GetInputEmbossProperties();
313 bool SetOutlineProperties( ControllerPtr controller, const Property::Value& value, EffectStyle::Type type )
319 const std::string properties = value.Get< std::string >();
323 case EffectStyle::DEFAULT:
325 // Stores the default outline's properties string to be recovered by the GetOutlineProperties() function.
326 controller->SetDefaultOutlineProperties( properties );
329 case EffectStyle::INPUT:
331 // Stores the input outline's properties string to be recovered by the GetOutlineProperties() function.
332 controller->SetInputOutlineProperties( properties );
341 void GetOutlineProperties( ControllerPtr controller, Property::Value& value, EffectStyle::Type type )
347 case EffectStyle::DEFAULT:
349 value = controller->GetDefaultOutlineProperties();
352 case EffectStyle::INPUT:
354 value = controller->GetInputOutlineProperties();
363 } // namespace Toolkit