DALi Version 2.1.5
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / glyph-metrics-helper.h
1 #ifndef DALI_TOOLKIT_TEXT_GLYPH_METRICS_HELPER_H
2 #define DALI_TOOLKIT_TEXT_GLYPH_METRICS_HELPER_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
21 // INTERNAL INCLUDES
22 #include <dali-toolkit/internal/text/metrics.h>
23
24 namespace Dali
25 {
26 namespace Toolkit
27 {
28 namespace Text
29 {
30 /**
31  * @brief Some characters can be shaped in more than one glyph.
32  * This struct is used to retrieve metrics from these group of glyphs.
33  */
34 struct GlyphMetrics
35 {
36   GlyphMetrics()
37   : fontId(0u),
38     fontHeight(0.f),
39     width(0.f),
40     advance(0.f),
41     ascender(0.f),
42     xBearing(0.f)
43   {
44   }
45
46   ~GlyphMetrics()
47   {
48   }
49
50   FontId fontId;     ///< The font id of the glyphs.
51   float  fontHeight; ///< The font's height of those glyphs.
52   float  width;      ///< The width of the group.
53   float  advance;    ///< The sum of all the advances of all the glyphs.
54   float  ascender;   ///< The font's ascender.
55   float  xBearing;   ///< The x bearing of the group.
56 };
57
58 /**
59  * @brief Returns the number of glyphs of a group of glyphs.
60  *
61  * @param[in] glyphIndex The first glyph of the group.
62  * @param[in] lastGlyphPlusOne Index to one after the last glyph.
63  * @param[in] charactersPerGlyphBuffer The number of characters per glyph buffer.
64  *
65  * @return The number of glyphs of the group.
66  */
67 Length GetNumberOfGlyphsOfGroup(GlyphIndex          glyphIndex,
68                                 GlyphIndex          lastGlyphPlusOne,
69                                 const Length* const charactersPerGlyphBuffer);
70
71 /**
72  * @brief Get some glyph's metrics of a group of glyphs formed as a result of shaping one character.
73  *
74  * @param[in] glyphIndex The index to the first glyph.
75  * @param[in] numberOfGlyphs The number of glyphs.
76  * @param[out] glyphMetrics Some glyph metrics (font height, advance, ascender and x bearing).
77  * @param[in] glyphsBuffer The glyphs buffer.
78  * @param[in] metrics Used to access metrics from FontClient.
79  */
80 void GetGlyphsMetrics(GlyphIndex             glyphIndex,
81                       Length                 numberOfGlyphs,
82                       GlyphMetrics&          glyphMetrics,
83                       const GlyphInfo* const glyphsBuffer,
84                       MetricsPtr&            metrics);
85
86 /**
87  * @brief Takes the character index, obtains the glyph index (and the number of Glyphs) from it and finally gets the glyph metrics.
88  *
89  * @param[in] index The character index.
90  * @param[in] glyphInfoBuffer The glyphs buffer.
91  * @param[in] charactersToGlyphBuffer A vector containing the glyph index for each character.
92  * @param[in] glyphsPerCharacterBuffer A vector containing the number of glyphs in each character.
93  * @param[in] metrics Used to access metrics from FontClient.
94  * @param[out] glyphMetrics Some glyph metrics (font height, advance, ascender and x bearing).
95  * @param[out] glyphIndex The glyph index obtained from the character index.
96  * @param[out] numberOfGlyphs The number of glyphs in the character of which the index was passed to the function.
97  *
98  */
99 void GetGlyphMetricsFromCharacterIndex(CharacterIndex          index,
100                                        const GlyphInfo* const  glyphInfoBuffer,
101                                        const GlyphIndex* const charactersToGlyphBuffer,
102                                        const Length* const     glyphsPerCharacterBuffer,
103                                        MetricsPtr&             metrics,
104                                        GlyphMetrics&           glyphMetrics,
105                                        GlyphIndex&             glyphIndex,
106                                        Length&                 numberOfGlyphs);
107
108 } // namespace Text
109
110 } // namespace Toolkit
111
112 } // namespace Dali
113
114 #endif // DALI_TOOLKIT_TEXT_GLYPH_METRICS_HELPER_H