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