[dali_2.3.19] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / text / bitmap-font.h
1 #ifndef DALI_TOOLKIT_FONT_BITMAP_DEVEL_H
2 #define DALI_TOOLKIT_FONT_BITMAP_DEVEL_H
3
4 /*
5  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali-toolkit/public-api/dali-toolkit-common.h>
23 #include <dali/public-api/common/vector-wrapper.h>
24 #include <cstdint>
25 #include <string>
26
27 namespace Dali
28 {
29 namespace TextAbstraction
30 {
31 // Forward declarations
32 struct BitmapFont;
33 } // namespace TextAbstraction
34
35 namespace Toolkit
36 {
37 namespace DevelText
38 {
39 /**
40  * @brief Struct that stores the needed info to create a bitmap glyph.
41  */
42
43 struct DALI_TOOLKIT_API Glyph
44 {
45   /**
46    * @brief Default constructor.
47    *
48    * Initialize the members to its defaults.
49    */
50   Glyph();
51
52   /**
53    * @brief Constructor.
54    *
55    * Initialize the members with the given values.
56    *
57    * @param[in] url The url of the bitmap for that glyph.
58    * @param[in] utf8 The utf8 codification of the glyph.
59    * @param[in] ascender The ascender of the glyph.
60    * @param[in] descender The descender of the glyph.
61    */
62   Glyph(const std::string& url, const std::string utf8, float ascender, float descender);
63
64   /**
65    * @brief Default destructor.
66    */
67   ~Glyph();
68
69   std::string url;       ///< The url of the glyph.
70   uint8_t     utf8[6];   ///< the glyph encoded in utf8
71   float       ascender;  ///< The ascender. The distance from the base line to the top of the glyph.
72   float       descender; ///< The descender. The distance from the base line to the bottom of the glyph.
73 };
74
75 /**
76  * @brief Describes a bitmap font.
77  */
78 struct DALI_TOOLKIT_API BitmapFontDescription
79 {
80   /**
81    * @brief Default constructor.
82    *
83    * Initialize the members to its defaults.
84    */
85   BitmapFontDescription();
86
87   /**
88    * @brief Default destructor.
89    */
90   ~BitmapFontDescription();
91
92   std::vector<Glyph> glyphs;             ///< Vector of glyphs.
93   std::string        name;               ///< Name of the font.
94   float              underlinePosition;  ///< The position of the underline from the base line.
95   float              underlineThickness; ///< The thickness of the underline.
96   bool               isColorFont : 1;    ///< Whether the glyphs of this font have their own colors.
97 };
98
99 /**
100  * @brief Creates a bitmap font with the given description.
101  *
102  * The @p bitmapFont output can be passed to the FontClient::GetFontId()
103  * method to load the font and get an Id.
104  *
105  * @param[in] description The description of the bitmap font.
106  * @param[out] bitmapFont A bitmap font.
107  *
108  * @note If the @e ascender and @e descender of the glyphs are zero, the @e descender value will be left as zero and all the bitmaps will be loaded to find out the @e ascender value.
109  */
110 DALI_TOOLKIT_API void CreateBitmapFont(const BitmapFontDescription& description, TextAbstraction::BitmapFont& bitmapFont);
111
112 } // namespace DevelText
113
114 } // namespace Toolkit
115
116 } // namespace Dali
117
118 #endif // DALI_TOOLKIT_TEXT_UTILS_DEVEL_H