[dali_2.3.25] Merge branch 'devel/master'
[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/devel-api/adaptor-framework/environment-variable.h>
23 #include <dali/internal/text/text-abstraction/font-client-impl.h>
24
25 namespace Dali
26 {
27 namespace TextAbstraction
28 {
29 // FontClient static const value definition.
30
31 const PointSize26Dot6 FontClient::DEFAULT_POINT_SIZE   = 768u;                           // 12*64
32 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).
33
34 //Default atlas block
35 const bool     FontClient::DEFAULT_ATLAS_LIMITATION_ENABLED = true;
36 const uint32_t FontClient::DEFAULT_TEXT_ATLAS_WIDTH         = 512u;
37 const uint32_t FontClient::DEFAULT_TEXT_ATLAS_HEIGHT        = 512u;
38 const Size     FontClient::DEFAULT_TEXT_ATLAS_SIZE(DEFAULT_TEXT_ATLAS_WIDTH, DEFAULT_TEXT_ATLAS_HEIGHT);
39
40 //Maximum atlas block
41 const uint32_t FontClient::MAX_TEXT_ATLAS_WIDTH  = 1024u;
42 const uint32_t FontClient::MAX_TEXT_ATLAS_HEIGHT = 1024u;
43 const Size     FontClient::MAX_TEXT_ATLAS_SIZE(MAX_TEXT_ATLAS_WIDTH, MAX_TEXT_ATLAS_HEIGHT);
44
45 //MAX_WIDTH_FIT_IN_ATLAS: blockWidth + 2 * DOUBLE_PIXEL_PADDING + 1u <= atlasWidth
46 //MAX_HEIGHT_FIT_IN_ATLAS: blockHeight + 2 * DOUBLE_PIXEL_PADDING + 1u <= atlasHeight
47 const uint16_t FontClient::PADDING_TEXT_ATLAS_BLOCK = 5u; // 2 * DOUBLE_PIXEL_PADDING + 1u
48
49 //Maximum block size to fit into atlas block
50 const Size FontClient::MAX_SIZE_FIT_IN_ATLAS(MAX_TEXT_ATLAS_WIDTH - PADDING_TEXT_ATLAS_BLOCK, MAX_TEXT_ATLAS_HEIGHT - PADDING_TEXT_ATLAS_BLOCK);
51
52 const uint32_t FontClient::NUMBER_OF_POINTS_PER_ONE_UNIT_OF_POINT_SIZE = 64u; //Found this value from toolkit
53
54 // For Debug
55 static    bool     TEXT_PERFORMANCE_LOG_SET                = false;
56 static    uint32_t TEXT_PERFORMANCE_LOG_THRESHOLD_TIME     = 0u;
57 constexpr auto     TEXT_PERFORMANCE_LOG_THRESHOLD_TIME_ENV = "DALI_TEXT_PERFORMANCE_LOG_THRESHOLD_TIME";
58
59 uint32_t FontClient::GetPerformanceLogThresholdTime()
60 {
61   uint32_t time = TEXT_PERFORMANCE_LOG_THRESHOLD_TIME;
62   if(!TEXT_PERFORMANCE_LOG_SET)
63   {
64     // Threshold time in miliseconds.
65     auto timeString = Dali::EnvironmentVariable::GetEnvironmentVariable(TEXT_PERFORMANCE_LOG_THRESHOLD_TIME_ENV);
66     time = timeString ? static_cast<uint32_t>(std::atoi(timeString)) : 0u;
67     TEXT_PERFORMANCE_LOG_THRESHOLD_TIME = time;
68     TEXT_PERFORMANCE_LOG_SET = true;
69   }
70   return time;
71 }
72
73 bool FontClient::IsPerformanceLogEnabled()
74 {
75   return GetPerformanceLogThresholdTime() > 0 ? true : false;
76 }
77
78 // FontClient
79
80 FontClient FontClient::Get()
81 {
82   return Internal::FontClient::Get();
83 }
84
85 FontClient FontClient::New(uint32_t horizontalDpi, uint32_t verticalDpi)
86 {
87   auto fontClientImpl = new Internal::FontClient();
88
89   fontClientImpl->SetDpi(horizontalDpi, verticalDpi);
90
91   return FontClient(fontClientImpl);
92 }
93
94 FontClient::FontClient()
95 {
96 }
97
98 FontClient::~FontClient()
99 {
100 }
101
102 FontClient::FontClient(const FontClient& handle) = default;
103
104 FontClient& FontClient::operator=(const FontClient& handle) = default;
105
106 FontClient::FontClient(FontClient&& handle) = default;
107
108 FontClient& FontClient::operator=(FontClient&& handle) = default;
109
110 void FontClient::ClearCache()
111 {
112   GetImplementation(*this).ClearCache();
113 }
114
115 void FontClient::ClearCacheOnLocaleChanged()
116 {
117   GetImplementation(*this).ClearCacheOnLocaleChanged();
118 }
119
120 void FontClient::SetDpi(unsigned int horizontalDpi, unsigned int verticalDpi)
121 {
122   GetImplementation(*this).SetDpi(horizontalDpi, verticalDpi);
123 }
124
125 void FontClient::GetDpi(unsigned int& horizontalDpi, unsigned int& verticalDpi)
126 {
127   GetImplementation(*this).GetDpi(horizontalDpi, verticalDpi);
128 }
129
130 int FontClient::GetDefaultFontSize()
131 {
132   return GetImplementation(*this).GetDefaultFontSize();
133 }
134
135 void FontClient::ResetSystemDefaults()
136 {
137   GetImplementation(*this).ResetSystemDefaults();
138 }
139
140 void FontClient::GetDefaultFonts(FontList& defaultFonts)
141 {
142   GetImplementation(*this).GetDefaultFonts(defaultFonts);
143 }
144
145 void FontClient::InitDefaultFontDescription()
146 {
147   GetImplementation(*this).InitDefaultFontDescription();
148 }
149
150 void FontClient::GetDefaultPlatformFontDescription(FontDescription& fontDescription)
151 {
152   GetImplementation(*this).GetDefaultPlatformFontDescription(fontDescription);
153 }
154
155 void FontClient::GetSystemFonts(FontList& systemFonts)
156 {
157   GetImplementation(*this).GetSystemFonts(systemFonts);
158 }
159
160 void FontClient::GetDescription(FontId fontId, FontDescription& fontDescription)
161 {
162   GetImplementation(*this).GetDescription(fontId, fontDescription);
163 }
164
165 PointSize26Dot6 FontClient::GetPointSize(FontId fontId)
166 {
167   return GetImplementation(*this).GetPointSize(fontId);
168 }
169
170 bool FontClient::IsCharacterSupportedByFont(FontId fontId, Character character)
171 {
172   return GetImplementation(*this).IsCharacterSupportedByFont(fontId, character);
173 }
174
175 FontId FontClient::FindDefaultFont(Character       charcode,
176                                    PointSize26Dot6 requestedPointSize,
177                                    bool            preferColor)
178 {
179   return GetImplementation(*this).FindDefaultFont(charcode,
180                                                   requestedPointSize,
181                                                   preferColor);
182 }
183
184 FontId FontClient::FindFallbackFont(Character              charcode,
185                                     const FontDescription& preferredFontDescription,
186                                     PointSize26Dot6        requestedPointSize,
187                                     bool                   preferColor)
188 {
189   return GetImplementation(*this).FindFallbackFont(charcode, preferredFontDescription, requestedPointSize, preferColor);
190 }
191
192 FontId FontClient::GetFontId(const FontPath& path, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex)
193 {
194   return GetImplementation(*this).GetFontId(path, requestedPointSize, faceIndex);
195 }
196
197 FontId FontClient::GetFontId(const FontDescription& fontDescription,
198                              PointSize26Dot6        requestedPointSize,
199                              FaceIndex              faceIndex)
200 {
201   return GetImplementation(*this).GetFontId(fontDescription,
202                                             requestedPointSize,
203                                             faceIndex);
204 }
205
206 FontId FontClient::GetFontId(const BitmapFont& bitmapFont)
207 {
208   return GetImplementation(*this).GetFontId(bitmapFont);
209 }
210
211 bool FontClient::IsScalable(const FontPath& path)
212 {
213   return GetImplementation(*this).IsScalable(path);
214 }
215
216 bool FontClient::IsScalable(const FontDescription& fontDescription)
217 {
218   return GetImplementation(*this).IsScalable(fontDescription);
219 }
220
221 void FontClient::GetFixedSizes(const FontPath& path, Dali::Vector<PointSize26Dot6>& sizes)
222 {
223   GetImplementation(*this).GetFixedSizes(path, sizes);
224 }
225
226 void FontClient::GetFixedSizes(const FontDescription&         fontDescription,
227                                Dali::Vector<PointSize26Dot6>& sizes)
228 {
229   GetImplementation(*this).GetFixedSizes(fontDescription, sizes);
230 }
231
232 bool FontClient::HasItalicStyle(FontId fontId) const
233 {
234   return GetImplementation(*this).HasItalicStyle(fontId);
235 }
236
237 void FontClient::GetFontMetrics(FontId fontId, FontMetrics& metrics)
238 {
239   GetImplementation(*this).GetFontMetrics(fontId, metrics);
240 }
241
242 GlyphIndex FontClient::GetGlyphIndex(FontId fontId, Character charcode)
243 {
244   return GetImplementation(*this).GetGlyphIndex(fontId, charcode);
245 }
246
247 GlyphIndex FontClient::GetGlyphIndex(FontId fontId, Character charcode, Character variantSelector)
248 {
249   return GetImplementation(*this).GetGlyphIndex(fontId, charcode, variantSelector);
250 }
251
252 bool FontClient::GetGlyphMetrics(GlyphInfo* array, uint32_t size, GlyphType type, bool horizontal)
253 {
254   return GetImplementation(*this).GetGlyphMetrics(array, size, type, horizontal);
255 }
256
257 void FontClient::CreateBitmap(FontId fontId, GlyphIndex glyphIndex, bool isItalicRequired, bool isBoldRequired, GlyphBufferData& data, int outlineWidth)
258 {
259   GetImplementation(*this).CreateBitmap(fontId, glyphIndex, isItalicRequired, isBoldRequired, data, outlineWidth);
260 }
261
262 PixelData FontClient::CreateBitmap(FontId fontId, GlyphIndex glyphIndex, int outlineWidth)
263 {
264   return GetImplementation(*this).CreateBitmap(fontId, glyphIndex, outlineWidth);
265 }
266
267 void FontClient::CreateVectorBlob(FontId fontId, GlyphIndex glyphIndex, VectorBlob*& blob, unsigned int& blobLength, unsigned int& nominalWidth, unsigned int& nominalHeight)
268 {
269   GetImplementation(*this).CreateVectorBlob(fontId, glyphIndex, blob, blobLength, nominalWidth, nominalHeight);
270 }
271
272 const GlyphInfo& FontClient::GetEllipsisGlyph(PointSize26Dot6 requestedPointSize)
273 {
274   return GetImplementation(*this).GetEllipsisGlyph(requestedPointSize);
275 }
276
277 bool FontClient::IsColorGlyph(FontId fontId, GlyphIndex glyphIndex)
278 {
279   return GetImplementation(*this).IsColorGlyph(fontId, glyphIndex);
280 }
281
282 bool FontClient::AddCustomFontDirectory(const FontPath& path)
283 {
284   return GetImplementation(*this).AddCustomFontDirectory(path);
285 }
286
287 GlyphIndex FontClient::CreateEmbeddedItem(const EmbeddedItemDescription& description, Pixel::Format& pixelFormat)
288 {
289   return GetImplementation(*this).CreateEmbeddedItem(description, pixelFormat);
290 }
291
292 void FontClient::EnableAtlasLimitation(bool enabled)
293 {
294   return GetImplementation(*this).EnableAtlasLimitation(enabled);
295 }
296
297 bool FontClient::IsAtlasLimitationEnabled() const
298 {
299   return GetImplementation(*this).IsAtlasLimitationEnabled();
300 }
301
302 Size FontClient::GetMaximumTextAtlasSize() const
303 {
304   return GetImplementation(*this).GetMaximumTextAtlasSize();
305 }
306
307 Size FontClient::GetDefaultTextAtlasSize() const
308 {
309   return GetImplementation(*this).GetDefaultTextAtlasSize();
310 }
311
312 Size FontClient::GetCurrentMaximumBlockSizeFitInAtlas() const
313 {
314   return GetImplementation(*this).GetCurrentMaximumBlockSizeFitInAtlas();
315 }
316
317 bool FontClient::SetCurrentMaximumBlockSizeFitInAtlas(const Size& currentMaximumBlockSizeFitInAtlas)
318 {
319   return GetImplementation(*this).SetCurrentMaximumBlockSizeFitInAtlas(currentMaximumBlockSizeFitInAtlas);
320 }
321
322 uint32_t FontClient::GetNumberOfPointsPerOneUnitOfPointSize() const
323 {
324   return GetImplementation(*this).GetNumberOfPointsPerOneUnitOfPointSize();
325 }
326
327 FontClient::FontClient(Internal::FontClient* internal)
328 : BaseHandle(internal)
329 {
330 }
331
332 FontClient FontClientPreInitialize()
333 {
334   return Internal::FontClient::PreInitialize();
335 }
336
337 void FontClientPreCache(const FontFamilyList& fallbackFamilyList, const FontFamilyList& extraFamilyList, const FontFamily& localeFamily, bool useThread, bool syncCreation)
338 {
339   Internal::FontClient::PreCache(fallbackFamilyList, extraFamilyList, localeFamily, useThread, syncCreation);
340 }
341
342 void FontClientFontPreLoad(const FontPathList& fontPathList, const FontPathList& memoryFontPathList, bool useThread, bool syncCreation)
343 {
344   Internal::FontClient::PreLoad(fontPathList, memoryFontPathList, useThread, syncCreation);
345 }
346
347 void FontClientJoinFontThreads()
348 {
349   Internal::FontClient::JoinFontThreads();
350 }
351
352 } // namespace TextAbstraction
353
354 } // namespace Dali