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