FontClient ValueToIndex index logic fixed for width, weight and slant
[platform/core/uifw/dali-adaptor.git] / text / dali / internal / text-abstraction / font-client-helper.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 "font-client-helper.h"
20
21 // INTERNAL INCLUDES
22
23 #include <dali/integration-api/debug.h>
24
25 namespace
26 {
27 #if defined(DEBUG_ENABLED)
28 Dali::Integration::Log::Filter* gLogFilter = Dali::Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_FONT_CLIENT");
29 #endif
30 }
31
32 namespace Dali
33 {
34
35 namespace TextAbstraction
36 {
37
38 namespace Internal
39 {
40
41 int ValueToIndex( int value, const int* const table, unsigned int maxIndex )
42 {
43   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->FontClient::Plugin::ValueToIndex value(%d)\n", value);
44
45   if( ( NULL == table ) ||
46       ( value <= table[0] ) )
47   {
48     return 0;
49   }
50
51   if( value >= table[maxIndex] )
52   {
53     return maxIndex;
54   }
55
56   for( unsigned int index = 0u; index < maxIndex; )
57   {
58     const int v1 = table[index];
59     const unsigned int indexPlus = ++index;
60     const int v2 = table[indexPlus];
61     if( ( v1 < value ) && ( value <= v2 ) )
62     {
63       const int result = ( ( value - v1 ) < ( v2 - value ) ) ? index : indexPlus;
64       DALI_LOG_INFO( gLogFilter, Debug::Verbose, "FontClient::Plugin::ValueToIndex result(%d)\n",  result );
65       return result;
66     }
67   }
68
69   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "FontClient::Plugin::ValueToIndex exit 0 <-- \n");
70
71   return 0;
72 }
73
74 } // namespace Internal
75
76 } // namespace TextAbstraction
77
78 } // namespace Dali