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>
29 namespace TextAbstraction
35 struct Segmentation::Plugin
37 void GetLineBreakPositions( const Character* const text,
38 Length numberOfCharacters,
39 LineBreakInfo* breakInfo )
41 set_linebreaks_utf32( text, numberOfCharacters, NULL, breakInfo );
44 void GetWordBreakPositions( const Character* const text,
45 Length numberOfCharacters,
46 WordBreakInfo* breakInfo )
48 set_wordbreaks_utf32( text, numberOfCharacters, NULL, breakInfo );
52 Segmentation::Segmentation()
56 Segmentation::~Segmentation()
61 TextAbstraction::Segmentation Segmentation::Get()
63 TextAbstraction::Segmentation segmentationHandle;
65 SingletonService service( SingletonService::Get() );
68 // Check whether the singleton is already created
69 Dali::BaseHandle handle = service.GetSingleton( typeid( TextAbstraction::Segmentation ) );
72 // If so, downcast the handle
73 Segmentation* impl = dynamic_cast< Internal::Segmentation* >( handle.GetObjectPtr() );
74 segmentationHandle = TextAbstraction::Segmentation( impl );
76 else // create and register the object
78 segmentationHandle = TextAbstraction::Segmentation( new Segmentation );
79 service.Register( typeid( segmentationHandle ), segmentationHandle );
83 return segmentationHandle;
86 void Segmentation::GetLineBreakPositions( const Character* const text,
87 Length numberOfCharacters,
88 LineBreakInfo* breakInfo )
92 mPlugin->GetLineBreakPositions( text, numberOfCharacters, breakInfo );
95 void Segmentation::GetWordBreakPositions( const Character* const text,
96 Length numberOfCharacters,
97 WordBreakInfo* breakInfo )
101 mPlugin->GetWordBreakPositions( text, numberOfCharacters, breakInfo );
104 void Segmentation::CreatePlugin()
108 mPlugin = new Plugin();
112 } // namespace Internal
114 } // namespace TextAbstraction