2 * Copyright (c) 2022 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-underline.h>
22 #include <dali/public-api/common/dali-vector.h>
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>
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");
44 const unsigned int MAX_TYPE_ATTRIBUTE_SIZE = 7u; ///< The maximum length of any of the possible 'type' values.
48 void ProcessTypeAttribute(const Attribute& attribute, UnderlinedCharacterRun& underlinedCharacterRun)
50 underlinedCharacterRun.properties.typeDefined = ProcessEnumerationAttribute<Text::Underline::Type>(attribute,
51 MAX_TYPE_ATTRIBUTE_SIZE,
52 &StringToUnderlineType,
53 underlinedCharacterRun.properties.type);
56 void ProcessDashGapAttribute(const Attribute& attribute, UnderlinedCharacterRun& underlinedCharacterRun)
58 underlinedCharacterRun.properties.dashGap = ProcessFloatAttribute(attribute);
59 underlinedCharacterRun.properties.dashGapDefined = true;
62 void ProcessDashWidthAttribute(const Attribute& attribute, UnderlinedCharacterRun& underlinedCharacterRun)
64 underlinedCharacterRun.properties.dashWidth = ProcessFloatAttribute(attribute);
65 underlinedCharacterRun.properties.dashWidthDefined = true;
67 void ProcessHeightAttribute(const Attribute& attribute, UnderlinedCharacterRun& underlinedCharacterRun)
69 underlinedCharacterRun.properties.height = ProcessFloatAttribute(attribute);
70 underlinedCharacterRun.properties.heightDefined = true;
73 void ProcessColorAttribute(const Attribute& attribute, UnderlinedCharacterRun& underlinedCharacterRun)
75 ColorStringToVector4(attribute.valueBuffer, attribute.valueLength, underlinedCharacterRun.properties.color);
76 underlinedCharacterRun.properties.colorDefined = true;
79 void ProcessUnderlineTag(const Tag& tag, UnderlinedCharacterRun& underlinedCharacterRun)
81 for(Vector<Attribute>::ConstIterator it = tag.attributes.Begin(),
82 endIt = tag.attributes.End();
86 const Attribute& attribute(*it);
88 if(TokenComparison(XHTML_COLOR_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
90 ProcessColorAttribute(attribute, underlinedCharacterRun);
92 else if(TokenComparison(XHTML_HEIGHT_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
94 ProcessHeightAttribute(attribute, underlinedCharacterRun);
96 else if(TokenComparison(XHTML_TYPE_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
98 ProcessTypeAttribute(attribute, underlinedCharacterRun);
100 else if(TokenComparison(XHTML_DASH_GAP_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
102 ProcessDashGapAttribute(attribute, underlinedCharacterRun);
104 else if(TokenComparison(XHTML_DASH_WIDTH_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
106 ProcessDashWidthAttribute(attribute, underlinedCharacterRun);
111 void OverrideNestedUnderlinedCharacterRuns(Vector<UnderlinedCharacterRun>& underlinedCharacterRuns)
113 // Handle nested tags
114 // The inner tag inherit the attributes of the outer tag and override them when defined in the inner tag.
116 // <u height='5.0f' color='blue'> outer tag before <u color='green'> inner tag </u> outer tag after </u>
117 // "outer tag before" and "outer tag after" have height = 5.0f and color = 'blue'
118 // "inner tag" has height = 5.0f and color = 'green'
120 if(underlinedCharacterRuns.Count() > 0u)
122 Vector<UnderlinedCharacterRun>::ConstIterator preIt = underlinedCharacterRuns.Begin();
124 Vector<UnderlinedCharacterRun>::Iterator it = underlinedCharacterRuns.Begin() + 1;
125 Vector<UnderlinedCharacterRun>::ConstIterator endIt = underlinedCharacterRuns.End();
129 const UnderlinedCharacterRun& run = *it;
130 const CharacterIndex& characterIndex = run.characterRun.characterIndex;
131 const Length& numberOfCharacters = run.characterRun.numberOfCharacters;
133 const UnderlinedCharacterRun& preRun = *preIt;
134 const CharacterIndex& preCharacterIndex = preRun.characterRun.characterIndex;
135 const Length& preNumberOfCharacters = preRun.characterRun.numberOfCharacters;
137 if((preCharacterIndex <= characterIndex) &&
138 ((characterIndex + numberOfCharacters) <= (preCharacterIndex + preNumberOfCharacters)))
140 it->properties.CopyIfNotDefined(preIt->properties);
151 } // namespace Toolkit