More ItemView Insert/Remove/Replace APIs
[platform/core/uifw/dali-toolkit.git] / capi / dali-toolkit / public-api / markup-processor / markup-processor.h
1 #ifndef __DALI_TOOLKIT_MARKUP_PROCESSOR_H__
2 #define __DALI_TOOLKIT_MARKUP_PROCESSOR_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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  * @addtogroup CAPI_DALI_FRAMEWORK
22  * @{
23  */
24
25 // INTERNAL INCLUDES
26 #include <dali/public-api/common/vector-wrapper.h>
27
28 #include <dali/public-api/text/text.h>
29 #include <dali/public-api/text/text-style.h>
30
31 namespace Dali DALI_IMPORT_API
32 {
33
34 namespace Toolkit
35 {
36
37 namespace MarkupProcessor
38 {
39
40 /**
41  * Holds text and its style.
42  *
43  * mText is a Dali::Text object which can store text in different languages. mStyle is a Dali::TextStyle object which can
44  * store all text styling features provided by Dali::TextActor.
45  */
46 struct StyledText
47 {
48   StyledText()
49   : mText(),
50     mStyle()
51   {
52   }
53
54   StyledText( const Text& text, const TextStyle& style )
55   : mText( text ),
56     mStyle( style )
57   {
58   }
59
60   Text      mText;  ///< Store text. Could be a mix of different languages.
61   TextStyle mStyle; ///< Store the style for the text.
62 };
63
64 /**
65  * This type defines a vector of StyledText. It's used to store a whole text with its style
66  * and set it to a Dali::Toolkit::TextView. It could be used in other UI Dali::Toolkit::Control classes
67  * which need text with style.
68  */
69 typedef std::vector<StyledText> StyledTextArray;
70
71 /**
72  * Creates a text array with its style from a markup string.
73  * The syntax of a markup string is html-ish. It contains open, close and empty tags and some of them can contain parameters.
74  * <ul>
75  *   <li>\e \<b\>\</b\> Bold text.
76  *   <li>\e \<i\>\</i\> Italic text.
77  *   <li>\e \<u\>\</u\> Underlined text.
78  *   <li>\e \<br /\> New line.
79  *   <li>\e \<font\>\</font\> Specifies font properties:
80  *     <ul>
81  *       <li> \e face Font face.
82  *       <li> \e size Font size.
83  *       <li> \e color Font color.
84  *     </ul>
85  *   <li>\e \<shadow\>\</shadow\> Specifies shadow properties @see Dali::TextActor::SetShadow().
86  *     <ul>
87  *       <li> \e paramx X offset.
88  *       <li> \e paramy Y offset.
89  *       <li> \e color Shadow color.
90  *     </ul>
91  *   <li>\e \<glow\>\</glow\> Specifies glow properties @see Dali::TextActor::SetGlow().
92  *     <ul>
93  *       <li> \e param Glow around the text.
94  *       <li> \e color Glow color.
95  *     </ul>
96  *   <li>\e \<outline\>\</outline\> Specifies outline properties @see Dali::TextActor::SetOutline().
97  *     <ul>
98  *       <li> \e paramx X thickness.
99  *       <li> \e paramy Y thickness.
100  *       <li> \e color Outline color.
101  *     </ul>
102  *   <li>\e \<smooth\>\</smooth\> Specify the smooth edge @see Dali::TextActor::SetSmoothEdge().
103  *     <ul>
104  *       <li> \e paramx Distance field.
105  *     </ul>
106  * </ul>
107  *
108  * It transform any pair CR+LF new line characters into a single LF new line character.
109  * @param [in] markupString A string with style.
110  * @param [out] styledTextArray A text array split in characters, each one with its style.
111  */
112 void GetStyledTextArray( const std::string& markupString, StyledTextArray& styledTextArray );
113
114 /**
115  * Creates a plain string from a text array (thus stripping the style meta)
116  * @param [in] styledTextArray A text array split in characters, each one with its style.
117  * @param [out] plainString A string without style.
118  */
119 void GetPlainString( const StyledTextArray& styledTextArray, std::string& plainString );
120
121 /**
122  * Creates a markup string from a text array with its style.
123  * @param [in] styledTextArray A text array split in characters, each one with its style.
124  * @param [out] markupString A string with style.
125  */
126 void GetMarkupString( const StyledTextArray& styledTextArray, std::string& markupString );
127
128 /**
129  * Sets a text style to the given text.
130  * By default all style settings are applied but a bit mask could be used to modify only certain style settings.
131  * @param[in,out] styledTextArray The given text
132  * @param[in] style The given style
133  * @param[in] mask The bit mask.
134  */
135 void SetTextStyle( StyledTextArray& styledTextArray, const TextStyle& style, const TextStyle::Mask mask = TextStyle::ALL );
136
137 /**
138  * @see SetTextStyle( StyledTextArray& styledTextArray, const TextStyle& style, StyleMask mask )
139  * @param[in] text The input text.
140  * @param[out] styledTextArray The input text with the given style.
141  * @param[in] style The given style.
142  * @param[in] mask The bit mask.
143  */
144 void SetTextStyle( const Text& text, StyledTextArray& styledTextArray, const TextStyle& style, const TextStyle::Mask mask = TextStyle::ALL );
145
146 /**
147  * Sets a text style to a range of characters of the given text.
148  * By default all style settings are applied but a bit mask could be used to modify only certain style settings.
149  * @param[in,out] styledTextArray The given text
150  * @param[in] style The given style
151  * @param[in] mask The bit mask.
152  * @param[in] begin The first character of the range.
153  * @param[in] end The last character of the range.
154  * @note It will assert if begin or end are out of range, or if begin > end.
155  */
156 void SetTextStyleToRange( StyledTextArray& styledTextArray, const TextStyle& style, const TextStyle::Mask mask, const std::size_t begin, const std::size_t end );
157
158 } // namespace MarkupProcessor
159
160 } // namespace Toolkit
161
162 } // namespace Dali
163
164 /**
165  * @}
166  */
167 #endif // __DALI_TOOLKIT_MARKUP_PROCESSOR_H__