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