Merge "[AT-SPI] Add API for blocking automatic Bridge initialization" into devel...
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / text-abstraction / font-client.cpp
1 /*
2  * Copyright (c) 2020 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 const PointSize26Dot6 FontClient::DEFAULT_POINT_SIZE   = 768u;                           // 12*64
29 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).
30
31 //Default atlas block
32 const bool     FontClient::DEFAULT_ATLAS_LIMITATION_ENABLED  = true;
33 const uint32_t FontClient::DEFAULT_TEXT_ATLAS_WIDTH          = 512u;
34 const uint32_t FontClient::DEFAULT_TEXT_ATLAS_HEIGHT         = 512u;
35 const Size     FontClient::DEFAULT_TEXT_ATLAS_SIZE(DEFAULT_TEXT_ATLAS_WIDTH, DEFAULT_TEXT_ATLAS_HEIGHT);
36
37 //Maximum atlas block
38 const uint32_t FontClient::MAX_TEXT_ATLAS_WIDTH  = 1024u;
39 const uint32_t FontClient::MAX_TEXT_ATLAS_HEIGHT = 1024u;
40 const Size     FontClient::MAX_TEXT_ATLAS_SIZE(MAX_TEXT_ATLAS_WIDTH, MAX_TEXT_ATLAS_HEIGHT);
41
42 //MAX_WIDTH_FIT_IN_ATLAS: blockWidth + 2 * DOUBLE_PIXEL_PADDING + 1u <= atlasWidth
43 //MAX_HEIGHT_FIT_IN_ATLAS: blockHeight + 2 * DOUBLE_PIXEL_PADDING + 1u <= atlasHeight
44 const uint16_t FontClient::PADDING_TEXT_ATLAS_BLOCK = 5u; // 2 * DOUBLE_PIXEL_PADDING + 1u
45
46 //Maximum block size to fit into atlas block
47 const Size  FontClient::MAX_SIZE_FIT_IN_ATLAS(MAX_TEXT_ATLAS_WIDTH - PADDING_TEXT_ATLAS_BLOCK, MAX_TEXT_ATLAS_HEIGHT - PADDING_TEXT_ATLAS_BLOCK );
48
49 const uint32_t FontClient::NUMBER_OF_POINTS_PER_ONE_UNIT_OF_POINT_SIZE = 64u;//Found this value from toolkit
50
51 FontClient::GlyphBufferData::GlyphBufferData()
52 : buffer{nullptr},
53   width{0u},
54   height{0u},
55   outlineOffsetX{0},
56   outlineOffsetY{0},
57   format{Pixel::A8},
58   isColorEmoji{false},
59   isColorBitmap{false}
60 {
61 }
62
63 FontClient::GlyphBufferData::~GlyphBufferData()
64 {
65 }
66
67 FontClient FontClient::Get()
68 {
69   return Internal::FontClient::Get();
70 }
71
72 FontClient::FontClient()
73 {
74 }
75
76 FontClient::~FontClient()
77 {
78 }
79
80 FontClient::FontClient(const FontClient& handle)
81 : BaseHandle(handle)
82 {
83 }
84
85 FontClient& FontClient::operator=(const FontClient& handle)
86 {
87   BaseHandle::operator=(handle);
88   return *this;
89 }
90
91 void FontClient::ClearCache()
92 {
93   GetImplementation(*this).ClearCache();
94 }
95
96 void FontClient::SetDpi(unsigned int horizontalDpi, unsigned int verticalDpi)
97 {
98   GetImplementation(*this).SetDpi(horizontalDpi, verticalDpi);
99 }
100
101 void FontClient::GetDpi(unsigned int& horizontalDpi, unsigned int& verticalDpi)
102 {
103   GetImplementation(*this).GetDpi(horizontalDpi, verticalDpi);
104 }
105
106 int FontClient::GetDefaultFontSize()
107 {
108   return GetImplementation(*this).GetDefaultFontSize();
109 }
110
111 void FontClient::ResetSystemDefaults()
112 {
113   GetImplementation(*this).ResetSystemDefaults();
114 }
115
116 void FontClient::GetDefaultFonts(FontList& defaultFonts)
117 {
118   GetImplementation(*this).GetDefaultFonts(defaultFonts);
119 }
120
121 void FontClient::GetDefaultPlatformFontDescription(FontDescription& fontDescription)
122 {
123   GetImplementation(*this).GetDefaultPlatformFontDescription(fontDescription);
124 }
125
126 void FontClient::GetSystemFonts(FontList& systemFonts)
127 {
128   GetImplementation(*this).GetSystemFonts(systemFonts);
129 }
130
131 void FontClient::GetDescription(FontId id, FontDescription& fontDescription)
132 {
133   GetImplementation(*this).GetDescription(id, fontDescription);
134 }
135
136 PointSize26Dot6 FontClient::GetPointSize(FontId id)
137 {
138   return GetImplementation(*this).GetPointSize(id);
139 }
140
141 bool FontClient::IsCharacterSupportedByFont(FontId fontId, Character character)
142 {
143   return GetImplementation(*this).IsCharacterSupportedByFont(fontId, character);
144 }
145
146 FontId FontClient::FindDefaultFont(Character       charcode,
147                                    PointSize26Dot6 requestedPointSize,
148                                    bool            preferColor)
149 {
150   return GetImplementation(*this).FindDefaultFont(charcode,
151                                                   requestedPointSize,
152                                                   preferColor);
153 }
154
155 FontId FontClient::FindFallbackFont(Character              charcode,
156                                     const FontDescription& preferredFontDescription,
157                                     PointSize26Dot6        requestedPointSize,
158                                     bool                   preferColor)
159 {
160   return GetImplementation(*this).FindFallbackFont(charcode, preferredFontDescription, requestedPointSize, preferColor);
161 }
162
163 FontId FontClient::GetFontId(const FontPath& path, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex)
164 {
165   return GetImplementation(*this).GetFontId(path, requestedPointSize, faceIndex);
166 }
167
168 FontId FontClient::GetFontId(const FontDescription& fontDescription,
169                              PointSize26Dot6        requestedPointSize,
170                              FaceIndex              faceIndex)
171 {
172   return GetImplementation(*this).GetFontId(fontDescription,
173                                             requestedPointSize,
174                                             faceIndex);
175 }
176
177 FontId FontClient::GetFontId(const BitmapFont& bitmapFont)
178 {
179   return GetImplementation(*this).GetFontId(bitmapFont);
180 }
181
182 bool FontClient::IsScalable(const FontPath& path)
183 {
184   return GetImplementation(*this).IsScalable(path);
185 }
186
187 bool FontClient::IsScalable(const FontDescription& fontDescription)
188 {
189   return GetImplementation(*this).IsScalable(fontDescription);
190 }
191
192 void FontClient::GetFixedSizes(const FontPath& path, Dali::Vector<PointSize26Dot6>& sizes)
193 {
194   GetImplementation(*this).GetFixedSizes(path, sizes);
195 }
196
197 void FontClient::GetFixedSizes(const FontDescription&         fontDescription,
198                                Dali::Vector<PointSize26Dot6>& sizes)
199 {
200   GetImplementation(*this).GetFixedSizes(fontDescription, sizes);
201 }
202
203 bool FontClient::HasItalicStyle(FontId fontId) const
204 {
205   return GetImplementation(*this).HasItalicStyle(fontId);
206 }
207
208 void FontClient::GetFontMetrics(FontId fontId, FontMetrics& metrics)
209 {
210   GetImplementation(*this).GetFontMetrics(fontId, metrics);
211 }
212
213 GlyphIndex FontClient::GetGlyphIndex(FontId fontId, Character charcode)
214 {
215   return GetImplementation(*this).GetGlyphIndex(fontId, charcode);
216 }
217
218 bool FontClient::GetGlyphMetrics(GlyphInfo* array, uint32_t size, GlyphType type, bool horizontal)
219 {
220   return GetImplementation(*this).GetGlyphMetrics(array, size, type, horizontal);
221 }
222
223 void FontClient::CreateBitmap(FontId fontId, GlyphIndex glyphIndex, bool isItalicRequired, bool isBoldRequired, GlyphBufferData& data, int outlineWidth)
224 {
225   GetImplementation(*this).CreateBitmap(fontId, glyphIndex, isItalicRequired, isBoldRequired, data, outlineWidth);
226 }
227
228 PixelData FontClient::CreateBitmap(FontId fontId, GlyphIndex glyphIndex, int outlineWidth)
229 {
230   return GetImplementation(*this).CreateBitmap(fontId, glyphIndex, outlineWidth);
231 }
232
233 void FontClient::CreateVectorBlob(FontId fontId, GlyphIndex glyphIndex, VectorBlob*& blob, unsigned int& blobLength, unsigned int& nominalWidth, unsigned int& nominalHeight)
234 {
235   GetImplementation(*this).CreateVectorBlob(fontId, glyphIndex, blob, blobLength, nominalWidth, nominalHeight);
236 }
237
238 const GlyphInfo& FontClient::GetEllipsisGlyph(PointSize26Dot6 requestedPointSize)
239 {
240   return GetImplementation(*this).GetEllipsisGlyph(requestedPointSize);
241 }
242
243 bool FontClient::IsColorGlyph(FontId fontId, GlyphIndex glyphIndex)
244 {
245   return GetImplementation(*this).IsColorGlyph(fontId, glyphIndex);
246 }
247
248 bool FontClient::AddCustomFontDirectory(const FontPath& path)
249 {
250   return GetImplementation(*this).AddCustomFontDirectory(path);
251 }
252
253 GlyphIndex FontClient::CreateEmbeddedItem(const EmbeddedItemDescription& description, Pixel::Format& pixelFormat)
254 {
255   return GetImplementation(*this).CreateEmbeddedItem(description, pixelFormat);
256 }
257
258 void FontClient::EnableAtlasLimitation(bool enabled)
259 {
260   return GetImplementation(*this).EnableAtlasLimitation(enabled);
261 }
262
263 bool FontClient::IsAtlasLimitationEnabled() const
264 {
265   return GetImplementation(*this).IsAtlasLimitationEnabled( );
266 }
267
268 Size FontClient::GetMaximumTextAtlasSize() const
269 {
270   return GetImplementation(*this).GetMaximumTextAtlasSize( );
271 }
272
273 Size FontClient::GetDefaultTextAtlasSize() const
274 {
275   return GetImplementation(*this).GetDefaultTextAtlasSize( );
276 }
277
278 Size FontClient::GetCurrentMaximumBlockSizeFitInAtlas() const
279 {
280   return GetImplementation(*this).GetCurrentMaximumBlockSizeFitInAtlas( );
281 }
282
283 bool FontClient::SetCurrentMaximumBlockSizeFitInAtlas(const Size& currentMaximumBlockSizeFitInAtlas)
284 {
285   return GetImplementation(*this).SetCurrentMaximumBlockSizeFitInAtlas(currentMaximumBlockSizeFitInAtlas);
286 }
287
288 uint32_t FontClient::GetNumberOfPointsPerOneUnitOfPointSize() const
289 {
290   return GetImplementation(*this).GetNumberOfPointsPerOneUnitOfPointSize();
291 }
292
293 FontClient::FontClient(Internal::FontClient* internal)
294 : BaseHandle(internal)
295 {
296 }
297
298 FontClient FontClientPreInitialize()
299 {
300   return Internal::FontClient::PreInitialize();
301 }
302
303 } // namespace TextAbstraction
304
305 } // namespace Dali