Merge branch 'tizen' into new_text
[platform/core/uifw/dali-core.git] / dali / internal / event / text / atlas / atlas-ranking.h
1 #ifndef __DALI_INTERNAL_ATLAS_RANKING_H__
2 #define __DALI_INTERNAL_ATLAS_RANKING_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21
22 namespace Dali
23 {
24
25 namespace Internal
26 {
27
28 /**
29  * Small class used to store and compare how suitable an atlas is
30  * for storing a string of text.
31  *
32  * The search ranking allows us to chose the best Atlas / tweak behaviour.
33  *
34  * The ranking algorithm is based on various factors, such as:
35  * - Whether all or some of the characters are in the atlas already
36  * - Whether the atlas contains other characters of the same font
37  * - Whether the atlas is full but can be split up (if it has more than one font)
38  * - Whether the atlas is full, but can be enlarged.
39  *
40  * Contains POD
41  */
42 class AtlasRanking
43 {
44
45 public:
46
47   /**
48    * Character match status
49    */
50   enum CharacterMatch
51   {
52     NO_CHARACTERS_MATCHED    = 0x0,   ///< Atlas contains no matching characters
53     SOME_CHARACTERS_MATCHED  = 0x1,   ///< Some characters are in the Atlas
54     ALL_CHARACTERS_MATCHED   = 0x2    ///< All characters are in the atlas
55   };
56
57   /**
58    * Font match status
59    */
60   enum FontMatch
61   {
62     NO_FONT_MATCHED  = 0x0,           ///< Atlas has no characters using the the same font
63     FONT_MATCHED     = 0x1            ///< Atlas characters using the same font
64   };
65
66   /**
67    * Space status
68    */
69   enum SpaceStatus
70   {
71     FULL_CANNOT_BE_RESIZED = 0x0,     ///< Atlas can't be resized ( recached max texture size)
72     FULL_CAN_BE_SPLIT      = 0x1,     ///< Atlas is full and contains more than one font, so can be split up
73     FULL_CAN_BE_RESIZED    = 0x2,     ///< Atlas is full and can be resized
74     HAS_SPACE              = 0x4      ///< Atlas has free space
75   };
76
77   /**
78    * Constructor.
79    * @param[in] unMatchedCharacters number of un-matched characters
80    */
81   AtlasRanking( unsigned int unMatchedCharacters );
82
83   /**
84    * Constructor
85    * @param[in] characterMatch character match status
86    * @param[in] fontMatch font match status
87    * @param[in] spaceStatus space status
88    * @param[in] unMatchedCharacters number of un-matched characters
89    */
90   AtlasRanking( CharacterMatch characterMatch,
91                 FontMatch fontMatch,
92                 SpaceStatus spaceStatus,
93                 unsigned int unMatchedCharacters);
94
95
96   /**
97    * non virtual destructor, not intended as a base class.
98    */
99   ~AtlasRanking();
100
101   /**
102    * Copy constructor
103    * @param[in] rhs atlas to copy
104    */
105   AtlasRanking( const AtlasRanking& rhs);
106
107   /**
108    * Assignment operator.
109    * @param[in] rhs atlas to assign
110    * @return reference to this
111    */
112   AtlasRanking& operator=( const AtlasRanking& rhs );
113
114   /**
115    * Returns if this atlas ranking is higher than the
116    * parameter passed in,
117    * @param atlasRank the rank to compare against
118    * @return true if it is higher ranked
119    */
120   bool HigherRanked(const AtlasRanking &atlasRank) const;
121
122   /**
123    * @return true if the text fits in the atlas
124    */
125   bool TextFits() const;
126
127   /**
128    * @return true if the atlas already contains all the characters in the text
129    */
130   bool AllCharactersMatched() const;
131
132   /**
133    * @return the atlas space status
134    */
135   SpaceStatus GetSpaceStatus() const;
136
137 private:
138
139   /**
140    * Compare two atlas rankings
141    * @param a atlas a ranking
142    * @param b atlas b ranking
143    * @return -1 if a<b, 0 if a==b, 1 if a > b
144    */
145   int Compare( const AtlasRanking &a, const AtlasRanking &b) const;
146
147   unsigned int    mUnMatchedCharacters:10;   ///< number of un-matched characters
148   CharacterMatch  mChararacterMatch:2;       ///< character match status
149   FontMatch       mFontMatch:1;              ///< font match status
150   SpaceStatus     mSpaceStatus:3;            ///< space tatus
151 };
152
153 } // namespace Internal
154
155 } // namespace Dali
156
157 #endif // __DALI_INTERNAL_ATLAS_RANKING_H__