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 );
117 case EffectStyle::INPUT:
119 // Sets the input underline values.
120 // TODO: to be implemented.
127 // Disable underline.
128 if( controller->IsUnderlineEnabled() )
130 controller->SetUnderlineEnabled( false );
139 void GetUnderlineProperties( ControllerPtr controller, Property::Value& value, EffectStyle::Type type )
145 case EffectStyle::DEFAULT:
147 value = controller->GetDefaultUnderlineProperties();
150 case EffectStyle::INPUT:
152 value = controller->GetInputUnderlineProperties();
159 bool SetShadowProperties( ControllerPtr controller, const Property::Value& value, EffectStyle::Type type )
165 const std::string properties = value.Get< std::string >();
169 case EffectStyle::DEFAULT:
171 // Stores the default shadow's properties string to be recovered by the GetShadowProperties() function.
172 controller->SetDefaultShadowProperties( properties );
175 case EffectStyle::INPUT:
177 // Stores the input shadow's properties string to be recovered by the GetShadowProperties() function.
178 controller->SetInputShadowProperties( properties );
183 // Parses and applies the style.
185 ParsePropertyString( properties, map );
190 Property::Value* colorValue = map.Find( COLOR_KEY );
193 const bool colorDefined = colorValue != NULL;
196 const std::string colorStr = colorValue->Get<std::string>();
198 ColorStringToVector4( colorStr.c_str(), colorStr.size(), color );
202 Property::Value* offsetValue = map.Find( OFFSET_KEY );
205 const bool offsetDefined = offsetValue != NULL;
208 const std::string offsetStr = offsetValue->Get<std::string>();
210 StringOffsetToVector2( offsetStr, offset );
215 case EffectStyle::DEFAULT:
217 // Sets the default shadow values.
218 if( colorDefined && ( controller->GetShadowColor() != color ) )
220 controller->SetShadowColor( color );
224 if( offsetDefined && ( controller->GetShadowOffset() != offset ) )
226 controller->SetShadowOffset( offset );
230 case EffectStyle::INPUT:
232 // Sets the input shadow values.
233 // TODO: to be implemented.
243 void GetShadowProperties( ControllerPtr controller, Property::Value& value, EffectStyle::Type type )
249 case EffectStyle::DEFAULT:
251 value = controller->GetDefaultShadowProperties();
254 case EffectStyle::INPUT:
256 value = controller->GetInputShadowProperties();
263 bool SetEmbossProperties( ControllerPtr controller, const Property::Value& value, EffectStyle::Type type )
269 const std::string properties = value.Get< std::string >();
273 case EffectStyle::DEFAULT:
275 // Stores the default emboss's properties string to be recovered by the GetEmbossProperties() function.
276 controller->SetDefaultEmbossProperties( properties );
279 case EffectStyle::INPUT:
281 // Stores the input emboss's properties string to be recovered by the GetEmbossProperties() function.
282 controller->SetInputEmbossProperties( properties );
291 void GetEmbossProperties( ControllerPtr controller, Property::Value& value, EffectStyle::Type type )
297 case EffectStyle::DEFAULT:
299 value = controller->GetDefaultEmbossProperties();
302 case EffectStyle::INPUT:
304 value = controller->GetInputEmbossProperties();
311 bool SetOutlineProperties( 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 outline's properties string to be recovered by the GetOutlineProperties() function.
324 controller->SetDefaultOutlineProperties( properties );
327 case EffectStyle::INPUT:
329 // Stores the input outline's properties string to be recovered by the GetOutlineProperties() function.
330 controller->SetInputOutlineProperties( properties );
339 void GetOutlineProperties( ControllerPtr controller, Property::Value& value, EffectStyle::Type type )
345 case EffectStyle::DEFAULT:
347 value = controller->GetDefaultOutlineProperties();
350 case EffectStyle::INPUT:
352 value = controller->GetInputOutlineProperties();
361 } // namespace Toolkit