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/internal/system/common/singleton-service-impl.h>
25 #include <third-party/libunibreak/linebreak.h>
26 #include <third-party/libunibreak/wordbreak.h>
31 namespace TextAbstraction
37 struct Segmentation::Plugin
39 void GetLineBreakPositions( const Character* const text,
40 Length numberOfCharacters,
41 LineBreakInfo* breakInfo )
43 set_linebreaks_utf32( text, numberOfCharacters, NULL, breakInfo );
46 void GetWordBreakPositions( const Character* const text,
47 Length numberOfCharacters,
48 WordBreakInfo* breakInfo )
50 set_wordbreaks_utf32( text, numberOfCharacters, NULL, breakInfo );
54 Segmentation::Segmentation()
58 Segmentation::~Segmentation()
63 TextAbstraction::Segmentation Segmentation::Get()
65 TextAbstraction::Segmentation segmentationHandle;
67 SingletonService service( SingletonService::Get() );
70 // Check whether the singleton is already created
71 Dali::BaseHandle handle = service.GetSingleton( typeid( TextAbstraction::Segmentation ) );
74 // If so, downcast the handle
75 Segmentation* impl = dynamic_cast< Internal::Segmentation* >( handle.GetObjectPtr() );
76 segmentationHandle = TextAbstraction::Segmentation( impl );
78 else // create and register the object
80 segmentationHandle = TextAbstraction::Segmentation( new Segmentation );
81 service.Register( typeid( segmentationHandle ), segmentationHandle );
85 return segmentationHandle;
88 void Segmentation::GetLineBreakPositions( const Character* const text,
89 Length numberOfCharacters,
90 LineBreakInfo* breakInfo )
94 mPlugin->GetLineBreakPositions( text, numberOfCharacters, breakInfo );
97 void Segmentation::GetWordBreakPositions( const Character* const text,
98 Length numberOfCharacters,
99 WordBreakInfo* breakInfo )
103 mPlugin->GetWordBreakPositions( text, numberOfCharacters, breakInfo );
106 void Segmentation::CreatePlugin()
110 mPlugin = new Plugin();
114 } // namespace Internal
116 } // namespace TextAbstraction