Merge "Set proper locale to harfbuzz" into devel/master
[platform/core/uifw/dali-adaptor.git] / text / dali / internal / text-abstraction / segmentation-impl.cpp
1 /*
2  * Copyright (c) 2015 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 "segmentation-impl.h"
20
21 // INTERNAL INCLUDES
22 #include <singleton-service-impl.h>
23
24 // EXTERNAL INCLUDES
25 #include <linebreak.h>
26 #include <wordbreak.h>
27
28 namespace Dali
29 {
30
31 namespace TextAbstraction
32 {
33
34 namespace Internal
35 {
36
37 struct Segmentation::Plugin
38 {
39   void GetLineBreakPositions( const Character* const text,
40                               Length numberOfCharacters,
41                               LineBreakInfo* breakInfo )
42   {
43     set_linebreaks_utf32( text, numberOfCharacters, NULL, breakInfo );
44   }
45
46   void GetWordBreakPositions( const Character* const text,
47                               Length numberOfCharacters,
48                               WordBreakInfo* breakInfo )
49   {
50     set_wordbreaks_utf32( text, numberOfCharacters, NULL, breakInfo );
51   }
52 };
53
54 Segmentation::Segmentation()
55 : mPlugin( NULL )
56 {}
57
58 Segmentation::~Segmentation()
59 {
60   delete mPlugin;
61 }
62
63 TextAbstraction::Segmentation Segmentation::Get()
64 {
65   TextAbstraction::Segmentation segmentationHandle;
66
67   SingletonService service( SingletonService::Get() );
68   if( service )
69   {
70     // Check whether the singleton is already created
71     Dali::BaseHandle handle = service.GetSingleton( typeid( TextAbstraction::Segmentation ) );
72     if( handle )
73     {
74       // If so, downcast the handle
75       Segmentation* impl = dynamic_cast< Internal::Segmentation* >( handle.GetObjectPtr() );
76       segmentationHandle = TextAbstraction::Segmentation( impl );
77     }
78     else // create and register the object
79     {
80       segmentationHandle = TextAbstraction::Segmentation( new Segmentation );
81       service.Register( typeid( segmentationHandle ), segmentationHandle );
82     }
83   }
84
85   return segmentationHandle;
86 }
87
88 void Segmentation::GetLineBreakPositions( const Character* const text,
89                                           Length numberOfCharacters,
90                                           LineBreakInfo* breakInfo )
91 {
92   CreatePlugin();
93
94   mPlugin->GetLineBreakPositions( text, numberOfCharacters, breakInfo );
95 }
96
97 void Segmentation::GetWordBreakPositions( const Character* const text,
98                                           Length numberOfCharacters,
99                                           WordBreakInfo* breakInfo )
100 {
101   CreatePlugin();
102
103   mPlugin->GetWordBreakPositions( text, numberOfCharacters, breakInfo );
104 }
105
106 void Segmentation::CreatePlugin()
107 {
108   if( !mPlugin )
109   {
110     mPlugin = new Plugin();
111   }
112 }
113
114 } // namespace Internal
115
116 } // namespace TextAbstraction
117
118 } // namespace Dali