Merge base & optional
[platform/core/uifw/dali-toolkit.git] / 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 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/vector-wrapper.h>
23 #include <dali/public-api/text/text.h>
24 #include <dali/public-api/text/text-style.h>
25
26 namespace Dali
27 {
28
29 namespace Toolkit
30 {
31
32 /**
33  * @brief Markup Processor enumerations, structures and functions.
34  *
35  * See the \link markup-processor Markup Processor \endlink page in the Programming Guide.
36  */
37 namespace MarkupProcessor
38 {
39
40 /**
41  * @brief A pair of Dali::Text and Dali::TextStyle.
42  *
43  * mText is a Dali::Text object which can store text in different
44  * languages. mStyle is a Dali::TextStyle object which can store all
45  * text styling features provided by Dali::TextActor.
46  */
47 struct StyledText
48 {
49   /**
50    * @brief Constructor
51    */
52   StyledText()
53   : mText(),
54     mStyle()
55   {
56   }
57
58   /**
59    * @brief Constructor
60    *
61    * @param[in] text  A Text object
62    * @param[in] style A Style object
63    */
64   StyledText( const Text& text, const TextStyle& style )
65   : mText( text ),
66     mStyle( style )
67   {
68   }
69
70   Text      mText;  ///< Store text. Could be a mix of different languages.
71   TextStyle mStyle; ///< Store the style for the text.
72 };
73
74 /**
75  * @brief This type defines a vector of StyledText.
76  *
77  * It's used to store a whole text with its style and set it to a
78  * Dali::Toolkit::TextView. It could be used in other UI
79  * Dali::Toolkit::Control classes which need text with style.
80  */
81 typedef std::vector<StyledText> StyledTextArray;
82
83 /**
84  * @brief Creates a text array with its style from a markup string.
85  *
86  * Refer to the \link markup-processor Markup Processor \endlink page in the Programming Guide
87  * to see the html-ish sintax and some examples.
88  *
89  * @param [in] markupString A string with style.
90  * @param [out] styledTextArray A text array split in characters, each one with its style.
91  * @param [in] scanForMarkup If true will check to see string contains markup, else assume not
92  */
93 DALI_IMPORT_API void GetStyledTextArray( const std::string& markupString, StyledTextArray& styledTextArray, bool scanForMarkup );
94
95 /**
96  * @brief Creates a plain string from a text array (thus stripping the style meta).
97  *
98  * @param [in] styledTextArray A text array split in characters, each one with its style.
99  * @param [out] plainString A string without style.
100  */
101 DALI_IMPORT_API void GetPlainString( const StyledTextArray& styledTextArray, std::string& plainString );
102
103 /**
104  * @brief Creates a markup string from a text array with its style.
105  *
106  * @param [in] styledTextArray A text array split in characters, each one with its style.
107  * @param [out] markupString A string with style.
108  */
109 DALI_IMPORT_API void GetMarkupString( const StyledTextArray& styledTextArray, std::string& markupString );
110
111 /**
112  * @brief Sets a text style to the given text.
113  *
114  * By default all style settings are applied but a bit mask could be used to modify only certain style settings.
115  * @param[in,out] styledTextArray The given text
116  * @param[in] style The given style
117  * @param[in] mask The bit mask.
118  */
119 DALI_IMPORT_API void SetTextStyle( StyledTextArray& styledTextArray, const TextStyle& style, TextStyle::Mask mask = TextStyle::ALL );
120
121 /**
122  * @brief Sets a text style to the given text.
123  *
124  * @see SetTextStyle( StyledTextArray& styledTextArray, const TextStyle& style, TextStyle::Mask mask )
125  *
126  * @param[in] text The input text.
127  * @param[out] styledTextArray The input text with the given style.
128  * @param[in] style The given style.
129  * @param[in] mask The bit mask.
130  */
131 DALI_IMPORT_API void SetTextStyle( const Text& text, StyledTextArray& styledTextArray, const TextStyle& style, TextStyle::Mask mask = TextStyle::ALL );
132
133 /**
134  * @brief Sets a text style to a range of characters of the given text.
135  *
136  * By default all style settings are applied but a bit mask could be used to modify only certain style settings.
137  * @param[in,out] styledTextArray The given text
138  * @param[in] style The given style
139  * @param[in] mask The bit mask.
140  * @param[in] begin The first character of the range.
141  * @param[in] end The last character of the range.
142  * @note It will assert if begin or end are out of range, or if begin > end.
143  */
144 DALI_IMPORT_API void SetTextStyleToRange( StyledTextArray& styledTextArray, const TextStyle& style, TextStyle::Mask mask, std::size_t begin, std::size_t end );
145
146 } // namespace MarkupProcessor
147
148 } // namespace Toolkit
149
150 } // namespace Dali
151
152 #endif // __DALI_TOOLKIT_MARKUP_PROCESSOR_H__