License conversion from Flora to Apache 2.0
[platform/core/uifw/dali-core.git] / dali / internal / event / text / atlas / atlas-ranking.cpp
1
2 /*
3  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18
19 // CLASS HEADER
20 #include <dali/internal/event/text/atlas/atlas-ranking.h>
21
22 namespace Dali
23 {
24
25 namespace Internal
26 {
27
28 AtlasRanking::AtlasRanking( unsigned int unMatchedCharacters )
29 : mUnMatchedCharacters( unMatchedCharacters ),
30   mChararacterMatch( NO_CHARACTERS_MATCHED ),
31   mFontMatch( NO_FONT_MATCHED ),
32   mSpaceStatus( FULL_CANNOT_BE_RESIZED )
33 {
34 }
35
36 AtlasRanking::AtlasRanking( CharacterMatch characterMatch,
37                             FontMatch fontMatch,
38                             SpaceStatus spaceStatus,
39                             unsigned int unMatchedCharacters )
40 : mUnMatchedCharacters( unMatchedCharacters ),
41   mChararacterMatch( characterMatch ),
42   mFontMatch( fontMatch ),
43   mSpaceStatus( spaceStatus )
44 {
45
46 }
47
48 AtlasRanking::~AtlasRanking()
49 {
50
51 }
52
53 AtlasRanking::AtlasRanking( const AtlasRanking& rhs)
54 : mUnMatchedCharacters( rhs.mUnMatchedCharacters ),
55   mChararacterMatch( rhs.mChararacterMatch ),
56   mFontMatch( rhs.mFontMatch ),
57   mSpaceStatus( rhs.mSpaceStatus )
58 {
59
60 }
61
62 AtlasRanking& AtlasRanking::operator=( const AtlasRanking& rhs)
63 {
64   mUnMatchedCharacters = rhs.mUnMatchedCharacters;
65   mChararacterMatch = rhs.mChararacterMatch;
66   mFontMatch = rhs.mFontMatch;
67   mSpaceStatus = rhs.mSpaceStatus;
68   return *this;
69 }
70
71 bool AtlasRanking::HigherRanked(const AtlasRanking &atlasRank) const
72 {
73   int ret = Compare( *this , atlasRank );
74   return (ret == 1);
75 }
76
77 bool AtlasRanking::TextFits() const
78 {
79   return ( mSpaceStatus == HAS_SPACE ) || (mChararacterMatch == ALL_CHARACTERS_MATCHED);
80 }
81
82 bool AtlasRanking::AllCharactersMatched() const
83 {
84   return ( mChararacterMatch == ALL_CHARACTERS_MATCHED );
85 }
86
87 AtlasRanking::SpaceStatus AtlasRanking::GetSpaceStatus() const
88 {
89   return mSpaceStatus;
90 }
91
92 int AtlasRanking::Compare( const AtlasRanking &a, const AtlasRanking &b) const
93 {
94   if( a.mChararacterMatch != b.mChararacterMatch )
95   {
96     return  a.mChararacterMatch > b.mChararacterMatch ? 1 : -1;
97   }
98
99   if( a.mFontMatch != b.mFontMatch )
100   {
101     return  a.mFontMatch > b.mFontMatch ? 1 : -1;
102   }
103
104   if( a.mSpaceStatus != b.mSpaceStatus )
105   {
106     return  a.mSpaceStatus > b.mSpaceStatus ? 1 : -1;
107   }
108
109   if( a.mUnMatchedCharacters != b.mUnMatchedCharacters )
110   {
111     return a.mUnMatchedCharacters < b.mUnMatchedCharacters ? 1: -1;
112   }
113   return 0;
114 }
115
116 } // namespace Internal
117
118 } // namespace Dali