[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / text / bitmap-font.cpp
1 /*
2  * Copyright (c) 2023 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 // FILE HEADER
19 #include <dali-toolkit/devel-api/text/bitmap-font.h>
20
21 // EXTERNAL INCLUDE
22 #include <dali/devel-api/text-abstraction/bitmap-font.h>
23 #include <cstring>
24
25 // INTERNAL INCLUDE
26 #include <dali-toolkit/internal/text/character-set-conversion.h>
27
28 namespace Dali
29 {
30 namespace Toolkit
31 {
32 namespace DevelText
33 {
34 Glyph::Glyph()
35 : url{},
36   utf8{},
37   ascender{0.f},
38   descender{0.f}
39 {
40 }
41
42 Glyph::Glyph(const std::string& url, const std::string utf8Character, float ascender, float descender)
43 : url{url},
44   utf8{},
45   ascender{ascender},
46   descender{descender}
47 {
48   DALI_ASSERT_DEBUG(utf8Character.size() <= 6u);
49
50 #pragma GCC diagnostic push
51 #pragma GCC diagnostic ignored "-Wstringop-overflow"
52   std::copy(utf8Character.begin(), utf8Character.end(), utf8);
53 #pragma GCC diagnostic pop
54 }
55
56 Glyph::~Glyph()
57 {
58 }
59
60 BitmapFontDescription::BitmapFontDescription()
61 : glyphs{},
62   name{},
63   underlinePosition{0.f},
64   underlineThickness{1.f},
65   isColorFont{false}
66 {
67 }
68
69 BitmapFontDescription::~BitmapFontDescription()
70 {
71 }
72
73 void CreateBitmapFont(const BitmapFontDescription& description, TextAbstraction::BitmapFont& bitmapFont)
74 {
75   bitmapFont.glyphs.reserve(description.glyphs.size());
76   bitmapFont.name               = description.name;
77   bitmapFont.underlinePosition  = description.underlinePosition;
78   bitmapFont.underlineThickness = description.underlineThickness;
79   bitmapFont.isColorFont        = description.isColorFont;
80
81   for(const auto& glyph : description.glyphs)
82   {
83     uint32_t c = 0u;
84     Text::Utf8ToUtf32(glyph.utf8, Text::GetUtf8Length(glyph.utf8[0u]), &c);
85
86     TextAbstraction::BitmapGlyph bitmapGlyph(glyph.url, c, glyph.ascender, glyph.descender);
87
88     bitmapFont.glyphs.push_back(std::move(bitmapGlyph));
89   }
90 }
91
92 } // namespace DevelText
93
94 } // namespace Toolkit
95
96 } // namespace Dali