[dali_1.0.43] Merge branch 'tizen'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / rendering / atlas / atlas-glyph-manager.h
1 #ifndef __DALI_TOOLKIT_ATLAS_GLYPH_MANAGER_H__
2 #define __DALI_TOOLKIT_ATLAS_GLYPH_MANAGER_H__
3
4 /*
5  * Copyright (c) 2015 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 // INTERNAL INCLUDES
22 #include <dali-toolkit/internal/atlas-manager/atlas-manager.h>
23 #include <dali-toolkit/internal/text/text-definitions.h>
24
25 namespace Dali
26 {
27
28 namespace Toolkit
29 {
30
31 namespace Internal DALI_INTERNAL
32 {
33 class AtlasGlyphManager;
34 }
35
36
37 class AtlasGlyphManager : public BaseHandle
38 {
39 public:
40
41   /**
42    * Description of GlyphManager state
43    */
44   struct Metrics
45   {
46     uint32_t mGlyphCount;                   // number of glyphs being managed
47     AtlasManager::Metrics mAtlasMetrics;    // metrics from the Atlas Manager
48   };
49
50   /**
51    * @brief Create a AtlasGlyphManager handle.
52    *
53    * Calling member functions with an uninitialised handle is not allowed.
54    */
55   AtlasGlyphManager();
56
57   /**
58    * @brief Destructor
59    *
60    * This is non-virtual since derived Handle types must not contain data or virtual methods.
61    */
62   ~AtlasGlyphManager();
63
64   /**
65    * @brief Create or retrieve AtlasGlyphManager singleton.
66    *
67    * @return A handle to the AtlasGlyphManager control.
68    */
69   static AtlasGlyphManager Get();
70
71   /**
72    * @brief Ask Atlas Manager to add a glyph
73    *
74    * @param[in] glyph glyph to add to an atlas
75    * @param[in] bitmap bitmap to use for glyph addition
76    * @param[out] slot information returned by atlas manager for addition
77    */
78   void Add( const Text::GlyphInfo& glyph,
79             const BufferImage& bitmap,
80             AtlasManager::AtlasSlot& slot );
81
82   /**
83    * @brief Generate mesh data for an image contained in an atlas
84    *
85    * @param[in] imageId ID of image to generate geometry for
86    * @param[in] position top left of image
87    * @param[out] meshData generated MeshData
88    */
89   void GenerateMeshData( uint32_t imageId,
90                          const Vector2& position,
91                          MeshData& meshData );
92
93   /**
94    * @brief Stitch Two Meshes together
95    *
96    * @param[in] first first mesh
97    * @param[in] second second mesh
98    */
99   void StitchMesh( MeshData& first,
100                    const MeshData& second );
101
102   /**
103    * @brief Check to see if a glyph is being cached
104    *
105    * @param[in] fontId The font that this glyph comes from
106    * @param[in] index The GlyphIndex of this glyph
107    * @param[out] slot container holding information about the glyph( mImage = 0 indicates not being cached )
108    */
109   void Cached( Text::FontId fontId,
110                Text::GlyphIndex index,
111                AtlasManager::AtlasSlot& slot );
112
113   /**
114    * @brief Retrieve the size of an atlas
115    *
116    * @param[in] atlasId Id of the atlas to interrogate
117    *
118    * @return The pixel size of the atlas
119    */
120   Vector2 GetAtlasSize( uint32_t atlasId );
121
122    /**
123     * @brief Set the atlas size and block size for subsequent Atlas generation
124     *
125     * @param[in] width width of atlas in pixels
126     * @param[in] height height of atlas in pixels
127     * @param[in] blockWidth width of a block in pixels
128     * @param[in] blockHeight height of a block in pixels
129     */
130   void SetNewAtlasSize( uint32_t width, uint32_t height, uint32_t blockWidth, uint32_t blockHeight );
131
132   /**
133    * @brief Unreference an image from the atlas and remove from cache if no longer needed
134    *
135    * @param[in] imageId ID of the image
136    */
137   void Remove( uint32_t imageId );
138
139   /**
140    * @brief Get the Pixel Format used by an atlas
141    *
142    * @param[in] atlasId Id of atlas to check
143    *
144    * @return The pixel format of the atlas
145    */
146   Pixel::Format GetPixelFormat( uint32_t atlasId );
147
148   /**
149    * @brief Get Glyph Manager metrics
150    *
151    * @return const reference to glyph manager metrics
152    */
153   const Metrics& GetMetrics();
154
155 private:
156
157   explicit DALI_INTERNAL AtlasGlyphManager(Internal::AtlasGlyphManager *impl);
158
159 };
160
161 } // namespace Toolkit
162
163 } // namespace Dali
164
165 #endif // __DALI_TOOLKIT_ATLAS_GLYPH_MANAGER_H__