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/text-view.h>
29 #include <dali-toolkit/public-api/text/visual-model.h>
40 struct Controller::Impl
43 : mNewTextArrived( false )
45 mLogicalModel = LogicalModel::New();
46 mVisualModel = VisualModel::New();
48 mView.SetVisualModel( mVisualModel );
50 mFontClient = TextAbstraction::FontClient::Get();
56 LogicalModelPtr mLogicalModel;
57 VisualModelPtr mVisualModel;
61 LayoutEngine mLayoutEngine;
63 TextAbstraction::FontClient mFontClient;
66 ControllerPtr Controller::New()
68 return ControllerPtr( new Controller() );
71 void Controller::SetText( const std::string& text )
73 // Keep until size negotiation
74 mImpl->mNewText = text;
75 mImpl->mNewTextArrived = true;
78 bool Controller::Relayout( const Vector2& size )
80 bool viewUpdated( false );
82 if( mImpl->mNewTextArrived )
84 std::string& text = mImpl->mNewText;
86 // Convert text into UTF-32
87 Vector<Character> utf32Characters;
88 utf32Characters.Resize( text.size() );
90 // This is a bit horrible but std::string returns a (signed) char*
91 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
93 Length characterCount = Utf8ToUtf32( utf8, text.size(), &utf32Characters[0] );
95 // Manipulate the logical model
96 mImpl->mLogicalModel->SetText( &utf32Characters[0], characterCount );
98 // Update the visual model
99 mImpl->mLayoutEngine.UpdateVisualModel( size, *mImpl->mLogicalModel, *mImpl->mVisualModel );
101 // Discard temporary text
102 mImpl->mNewTextArrived = false;
111 View& Controller::GetView()
116 LayoutEngine& Controller::GetLayoutEngine()
118 return mImpl->mLayoutEngine;
121 Controller::~Controller()
126 Controller::Controller()
129 mImpl = new Controller::Impl();
134 } // namespace Toolkit