Refactored font-client-plugin-impl
[platform/core/uifw/dali-adaptor.git] / dali / internal / text / text-abstraction / plugin / embedded-item.cpp
1 /*
2  * Copyright (c) 2021 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 #include <dali/internal/text/text-abstraction/plugin/embedded-item.h>
18
19 #include <dali/internal/text/text-abstraction/plugin/font-client-utils.h>
20
21 namespace Dali::TextAbstraction::Internal
22 {
23 void EmbeddedItem::GetGlyphMetrics(GlyphInfo& glyph)
24 {
25   glyph.width       = static_cast<float>(width);
26   glyph.height      = static_cast<float>(height);
27   glyph.xBearing    = 0.f;
28   glyph.yBearing    = glyph.height;
29   glyph.advance     = glyph.width;
30   glyph.scaleFactor = 1.f;
31 }
32
33 void EmbeddedItem::CreateBitmap(const std::vector<PixelBufferCacheItem>&            pixelBufferCache,
34                                 Dali::TextAbstraction::FontClient::GlyphBufferData& data)
35 {
36   data.width  = width;
37   data.height = height;
38   if(0u != pixelBufferId)
39   {
40     Devel::PixelBuffer pixelBuffer = pixelBufferCache[pixelBufferId - 1u].pixelBuffer;
41     if(pixelBuffer)
42     {
43       ConvertBitmap(data, pixelBuffer.GetWidth(), pixelBuffer.GetHeight(), pixelBuffer.GetBuffer());
44
45       // Sets the pixel format.
46       data.format = pixelBuffer.GetPixelFormat();
47     }
48   }
49   else
50   {
51     // Creates the output buffer
52     const unsigned int bufferSize = data.width * data.height * 4u;
53     data.buffer                   = new unsigned char[bufferSize]; // @note The caller is responsible for deallocating the bitmap data using delete[].
54
55     memset(data.buffer, 0u, bufferSize);
56
57     // Just creates a void buffer. Doesn't matter what pixel format is set as is the application code the responsible of filling it.
58   }
59 }
60
61 } // namespace Dali::TextAbstraction::Internal