3 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include <dali/internal/text/text-abstraction/plugin/bitmap-font-cache-item.h>
20 #include <dali/devel-api/adaptor-framework/image-loading.h>
21 #include <dali/integration-api/debug.h>
22 #include <dali/internal/text/text-abstraction/plugin/font-client-utils.h>
24 #if defined(DEBUG_ENABLED)
25 extern Dali::Integration::Log::Filter* gFontClientLogFilter;
28 namespace Dali::TextAbstraction::Internal
30 BitmapFontCacheItem::BitmapFontCacheItem(const BitmapFont& bitmapFont, FontId fontId)
34 // Resize the vector with the pixel buffers.
35 pixelBuffers.resize(bitmapFont.glyphs.size());
37 // Traverse all the glyphs and load the pixel buffer of those with ascender and descender equal to zero.
38 unsigned int index = 0u;
39 for(auto& glyph : font.glyphs)
41 Devel::PixelBuffer& pixelBuffer = pixelBuffers[index];
43 if(EqualsZero(glyph.ascender) && EqualsZero(glyph.descender))
46 pixelBuffer = LoadImageFromFile(glyph.url);
50 glyph.ascender = static_cast<float>(pixelBuffer.GetHeight());
54 font.ascender = std::max(glyph.ascender, font.ascender);
55 font.descender = std::min(glyph.descender, font.descender);
61 void BitmapFontCacheItem::GetFontMetrics(FontMetrics& metrics, unsigned int dpiVertical) const
63 metrics.ascender = font.ascender;
64 metrics.descender = font.descender;
65 metrics.height = metrics.ascender - metrics.descender;
66 metrics.underlinePosition = font.underlinePosition;
67 metrics.underlineThickness = font.underlineThickness;
70 bool BitmapFontCacheItem::GetGlyphMetrics(GlyphInfo& glyph, unsigned int dpiVertical, bool horizontal) const
74 unsigned int index = 0u;
75 for(auto& item : font.glyphs)
77 if(item.utf32 == glyph.index)
79 Devel::PixelBuffer& pixelBuffer = const_cast<Devel::PixelBuffer&>(pixelBuffers[index]);
82 pixelBuffer = LoadImageFromFile(item.url);
85 glyph.width = static_cast<float>(pixelBuffer.GetWidth());
86 glyph.height = static_cast<float>(pixelBuffer.GetHeight());
88 glyph.yBearing = glyph.height + item.descender;
89 glyph.advance = glyph.width;
90 glyph.scaleFactor = 1.f;
99 void BitmapFontCacheItem::CreateBitmap(
100 GlyphIndex glyphIndex, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth, bool isItalicRequired, bool isBoldRequired) const
102 unsigned int index = 0u;
103 for(auto& item : font.glyphs)
105 if(item.utf32 == glyphIndex)
107 Devel::PixelBuffer& pixelBuffer = const_cast<Devel::PixelBuffer&>(pixelBuffers[index]);
110 pixelBuffer = LoadImageFromFile(item.url);
113 data.width = pixelBuffer.GetWidth();
114 data.height = pixelBuffer.GetHeight();
116 data.isColorBitmap = font.isColorFont;
118 ConvertBitmap(data, data.width, data.height, pixelBuffer.GetBuffer());
120 // Sets the pixel format.
121 data.format = pixelBuffer.GetPixelFormat();
128 bool BitmapFontCacheItem::IsCharacterSupported(Character character)
130 for(const auto& glyph : font.glyphs)
132 if(glyph.utf32 == character)
140 } // namespace Dali::TextAbstraction::Internal