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