[dali_1.0.31] Merge branch 'tizen'
[platform/core/uifw/dali-core.git] / dali / internal / event / text / font-factory.h
1 #ifndef __DALI_INTERNAL_FONT_FACTORY_H__
2 #define __DALI_INTERNAL_FONT_FACTORY_H__
3
4 /*
5  * Copyright (c) 2014 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/internal/event/text/atlas/glyph-atlas-manager-interface.h>
23 #include <dali/internal/event/text/font-metrics.h>
24 #include <dali/internal/event/text/resource/font-lookup-interface.h>
25
26 namespace Dali
27 {
28
29 namespace Internal
30 {
31
32 class ResourceClient;
33 class GlyphAtlasManager;
34
35 /**
36  * FontFactory is used to do the following:
37  * - create FontMetric objects
38  * - Allocate Atlas Manager
39  * - provide a FontLookupInterface
40  *
41  * @todo class needs renaming, possibly splitting as it's
42  * doing more than one thing.
43  */
44 class FontFactory : public FontLookupInterface
45 {
46 public:
47
48   /**
49    * default constructor
50    * @param resource client
51    */
52   FontFactory( ResourceClient& resourceClient );
53
54   /**
55    * Default destructor
56    */
57   virtual ~FontFactory();
58
59   /**
60    * Gets a pre-existing font metrics object, or creates a new one if not found.
61    * @param[in] fontFamily The name of the font's family used to generate a hash for fast lookup
62    * @param[in] fontStyle The font's style used to generate a hash for fast lookup
63    * @return a pointer to a ref counted object
64    */
65   FontMetricsIntrusivePtr GetFontMetrics( const std::string& fontFamily, const std::string& fontStyle );
66
67   /**
68    * Removes the font metrics associated with a font, from the font factory cache.
69    *
70    * @param[in] fontFamily The name of the font's family used to generate a hash for fast lookup
71    * @param[in] fontStyle The font's style used to generate a hash for fast lookup
72    */
73   void RemoveFontMetrics(const std::string& fontFamily,
74                          const std::string& fontStyle);
75
76   /**
77    * Send a single resource request for any text which is required, but is not loaded.
78    * Should be called at the end of each event cycle.
79    */
80   void SendTextRequests();
81
82   /**
83    * Get the glyph atlas manager interface
84    * @return atlas manager interface
85    */
86   GlyphAtlasManagerInterface& GetAtlasManagerInterface();
87
88   /**
89    * set the dpi
90    * @param[in] horizontalDpi horizontal dpi
91    * @param[in] verticalDpi vertical dpi
92    */
93   void SetDpi( float horizontalDpi, float verticalDpi );
94
95   /**
96    * Called when context has been regained after a loss. The text subsystem will
97    * reload the glyphs into a new atlas and inform their observers.
98    */
99   void RecoverFromContextLoss();
100
101 public: // FontLookupInterface
102
103   /**
104    * @copydoc FontLookupInterface::GetFontInformation()
105    */
106   virtual void GetFontInformation( FontId fontId,
107                                    std::string& family,
108                                    std::string& style,
109                                    float& maxGlyphWidth,
110                                    float& maxGlyphHeight ) const;
111
112 private:
113
114   // Undefined
115   FontFactory( const FontFactory& );
116
117   // Undefined
118   FontFactory& operator=( const FontFactory& rhs );
119
120 private:
121
122   GlyphAtlasManager* mAtlasManager;     ///< Font atlas manager
123   ResourceClient& mResourceClient;      ///< resource client
124   FontMetricsMap mMetricsCache;         ///< Cache of font metrics
125   unsigned int mFontCount;              ///< font count
126   float mHorizontalDpi;                 ///< horizontal dpi
127   float mVerticalDpi;                   ///< vertical dpi
128
129 };
130
131 } // namespace Internal
132
133 } // namespace Dali
134
135 #endif // __DALI_INTERNAL_FONT_FACTORY_H__