Adding Character Spacing
[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) 2022 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/logical-model-impl.h>
23 #include <dali-toolkit/internal/text/metrics.h>
24 #include <dali-toolkit/internal/text/visual-model-impl.h>
25
26 namespace Dali
27 {
28 namespace Toolkit
29 {
30 namespace Text
31 {
32 /**
33  * @brief Some characters can be shaped in more than one glyph.
34  * This struct is used to retrieve metrics from these group of glyphs.
35  */
36 struct GlyphMetrics
37 {
38   GlyphMetrics()
39   : fontId(0u),
40     fontHeight(0.f),
41     width(0.f),
42     advance(0.f),
43     ascender(0.f),
44     xBearing(0.f)
45   {
46   }
47
48   ~GlyphMetrics()
49   {
50   }
51
52   FontId fontId;     ///< The font id of the glyphs.
53   float  fontHeight; ///< The font's height of those glyphs.
54   float  width;      ///< The width of the group.
55   float  advance;    ///< The sum of all the advances of all the glyphs.
56   float  ascender;   ///< The font's ascender.
57   float  xBearing;   ///< The x bearing of the group.
58 };
59
60 /**
61  * @brief Returns the number of glyphs of a group of glyphs.
62  *
63  * @param[in] glyphIndex The first glyph of the group.
64  * @param[in] lastGlyphPlusOne Index to one after the last glyph.
65  * @param[in] charactersPerGlyphBuffer The number of characters per glyph buffer.
66  *
67  * @return The number of glyphs of the group.
68  */
69 Length GetNumberOfGlyphsOfGroup(GlyphIndex          glyphIndex,
70                                 GlyphIndex          lastGlyphPlusOne,
71                                 const Length* const charactersPerGlyphBuffer);
72
73 /**
74  * @brief Get some glyph's metrics of a group of glyphs formed as a result of shaping one character.
75  *
76  * @param[in] glyphIndex The index to the first glyph.
77  * @param[in] numberOfGlyphs The number of glyphs.
78  * @param[out] glyphMetrics Some glyph metrics (font height, advance, ascender and x bearing).
79  * @param[in] glyphsBuffer The glyphs buffer.
80  * @param[in] metrics Used to access metrics from FontClient.
81  * @param[in] calculatedAdvance The final advance value obtained by adding the CharacterSpacing value to the original advance. In some cases the CharacterSpacing should not be added. Ex: when the glyph is a ZWSP (Zero Width Space)
82  */
83 void GetGlyphsMetrics(GlyphIndex             glyphIndex,
84                       Length                 numberOfGlyphs,
85                       GlyphMetrics&          glyphMetrics,
86                       const GlyphInfo* const glyphsBuffer,
87                       MetricsPtr&            metrics,
88                       float                  calculatedAdvance);
89
90 /**
91  * @brief Gets the final advance value by adding the CharacterSpacing value to it
92  *In some cases the CharacterSpacing should not be added. Ex: when the glyph is a ZWSP (Zero Width Space)
93  *
94  * @param[in] character The character of which the advance is to be calculated.
95  * @param[in] characterSpacing The character spacing to be added to the advance.
96  * @param[in] advance The original advance.
97  *
98  * @return The calculated advance
99  */
100 float GetCalculatedAdvance(unsigned int character, float characterSpacing, float advance);
101
102 /**
103  * @brief Takes the character index, obtains the glyph index (and the number of Glyphs) from it and finally gets the glyph metrics.
104  *
105  * @param[in] index The character index.
106  * @param[in] visualModel The visual model.
107  * @param[in] logicalModel The logical model.
108  * @param[in] metrics Used to access metrics from FontClient.
109  * @param[out] glyphMetrics Some glyph metrics (font height, advance, ascender and x bearing).
110  * @param[out] glyphIndex The glyph index obtained from the character index.
111  * @param[out] numberOfGlyphs The number of glyphs in the character of which the index was passed to the function.
112  *
113  */
114 void GetGlyphMetricsFromCharacterIndex(CharacterIndex         index,
115                                        const VisualModelPtr&  visualModel,
116                                        const LogicalModelPtr& logicalModel,
117                                        MetricsPtr&            metrics,
118                                        GlyphMetrics&          glyphMetrics,
119                                        GlyphIndex&            glyphIndex,
120                                        Length&                numberOfGlyphs);
121
122 } // namespace Text
123
124 } // namespace Toolkit
125
126 } // namespace Dali
127
128 #endif // DALI_TOOLKIT_TEXT_GLYPH_METRICS_HELPER_H