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 Vector<LineBreakInfo>& lineBreakInfo )
55 const Length numberOfCharacters = text.Count();
57 if( 0u == numberOfCharacters )
59 // Nothing to do if there are no characters.
63 // Retrieve the line break info.
64 lineBreakInfo.Resize( numberOfCharacters );
65 TextAbstraction::Segmentation::Get().GetLineBreakPositions( text.Begin(),
67 lineBreakInfo.Begin() );
69 if( gLogFilter->IsEnabledFor(Debug::Verbose) )
72 Utf32ToUtf8( text.Begin(), numberOfCharacters, utf8 );
75 info.reserve( numberOfCharacters );
76 for( unsigned int i=0; i<lineBreakInfo.Count(); ++i )
78 info.push_back( static_cast<char>('0' + lineBreakInfo[i]) );
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() );
87 void SetWordBreakInfo( const Vector<Character>& text,
88 CharacterIndex startIndex,
89 Length numberOfCharacters,
90 Vector<WordBreakInfo>& wordBreakInfo )
92 const Length totalNumberOfCharacters = text.Count();
94 if( 0u == totalNumberOfCharacters )
96 // Nothing to do if there are no characters.
100 // Resize the vector.
101 wordBreakInfo.Resize( totalNumberOfCharacters );
103 // Whether the current buffer is being updated or is set from scratch.
104 const bool updateCurrentBuffer = numberOfCharacters < totalNumberOfCharacters;
106 WordBreakInfo* wordBreakInfoBuffer = NULL;
107 Vector<WordBreakInfo> newWordBreakInfo;
109 if( updateCurrentBuffer )
111 newWordBreakInfo.Resize( numberOfCharacters );
112 wordBreakInfoBuffer = newWordBreakInfo.Begin();
116 wordBreakInfoBuffer = wordBreakInfo.Begin();
119 // Retrieve the word break info.
120 TextAbstraction::Segmentation::Get().GetWordBreakPositions( text.Begin() + startIndex,
122 wordBreakInfoBuffer );
124 // If the word break info is updated, it needs to be inserted in the model.
125 if( updateCurrentBuffer )
127 wordBreakInfo.Insert( wordBreakInfo.Begin() + startIndex,
128 newWordBreakInfo.Begin(),
129 newWordBreakInfo.End() );
130 wordBreakInfo.Resize( totalNumberOfCharacters );
134 if( gLogFilter->IsEnabledFor(Debug::Verbose) )
137 Utf32ToUtf8( text.Begin(), totalNumberOfCharacters, utf8 );
140 info.reserve( totalNumberOfCharacters );
141 for( unsigned int i=0; i<wordBreakInfo.Count(); ++i )
143 info.push_back( static_cast<char>('0' + wordBreakInfo[i]) );
146 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "SetWordBreakInfo Characters: %s\n", utf8.c_str() );
147 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "SetWordBreakInfo Break info: %s\n", info.c_str() );
154 } // namespace Toolkit