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 Flora License, Version 1.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://floralicense.org/license/
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/internal/event/text/glyph-status/glyph-status.h>
23 #include <dali/internal/common/text-array.h>
37 * Maintains a set of reference counted characters (glyph status objects).
38 * The glyph status objects are sorted by character code and font id.
40 * The class provides an API for inserting glyph status objects into
41 * the container and increasing / decreasing their reference count.
43 * Once a glyph status object reaches a ref count = 0, it remains in
44 * the container, but a pointer to it is added to the mDeadCharacters list.
45 * The dead character list is sorted by dead time.
47 * If new glyph objects are inserted when the container is full,
48 * dead characters (ref = 0) are replaced, starting with the oldest first.
50 * To see what is happening on the console, enable DEBUG_GLYPH_STATUS_CONTAINER in
51 * glyph-status-container-debug.h
54 class GlyphStatusContainer
61 * @param numberOfCharacters how many characters the container should hold
63 GlyphStatusContainer( unsigned int numberOfCharacters );
66 * destructor, non-virtual not intended as a base class.
68 ~GlyphStatusContainer();
71 * Increase the reference count of a character
72 * @param[in] character code
75 void IncreaseRefCount( uint32_t charCode, FontId fontId);
78 * @param[in] charCode character code
79 * @param[in] fontId font id
81 void DecreaseRefCount( uint32_t charCode, FontId fontId);
84 * enum to represent the result of a character insertion.
88 INSERTED_OK, ///< character was inserted in to an empty space
89 REPLACE_DEAD_CHARACTER, ///< character replaced a cached dead character.
93 * Insert a new character in to the container
94 * @param[in] charCode character code
95 * @param[in] fontId font id
96 * @param[out] deadUniqueId the id of a dead character, if one was replaced
97 * @return insertion result
99 InsertResult InsertNewCharacter( uint32_t charCode, FontId fontId, unsigned int& deadUniqueId );
102 * Find the glyph status object given a character code and font id
103 * @param[in] charCode character code
104 * @param[in] fontId font id
105 * @return glyph status object if it exists, NULL if it doesn't
107 const GlyphStatus* FindGlyphStatus( uint32_t charCode, FontId fontId) const;
110 * Return a reference to a glyph status object given a character code and font id
111 * @param[in] charCode character code
112 * @param[in] fontId font id
113 * @return glyph status object
115 const GlyphStatus& GetStatus( uint32_t charCode, FontId fontId) const;
118 * Status set typedef. Uses a custom sort function to sort by character code and font id
120 typedef std::set< GlyphStatus, GlyphStatus::Comparator > StatusSet;
123 * Get the glyph status set
124 * @todo find a better solution than allowing direct access to the set
125 * @return the glyph status set
127 const StatusSet& GetStatusSet() const;
130 * Check if all characters in a text array are marked as loaded
131 * @param[in] text the text array
132 * @param[in] fontId font id
133 * @return true if all characters are loaded false if not
135 bool IsTextLoaded( const TextArray& text, FontId fontId) const;
138 * Given a text array, find how many character are loaded and
139 * whether it will fit in to the container.
140 * @param[in] text the text array
141 * @param[in] fontId font id
142 * @param[out] charsNotLoaded how many characters are not loaded
143 * @param[out] fitsInContainer whether the text fits in the container
145 void GetTextStatus( const TextArray& text,
147 unsigned int& charsNotLoaded,
148 bool& fitsInContainer ) const;
151 * Clone the contents of one container, into this container
152 * @param[in] clone the container to clone
154 void CloneContents( const GlyphStatusContainer& clone );
157 * Get the list of dead characters
158 * @param[out] deadList to be filled with a list of dead characters
160 void GetDeadCharacters( std::vector< unsigned int >& deadList );
163 * Clear dead characters.
165 void ClearDeadCharacters();
168 * Check if the container is empty
169 * @return true if container is empty
174 * @return the container size
176 unsigned int GetSize() const;
179 * Clear the container contents.
181 void ClearContents();
186 * Add a character to the dead character list
187 * @param[in] deadCharacter dead character
189 void AddDeadCharacter( const GlyphStatus* deadCharacter);
192 * Remove a character from the dead character list.
193 * This happens if a characters reference count goes from 0 -> 1.
194 * @param[in] deadCharacter dead character
196 void RemoveDeadCharacter( const GlyphStatus* deadCharacter );
199 * Remove the oldest dead character
200 * @return oldest dead character
202 const GlyphStatus* RemoveOldestDeadCharacter( );
205 * Insert a character in to the lookup
206 * @param[in] charCode character code
207 * @param[in] fontId font id
209 void InsertCharacterIntoLookup(uint32_t charCode, FontId fontId );
212 * Reset the dead time stamps of all glyph objects in the
213 * dead character list. This is called when mTimeStamp value reaches
214 * GlyphStatus::GetMaximumDeadTime()
216 void ResetTimeStamps();
219 * Get the total available space in the container.
220 * This is empty space + space used by dead characters that can be replaced
221 * @return total space
223 unsigned int TotalAvailableSpace() const;
225 unsigned int mContainerSize; ///< container size
226 unsigned int mEmptySpace; ///< amount of space that is empty (has never been used)
229 * Status pointer set typedef, sorted by custom function
231 typedef std::set< const GlyphStatus*, GlyphStatus::PointerComparator > StatusPointerSet;
233 StatusSet mCharacterLookup; ///< set of glyph status objects sorted by font id and character code
234 StatusPointerSet mDeadCharacters; ///< set of characters with a ref count of zero, which are still cached.
235 unsigned int mTimeStamp; ///< current time stamp
240 } // namespace Internal
244 #endif // __DALI_INTERNAL_GLYPH_STATUS_CONTAINER_H__