da32553645342d67afa757fd3323880cc03bb338
[platform/core/uifw/dali-core.git] / dali / internal / event / text / atlas / atlas-rank-generator.cpp
1 /*
2  * Copyright (c) 2014 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 // INTERNAL INCLUDES
19 #include <dali/internal/event/text/atlas/atlas-rank-generator.h>
20
21 namespace Dali
22 {
23
24 namespace Internal
25 {
26
27 namespace // un-named namespace
28 {
29
30 /**
31  * Given a text string, and the number of characters matched, return the match status
32  * @param textSize, size of the text
33  * @param charMissing number of characters that don't exist in the Atlas
34  * @return the character match status
35  */
36 AtlasRanking::CharacterMatch GetTextMatchStatus( std::size_t textSize, std::size_t charsMissing )
37 {
38   if( charsMissing == 0 )
39   {
40     return AtlasRanking::ALL_CHARACTERS_MATCHED;
41   }
42   else if ( charsMissing == textSize )
43   {
44     return  AtlasRanking::NO_CHARACTERS_MATCHED;
45   }
46   else
47   {
48     return AtlasRanking::SOME_CHARACTERS_MATCHED;
49   }
50 }
51
52 /**
53  * Returns the space status of the atlas based on whether the text will
54  * fit in it and if it can be resized
55  * @param canFit whether the text can fit in the atlas
56  * @param atlasResizable whether the atlas is resizable.
57  * @return the space status
58  */
59 AtlasRanking::SpaceStatus GetAtlasSpaceStatus( bool canFit,  bool atlasResizable)
60 {
61   if( canFit )
62   {
63     return AtlasRanking::HAS_SPACE;
64   }
65   else if( atlasResizable )
66   {
67     return AtlasRanking::FULL_CAN_BE_RESIZED;
68   }
69   else
70   {
71       return AtlasRanking::FULL_CANNOT_BE_RESIZED;
72   }
73 }
74
75 } // un-named namespace
76
77 AtlasRanking GetAtlasRanking( const TextArray& text,
78                                FontId fontId,
79                                const GlyphStatusContainer&  container,
80                                bool atlasResizable)
81 {
82   bool canFit(false);
83   unsigned int charsNotLoaded(0);
84
85   // find if the text will fit or not, and how many characters are missing
86   container.GetTextStatus( text, fontId, charsNotLoaded, canFit);
87
88   AtlasRanking::CharacterMatch charMatchStatus = GetTextMatchStatus( text.size(), charsNotLoaded );
89
90   AtlasRanking::SpaceStatus spaceStatus = GetAtlasSpaceStatus( canFit,  atlasResizable);
91
92   AtlasRanking ranking( charMatchStatus,
93                          AtlasRanking::FONT_MATCHED, // @todo hard coded for now, until atlas splitting supported
94                          spaceStatus,
95                          charsNotLoaded );
96   return ranking;
97 }
98
99 } // namespace Internal
100 } // namespace Dali