Support character-spacing in span tag
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / markup-processor-span.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // FILE HEADER
19 #include <dali-toolkit/internal/text/markup-processor-color.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/dali-vector.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/internal/text/color-run.h>
26 #include <dali-toolkit/internal/text/font-description-run.h>
27 #include <dali-toolkit/internal/text/markup-processor-character-spacing.h>
28 #include <dali-toolkit/internal/text/markup-processor-font.h>
29 #include <dali-toolkit/internal/text/markup-processor-helper-functions.h>
30 #include <dali-toolkit/internal/text/markup-processor-strikethrough.h>
31 #include <dali-toolkit/internal/text/markup-processor-underline.h>
32
33 namespace Dali
34 {
35 namespace Toolkit
36 {
37 namespace Text
38 {
39 namespace
40 {
41 const std::string XHTML_FAMILY_ATTRIBUTE("font-family");
42 const std::string XHTML_SIZE_ATTRIBUTE("font-size");
43 const std::string XHTML_WEIGHT_ATTRIBUTE("font-weight");
44 const std::string XHTML_WIDTH_ATTRIBUTE("font-width");
45 const std::string XHTML_SLANT_ATTRIBUTE("font-slant");
46
47 const std::string XHTML_COLOR_ATTRIBUTE("text-color");
48 const std::string XHTML_BACKGROUND_COLOR_ATTRIBUTE("background-color");
49
50 //the underlined character's attributes
51 const std::string XHTML_UNDERLINE_COLOR_ATTRIBUTE("u-color");
52 const std::string XHTML_UNDERLINE_HEIGHT_ATTRIBUTE("u-height");
53 const std::string XHTML_UNDERLINE_TYPE_ATTRIBUTE("u-type");
54 const std::string XHTML_UNDERLINE_DASH_GAP_ATTRIBUTE("u-dash-gap");
55 const std::string XHTML_UNDERLINE_DASH_WIDTH_ATTRIBUTE("u-dash-width");
56
57 //the strikethroughed character's attributes
58 const std::string XHTML_STRIKETHROUGH_COLOR_ATTRIBUTE("s-color");
59 const std::string XHTML_STRIKETHROUGH_HEIGHT_ATTRIBUTE("s-height");
60
61 //the character-spacing character's attributes
62 const std::string XHTML_CHARACTER_SPACING_VALUE_ATTRIBUTE("char-space-value");
63
64 //NOTE: the MAX_NUM_OF_ATTRIBUTES in "markup-processor.cpp" should be updated when add a new attribute for span tag.
65
66 } // namespace
67
68 void ProcessSpanTag(const Tag&                    tag,
69                     ColorRun&                     colorRun,
70                     FontDescriptionRun&           fontRun,
71                     UnderlinedCharacterRun&       underlinedCharacterRun,
72                     ColorRun&                     backgroundColorRun,
73                     StrikethroughCharacterRun&    strikethroughRun,
74                     CharacterSpacingCharacterRun& characterSpacingCharacterRun,
75                     bool&                         isColorDefined,
76                     bool&                         isFontDefined,
77                     bool&                         isUnderlinedCharacterDefined,
78                     bool&                         isBackgroundColorDefined,
79                     bool&                         isStrikethroughDefined,
80                     bool&                         isCharacterSpacingDefined)
81 {
82   for(Vector<Attribute>::ConstIterator it    = tag.attributes.Begin(),
83                                        endIt = tag.attributes.End();
84       it != endIt;
85       ++it)
86   {
87     const Attribute& attribute(*it);
88
89     if(TokenComparison(XHTML_COLOR_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
90     {
91       isColorDefined = true;
92       ProcessColor(attribute, colorRun);
93     }
94     else if(TokenComparison(XHTML_BACKGROUND_COLOR_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
95     {
96       isBackgroundColorDefined = true;
97       ProcessColor(attribute, backgroundColorRun);
98     }
99     else if(TokenComparison(XHTML_FAMILY_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
100     {
101       isFontDefined = true;
102       ProcessFontFamily(attribute, fontRun);
103     }
104     else if(TokenComparison(XHTML_SIZE_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
105     {
106       isFontDefined = true;
107       ProcessFontSize(attribute, fontRun);
108     }
109     else if(TokenComparison(XHTML_WEIGHT_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
110     {
111       isFontDefined = true;
112       ProcessFontWeight(attribute, fontRun);
113     }
114     else if(TokenComparison(XHTML_WIDTH_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
115     {
116       isFontDefined = true;
117       ProcessFontWidth(attribute, fontRun);
118     }
119     else if(TokenComparison(XHTML_SLANT_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
120     {
121       isFontDefined = true;
122       ProcessFontSlant(attribute, fontRun);
123     }
124     else if(TokenComparison(XHTML_UNDERLINE_COLOR_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
125     {
126       isUnderlinedCharacterDefined = true;
127       ProcessColorAttribute(attribute, underlinedCharacterRun);
128     }
129     else if(TokenComparison(XHTML_UNDERLINE_HEIGHT_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
130     {
131       isUnderlinedCharacterDefined = true;
132       ProcessHeightAttribute(attribute, underlinedCharacterRun);
133     }
134     else if(TokenComparison(XHTML_UNDERLINE_TYPE_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
135     {
136       isUnderlinedCharacterDefined = true;
137       ProcessTypeAttribute(attribute, underlinedCharacterRun);
138     }
139     else if(TokenComparison(XHTML_UNDERLINE_DASH_GAP_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
140     {
141       isUnderlinedCharacterDefined = true;
142       ProcessDashGapAttribute(attribute, underlinedCharacterRun);
143     }
144     else if(TokenComparison(XHTML_UNDERLINE_DASH_WIDTH_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
145     {
146       isUnderlinedCharacterDefined = true;
147       ProcessDashWidthAttribute(attribute, underlinedCharacterRun);
148     }
149     else if(TokenComparison(XHTML_STRIKETHROUGH_COLOR_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
150     {
151       isStrikethroughDefined = true;
152       ProcessColorAttribute(attribute, strikethroughRun);
153     }
154     else if(TokenComparison(XHTML_STRIKETHROUGH_HEIGHT_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
155     {
156       isStrikethroughDefined = true;
157       ProcessHeightAttribute(attribute, strikethroughRun);
158     }
159     else if(TokenComparison(XHTML_CHARACTER_SPACING_VALUE_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
160     {
161       isCharacterSpacingDefined = true;
162       ProcessValueAttribute(attribute, characterSpacingCharacterRun);
163     }
164   }
165 }
166
167 } // namespace Text
168
169 } // namespace Toolkit
170
171 } // namespace Dali