5008e5777f2e16ec6ed4c52d01af2151515e7aad
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / text-abstraction / font-client.cpp
1 /*
2  * Copyright (c) 2023 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::New(uint32_t horizontalDpi, uint32_t verticalDpi)
61 {
62   auto fontClientImpl = new Internal::FontClient();
63
64   fontClientImpl->SetDpi(horizontalDpi, verticalDpi);
65
66   return FontClient(fontClientImpl);
67 }
68
69 FontClient::FontClient()
70 {
71 }
72
73 FontClient::~FontClient()
74 {
75 }
76
77 FontClient::FontClient(const FontClient& handle) = default;
78
79 FontClient& FontClient::operator=(const FontClient& handle) = default;
80
81 FontClient::FontClient(FontClient&& handle) = default;
82
83 FontClient& FontClient::operator=(FontClient&& handle) = default;
84
85 void FontClient::ClearCache()
86 {
87   GetImplementation(*this).ClearCache();
88 }
89
90 void FontClient::SetDpi(unsigned int horizontalDpi, unsigned int verticalDpi)
91 {
92   GetImplementation(*this).SetDpi(horizontalDpi, verticalDpi);
93 }
94
95 void FontClient::GetDpi(unsigned int& horizontalDpi, unsigned int& verticalDpi)
96 {
97   GetImplementation(*this).GetDpi(horizontalDpi, verticalDpi);
98 }
99
100 int FontClient::GetDefaultFontSize()
101 {
102   return GetImplementation(*this).GetDefaultFontSize();
103 }
104
105 void FontClient::ResetSystemDefaults()
106 {
107   GetImplementation(*this).ResetSystemDefaults();
108 }
109
110 void FontClient::GetDefaultFonts(FontList& defaultFonts)
111 {
112   GetImplementation(*this).GetDefaultFonts(defaultFonts);
113 }
114
115 void FontClient::InitDefaultFontDescription()
116 {
117   GetImplementation(*this).InitDefaultFontDescription();
118 }
119
120 void FontClient::GetDefaultPlatformFontDescription(FontDescription& fontDescription)
121 {
122   GetImplementation(*this).GetDefaultPlatformFontDescription(fontDescription);
123 }
124
125 void FontClient::GetSystemFonts(FontList& systemFonts)
126 {
127   GetImplementation(*this).GetSystemFonts(systemFonts);
128 }
129
130 void FontClient::GetDescription(FontId fontId, FontDescription& fontDescription)
131 {
132   GetImplementation(*this).GetDescription(fontId, fontDescription);
133 }
134
135 PointSize26Dot6 FontClient::GetPointSize(FontId fontId)
136 {
137   return GetImplementation(*this).GetPointSize(fontId);
138 }
139
140 bool FontClient::IsCharacterSupportedByFont(FontId fontId, Character character)
141 {
142   return GetImplementation(*this).IsCharacterSupportedByFont(fontId, character);
143 }
144
145 FontId FontClient::FindDefaultFont(Character       charcode,
146                                    PointSize26Dot6 requestedPointSize,
147                                    bool            preferColor)
148 {
149   return GetImplementation(*this).FindDefaultFont(charcode,
150                                                   requestedPointSize,
151                                                   preferColor);
152 }
153
154 FontId FontClient::FindFallbackFont(Character              charcode,
155                                     const FontDescription& preferredFontDescription,
156                                     PointSize26Dot6        requestedPointSize,
157                                     bool                   preferColor)
158 {
159   return GetImplementation(*this).FindFallbackFont(charcode, preferredFontDescription, requestedPointSize, preferColor);
160 }
161
162 FontId FontClient::GetFontId(const FontPath& path, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex)
163 {
164   return GetImplementation(*this).GetFontId(path, requestedPointSize, faceIndex);
165 }
166
167 FontId FontClient::GetFontId(const FontDescription& fontDescription,
168                              PointSize26Dot6        requestedPointSize,
169                              FaceIndex              faceIndex)
170 {
171   return GetImplementation(*this).GetFontId(fontDescription,
172                                             requestedPointSize,
173                                             faceIndex);
174 }
175
176 FontId FontClient::GetFontId(const BitmapFont& bitmapFont)
177 {
178   return GetImplementation(*this).GetFontId(bitmapFont);
179 }
180
181 bool FontClient::IsScalable(const FontPath& path)
182 {
183   return GetImplementation(*this).IsScalable(path);
184 }
185
186 bool FontClient::IsScalable(const FontDescription& fontDescription)
187 {
188   return GetImplementation(*this).IsScalable(fontDescription);
189 }
190
191 void FontClient::GetFixedSizes(const FontPath& path, Dali::Vector<PointSize26Dot6>& sizes)
192 {
193   GetImplementation(*this).GetFixedSizes(path, sizes);
194 }
195
196 void FontClient::GetFixedSizes(const FontDescription&         fontDescription,
197                                Dali::Vector<PointSize26Dot6>& sizes)
198 {
199   GetImplementation(*this).GetFixedSizes(fontDescription, sizes);
200 }
201
202 bool FontClient::HasItalicStyle(FontId fontId) const
203 {
204   return GetImplementation(*this).HasItalicStyle(fontId);
205 }
206
207 void FontClient::GetFontMetrics(FontId fontId, FontMetrics& metrics)
208 {
209   GetImplementation(*this).GetFontMetrics(fontId, metrics);
210 }
211
212 GlyphIndex FontClient::GetGlyphIndex(FontId fontId, Character charcode)
213 {
214   return GetImplementation(*this).GetGlyphIndex(fontId, charcode);
215 }
216
217 GlyphIndex FontClient::GetGlyphIndex(FontId fontId, Character charcode, Character variantSelector)
218 {
219   return GetImplementation(*this).GetGlyphIndex(fontId, charcode, variantSelector);
220 }
221
222 bool FontClient::GetGlyphMetrics(GlyphInfo* array, uint32_t size, GlyphType type, bool horizontal)
223 {
224   return GetImplementation(*this).GetGlyphMetrics(array, size, type, horizontal);
225 }
226
227 void FontClient::CreateBitmap(FontId fontId, GlyphIndex glyphIndex, bool isItalicRequired, bool isBoldRequired, GlyphBufferData& data, int outlineWidth)
228 {
229   GetImplementation(*this).CreateBitmap(fontId, glyphIndex, isItalicRequired, isBoldRequired, data, outlineWidth);
230 }
231
232 PixelData FontClient::CreateBitmap(FontId fontId, GlyphIndex glyphIndex, int outlineWidth)
233 {
234   return GetImplementation(*this).CreateBitmap(fontId, glyphIndex, outlineWidth);
235 }
236
237 void FontClient::CreateVectorBlob(FontId fontId, GlyphIndex glyphIndex, VectorBlob*& blob, unsigned int& blobLength, unsigned int& nominalWidth, unsigned int& nominalHeight)
238 {
239   GetImplementation(*this).CreateVectorBlob(fontId, glyphIndex, blob, blobLength, nominalWidth, nominalHeight);
240 }
241
242 const GlyphInfo& FontClient::GetEllipsisGlyph(PointSize26Dot6 requestedPointSize)
243 {
244   return GetImplementation(*this).GetEllipsisGlyph(requestedPointSize);
245 }
246
247 bool FontClient::IsColorGlyph(FontId fontId, GlyphIndex glyphIndex)
248 {
249   return GetImplementation(*this).IsColorGlyph(fontId, glyphIndex);
250 }
251
252 bool FontClient::AddCustomFontDirectory(const FontPath& path)
253 {
254   return GetImplementation(*this).AddCustomFontDirectory(path);
255 }
256
257 GlyphIndex FontClient::CreateEmbeddedItem(const EmbeddedItemDescription& description, Pixel::Format& pixelFormat)
258 {
259   return GetImplementation(*this).CreateEmbeddedItem(description, pixelFormat);
260 }
261
262 void FontClient::EnableAtlasLimitation(bool enabled)
263 {
264   return GetImplementation(*this).EnableAtlasLimitation(enabled);
265 }
266
267 bool FontClient::IsAtlasLimitationEnabled() const
268 {
269   return GetImplementation(*this).IsAtlasLimitationEnabled();
270 }
271
272 Size FontClient::GetMaximumTextAtlasSize() const
273 {
274   return GetImplementation(*this).GetMaximumTextAtlasSize();
275 }
276
277 Size FontClient::GetDefaultTextAtlasSize() const
278 {
279   return GetImplementation(*this).GetDefaultTextAtlasSize();
280 }
281
282 Size FontClient::GetCurrentMaximumBlockSizeFitInAtlas() const
283 {
284   return GetImplementation(*this).GetCurrentMaximumBlockSizeFitInAtlas();
285 }
286
287 bool FontClient::SetCurrentMaximumBlockSizeFitInAtlas(const Size& currentMaximumBlockSizeFitInAtlas)
288 {
289   return GetImplementation(*this).SetCurrentMaximumBlockSizeFitInAtlas(currentMaximumBlockSizeFitInAtlas);
290 }
291
292 uint32_t FontClient::GetNumberOfPointsPerOneUnitOfPointSize() const
293 {
294   return GetImplementation(*this).GetNumberOfPointsPerOneUnitOfPointSize();
295 }
296
297 FontClient::FontClient(Internal::FontClient* internal)
298 : BaseHandle(internal)
299 {
300 }
301
302 FontClient FontClientPreInitialize()
303 {
304   return Internal::FontClient::PreInitialize();
305 }
306
307 void FontClientPreCache(const FontFamilyList& fallbackFamilyList, const FontFamilyList& extraFamilyList, const FontFamily& localeFamily, bool useThread, bool syncCreation)
308 {
309   Internal::FontClient::PreCache(fallbackFamilyList, extraFamilyList, localeFamily, useThread, syncCreation);
310 }
311
312 void FontClientFontPreLoad(const FontPathList& fontPathList, const FontPathList& memoryFontPathList, bool useThread, bool syncCreation)
313 {
314   Internal::FontClient::PreLoad(fontPathList, memoryFontPathList, useThread, syncCreation);
315 }
316
317 } // namespace TextAbstraction
318
319 } // namespace Dali