fix linespacing calculation in TextLabel
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-view-interface.h
1 #ifndef DALI_TOOLKIT_TEXT_VIEW_INTERFACE_H
2 #define DALI_TOOLKIT_TEXT_VIEW_INTERFACE_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 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/dali-vector.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/devel-api/text/text-enumerations-devel.h>
26 #include <dali-toolkit/internal/text/bounded-paragraph-run.h>
27 #include <dali-toolkit/internal/text/text-definitions.h>
28 #include <dali-toolkit/internal/text/underlined-glyph-run.h>
29 #include <dali-toolkit/public-api/text/text-enumerations.h>
30
31 namespace Dali
32 {
33 struct Vector2;
34 struct Vector4;
35
36 namespace Toolkit
37 {
38 namespace Text
39 {
40 struct GlyphRun;
41 struct StrikethroughGlyphRun;
42
43 /**
44  * @brief Abstract interface to provide the information necessary to display text.
45  *
46  * This includes:
47  * - The font & glyph IDs needed to get bitmaps etc. from TextAbstraction
48  * - The visual position of each glyph within the layout
49  * - A window into the text layout e.g. which page of a document to view
50  */
51 class ViewInterface
52 {
53 public:
54   /**
55    * @brief Constructor.
56    */
57   ViewInterface();
58
59   /**
60    * @brief Virtual destructor
61    */
62   virtual ~ViewInterface();
63
64   /**
65    * @brief Retrieves the target size of the UI control.
66    *
67    * @return The control's size.
68    */
69   virtual const Vector2& GetControlSize() const = 0;
70
71   /**
72    * @brief Retrieves the text's layout size.
73    *
74    * @return The text's size. Note that this may be larger than the control size,
75    * in the case where text is scrolling/clipped.
76    */
77   virtual const Vector2& GetLayoutSize() const = 0;
78
79   /**
80    * Retrieves the number of glyphs.
81    *
82    * @return The number of glyphs.
83    */
84   virtual Length GetNumberOfGlyphs() const = 0;
85
86   /**
87    * @brief Retrieves glyphs and positions in the given buffers.
88    *
89    * @note The size of the @p glyphs and @p glyphPositions buffers need to be big enough to copy the @p numberOfGlyphs glyphs and positions.
90    * @note The returned number of glyphs may be less than @p numberOfGlyphs if a line has ellipsis.
91    *
92    * @param[out] glyphs Pointer to a buffer where the glyphs are copied.
93    * @param[out] glyphPositions Pointer to a buffer where the glyph's positions are copied.
94    * @param[out] minLineOffset The minimum line offset.
95    * @param[in] glyphIndex Index to the first glyph.
96    * @param[in] numberOfGlyphs Number of glyphs to be copied.
97    *
98    * @return The number of glyphs.
99    */
100   virtual Length GetGlyphs(GlyphInfo* glyphs,
101                            Vector2*   glyphPositions,
102                            float&     minLineOffset,
103                            GlyphIndex glyphIndex,
104                            Length     numberOfGlyphs) const = 0;
105
106   /**
107    * @brief Retrieves the vector of colors.
108    *
109    * @return Pointer to the vector of colors.
110    */
111   virtual const Vector4* const GetColors() const = 0;
112
113   /**
114    * @brief Retrieves the vector of indices to the vector of colors.
115    *
116    * @return Pointer to a vector which stores for each glyph the index to the vector of colors.
117    */
118   virtual const ColorIndex* const GetColorIndices() const = 0;
119
120   /**
121    * @brief Retrieves the vector of background colors.
122    *
123    * @return Pointer to the vector of background colors.
124    */
125   virtual const Vector4* const GetBackgroundColors() const = 0;
126
127   /**
128    * @brief Retrieves the vector of indices to the vector of background colors.
129    *
130    * @return Pointer to a vector which stores for each glyph the index to the vector of background colors.
131    */
132   virtual const ColorIndex* const GetBackgroundColorIndices() const = 0;
133
134   /**
135    * @brief checks if there is background colors set using markup.
136    *
137    * @return boolean if there is background colors set using markup .
138    */
139   virtual bool const IsMarkupBackgroundColorSet() const = 0;
140
141   /**
142    * @brief Retrieves the text color
143    *
144    * @return The text color
145    */
146   virtual const Vector4& GetTextColor() const = 0;
147
148   /**
149    * @brief Retrieves the shadow offset, 0 indicates no shadow.
150    *
151    * @return The shadow offset.
152    */
153   virtual const Vector2& GetShadowOffset() const = 0;
154
155   /**
156    * @brief Retrieves the shadow color.
157    *
158    * @return The shadow color.
159    */
160   virtual const Vector4& GetShadowColor() const = 0;
161
162   /**
163    * @brief Retrieves the underline color.
164    *
165    * @return The underline color.
166    */
167   virtual const Vector4& GetUnderlineColor() const = 0;
168
169   /**
170    * @brief Returns whether underline is enabled or not.
171    *
172    * @return The underline state.
173    */
174   virtual bool IsUnderlineEnabled() const = 0;
175
176   /**
177    * @brief Returns the hyphens glyph info.
178    *
179    * @return hyphens glyph info.
180    */
181   virtual const GlyphInfo* GetHyphens() const = 0;
182
183   /**
184    * @brief Returns the indices of the hyphen in the text.
185    *
186    * @return the hyphen indices.
187    */
188   virtual const Length* GetHyphenIndices() const = 0;
189
190   /**
191    * @brief Returns number of hyphens to add in text.
192    *
193    * @return number of hyphens.
194    */
195   virtual Length GetHyphensCount() const = 0;
196   /**
197    * @brief Retrieves the underline height override
198    *
199    * @return Returns the override height for an underline, 0 indicates that adaptor will determine the height
200    */
201   virtual float GetUnderlineHeight() const = 0;
202
203   /**
204    * @brief Retrieves the underline type override
205    *
206    * @return Returns the override type for an underline.
207    */
208   virtual Text::Underline::Type GetUnderlineType() const = 0;
209
210   /**
211    * @brief Retrieves the dashed underline width override.
212    *
213    * @return Returns the override width for the dashed underline.
214    */
215   virtual float GetDashedUnderlineWidth() const = 0;
216
217   /**
218    * @brief Retrieves the dashed underline gap override.
219    *
220    * @return Returns the override gap for the dashed underline.
221    */
222   virtual float GetDashedUnderlineGap() const = 0;
223
224   /**
225    * @brief Retrieves the number of underline runs.
226    *
227    * @return The number of underline runs.
228    */
229   virtual Length GetNumberOfUnderlineRuns() const = 0;
230
231   /**
232    * @brief Retrieves the underline runs.
233    *
234    * @param[out] underlineRuns Pointer to a buffer where the underline runs are copied.
235    * @param[in] index Index of the first underline run to be copied.
236    * @param[in] numberOfRuns Number of underline runs to be copied.
237    */
238   virtual void GetUnderlineRuns(UnderlinedGlyphRun* underlineRuns,
239                                 UnderlineRunIndex   index,
240                                 Length              numberOfRuns) const = 0;
241
242   /**
243    * @brief Retrieve the outline color.
244    *
245    * @return The outline color.
246    */
247   virtual const Vector4& GetOutlineColor() const = 0;
248
249   /**
250    * @brief Retrieves the width of an outline
251    *
252    * @return The width of the outline.
253    */
254   virtual uint16_t GetOutlineWidth() const = 0;
255
256   /**
257    * @brief Retrieves ellipsis position for text.
258    *
259    * @return The ellipsis position.
260    */
261   virtual DevelText::EllipsisPosition::Type GetEllipsisPosition() const = 0;
262
263   /**
264    * @brief Whether the text elide property is enabled.
265    *
266    * @return @e true if the text elide property is enabled, @e false otherwise.
267    */
268   virtual bool IsTextElideEnabled() const = 0;
269
270   /**
271    * @brief Retrieves the start index of laid-out glyphs.
272    *
273    * @return The start index of laid-out glyphs.
274    */
275   virtual GlyphIndex GetStartIndexOfElidedGlyphs() const = 0;
276
277   /**
278    * @brief Retrieves the end index of laid-out glyphs.
279    *
280    * @return The end index of laid-out glyphs.
281    */
282   virtual GlyphIndex GetEndIndexOfElidedGlyphs() const = 0;
283
284   /**
285    * @brief Retrieves the first middle index of elided glyphs, index before ellipsis of middle.
286    *
287    * @return The first middle index of elided glyphs, index before ellipsis of middle.
288    */
289   virtual GlyphIndex GetFirstMiddleIndexOfElidedGlyphs() const = 0;
290
291   /**
292    * @brief Retrieves the second middle index of elided glyphs, index of ellipsis of middle.
293    *
294    * @return The second middle index of elided glyphs, index of ellipsis of middle.
295    */
296   virtual GlyphIndex GetSecondMiddleIndexOfElidedGlyphs() const = 0;
297
298   /**
299    * @brief Retrieves the strikethrough color.
300    *
301    * @return The strikethrough color.
302    */
303   virtual const Vector4& GetStrikethroughColor() const = 0;
304
305   /**
306    * @brief Returns whether strikethrough is enabled or not.
307    *
308    * @return The strikethrough state.
309    */
310   virtual bool IsStrikethroughEnabled() const = 0;
311
312   /**
313    * @brief Retrieves the strikethrough height override
314    *
315    * @return Returns the override height for a strikethrough, 0 indicates that adaptor will determine the height
316    */
317   virtual float GetStrikethroughHeight() const = 0;
318
319   /**
320    * @brief Retrieves the number of strikethrough runs.
321    *
322    * @return The number of strikethrough runs.
323    */
324   virtual Length GetNumberOfStrikethroughRuns() const = 0;
325
326   /**
327    * @brief Retrieves the number of bounded paragraph runs.
328    *
329    * @return The number of bounded paragraph runs.
330    */
331   virtual Length GetNumberOfBoundedParagraphRuns() const = 0;
332
333   /**
334    * @brief Retrieves the reference for bounded paragraph runs.
335    *
336    * @return The reference for bounded paragraph runs.
337    */
338   virtual const Vector<BoundedParagraphRun>& GetBoundedParagraphRuns() const = 0;
339
340   /**
341    * @brief Retrieves the strikethrough runs.
342    *
343    * @param[out] strikethroughRuns Pointer to a buffer where the strikethrough runs are copied.
344    * @param[in] index Index of the first strikethrough run to be copied.
345    * @param[in] numberOfRuns Number of strikethrough runs to be copied.
346    */
347   virtual void GetStrikethroughRuns(StrikethroughGlyphRun* strikethroughRuns,
348                                     StrikethroughRunIndex  index,
349                                     Length                 numberOfRuns) const = 0;
350
351   /**
352    * @brief The spaces between characters in Pixels.
353    *
354    * @note A positive value will make the characters far apart (expanded) and a negative value will bring them closer (condensed).
355    *
356    * @return characterSpacing.
357    */
358   virtual const float GetCharacterSpacing() const = 0;
359
360   /**
361    * @brief The text buffer.
362    *
363    * @return The text buffer.
364    */
365   virtual const Character* GetTextBuffer() const = 0;
366
367   /**
368    * @brief The text Glyph to Characters Array.
369    *
370    * @return GetGlyphsToCharacters.
371    */
372   virtual const Vector<CharacterIndex>& GetGlyphsToCharacters() const = 0;
373 };
374
375 } // namespace Text
376
377 } // namespace Toolkit
378
379 } // namespace Dali
380
381 #endif // DALI_TOOLKIT_TEXT_VIEW_INTERFACE_H