Add GetHeightForWidth for text visual model
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / controller / text-controller-spannable-handler.cpp
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali-toolkit/internal/text/controller/text-controller-spannable-handler.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/integration-api/debug.h>
23 #include <memory.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/internal/text/controller/text-controller-impl.h>
27 #include <dali-toolkit/internal/text/controller/text-controller-text-updater.h>
28 #include <dali-toolkit/internal/text/logical-model-impl.h>
29 #include <dali-toolkit/internal/text/spannable/spans/base-span-impl.h>
30
31 namespace
32 {
33 #if defined(DEBUG_ENABLED)
34 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
35 #endif
36
37 } // namespace
38
39 namespace Dali
40 {
41 namespace Toolkit
42 {
43 namespace Text
44 {
45 void Controller::SpannableHandler::SetSpannedText(Controller& controller, const Text::Spanned& spannedText)
46 {
47   // Copy content(text)
48   const std::string& text = spannedText.ToString();
49   Controller::TextUpdater::SetText(controller, text);
50
51   Controller::Impl& impl         = *controller.mImpl;
52   LogicalModelPtr&  logicalModel = impl.mModel->mLogicalModel;
53
54   // Set spanned-text
55   logicalModel->mSpannedTextPlaced = true;
56
57   std::vector<Dali::Toolkit::Text::BaseSpan> spans;
58   std::vector<Dali::Toolkit::Text::Range>    ranges;
59   spannedText.RetrieveAllSpansAndRanges(spans, ranges);
60
61   for(std::vector<Dali::Toolkit::Text::BaseSpan>::size_type i = 0; i < spans.size(); i++)
62   {
63     GetImplementation(spans[i]).CreateStyleCharacterRun(logicalModel, ranges[i]);
64   }
65 }
66 } // namespace Text
67
68 } // namespace Toolkit
69
70 } // namespace Dali