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.
21 #include <dali/public-api/common/set-wrapper.h>
22 #include <dali/internal/event/text/glyph-status/glyph-status.h>
23 #include <dali/internal/common/text-array.h>
33 * Maintains a set of reference counted characters (glyph status objects).
34 * The glyph status objects are sorted by character code and font id.
36 * The class provides an API for inserting glyph status objects into
37 * the container and increasing / decreasing their reference count.
39 * Once a glyph status object reaches a ref count = 0, it remains in
40 * the container, but a pointer to it is added to the mDeadCharacters list.
41 * The dead character list is sorted by dead time.
43 * If new glyph objects are inserted when the container is full,
44 * dead characters (ref = 0) are replaced, starting with the oldest first.
46 * To see what is happening on the console, enable DEBUG_GLYPH_STATUS_CONTAINER in
47 * glyph-status-container-debug.h
50 class GlyphStatusContainer
57 * @param numberOfCharacters how many characters the container should hold
59 GlyphStatusContainer( unsigned int numberOfCharacters );
62 * destructor, non-virtual not intended as a base class.
64 ~GlyphStatusContainer();
67 * Increase the reference count of a character
68 * @param[in] character code
71 void IncreaseRefCount( uint32_t charCode, FontId fontId);
74 * @param[in] charCode character code
75 * @param[in] fontId font id
77 void DecreaseRefCount( uint32_t charCode, FontId fontId);
80 * enum to represent the result of a character insertion.
84 INSERTED_OK, ///< character was inserted in to an empty space
85 REPLACE_DEAD_CHARACTER, ///< character replaced a cached dead character.
89 * Insert a new character in to the container
90 * @param[in] charCode character code
91 * @param[in] fontId font id
92 * @param[out] deadUniqueId the id of a dead character, if one was replaced
93 * @return insertion result
95 InsertResult InsertNewCharacter( uint32_t charCode, FontId fontId, unsigned int& deadUniqueId );
98 * Find the glyph status object given a character code and font id
99 * @param[in] charCode character code
100 * @param[in] fontId font id
101 * @return glyph status object if it exists, NULL if it doesn't
103 const GlyphStatus* FindGlyphStatus( uint32_t charCode, FontId fontId) const;
106 * Return a reference to a glyph status object given a character code and font id
107 * @param[in] charCode character code
108 * @param[in] fontId font id
109 * @return glyph status object
111 const GlyphStatus& GetStatus( uint32_t charCode, FontId fontId) const;
114 * Status set typedef. Uses a custom sort function to sort by character code and font id
116 typedef std::set< GlyphStatus, GlyphStatus::Comparator > StatusSet;
119 * Get the glyph status set
120 * @todo find a better solution than allowing direct access to the set
121 * @return the glyph status set
123 const StatusSet& GetStatusSet() const;
126 * Check if all characters in a text array are marked as loaded
127 * @param[in] text the text array
128 * @param[in] fontId font id
129 * @return true if all characters are loaded false if not
131 bool IsTextLoaded( const TextArray& text, FontId fontId) const;
134 * Given a text array, find how many character are loaded and
135 * whether it will fit in to the container.
136 * @param[in] text the text array
137 * @param[in] fontId font id
138 * @param[out] charsNotLoaded how many characters are not loaded
139 * @param[out] fitsInContainer whether the text fits in the container
141 void GetTextStatus( const TextArray& text,
143 unsigned int& charsNotLoaded,
144 bool& fitsInContainer ) const;
147 * Clone the contents of one container, into this container
148 * @param[in] clone the container to clone
150 void CloneContents( const GlyphStatusContainer& clone );
153 * Get the list of dead characters
154 * @param[out] deadList to be filled with a list of dead characters
156 void GetDeadCharacters( std::vector< unsigned int >& deadList );
159 * Clear dead characters.
161 void ClearDeadCharacters();
164 * Check if the container is empty
165 * @return true if container is empty
170 * @return the container size
172 unsigned int GetSize() const;
175 * Clear the container contents.
177 void ClearContents();
182 * Add a character to the dead character list
183 * @param[in] deadCharacter dead character
185 void AddDeadCharacter( const GlyphStatus* deadCharacter);
188 * Remove a character from the dead character list.
189 * This happens if a characters reference count goes from 0 -> 1.
190 * @param[in] deadCharacter dead character
192 void RemoveDeadCharacter( const GlyphStatus* deadCharacter );
195 * Remove the oldest dead character
196 * @return oldest dead character
198 const GlyphStatus* RemoveOldestDeadCharacter( );
201 * Insert a character in to the lookup
202 * @param[in] charCode character code
203 * @param[in] fontId font id
205 void InsertCharacterIntoLookup(uint32_t charCode, FontId fontId );
208 * Reset the dead time stamps of all glyph objects in the
209 * dead character list. This is called when mTimeStamp value reaches
210 * GlyphStatus::GetMaximumDeadTime()
212 void ResetTimeStamps();
215 * Get the total available space in the container.
216 * This is empty space + space used by dead characters that can be replaced
217 * @return total space
219 unsigned int TotalAvailableSpace() const;
221 unsigned int mContainerSize; ///< container size
222 unsigned int mEmptySpace; ///< amount of space that is empty (has never been used)
225 * Status pointer set typedef, sorted by custom function
227 typedef std::set< const GlyphStatus*, GlyphStatus::PointerComparator > StatusPointerSet;
229 StatusSet mCharacterLookup; ///< set of glyph status objects sorted by font id and character code
230 StatusPointerSet mDeadCharacters; ///< set of characters with a ref count of zero, which are still cached.
231 unsigned int mTimeStamp; ///< current time stamp
236 } // namespace Internal
240 #endif // __DALI_INTERNAL_GLYPH_STATUS_CONTAINER_H__