2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/devel-api/text-abstraction/font-client.h>
22 #include <dali/internal/text/text-abstraction/font-client-impl.h>
26 namespace TextAbstraction
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).
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);
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);
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
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);
49 const uint32_t FontClient::NUMBER_OF_POINTS_PER_ONE_UNIT_OF_POINT_SIZE = 64u; //Found this value from toolkit
51 FontClient::GlyphBufferData::GlyphBufferData()
63 FontClient::GlyphBufferData::~GlyphBufferData()
67 FontClient FontClient::Get()
69 return Internal::FontClient::Get();
72 FontClient::FontClient()
76 FontClient::~FontClient()
80 FontClient::FontClient(const FontClient& handle)
85 FontClient& FontClient::operator=(const FontClient& handle)
87 BaseHandle::operator=(handle);
91 void FontClient::ClearCache()
93 GetImplementation(*this).ClearCache();
96 void FontClient::SetDpi(unsigned int horizontalDpi, unsigned int verticalDpi)
98 GetImplementation(*this).SetDpi(horizontalDpi, verticalDpi);
101 void FontClient::GetDpi(unsigned int& horizontalDpi, unsigned int& verticalDpi)
103 GetImplementation(*this).GetDpi(horizontalDpi, verticalDpi);
106 int FontClient::GetDefaultFontSize()
108 return GetImplementation(*this).GetDefaultFontSize();
111 void FontClient::ResetSystemDefaults()
113 GetImplementation(*this).ResetSystemDefaults();
116 void FontClient::GetDefaultFonts(FontList& defaultFonts)
118 GetImplementation(*this).GetDefaultFonts(defaultFonts);
121 void FontClient::GetDefaultPlatformFontDescription(FontDescription& fontDescription)
123 GetImplementation(*this).GetDefaultPlatformFontDescription(fontDescription);
126 void FontClient::GetSystemFonts(FontList& systemFonts)
128 GetImplementation(*this).GetSystemFonts(systemFonts);
131 void FontClient::GetDescription(FontId id, FontDescription& fontDescription)
133 GetImplementation(*this).GetDescription(id, fontDescription);
136 PointSize26Dot6 FontClient::GetPointSize(FontId id)
138 return GetImplementation(*this).GetPointSize(id);
141 bool FontClient::IsCharacterSupportedByFont(FontId fontId, Character character)
143 return GetImplementation(*this).IsCharacterSupportedByFont(fontId, character);
146 FontId FontClient::FindDefaultFont(Character charcode,
147 PointSize26Dot6 requestedPointSize,
150 return GetImplementation(*this).FindDefaultFont(charcode,
155 FontId FontClient::FindFallbackFont(Character charcode,
156 const FontDescription& preferredFontDescription,
157 PointSize26Dot6 requestedPointSize,
160 return GetImplementation(*this).FindFallbackFont(charcode, preferredFontDescription, requestedPointSize, preferColor);
163 FontId FontClient::GetFontId(const FontPath& path, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex)
165 return GetImplementation(*this).GetFontId(path, requestedPointSize, faceIndex);
168 FontId FontClient::GetFontId(const FontDescription& fontDescription,
169 PointSize26Dot6 requestedPointSize,
172 return GetImplementation(*this).GetFontId(fontDescription,
177 FontId FontClient::GetFontId(const BitmapFont& bitmapFont)
179 return GetImplementation(*this).GetFontId(bitmapFont);
182 bool FontClient::IsScalable(const FontPath& path)
184 return GetImplementation(*this).IsScalable(path);
187 bool FontClient::IsScalable(const FontDescription& fontDescription)
189 return GetImplementation(*this).IsScalable(fontDescription);
192 void FontClient::GetFixedSizes(const FontPath& path, Dali::Vector<PointSize26Dot6>& sizes)
194 GetImplementation(*this).GetFixedSizes(path, sizes);
197 void FontClient::GetFixedSizes(const FontDescription& fontDescription,
198 Dali::Vector<PointSize26Dot6>& sizes)
200 GetImplementation(*this).GetFixedSizes(fontDescription, sizes);
203 bool FontClient::HasItalicStyle(FontId fontId) const
205 return GetImplementation(*this).HasItalicStyle(fontId);
208 void FontClient::GetFontMetrics(FontId fontId, FontMetrics& metrics)
210 GetImplementation(*this).GetFontMetrics(fontId, metrics);
213 GlyphIndex FontClient::GetGlyphIndex(FontId fontId, Character charcode)
215 return GetImplementation(*this).GetGlyphIndex(fontId, charcode);
218 bool FontClient::GetGlyphMetrics(GlyphInfo* array, uint32_t size, GlyphType type, bool horizontal)
220 return GetImplementation(*this).GetGlyphMetrics(array, size, type, horizontal);
223 void FontClient::CreateBitmap(FontId fontId, GlyphIndex glyphIndex, bool isItalicRequired, bool isBoldRequired, GlyphBufferData& data, int outlineWidth)
225 GetImplementation(*this).CreateBitmap(fontId, glyphIndex, isItalicRequired, isBoldRequired, data, outlineWidth);
228 PixelData FontClient::CreateBitmap(FontId fontId, GlyphIndex glyphIndex, int outlineWidth)
230 return GetImplementation(*this).CreateBitmap(fontId, glyphIndex, outlineWidth);
233 void FontClient::CreateVectorBlob(FontId fontId, GlyphIndex glyphIndex, VectorBlob*& blob, unsigned int& blobLength, unsigned int& nominalWidth, unsigned int& nominalHeight)
235 GetImplementation(*this).CreateVectorBlob(fontId, glyphIndex, blob, blobLength, nominalWidth, nominalHeight);
238 const GlyphInfo& FontClient::GetEllipsisGlyph(PointSize26Dot6 requestedPointSize)
240 return GetImplementation(*this).GetEllipsisGlyph(requestedPointSize);
243 bool FontClient::IsColorGlyph(FontId fontId, GlyphIndex glyphIndex)
245 return GetImplementation(*this).IsColorGlyph(fontId, glyphIndex);
248 bool FontClient::AddCustomFontDirectory(const FontPath& path)
250 return GetImplementation(*this).AddCustomFontDirectory(path);
253 GlyphIndex FontClient::CreateEmbeddedItem(const EmbeddedItemDescription& description, Pixel::Format& pixelFormat)
255 return GetImplementation(*this).CreateEmbeddedItem(description, pixelFormat);
258 void FontClient::EnableAtlasLimitation(bool enabled)
260 return GetImplementation(*this).EnableAtlasLimitation(enabled);
263 bool FontClient::IsAtlasLimitationEnabled() const
265 return GetImplementation(*this).IsAtlasLimitationEnabled();
268 Size FontClient::GetMaximumTextAtlasSize() const
270 return GetImplementation(*this).GetMaximumTextAtlasSize();
273 Size FontClient::GetDefaultTextAtlasSize() const
275 return GetImplementation(*this).GetDefaultTextAtlasSize();
278 Size FontClient::GetCurrentMaximumBlockSizeFitInAtlas() const
280 return GetImplementation(*this).GetCurrentMaximumBlockSizeFitInAtlas();
283 bool FontClient::SetCurrentMaximumBlockSizeFitInAtlas(const Size& currentMaximumBlockSizeFitInAtlas)
285 return GetImplementation(*this).SetCurrentMaximumBlockSizeFitInAtlas(currentMaximumBlockSizeFitInAtlas);
288 uint32_t FontClient::GetNumberOfPointsPerOneUnitOfPointSize() const
290 return GetImplementation(*this).GetNumberOfPointsPerOneUnitOfPointSize();
293 FontClient::FontClient(Internal::FontClient* internal)
294 : BaseHandle(internal)
298 FontClient FontClientPreInitialize()
300 return Internal::FontClient::PreInitialize();
303 } // namespace TextAbstraction