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/internal/text/text-abstraction/segmentation-impl.h>
22 #include <dali/devel-api/common/singleton-service.h>
23 #include <third-party/libunibreak/linebreak.h>
24 #include <third-party/libunibreak/wordbreak.h>
28 namespace TextAbstraction
32 struct Segmentation::Plugin
34 void GetLineBreakPositions(const Character* const text,
35 Length numberOfCharacters,
36 LineBreakInfo* breakInfo)
38 set_linebreaks_utf32(text, numberOfCharacters, NULL, breakInfo);
41 void GetWordBreakPositions(const Character* const text,
42 Length numberOfCharacters,
43 WordBreakInfo* breakInfo)
45 set_wordbreaks_utf32(text, numberOfCharacters, NULL, breakInfo);
49 Segmentation::Segmentation()
54 Segmentation::~Segmentation()
59 TextAbstraction::Segmentation Segmentation::Get()
61 TextAbstraction::Segmentation segmentationHandle;
63 SingletonService service(SingletonService::Get());
66 // Check whether the singleton is already created
67 Dali::BaseHandle handle = service.GetSingleton(typeid(TextAbstraction::Segmentation));
70 // If so, downcast the handle
71 Segmentation* impl = dynamic_cast<Internal::Segmentation*>(handle.GetObjectPtr());
72 segmentationHandle = TextAbstraction::Segmentation(impl);
74 else // create and register the object
76 segmentationHandle = TextAbstraction::Segmentation(new Segmentation);
77 service.Register(typeid(segmentationHandle), segmentationHandle);
81 return segmentationHandle;
84 void Segmentation::GetLineBreakPositions(const Character* const text,
85 Length numberOfCharacters,
86 LineBreakInfo* breakInfo)
90 mPlugin->GetLineBreakPositions(text, numberOfCharacters, breakInfo);
93 void Segmentation::GetWordBreakPositions(const Character* const text,
94 Length numberOfCharacters,
95 WordBreakInfo* breakInfo)
99 mPlugin->GetWordBreakPositions(text, numberOfCharacters, breakInfo);
102 void Segmentation::CreatePlugin()
106 mPlugin = new Plugin();
110 } // namespace Internal
112 } // namespace TextAbstraction