Make GlyphBufferData as another class
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / text-abstraction / font-client.cpp
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/devel-api/text-abstraction/font-client.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/internal/text/text-abstraction/font-client-impl.h>
23
24 namespace Dali
25 {
26 namespace TextAbstraction
27 {
28 // FontClient static const value definition.
29
30 const PointSize26Dot6 FontClient::DEFAULT_POINT_SIZE   = 768u;                           // 12*64
31 const float           FontClient::DEFAULT_ITALIC_ANGLE = 12.f * Dali::Math::PI_OVER_180; // FreeType documentation states the software italic is done by doing a horizontal shear of 12 degrees (file ftsynth.h).
32
33 //Default atlas block
34 const bool     FontClient::DEFAULT_ATLAS_LIMITATION_ENABLED = true;
35 const uint32_t FontClient::DEFAULT_TEXT_ATLAS_WIDTH         = 512u;
36 const uint32_t FontClient::DEFAULT_TEXT_ATLAS_HEIGHT        = 512u;
37 const Size     FontClient::DEFAULT_TEXT_ATLAS_SIZE(DEFAULT_TEXT_ATLAS_WIDTH, DEFAULT_TEXT_ATLAS_HEIGHT);
38
39 //Maximum atlas block
40 const uint32_t FontClient::MAX_TEXT_ATLAS_WIDTH  = 1024u;
41 const uint32_t FontClient::MAX_TEXT_ATLAS_HEIGHT = 1024u;
42 const Size     FontClient::MAX_TEXT_ATLAS_SIZE(MAX_TEXT_ATLAS_WIDTH, MAX_TEXT_ATLAS_HEIGHT);
43
44 //MAX_WIDTH_FIT_IN_ATLAS: blockWidth + 2 * DOUBLE_PIXEL_PADDING + 1u <= atlasWidth
45 //MAX_HEIGHT_FIT_IN_ATLAS: blockHeight + 2 * DOUBLE_PIXEL_PADDING + 1u <= atlasHeight
46 const uint16_t FontClient::PADDING_TEXT_ATLAS_BLOCK = 5u; // 2 * DOUBLE_PIXEL_PADDING + 1u
47
48 //Maximum block size to fit into atlas block
49 const Size FontClient::MAX_SIZE_FIT_IN_ATLAS(MAX_TEXT_ATLAS_WIDTH - PADDING_TEXT_ATLAS_BLOCK, MAX_TEXT_ATLAS_HEIGHT - PADDING_TEXT_ATLAS_BLOCK);
50
51 const uint32_t FontClient::NUMBER_OF_POINTS_PER_ONE_UNIT_OF_POINT_SIZE = 64u; //Found this value from toolkit
52
53 // FontClient
54
55 FontClient FontClient::Get()
56 {
57   return Internal::FontClient::Get();
58 }
59
60 FontClient::FontClient()
61 {
62 }
63
64 FontClient::~FontClient()
65 {
66 }
67
68 FontClient::FontClient(const FontClient& handle) = default;
69
70 FontClient& FontClient::operator=(const FontClient& handle) = default;
71
72 FontClient::FontClient(FontClient&& handle) = default;
73
74 FontClient& FontClient::operator=(FontClient&& handle) = default;
75
76 void FontClient::ClearCache()
77 {
78   GetImplementation(*this).ClearCache();
79 }
80
81 void FontClient::SetDpi(unsigned int horizontalDpi, unsigned int verticalDpi)
82 {
83   GetImplementation(*this).SetDpi(horizontalDpi, verticalDpi);
84 }
85
86 void FontClient::GetDpi(unsigned int& horizontalDpi, unsigned int& verticalDpi)
87 {
88   GetImplementation(*this).GetDpi(horizontalDpi, verticalDpi);
89 }
90
91 int FontClient::GetDefaultFontSize()
92 {
93   return GetImplementation(*this).GetDefaultFontSize();
94 }
95
96 void FontClient::ResetSystemDefaults()
97 {
98   GetImplementation(*this).ResetSystemDefaults();
99 }
100
101 void FontClient::GetDefaultFonts(FontList& defaultFonts)
102 {
103   GetImplementation(*this).GetDefaultFonts(defaultFonts);
104 }
105
106 void FontClient::GetDefaultPlatformFontDescription(FontDescription& fontDescription)
107 {
108   GetImplementation(*this).GetDefaultPlatformFontDescription(fontDescription);
109 }
110
111 void FontClient::GetSystemFonts(FontList& systemFonts)
112 {
113   GetImplementation(*this).GetSystemFonts(systemFonts);
114 }
115
116 void FontClient::GetDescription(FontId fontId, FontDescription& fontDescription)
117 {
118   GetImplementation(*this).GetDescription(fontId, fontDescription);
119 }
120
121 PointSize26Dot6 FontClient::GetPointSize(FontId fontId)
122 {
123   return GetImplementation(*this).GetPointSize(fontId);
124 }
125
126 bool FontClient::IsCharacterSupportedByFont(FontId fontId, Character character)
127 {
128   return GetImplementation(*this).IsCharacterSupportedByFont(fontId, character);
129 }
130
131 FontId FontClient::FindDefaultFont(Character       charcode,
132                                    PointSize26Dot6 requestedPointSize,
133                                    bool            preferColor)
134 {
135   return GetImplementation(*this).FindDefaultFont(charcode,
136                                                   requestedPointSize,
137                                                   preferColor);
138 }
139
140 FontId FontClient::FindFallbackFont(Character              charcode,
141                                     const FontDescription& preferredFontDescription,
142                                     PointSize26Dot6        requestedPointSize,
143                                     bool                   preferColor)
144 {
145   return GetImplementation(*this).FindFallbackFont(charcode, preferredFontDescription, requestedPointSize, preferColor);
146 }
147
148 FontId FontClient::GetFontId(const FontPath& path, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex)
149 {
150   return GetImplementation(*this).GetFontId(path, requestedPointSize, faceIndex);
151 }
152
153 FontId FontClient::GetFontId(const FontDescription& fontDescription,
154                              PointSize26Dot6        requestedPointSize,
155                              FaceIndex              faceIndex)
156 {
157   return GetImplementation(*this).GetFontId(fontDescription,
158                                             requestedPointSize,
159                                             faceIndex);
160 }
161
162 FontId FontClient::GetFontId(const BitmapFont& bitmapFont)
163 {
164   return GetImplementation(*this).GetFontId(bitmapFont);
165 }
166
167 bool FontClient::IsScalable(const FontPath& path)
168 {
169   return GetImplementation(*this).IsScalable(path);
170 }
171
172 bool FontClient::IsScalable(const FontDescription& fontDescription)
173 {
174   return GetImplementation(*this).IsScalable(fontDescription);
175 }
176
177 void FontClient::GetFixedSizes(const FontPath& path, Dali::Vector<PointSize26Dot6>& sizes)
178 {
179   GetImplementation(*this).GetFixedSizes(path, sizes);
180 }
181
182 void FontClient::GetFixedSizes(const FontDescription&         fontDescription,
183                                Dali::Vector<PointSize26Dot6>& sizes)
184 {
185   GetImplementation(*this).GetFixedSizes(fontDescription, sizes);
186 }
187
188 bool FontClient::HasItalicStyle(FontId fontId) const
189 {
190   return GetImplementation(*this).HasItalicStyle(fontId);
191 }
192
193 void FontClient::GetFontMetrics(FontId fontId, FontMetrics& metrics)
194 {
195   GetImplementation(*this).GetFontMetrics(fontId, metrics);
196 }
197
198 GlyphIndex FontClient::GetGlyphIndex(FontId fontId, Character charcode)
199 {
200   return GetImplementation(*this).GetGlyphIndex(fontId, charcode);
201 }
202
203 GlyphIndex FontClient::GetGlyphIndex(FontId fontId, Character charcode, Character variantSelector)
204 {
205   return GetImplementation(*this).GetGlyphIndex(fontId, charcode, variantSelector);
206 }
207
208 bool FontClient::GetGlyphMetrics(GlyphInfo* array, uint32_t size, GlyphType type, bool horizontal)
209 {
210   return GetImplementation(*this).GetGlyphMetrics(array, size, type, horizontal);
211 }
212
213 void FontClient::CreateBitmap(FontId fontId, GlyphIndex glyphIndex, bool isItalicRequired, bool isBoldRequired, GlyphBufferData& data, int outlineWidth)
214 {
215   GetImplementation(*this).CreateBitmap(fontId, glyphIndex, isItalicRequired, isBoldRequired, data, outlineWidth);
216 }
217
218 PixelData FontClient::CreateBitmap(FontId fontId, GlyphIndex glyphIndex, int outlineWidth)
219 {
220   return GetImplementation(*this).CreateBitmap(fontId, glyphIndex, outlineWidth);
221 }
222
223 void FontClient::CreateVectorBlob(FontId fontId, GlyphIndex glyphIndex, VectorBlob*& blob, unsigned int& blobLength, unsigned int& nominalWidth, unsigned int& nominalHeight)
224 {
225   GetImplementation(*this).CreateVectorBlob(fontId, glyphIndex, blob, blobLength, nominalWidth, nominalHeight);
226 }
227
228 const GlyphInfo& FontClient::GetEllipsisGlyph(PointSize26Dot6 requestedPointSize)
229 {
230   return GetImplementation(*this).GetEllipsisGlyph(requestedPointSize);
231 }
232
233 bool FontClient::IsColorGlyph(FontId fontId, GlyphIndex glyphIndex)
234 {
235   return GetImplementation(*this).IsColorGlyph(fontId, glyphIndex);
236 }
237
238 bool FontClient::AddCustomFontDirectory(const FontPath& path)
239 {
240   return GetImplementation(*this).AddCustomFontDirectory(path);
241 }
242
243 GlyphIndex FontClient::CreateEmbeddedItem(const EmbeddedItemDescription& description, Pixel::Format& pixelFormat)
244 {
245   return GetImplementation(*this).CreateEmbeddedItem(description, pixelFormat);
246 }
247
248 void FontClient::EnableAtlasLimitation(bool enabled)
249 {
250   return GetImplementation(*this).EnableAtlasLimitation(enabled);
251 }
252
253 bool FontClient::IsAtlasLimitationEnabled() const
254 {
255   return GetImplementation(*this).IsAtlasLimitationEnabled();
256 }
257
258 Size FontClient::GetMaximumTextAtlasSize() const
259 {
260   return GetImplementation(*this).GetMaximumTextAtlasSize();
261 }
262
263 Size FontClient::GetDefaultTextAtlasSize() const
264 {
265   return GetImplementation(*this).GetDefaultTextAtlasSize();
266 }
267
268 Size FontClient::GetCurrentMaximumBlockSizeFitInAtlas() const
269 {
270   return GetImplementation(*this).GetCurrentMaximumBlockSizeFitInAtlas();
271 }
272
273 bool FontClient::SetCurrentMaximumBlockSizeFitInAtlas(const Size& currentMaximumBlockSizeFitInAtlas)
274 {
275   return GetImplementation(*this).SetCurrentMaximumBlockSizeFitInAtlas(currentMaximumBlockSizeFitInAtlas);
276 }
277
278 uint32_t FontClient::GetNumberOfPointsPerOneUnitOfPointSize() const
279 {
280   return GetImplementation(*this).GetNumberOfPointsPerOneUnitOfPointSize();
281 }
282
283 FontClient::FontClient(Internal::FontClient* internal)
284 : BaseHandle(internal)
285 {
286 }
287
288 FontClient FontClientPreInitialize()
289 {
290   return Internal::FontClient::PreInitialize();
291 }
292
293 } // namespace TextAbstraction
294
295 } // namespace Dali