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