Merge "Fix setting a void string to the TEXT property." into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / segmentation.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 <dali-toolkit/internal/text/segmentation.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/devel-api/text-abstraction/segmentation.h>
23 #ifdef DEBUG_ENABLED
24 #include <string>
25 #include <dali/integration-api/debug.h>
26 #endif
27
28 // INTERNAL INCLUDES
29 #ifdef DEBUG_ENABLED
30 #include <dali-toolkit/internal/text/character-set-conversion.h>
31 #endif
32
33 namespace
34 {
35
36 #if defined(DEBUG_ENABLED)
37   Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_SEGMENTATION");
38 #endif
39
40 } // namespace
41
42
43 namespace Dali
44 {
45
46 namespace Toolkit
47 {
48
49 namespace Text
50 {
51
52 void SetLineBreakInfo( const Vector<Character>& text,
53                        Vector<LineBreakInfo>& lineBreakInfo )
54 {
55   const Length numberOfCharacters = text.Count();
56
57   if( 0u == numberOfCharacters )
58   {
59     // Nothing to do if there are no characters.
60     return;
61   }
62
63   // Retrieve the line break info.
64   lineBreakInfo.Resize( numberOfCharacters );
65   TextAbstraction::Segmentation::Get().GetLineBreakPositions( text.Begin(),
66                                                               numberOfCharacters,
67                                                               lineBreakInfo.Begin() );
68 #ifdef DEBUG_ENABLED
69   if( gLogFilter->IsEnabledFor(Debug::Verbose) )
70   {
71     std::string utf8;
72     Utf32ToUtf8( text.Begin(), numberOfCharacters, utf8 );
73
74     std::string info;
75     info.reserve( numberOfCharacters );
76     for( unsigned int i=0; i<lineBreakInfo.Count(); ++i )
77     {
78       info.push_back( static_cast<char>('0' + lineBreakInfo[i]) );
79     }
80
81     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "SetLineBreakInfo Characters: %s\n", utf8.c_str() );
82     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "SetLineBreakInfo Break info: %s\n", info.c_str() );
83   }
84 #endif
85 }
86
87 void SetWordBreakInfo( const Vector<Character>& text,
88                        Vector<WordBreakInfo>& wordBreakInfo )
89 {
90   const Length numberOfCharacters = text.Count();
91
92   if( 0u == numberOfCharacters )
93   {
94     // Nothing to do if there are no characters.
95     return;
96   }
97
98   // Retrieve the word break info.
99   wordBreakInfo.Resize( numberOfCharacters );
100   TextAbstraction::Segmentation::Get().GetWordBreakPositions( text.Begin(),
101                                                               numberOfCharacters,
102                                                               wordBreakInfo.Begin() );
103 #ifdef DEBUG_ENABLED
104   if( gLogFilter->IsEnabledFor(Debug::Verbose) )
105   {
106     std::string utf8;
107     Utf32ToUtf8( text.Begin(), numberOfCharacters, utf8 );
108
109     std::string info;
110     info.reserve( numberOfCharacters );
111     for( unsigned int i=0; i<wordBreakInfo.Count(); ++i )
112     {
113       info.push_back( static_cast<char>('0' + wordBreakInfo[i]) );
114     }
115
116     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "SetWordBreakInfo Characters: %s\n", utf8.c_str() );
117     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "SetWordBreakInfo Break info: %s\n", info.c_str() );
118   }
119 #endif
120 }
121
122 } // namespace Text
123
124 } // namespace Toolkit
125
126 } // namespace Dali