2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali-toolkit/internal/text/markup-processor-color.h>
22 #include <dali/public-api/common/dali-vector.h>
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-character-spacing.h>
28 #include <dali-toolkit/internal/text/markup-processor-font.h>
29 #include <dali-toolkit/internal/text/markup-processor-helper-functions.h>
30 #include <dali-toolkit/internal/text/markup-processor-strikethrough.h>
31 #include <dali-toolkit/internal/text/markup-processor-underline.h>
41 const std::string XHTML_FAMILY_ATTRIBUTE("font-family");
42 const std::string XHTML_SIZE_ATTRIBUTE("font-size");
43 const std::string XHTML_WEIGHT_ATTRIBUTE("font-weight");
44 const std::string XHTML_WIDTH_ATTRIBUTE("font-width");
45 const std::string XHTML_SLANT_ATTRIBUTE("font-slant");
47 const std::string XHTML_COLOR_ATTRIBUTE("text-color");
48 const std::string XHTML_BACKGROUND_COLOR_ATTRIBUTE("background-color");
50 //the underlined character's attributes
51 const std::string XHTML_UNDERLINE_COLOR_ATTRIBUTE("u-color");
52 const std::string XHTML_UNDERLINE_HEIGHT_ATTRIBUTE("u-height");
53 const std::string XHTML_UNDERLINE_TYPE_ATTRIBUTE("u-type");
54 const std::string XHTML_UNDERLINE_DASH_GAP_ATTRIBUTE("u-dash-gap");
55 const std::string XHTML_UNDERLINE_DASH_WIDTH_ATTRIBUTE("u-dash-width");
57 //the strikethroughed character's attributes
58 const std::string XHTML_STRIKETHROUGH_COLOR_ATTRIBUTE("s-color");
59 const std::string XHTML_STRIKETHROUGH_HEIGHT_ATTRIBUTE("s-height");
61 //the character-spacing character's attributes
62 const std::string XHTML_CHARACTER_SPACING_VALUE_ATTRIBUTE("char-space-value");
64 //NOTE: the MAX_NUM_OF_ATTRIBUTES in "markup-processor.cpp" should be updated when add a new attribute for span tag.
68 void ProcessSpanTag(const Tag& tag,
70 FontDescriptionRun& fontRun,
71 UnderlinedCharacterRun& underlinedCharacterRun,
72 ColorRun& backgroundColorRun,
73 StrikethroughCharacterRun& strikethroughRun,
74 CharacterSpacingCharacterRun& characterSpacingCharacterRun,
77 bool& isUnderlinedCharacterDefined,
78 bool& isBackgroundColorDefined,
79 bool& isStrikethroughDefined,
80 bool& isCharacterSpacingDefined)
82 for(Vector<Attribute>::ConstIterator it = tag.attributes.Begin(),
83 endIt = tag.attributes.End();
87 const Attribute& attribute(*it);
89 if(TokenComparison(XHTML_COLOR_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
91 isColorDefined = true;
92 ProcessColor(attribute, colorRun);
94 else if(TokenComparison(XHTML_BACKGROUND_COLOR_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
96 isBackgroundColorDefined = true;
97 ProcessColor(attribute, backgroundColorRun);
99 else if(TokenComparison(XHTML_FAMILY_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
101 isFontDefined = true;
102 ProcessFontFamily(attribute, fontRun);
104 else if(TokenComparison(XHTML_SIZE_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
106 isFontDefined = true;
107 ProcessFontSize(attribute, fontRun);
109 else if(TokenComparison(XHTML_WEIGHT_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
111 isFontDefined = true;
112 ProcessFontWeight(attribute, fontRun);
114 else if(TokenComparison(XHTML_WIDTH_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
116 isFontDefined = true;
117 ProcessFontWidth(attribute, fontRun);
119 else if(TokenComparison(XHTML_SLANT_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
121 isFontDefined = true;
122 ProcessFontSlant(attribute, fontRun);
124 else if(TokenComparison(XHTML_UNDERLINE_COLOR_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
126 isUnderlinedCharacterDefined = true;
127 ProcessColorAttribute(attribute, underlinedCharacterRun);
129 else if(TokenComparison(XHTML_UNDERLINE_HEIGHT_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
131 isUnderlinedCharacterDefined = true;
132 ProcessHeightAttribute(attribute, underlinedCharacterRun);
134 else if(TokenComparison(XHTML_UNDERLINE_TYPE_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
136 isUnderlinedCharacterDefined = true;
137 ProcessTypeAttribute(attribute, underlinedCharacterRun);
139 else if(TokenComparison(XHTML_UNDERLINE_DASH_GAP_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
141 isUnderlinedCharacterDefined = true;
142 ProcessDashGapAttribute(attribute, underlinedCharacterRun);
144 else if(TokenComparison(XHTML_UNDERLINE_DASH_WIDTH_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
146 isUnderlinedCharacterDefined = true;
147 ProcessDashWidthAttribute(attribute, underlinedCharacterRun);
149 else if(TokenComparison(XHTML_STRIKETHROUGH_COLOR_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
151 isStrikethroughDefined = true;
152 ProcessColorAttribute(attribute, strikethroughRun);
154 else if(TokenComparison(XHTML_STRIKETHROUGH_HEIGHT_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
156 isStrikethroughDefined = true;
157 ProcessHeightAttribute(attribute, strikethroughRun);
159 else if(TokenComparison(XHTML_CHARACTER_SPACING_VALUE_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
161 isCharacterSpacingDefined = true;
162 ProcessValueAttribute(attribute, characterSpacingCharacterRun);
169 } // namespace Toolkit