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-toolkit/internal/text/segmentation.h>
22 #include <dali/devel-api/text-abstraction/segmentation.h>
25 #include <dali/integration-api/debug.h>
30 #include <dali-toolkit/internal/text/character-set-conversion.h>
36 #if defined(DEBUG_ENABLED)
37 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_SEGMENTATION");
52 void SetLineBreakInfo( const Vector<Character>& text,
53 CharacterIndex startIndex,
54 Length numberOfCharacters,
55 Vector<LineBreakInfo>& lineBreakInfo )
57 const Length totalNumberOfCharacters = text.Count();
59 if( 0u == totalNumberOfCharacters )
61 // Nothing to do if there are no characters.
65 // Retrieve the line break info.
66 lineBreakInfo.Resize( totalNumberOfCharacters );
68 // Whether the current buffer is being updated or is set from scratch.
69 const bool updateCurrentBuffer = numberOfCharacters < totalNumberOfCharacters;
71 LineBreakInfo* lineBreakInfoBuffer = NULL;
72 Vector<LineBreakInfo> newLineBreakInfo;
74 if( updateCurrentBuffer )
76 newLineBreakInfo.Resize( numberOfCharacters );
77 lineBreakInfoBuffer = newLineBreakInfo.Begin();
81 lineBreakInfoBuffer = lineBreakInfo.Begin();
84 // Retrieve the line break info.
85 TextAbstraction::Segmentation::Get().GetLineBreakPositions( text.Begin() + startIndex,
87 lineBreakInfoBuffer );
89 // If the line break info is updated, it needs to be inserted in the model.
90 if( updateCurrentBuffer )
92 lineBreakInfo.Insert( lineBreakInfo.Begin() + startIndex,
93 newLineBreakInfo.Begin(),
94 newLineBreakInfo.End() );
95 lineBreakInfo.Resize( totalNumberOfCharacters );
99 if( gLogFilter->IsEnabledFor(Debug::Verbose) )
102 Utf32ToUtf8( text.Begin(), numberOfCharacters, utf8 );
105 info.reserve( numberOfCharacters );
106 for( unsigned int i=0; i<lineBreakInfo.Count(); ++i )
108 info.push_back( static_cast<char>('0' + lineBreakInfo[i]) );
111 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "SetLineBreakInfo Characters: %s\n", utf8.c_str() );
112 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "SetLineBreakInfo Break info: %s\n", info.c_str() );
117 void SetWordBreakInfo( const Vector<Character>& text,
118 CharacterIndex startIndex,
119 Length numberOfCharacters,
120 Vector<WordBreakInfo>& wordBreakInfo )
122 const Length totalNumberOfCharacters = text.Count();
124 if( 0u == totalNumberOfCharacters )
126 // Nothing to do if there are no characters.
130 // Resize the vector.
131 wordBreakInfo.Resize( totalNumberOfCharacters );
133 // Whether the current buffer is being updated or is set from scratch.
134 const bool updateCurrentBuffer = numberOfCharacters < totalNumberOfCharacters;
136 WordBreakInfo* wordBreakInfoBuffer = NULL;
137 Vector<WordBreakInfo> newWordBreakInfo;
139 if( updateCurrentBuffer )
141 newWordBreakInfo.Resize( numberOfCharacters );
142 wordBreakInfoBuffer = newWordBreakInfo.Begin();
146 wordBreakInfoBuffer = wordBreakInfo.Begin();
149 // Retrieve the word break info.
150 TextAbstraction::Segmentation::Get().GetWordBreakPositions( text.Begin() + startIndex,
152 wordBreakInfoBuffer );
154 // If the word break info is updated, it needs to be inserted in the model.
155 if( updateCurrentBuffer )
157 wordBreakInfo.Insert( wordBreakInfo.Begin() + startIndex,
158 newWordBreakInfo.Begin(),
159 newWordBreakInfo.End() );
160 wordBreakInfo.Resize( totalNumberOfCharacters );
164 if( gLogFilter->IsEnabledFor(Debug::Verbose) )
167 Utf32ToUtf8( text.Begin(), totalNumberOfCharacters, utf8 );
170 info.reserve( totalNumberOfCharacters );
171 for( unsigned int i=0; i<wordBreakInfo.Count(); ++i )
173 info.push_back( static_cast<char>('0' + wordBreakInfo[i]) );
176 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "SetWordBreakInfo Characters: %s\n", utf8.c_str() );
177 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "SetWordBreakInfo Break info: %s\n", info.c_str() );
184 } // namespace Toolkit