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