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 <dali-toolkit/public-api/text/text-controller.h>
22 #include <dali/public-api/text-abstraction/font-client.h>
25 #include <dali-toolkit/public-api/text/character-set-conversion.h>
26 #include <dali-toolkit/public-api/text/layouts/layout-engine.h>
27 #include <dali-toolkit/public-api/text/logical-model.h>
28 #include <dali-toolkit/public-api/text/multi-language-support.h>
29 #include <dali-toolkit/public-api/text/script-run.h>
30 #include <dali-toolkit/public-api/text/text-view.h>
31 #include <dali-toolkit/public-api/text/visual-model.h>
42 struct Controller::Impl
45 : mNewTextArrived( false )
47 mLogicalModel = LogicalModel::New();
48 mVisualModel = VisualModel::New();
50 mView.SetVisualModel( mVisualModel );
52 mFontClient = TextAbstraction::FontClient::Get();
58 LogicalModelPtr mLogicalModel;
59 VisualModelPtr mVisualModel;
63 LayoutEngine mLayoutEngine;
65 TextAbstraction::FontClient mFontClient;
68 ControllerPtr Controller::New()
70 return ControllerPtr( new Controller() );
73 void Controller::SetText( const std::string& text )
75 // Keep until size negotiation
76 mImpl->mNewText = text;
77 mImpl->mNewTextArrived = true;
80 bool Controller::Relayout( const Vector2& size )
82 bool viewUpdated( false );
84 if( mImpl->mNewTextArrived )
86 std::string& text = mImpl->mNewText;
88 // Convert text into UTF-32
89 Vector<Character> utf32Characters;
90 utf32Characters.Resize( text.size() );
92 // This is a bit horrible but std::string returns a (signed) char*
93 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
95 Length characterCount = Utf8ToUtf32( utf8, text.size(), &utf32Characters[0] );
96 utf32Characters.Resize( characterCount );
98 Vector<ScriptRun> scripts;
99 MultilanguageSupport multilanguageSupport = MultilanguageSupport::Get();
101 multilanguageSupport.SetScripts( utf32Characters,
104 Vector<FontRun> fonts;
105 multilanguageSupport.ValidateFonts( utf32Characters,
109 // Manipulate the logical model
110 mImpl->mLogicalModel->SetText( &utf32Characters[0], characterCount );
111 mImpl->mLogicalModel->SetScripts( &scripts[0], scripts.Count() );
112 mImpl->mLogicalModel->SetFonts( &fonts[0], fonts.Count() );
114 // Update the visual model
115 mImpl->mLayoutEngine.UpdateVisualModel( size, *mImpl->mLogicalModel, *mImpl->mVisualModel );
117 // Discard temporary text
118 mImpl->mNewTextArrived = false;
127 View& Controller::GetView()
132 LayoutEngine& Controller::GetLayoutEngine()
134 return mImpl->mLayoutEngine;
137 Controller::~Controller()
142 Controller::Controller()
145 mImpl = new Controller::Impl();
150 } // namespace Toolkit