[dali_2.3.20] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-geometry.h
1 #ifndef DALI_TOOLKIT_TEXT_GEOMETRY_H
2 #define DALI_TOOLKIT_TEXT_GEOMETRY_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 // EXTERNAL INCLUDES
22 #include <dali/public-api/math/rect.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/internal/text/text-model.h>
26 namespace Dali
27 {
28 namespace Toolkit
29 {
30 namespace Text
31 {
32 /**
33    * @brief Get the rendered size & position of a specific text range.
34    * if the requested text is at multilines, multiple sizes/positions will be returned for each text located in a separate line.
35    * if a line contains characters with different directions, multiple sizes will be returned for each block of contiguous characters with the same direction.
36    *
37    * @param[in] textModel text model containing text info.
38    * @param[in] startIndex start index of the text requested to get position/size for.
39    * @param[in] endIndex end index(included) of the text requested to get position/size for.
40    * @param[in] sizesList list of sizes for the reuested text.
41    * @param[in] positionsList list of positions for the requested text
42    */
43 void GetTextGeometry(ModelPtr textModel, CharacterIndex startIndex, CharacterIndex endIndex, Vector<Vector2>& sizesList, Vector<Vector2>& positionsList);
44
45 /**
46   * @brief Get the line bounding rectangle.
47   * if the requested index is out of range or the line is not yet rendered, a rect of {0, 0, 0, 0} is returned.
48   *
49   * @param[in] textModel text model containing line info.
50   * @param[in] lineIndex line index to which we want to calculate the geometry for.
51   * @return bounding rectangle.
52   */
53 Rect<float> GetLineBoundingRect(ModelPtr textModel, const uint32_t lineIndex);
54
55 /**
56   * @brief Get the left point of the line (x).
57   *
58   * @param[in] lineRun the requested line.
59   * @return x point of the line.
60   */
61 float GetLineLeft(const LineRun& lineRun);
62
63 /**
64   * @brief Get the top point of the line (y).
65   * if the requested line id the first; the top = 0, else the top = the heights of the previouse lines.
66   *
67   * @param[in] lines   the lines in the text controller.
68   * @param[in] lineRun the requested line.
69   * @return y point of the line.
70   */
71 float GetLineTop(const Vector<LineRun>& lines, const LineRun& lineRun);
72
73 /**
74   * @brief Get the rendered size and position of a specific character in a rectangle.
75   * If the text is not yet rendered or the index > text.Count(); a rect of {0, 0, 0, 0} is returned.
76   * The Width  of the character = glyph.advance
77   * The Height of the character = glyph.height
78   * The Left (X) of the character = characterPosition.x - glyph.xBearing; Regardless of the language direction RTL or LTR, the x point is the left x-point of the glyph. 
79   * The Top  (Y) of the character = characterPosition.y.
80   * @param[in] textModel text model containing text info.
81   * @param[in] charIndex character index to which we want to calculate the geometry for.
82   * @return Rect {x, y, width, height}.
83   */
84 Rect<> GetCharacterBoundingRect(ModelPtr textModel, const uint32_t charIndex);
85
86 /**
87   * @brief Get the character index.
88   * If the text is not yet rendered or the text is empty, -1 is returned.
89   *
90   * @param[in] textModel text model containing text info.
91   * @param[in] visualX visual x position.
92   * @param[in] visualY visual y position.
93   * @return character index.
94   */
95 int GetCharIndexAtPosition(ModelPtr textModel, float visualX, float visualY);
96
97 /**
98   * @brief Get the left point of the character (x).
99   *
100   * @param[in] glyph the requested character glyph.
101   * @param[in] characterPosition the position of the requested character.
102   * @return x point of the character.
103   */
104 float GetCharacterLeft(const GlyphInfo& glyph, const Vector2& characterPosition);
105
106 /**
107   * @brief Get the top point of the character (y).
108   *
109   * @param[in] characterPosition the position of the requested character.
110   * @return y point of the character.
111   */
112 float GetCharacterTop(const Vector2& characterPosition);
113
114 /**
115   * @brief Get the height of the character.
116   *
117   * @param[in] glyph the requested character glyph.
118   * @return height of the character.
119   */
120 float GetCharacterHeight(const GlyphInfo& glyph);
121
122 /**
123   * @brief Get the left point of the character.
124   *
125   * @param[in] glyph the requested character glyph.
126   * @return width of the character.
127   */
128 float GetCharacterWidth(const GlyphInfo& glyph);
129
130 } // namespace Text
131
132 } // namespace Toolkit
133
134 } // namespace Dali
135
136 #endif // DALI_TOOLKIT_TEXT_GEOMETRY_H