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