Merge "[AT-SPI] Rework intercepting key events" into devel/master
[platform/core/uifw/dali-adaptor.git] / dali / internal / text / text-abstraction / plugin / embedded-item.cpp
1 /*
2  * Copyright (c) 2024 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 #include <dali/integration-api/debug.h>
22
23 namespace Dali::TextAbstraction::Internal
24 {
25 void EmbeddedItem::GetGlyphMetrics(GlyphInfo& glyph)
26 {
27   glyph.width       = static_cast<float>(width);
28   glyph.height      = static_cast<float>(height);
29   glyph.xBearing    = 0.f;
30   glyph.yBearing    = glyph.height;
31   glyph.advance     = glyph.width;
32   glyph.scaleFactor = 1.f;
33 }
34
35 void EmbeddedItem::CreateBitmap(const std::vector<PixelBufferCacheItem>& pixelBufferCache,
36                                 Dali::TextAbstraction::GlyphBufferData&  data)
37 {
38   data.width  = width;
39   data.height = height;
40   if(0u != pixelBufferId)
41   {
42     Devel::PixelBuffer pixelBuffer = pixelBufferCache[pixelBufferId - 1u].pixelBuffer;
43     if(pixelBuffer)
44     {
45       ConvertBitmap(data, pixelBuffer.GetWidth(), pixelBuffer.GetHeight(), pixelBuffer.GetBuffer(), pixelBuffer.GetPixelFormat());
46     }
47   }
48   else
49   {
50     data.isBufferOwned   = true;
51     data.compressionType = Dali::TextAbstraction::GlyphBufferData::CompressionType::NO_COMPRESSION;
52
53     // Creates the output buffer
54     const uint32_t bufferSize = data.width * data.height * 4u;
55     data.buffer               = (uint8_t*)malloc(bufferSize); // @note The caller is responsible for deallocating the bitmap data using free.
56     if(DALI_UNLIKELY(!data.buffer))
57     {
58       DALI_LOG_ERROR("malloc is failed. request malloc size : %u\n", bufferSize);
59     }
60     else
61     {
62       memset(data.buffer, 0u, bufferSize);
63     }
64
65     // Just creates a void buffer. Doesn't matter what pixel format is set as is the application code the responsible of filling it.
66   }
67 }
68
69 } // namespace Dali::TextAbstraction::Internal