5e58f38819a0d97b83275e04b14eaa0a0e8ec7df
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / metrics.h
1 #ifndef __DALI_TOOLKIT_TEXT_METRICS_H__
2 #define __DALI_TOOLKIT_TEXT_METRICS_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 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/intrusive-ptr.h>
23 #include <dali/devel-api/text-abstraction/font-client.h>
24
25 namespace Dali
26 {
27
28 namespace Toolkit
29 {
30
31 namespace Text
32 {
33
34 class Metrics;
35 typedef IntrusivePtr<Metrics> MetricsPtr;
36
37 /**
38  * @brief A wrapper around FontClient used to get metrics & potentially down-scaled Emoji metrics.
39  */
40 class Metrics : public RefObject
41 {
42 public:
43
44   /**
45    * Create a new Metrics object
46    */
47   static Metrics* New( TextAbstraction::FontClient& fontClient )
48   {
49     return new Metrics( fontClient );
50   }
51
52   /**
53    * @brief Used to switch between bitmap & vector based glyphs
54    *
55    * @param[in] glyphType The type of glyph; note that metrics for bitmap & vector based glyphs are different.
56    */
57   void SetGlyphType( TextAbstraction::GlyphType glyphType )
58   {
59     mGlyphType = glyphType;
60   }
61
62   /**
63    * @brief Set the maximum Emoji size.
64    *
65    * @param[in] emojiSize Emoticons will be scaled to fit this size in pixels.
66    */
67   void SetMaxEmojiSize( int emojiSize )
68   {
69     mEmojiSize = emojiSize;
70   }
71
72   /**
73    * @brief Get the maximum Emoji size.
74    *
75    * @return The maximum Emoji size.
76    */
77   int GetMaxEmojiSize() const
78   {
79     return mEmojiSize;
80   }
81
82   /**
83    * @brief Query the metrics for a font.
84    *
85    * @param[in] fontId The ID of the font for the required glyph.
86    * @param[out] metrics The font metrics.
87    */
88   void GetFontMetrics( FontId fontId, FontMetrics& metrics )
89   {
90     mFontClient.GetFontMetrics( fontId, metrics, mEmojiSize ); // inline for performance
91   }
92
93   /**
94    * @brief Retrieve the metrics for a series of glyphs.
95    *
96    * @param[in,out] array An array of glyph-info structures with initialized FontId & GlyphIndex values.
97    * It may contain the advance and an offset set into the bearing from the shaping tool.
98    * On return, the glyph's size value will be initialized. The bearing value will be updated by adding the font's glyph bearing to the one set by the shaping tool.
99    * @param[in] size The size of the array.
100    * @return True if all of the requested metrics were found.
101    */
102   bool GetGlyphMetrics( GlyphInfo* array, uint32_t size )
103   {
104     return mFontClient.GetGlyphMetrics( array, size, mGlyphType, true, mEmojiSize ); // inline for performance
105   }
106
107 protected:
108
109   /**
110    * A reference counted object may only be deleted by calling Unreference()
111    */
112   virtual ~Metrics() {}
113
114 private:
115
116   /**
117    * Constructor.
118    */
119   Metrics( TextAbstraction::FontClient& fontClient )
120   : mFontClient( fontClient ),
121     mGlyphType( TextAbstraction::BITMAP_GLYPH ),
122     mEmojiSize( 0 )
123   {
124   }
125
126   // Undefined
127   Metrics(const Metrics&);
128
129   // Undefined
130   Metrics& operator=(const Metrics& rhs);
131
132 private:
133
134   TextAbstraction::FontClient mFontClient;
135   TextAbstraction::GlyphType mGlyphType;
136   int mEmojiSize;
137 };
138
139 } // namespace Text
140
141 } // namespace Toolkit
142
143 } // namespace Dali
144
145 #endif // __DALI_TOOLKIT_TEXT_METRICS_H__