Support character-spacing tag in markup
[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-font.h>
28 #include <dali-toolkit/internal/text/markup-processor-helper-functions.h>
29 #include <dali-toolkit/internal/text/markup-processor-strikethrough.h>
30 #include <dali-toolkit/internal/text/markup-processor-underline.h>
31
32 namespace Dali
33 {
34 namespace Toolkit
35 {
36 namespace Text
37 {
38 namespace
39 {
40 const std::string XHTML_FAMILY_ATTRIBUTE("font-family");
41 const std::string XHTML_SIZE_ATTRIBUTE("font-size");
42 const std::string XHTML_WEIGHT_ATTRIBUTE("font-weight");
43 const std::string XHTML_WIDTH_ATTRIBUTE("font-width");
44 const std::string XHTML_SLANT_ATTRIBUTE("font-slant");
45
46 const std::string XHTML_COLOR_ATTRIBUTE("text-color");
47 const std::string XHTML_BACKGROUND_COLOR_ATTRIBUTE("background-color");
48
49 //the underlined character's attributes
50 const std::string XHTML_UNDERLINE_COLOR_ATTRIBUTE("u-color");
51 const std::string XHTML_UNDERLINE_HEIGHT_ATTRIBUTE("u-height");
52 const std::string XHTML_UNDERLINE_TYPE_ATTRIBUTE("u-type");
53 const std::string XHTML_UNDERLINE_DASH_GAP_ATTRIBUTE("u-dash-gap");
54 const std::string XHTML_UNDERLINE_DASH_WIDTH_ATTRIBUTE("u-dash-width");
55
56 //the strikethroughed character's attributes
57 const std::string XHTML_STRIKETHROUGH_COLOR_ATTRIBUTE("s-color");
58 const std::string XHTML_STRIKETHROUGH_HEIGHT_ATTRIBUTE("s-height");
59
60 } // namespace
61
62 void ProcessSpanTag(const Tag&                 tag,
63                     ColorRun&                  colorRun,
64                     FontDescriptionRun&        fontRun,
65                     UnderlinedCharacterRun&    underlinedCharacterRun,
66                     ColorRun&                  backgroundColorRun,
67                     StrikethroughCharacterRun& strikethroughRun,
68                     bool&                      isColorDefined,
69                     bool&                      isFontDefined,
70                     bool&                      isUnderlinedCharacterDefined,
71                     bool&                      isBackgroundColorDefined,
72                     bool&                      isStrikethroughDefined)
73
74 {
75   for(Vector<Attribute>::ConstIterator it    = tag.attributes.Begin(),
76                                        endIt = tag.attributes.End();
77       it != endIt;
78       ++it)
79   {
80     const Attribute& attribute(*it);
81
82     if(TokenComparison(XHTML_COLOR_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
83     {
84       isColorDefined = true;
85       ProcessColor(attribute, colorRun);
86     }
87     else if(TokenComparison(XHTML_BACKGROUND_COLOR_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
88     {
89       isBackgroundColorDefined = true;
90       ProcessColor(attribute, backgroundColorRun);
91     }
92     else if(TokenComparison(XHTML_FAMILY_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
93     {
94       isFontDefined = true;
95       ProcessFontFamily(attribute, fontRun);
96     }
97     else if(TokenComparison(XHTML_SIZE_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
98     {
99       isFontDefined = true;
100       ProcessFontSize(attribute, fontRun);
101     }
102     else if(TokenComparison(XHTML_WEIGHT_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
103     {
104       isFontDefined = true;
105       ProcessFontWeight(attribute, fontRun);
106     }
107     else if(TokenComparison(XHTML_WIDTH_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
108     {
109       isFontDefined = true;
110       ProcessFontWidth(attribute, fontRun);
111     }
112     else if(TokenComparison(XHTML_SLANT_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
113     {
114       isFontDefined = true;
115       ProcessFontSlant(attribute, fontRun);
116     }
117     else if(TokenComparison(XHTML_UNDERLINE_COLOR_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
118     {
119       isUnderlinedCharacterDefined = true;
120       ProcessColorAttribute(attribute, underlinedCharacterRun);
121     }
122     else if(TokenComparison(XHTML_UNDERLINE_HEIGHT_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
123     {
124       isUnderlinedCharacterDefined = true;
125       ProcessHeightAttribute(attribute, underlinedCharacterRun);
126     }
127     else if(TokenComparison(XHTML_UNDERLINE_TYPE_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
128     {
129       isUnderlinedCharacterDefined = true;
130       ProcessTypeAttribute(attribute, underlinedCharacterRun);
131     }
132     else if(TokenComparison(XHTML_UNDERLINE_DASH_GAP_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
133     {
134       isUnderlinedCharacterDefined = true;
135       ProcessDashGapAttribute(attribute, underlinedCharacterRun);
136     }
137     else if(TokenComparison(XHTML_UNDERLINE_DASH_WIDTH_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
138     {
139       isUnderlinedCharacterDefined = true;
140       ProcessDashWidthAttribute(attribute, underlinedCharacterRun);
141     }
142     else if(TokenComparison(XHTML_STRIKETHROUGH_COLOR_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
143     {
144       isStrikethroughDefined = true;
145       ProcessColorAttribute(attribute, strikethroughRun);
146     }
147     else if(TokenComparison(XHTML_STRIKETHROUGH_HEIGHT_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
148     {
149       isStrikethroughDefined = true;
150       ProcessHeightAttribute(attribute, strikethroughRun);
151     }
152   }
153 }
154
155 } // namespace Text
156
157 } // namespace Toolkit
158
159 } // namespace Dali