2 * Copyright (c) 2015 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 "text-actor-api.h"
22 #include <dali/public-api/text/text-actor-parameters.h>
25 #include <object/handle-wrapper.h>
27 #include <object/property-value-wrapper.h>
28 #include <text/font-api.h>
37 namespace //unnamed name space
40 struct TextActorParametersInternal
42 TextActorParametersInternal()
43 : fontDetection( true )
51 TextActor GetTextActor( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
53 HandleWrapper* handleWrapper = HandleWrapper::Unwrap( isolate, args.This() );
54 return TextActor::DownCast( handleWrapper->mHandle );
58 void GetTextOptions( v8::Isolate* isolate,
59 v8::Local<v8::Value > options,
60 TextActorParametersInternal& textParams )
62 // fontDetection: true / false ( default true)
63 // font: dali font object
64 v8::HandleScope handleScope( isolate );
66 if( options->IsObject() )
68 v8::Local<v8::Object> obj = options->ToObject();
70 v8::Local<v8::Value> fontDetect = obj->Get( v8::String::NewFromUtf8( isolate, "fontDetection" ) );
71 if( fontDetect->IsBoolean() )
74 textParams.fontDetection = fontDetect->ToBoolean()->Value();
77 v8::Local<v8::Value> fontValue = obj->Get( v8::String::NewFromUtf8( isolate, "font" ) );
78 if( fontValue->IsObject() )
80 textParams.font = FontApi::GetFont( isolate, fontValue );
92 * @param {String} text
93 * @param {Object} [textOptions] data
94 * Options text options struct
95 * @param {Boolean} [textOptions.fontDetection]
96 * if true the fontDetection is used to make sure the text is displayed.
97 * E.g. if the current font used by the text-actor does not support certain characters
98 * it will find a new font that does. Default = true.
99 * @param {Object} [textOptions.font]
101 * @return {Object} TextActor
103 Actor TextActorApi::New( const v8::FunctionCallbackInfo<v8::Value>& args )
105 v8::Isolate* isolate = args.GetIsolate();
106 v8::HandleScope handleScope( isolate );
109 // TextActor( text, options (optional) )
114 // fontDetection: true / false ( default true)
117 // get the text (if passed in)
120 std::string text = V8Utils::GetStringParameter( PARAMETER_0, found, isolate, args );
122 TextActorParametersInternal params;
125 GetTextOptions( isolate, args[1], params );
131 style.SetFontName( params.font.GetName() );
132 style.SetFontStyle( params.font.GetStyle() );
133 style.SetFontPointSize( PointSize(params.font.GetPointSize()));
136 TextActorParameters textActorParameters( style, params.fontDetection? TextActorParameters::FONT_DETECTION_OFF:TextActorParameters::FONT_DETECTION_ON );
138 actor = TextActor::New( text, textActorParameters );
145 * Set text to the natural size of the text string.
147 * After this method the text actor always uses the natural size of the text
148 * when SetText is called unless SetSize is called to override the size.
151 * @method setToNaturalSize
153 void TextActorApi::SetToNaturalSize( const v8::FunctionCallbackInfo<v8::Value>& args )
155 v8::Isolate* isolate = args.GetIsolate();
156 v8::HandleScope handleScope( isolate );
158 TextActor textActor = GetTextActor( isolate, args );
159 textActor.SetToNaturalSize();
162 } // namespace V8Plugin