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