4465521e1ee8dbf6d6f0a96b550a3fde6c4a1e3d
[platform/core/uifw/dali-adaptor.git] / dali / internal / text / text-abstraction / plugin / font-client-utils.h
1 #ifndef DALI_TEST_ABSTRACTION_INTERNAL_FONT_CLIENT_UTILS_H
2 #define DALI_TEST_ABSTRACTION_INTERNAL_FONT_CLIENT_UTILS_H
3
4 /*
5  * Copyright (c) 2021 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 // INTERNAL INCLUDES
21 #include <dali/devel-api/text-abstraction/font-client.h>
22
23 // EXTERNAL INCLUDES
24 #include <fontconfig/fontconfig.h>
25
26 #include <ft2build.h>
27 #include FT_FREETYPE_H
28
29 namespace Dali::TextAbstraction::Internal
30 {
31 void ConvertBitmap(TextAbstraction::FontClient::GlyphBufferData& data,
32                    unsigned int                                  srcWidth,
33                    unsigned int                                  srcHeight,
34                    const unsigned char* const                    srcBuffer);
35
36 void ConvertBitmap(TextAbstraction::FontClient::GlyphBufferData& data,
37                    FT_Bitmap                                     srcBitmap,
38                    bool                                          isShearRequired);
39
40 /**
41  * @brief Creates a font family pattern used to match fonts.
42  *
43  * @note Need to call FcPatternDestroy to free the resources.
44  *
45  * @param[in] fontDescription The font to cache.
46  *
47  * @return The pattern.
48  */
49 FcPattern* CreateFontFamilyPattern(const FontDescription& fontDescription);
50
51 /**
52  * @brief Creates a character set from a given font's @p description.
53  *
54  * @note Need to call FcCharSetDestroy to free the resources.
55  *
56  * @param[in] description The font's description.
57  *
58  * @return A character set.
59  */
60 FcCharSet* CreateCharacterSetFromDescription(const FontDescription& description);
61
62 constexpr int ValueToIndex(int value, const int* const table, unsigned int maxIndex)
63 {
64   if(nullptr == table)
65   {
66     // Return an invalid index if there is no table.
67     return -1;
68   }
69
70   if(value <= table[0])
71   {
72     return 0;
73   }
74
75   if(value >= table[maxIndex])
76   {
77     return maxIndex;
78   }
79
80   for(unsigned int index = 0u; index < maxIndex; ++index)
81   {
82     const int          v1        = table[index];
83     const unsigned int indexPlus = index + 1u;
84     const int          v2        = table[indexPlus];
85     if((v1 < value) && (value <= v2))
86     {
87       const int result = ((v1 > 0) && ((value - v1) < (v2 - value))) ? index : indexPlus;
88       return result;
89     }
90   }
91   return 0;
92 }
93
94 /**
95  * @brief Returns the FontWidth's enum index for the given width value.
96  *
97  * @param[in] width The width value.
98  *
99  * @return The FontWidth's enum index.
100  */
101 const FontWidth::Type IntToWidthType(int width);
102
103 /**
104  * @brief Returns the FontWeight's enum index for the given weight value.
105  *
106  * @param[in] weight The weight value.
107  *
108  * @return The FontWeight's enum index.
109  */
110 const FontWeight::Type IntToWeightType(int weight);
111
112 /**
113  * @brief Returns the FontSlant's enum index for the given slant value.
114  *
115  * @param[in] slant The slant value.
116  *
117  * @return The FontSlant's enum index.
118  */
119 const FontSlant::Type IntToSlantType(int slant);
120
121 const FontWidth::Type  DefaultFontWidth();
122 const FontWeight::Type DefaultFontWeight();
123 const FontSlant::Type  DefaultFontSlant();
124
125 } // namespace Dali::TextAbstraction::Internal
126
127 #endif // DALI_TEST_ABSTRACTION_INTERNAL_FONT_CLIENT_UTILS_H