Merge "Support the underline and its attributes in span tag" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / markup-processor-underline.cpp
1 /*
2  * Copyright (c) 2022 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-underline.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/dali-vector.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/internal/text/markup-processor-attribute-helper-functions.h>
26 #include <dali-toolkit/internal/text/markup-processor-helper-functions.h>
27 #include <dali-toolkit/internal/text/text-effects-style.h>
28 #include <dali-toolkit/internal/text/underlined-character-run.h>
29
30 namespace Dali
31 {
32 namespace Toolkit
33 {
34 namespace Text
35 {
36 namespace
37 {
38 const std::string XHTML_COLOR_ATTRIBUTE("color");
39 const std::string XHTML_HEIGHT_ATTRIBUTE("height");
40 const std::string XHTML_TYPE_ATTRIBUTE("type");
41 const std::string XHTML_DASH_GAP_ATTRIBUTE("dash-gap");
42 const std::string XHTML_DASH_WIDTH_ATTRIBUTE("dash-width");
43
44 const unsigned int MAX_TYPE_ATTRIBUTE_SIZE = 7u; ///< The maximum length of any of the possible 'type' values.
45
46 } // namespace
47
48 void ProcessTypeAttribute(const Attribute& attribute, UnderlinedCharacterRun& underlinedCharacterRun)
49 {
50   underlinedCharacterRun.properties.typeDefined = ProcessEnumerationAttribute<Text::Underline::Type>(attribute,
51                                                                                                      MAX_TYPE_ATTRIBUTE_SIZE,
52                                                                                                      &StringToUnderlineType,
53                                                                                                      underlinedCharacterRun.properties.type);
54 }
55
56 void ProcessDashGapAttribute(const Attribute& attribute, UnderlinedCharacterRun& underlinedCharacterRun)
57 {
58   underlinedCharacterRun.properties.dashGap        = ProcessFloatAttribute(attribute);
59   underlinedCharacterRun.properties.dashGapDefined = true;
60 }
61
62 void ProcessDashWidthAttribute(const Attribute& attribute, UnderlinedCharacterRun& underlinedCharacterRun)
63 {
64   underlinedCharacterRun.properties.dashWidth        = ProcessFloatAttribute(attribute);
65   underlinedCharacterRun.properties.dashWidthDefined = true;
66 }
67 void ProcessHeightAttribute(const Attribute& attribute, UnderlinedCharacterRun& underlinedCharacterRun)
68 {
69   underlinedCharacterRun.properties.height        = ProcessFloatAttribute(attribute);
70   underlinedCharacterRun.properties.heightDefined = true;
71 }
72
73 void ProcessColorAttribute(const Attribute& attribute, UnderlinedCharacterRun& underlinedCharacterRun)
74 {
75   ColorStringToVector4(attribute.valueBuffer, attribute.valueLength, underlinedCharacterRun.properties.color);
76   underlinedCharacterRun.properties.colorDefined = true;
77 }
78
79 void ProcessUnderlineTag(const Tag& tag, UnderlinedCharacterRun& underlinedCharacterRun)
80 {
81   for(Vector<Attribute>::ConstIterator it    = tag.attributes.Begin(),
82                                        endIt = tag.attributes.End();
83       it != endIt;
84       ++it)
85   {
86     const Attribute& attribute(*it);
87
88     if(TokenComparison(XHTML_COLOR_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
89     {
90       ProcessColorAttribute(attribute, underlinedCharacterRun);
91     }
92     else if(TokenComparison(XHTML_HEIGHT_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
93     {
94       ProcessHeightAttribute(attribute, underlinedCharacterRun);
95     }
96     else if(TokenComparison(XHTML_TYPE_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
97     {
98       ProcessTypeAttribute(attribute, underlinedCharacterRun);
99     }
100     else if(TokenComparison(XHTML_DASH_GAP_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
101     {
102       ProcessDashGapAttribute(attribute, underlinedCharacterRun);
103     }
104     else if(TokenComparison(XHTML_DASH_WIDTH_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
105     {
106       ProcessDashWidthAttribute(attribute, underlinedCharacterRun);
107     }
108   }
109 }
110
111 } // namespace Text
112
113 } // namespace Toolkit
114
115 } // namespace Dali