Merge "Fix setting a void string to the TEXT property." into devel/master
[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 Set the maximum Emoji size.
54    *
55    * @param[in] emojiSize Emoticons will be scaled to fit this size in pixels.
56    */
57   void SetMaxEmojiSize( int emojiSize )
58   {
59     mEmojiSize = emojiSize;
60   }
61
62   /**
63    * @brief Get the maximum Emoji size.
64    *
65    * @return The maximum Emoji size.
66    */
67   int GetMaxEmojiSize() const
68   {
69     return mEmojiSize;
70   }
71
72   /**
73    * @brief Query the metrics for a font.
74    *
75    * @param[in] fontId The ID of the font for the required glyph.
76    * @param[out] metrics The font metrics.
77    */
78   void GetFontMetrics( FontId fontId, FontMetrics& metrics )
79   {
80     mFontClient.GetFontMetrics( fontId, metrics, mEmojiSize ); // inline for performance
81   }
82
83   /**
84    * @brief Retrieve the metrics for a series of glyphs.
85    *
86    * @param[in,out] array An array of glyph-info structures with initialized FontId & GlyphIndex values.
87    * It may contain the advance and an offset set into the bearing from the shaping tool.
88    * 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.
89    * @param[in] size The size of the array.
90    * @return True if all of the requested metrics were found.
91    */
92   bool GetGlyphMetrics( GlyphInfo* array, uint32_t size )
93   {
94     return mFontClient.GetGlyphMetrics( array, size, true, mEmojiSize ); // inline for performance
95   }
96
97 protected:
98
99   /**
100    * A reference counted object may only be deleted by calling Unreference()
101    */
102   virtual ~Metrics() {}
103
104 private:
105
106   /**
107    * Constructor.
108    */
109   Metrics( TextAbstraction::FontClient& fontClient )
110   : mFontClient( fontClient ),
111     mEmojiSize( 0 )
112   {
113   }
114
115   // Undefined
116   Metrics(const Metrics&);
117
118   // Undefined
119   Metrics& operator=(const Metrics& rhs);
120
121 private:
122
123   TextAbstraction::FontClient mFontClient;
124
125   int mEmojiSize;
126 };
127
128 } // namespace Text
129
130 } // namespace Toolkit
131
132 } // namespace Dali
133
134 #endif // __DALI_TOOLKIT_TEXT_METRICS_H__