1 #ifndef __DALI_INTERNAL_GLYPH_STATUS_CONTAINER_H__
2 #define __DALI_INTERNAL_GLYPH_STATUS_CONTAINER_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/common/set-wrapper.h>
23 #include <dali/internal/event/text/glyph-status/glyph-status.h>
24 #include <dali/integration-api/text-array.h>
34 * Maintains a set of reference counted characters (glyph status objects).
35 * The glyph status objects are sorted by character code and font id.
37 * The class provides an API for inserting glyph status objects into
38 * the container and increasing / decreasing their reference count.
40 * Once a glyph status object reaches a ref count = 0, it remains in
41 * the container, but a pointer to it is added to the mDeadCharacters list.
42 * The dead character list is sorted by dead time.
44 * If new glyph objects are inserted when the container is full,
45 * dead characters (ref = 0) are replaced, starting with the oldest first.
47 * To see what is happening on the console, enable DEBUG_GLYPH_STATUS_CONTAINER in
48 * glyph-status-container-debug.h
51 class GlyphStatusContainer
58 * @param numberOfCharacters how many characters the container should hold
60 GlyphStatusContainer( unsigned int numberOfCharacters );
63 * destructor, non-virtual not intended as a base class.
65 ~GlyphStatusContainer();
68 * Increase the reference count of a character
69 * @param[in] character code
72 void IncreaseRefCount( uint32_t charCode, FontId fontId);
75 * @param[in] charCode character code
76 * @param[in] fontId font id
78 void DecreaseRefCount( uint32_t charCode, FontId fontId);
81 * enum to represent the result of a character insertion.
85 INSERTED_OK, ///< character was inserted in to an empty space
86 REPLACE_DEAD_CHARACTER, ///< character replaced a cached dead character.
90 * Insert a new character in to the container
91 * @param[in] charCode character code
92 * @param[in] fontId font id
93 * @param[out] deadUniqueId the id of a dead character, if one was replaced
94 * @return insertion result
96 InsertResult InsertNewCharacter( uint32_t charCode, FontId fontId, unsigned int& deadUniqueId );
99 * Find the glyph status object given a character code and font id
100 * @param[in] charCode character code
101 * @param[in] fontId font id
102 * @return glyph status object if it exists, NULL if it doesn't
104 const GlyphStatus* FindGlyphStatus( uint32_t charCode, FontId fontId) const;
107 * Return a reference to a glyph status object given a character code and font id
108 * @param[in] charCode character code
109 * @param[in] fontId font id
110 * @return glyph status object
112 const GlyphStatus& GetStatus( uint32_t charCode, FontId fontId) const;
115 * Status set typedef. Uses a custom sort function to sort by character code and font id
117 typedef std::set< GlyphStatus, GlyphStatus::Comparator > StatusSet;
120 * Get the glyph status set
121 * @todo find a better solution than allowing direct access to the set
122 * @return the glyph status set
124 const StatusSet& GetStatusSet() const;
127 * Check if all characters in a text array are marked as loaded
128 * @param[in] text the text array
129 * @param[in] fontId font id
130 * @return true if all characters are loaded false if not
132 bool IsTextLoaded( const Integration::TextArray& text, FontId fontId) const;
135 * Given a text array, find how many character are loaded and
136 * whether it will fit in to the container.
137 * @param[in] text the text array
138 * @param[in] fontId font id
139 * @param[out] charsNotLoaded how many characters are not loaded
140 * @param[out] fitsInContainer whether the text fits in the container
142 void GetTextStatus( const Integration::TextArray& text,
144 unsigned int& charsNotLoaded,
145 bool& fitsInContainer ) const;
148 * Clone the contents of one container, into this container
149 * @param[in] clone the container to clone
151 void CloneContents( const GlyphStatusContainer& clone );
154 * Get the list of dead characters
155 * @param[out] deadList to be filled with a list of dead characters
157 void GetDeadCharacters( Integration::TextArray& deadList );
160 * Clear dead characters.
162 void ClearDeadCharacters();
165 * Check if the container is empty
166 * @return true if container is empty
171 * @return the container size
173 unsigned int GetSize() const;
176 * Clear the container contents.
178 void ClearContents();
183 * Add a character to the dead character list
184 * @param[in] deadCharacter dead character
186 void AddDeadCharacter( const GlyphStatus* deadCharacter);
189 * Remove a character from the dead character list.
190 * This happens if a characters reference count goes from 0 -> 1.
191 * @param[in] deadCharacter dead character
193 void RemoveDeadCharacter( const GlyphStatus* deadCharacter );
196 * Remove the oldest dead character
197 * @return oldest dead character
199 const GlyphStatus* RemoveOldestDeadCharacter( );
202 * Insert a character in to the lookup
203 * @param[in] charCode character code
204 * @param[in] fontId font id
206 void InsertCharacterIntoLookup(uint32_t charCode, FontId fontId );
209 * Reset the dead time stamps of all glyph objects in the
210 * dead character list. This is called when mTimeStamp value reaches
211 * GlyphStatus::GetMaximumDeadTime()
213 void ResetTimeStamps();
216 * Get the total available space in the container.
217 * This is empty space + space used by dead characters that can be replaced
218 * @return total space
220 unsigned int TotalAvailableSpace() const;
222 unsigned int mContainerSize; ///< container size
223 unsigned int mEmptySpace; ///< amount of space that is empty (has never been used)
226 * Status pointer set typedef, sorted by custom function
228 typedef std::set< const GlyphStatus*, GlyphStatus::PointerComparator > StatusPointerSet;
230 StatusSet mCharacterLookup; ///< set of glyph status objects sorted by font id and character code
231 StatusPointerSet mDeadCharacters; ///< set of characters with a ref count of zero, which are still cached.
232 unsigned int mTimeStamp; ///< current time stamp
237 } // namespace Internal
241 #endif // __DALI_INTERNAL_GLYPH_STATUS_CONTAINER_H__