636c331ce543e2965056a3b4bbd822f78609d4f0
[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
59 } // namespace
60
61 void ProcessSpanTag(const Tag&                 tag,
62                     ColorRun&                  colorRun,
63                     FontDescriptionRun&        fontRun,
64                     UnderlinedCharacterRun&    underlinedCharacterRun,
65                     ColorRun&                  backgroundColorRun,
66                     StrikethroughCharacterRun& strikethroughRun,
67                     bool&                      isColorDefined,
68                     bool&                      isFontDefined,
69                     bool&                      isUnderlinedCharacterDefined,
70                     bool&                      isBackgroundColorDefined,
71                     bool&                      isStrikethroughDefined)
72
73 {
74   for(Vector<Attribute>::ConstIterator it    = tag.attributes.Begin(),
75                                        endIt = tag.attributes.End();
76       it != endIt;
77       ++it)
78   {
79     const Attribute& attribute(*it);
80
81     if(TokenComparison(XHTML_COLOR_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
82     {
83       isColorDefined = true;
84       ProcessColor(attribute, colorRun);
85     }
86     else if(TokenComparison(XHTML_BACKGROUND_COLOR_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
87     {
88       isBackgroundColorDefined = true;
89       ProcessColor(attribute, backgroundColorRun);
90     }
91     else if(TokenComparison(XHTML_FAMILY_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
92     {
93       isFontDefined = true;
94       ProcessFontFamily(attribute, fontRun);
95     }
96     else if(TokenComparison(XHTML_SIZE_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
97     {
98       isFontDefined = true;
99       ProcessFontSize(attribute, fontRun);
100     }
101     else if(TokenComparison(XHTML_WEIGHT_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
102     {
103       isFontDefined = true;
104       ProcessFontWeight(attribute, fontRun);
105     }
106     else if(TokenComparison(XHTML_WIDTH_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
107     {
108       isFontDefined = true;
109       ProcessFontWidth(attribute, fontRun);
110     }
111     else if(TokenComparison(XHTML_SLANT_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
112     {
113       isFontDefined = true;
114       ProcessFontSlant(attribute, fontRun);
115     }
116     else if(TokenComparison(XHTML_UNDERLINE_COLOR_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
117     {
118       isUnderlinedCharacterDefined = true;
119       ProcessColorAttribute(attribute, underlinedCharacterRun);
120     }
121     else if(TokenComparison(XHTML_UNDERLINE_HEIGHT_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
122     {
123       isUnderlinedCharacterDefined = true;
124       ProcessHeightAttribute(attribute, underlinedCharacterRun);
125     }
126     else if(TokenComparison(XHTML_UNDERLINE_TYPE_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
127     {
128       isUnderlinedCharacterDefined = true;
129       ProcessTypeAttribute(attribute, underlinedCharacterRun);
130     }
131     else if(TokenComparison(XHTML_UNDERLINE_DASH_GAP_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
132     {
133       isUnderlinedCharacterDefined = true;
134       ProcessDashGapAttribute(attribute, underlinedCharacterRun);
135     }
136     else if(TokenComparison(XHTML_UNDERLINE_DASH_WIDTH_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
137     {
138       isUnderlinedCharacterDefined = true;
139       ProcessDashWidthAttribute(attribute, underlinedCharacterRun);
140     }
141     else if(TokenComparison(XHTML_STRIKETHROUGH_COLOR_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
142     {
143       isStrikethroughDefined = true;
144       ProcessColorAttribute(attribute, strikethroughRun);
145     }
146   }
147 }
148
149 } // namespace Text
150
151 } // namespace Toolkit
152
153 } // namespace Dali