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/markup-processor-underline.h>
22 #include <dali/public-api/common/dali-vector.h>
25 #include <dali-toolkit/internal/text/markup-processor/markup-processor-attribute-helper-functions.h>
26 #include <dali-toolkit/internal/text/markup-processor/markup-processor-helper-functions.h>
27 #include <dali-toolkit/internal/text/markup-tags-and-attributes.h>
28 #include <dali-toolkit/internal/text/text-effects-style.h>
29 #include <dali-toolkit/internal/text/underlined-character-run.h>
39 const unsigned int MAX_TYPE_ATTRIBUTE_SIZE = 7u; ///< The maximum length of any of the possible 'type' values.
43 void ProcessTypeAttribute(const Attribute& attribute, UnderlinedCharacterRun& underlinedCharacterRun)
45 underlinedCharacterRun.properties.typeDefined = ProcessEnumerationAttribute<Text::Underline::Type>(attribute,
46 MAX_TYPE_ATTRIBUTE_SIZE,
47 &StringToUnderlineType,
48 underlinedCharacterRun.properties.type);
51 void ProcessDashGapAttribute(const Attribute& attribute, UnderlinedCharacterRun& underlinedCharacterRun)
53 underlinedCharacterRun.properties.dashGap = ProcessFloatAttribute(attribute);
54 underlinedCharacterRun.properties.dashGapDefined = true;
57 void ProcessDashWidthAttribute(const Attribute& attribute, UnderlinedCharacterRun& underlinedCharacterRun)
59 underlinedCharacterRun.properties.dashWidth = ProcessFloatAttribute(attribute);
60 underlinedCharacterRun.properties.dashWidthDefined = true;
62 void ProcessHeightAttribute(const Attribute& attribute, UnderlinedCharacterRun& underlinedCharacterRun)
64 underlinedCharacterRun.properties.height = ProcessFloatAttribute(attribute);
65 underlinedCharacterRun.properties.heightDefined = true;
68 void ProcessColorAttribute(const Attribute& attribute, UnderlinedCharacterRun& underlinedCharacterRun)
70 ColorStringToVector4(attribute.valueBuffer, attribute.valueLength, underlinedCharacterRun.properties.color);
71 underlinedCharacterRun.properties.colorDefined = true;
74 void ProcessUnderlineTag(const Tag& tag, UnderlinedCharacterRun& underlinedCharacterRun)
76 for(Vector<Attribute>::ConstIterator it = tag.attributes.Begin(),
77 endIt = tag.attributes.End();
81 const Attribute& attribute(*it);
83 if(TokenComparison(MARKUP::UNDERLINE_ATTRIBUTES::COLOR, attribute.nameBuffer, attribute.nameLength))
85 ProcessColorAttribute(attribute, underlinedCharacterRun);
87 else if(TokenComparison(MARKUP::UNDERLINE_ATTRIBUTES::HEIGHT, attribute.nameBuffer, attribute.nameLength))
89 ProcessHeightAttribute(attribute, underlinedCharacterRun);
91 else if(TokenComparison(MARKUP::UNDERLINE_ATTRIBUTES::TYPE, attribute.nameBuffer, attribute.nameLength))
93 ProcessTypeAttribute(attribute, underlinedCharacterRun);
95 else if(TokenComparison(MARKUP::UNDERLINE_ATTRIBUTES::DASH_GAP, attribute.nameBuffer, attribute.nameLength))
97 ProcessDashGapAttribute(attribute, underlinedCharacterRun);
99 else if(TokenComparison(MARKUP::UNDERLINE_ATTRIBUTES::DASH_WIDTH, attribute.nameBuffer, attribute.nameLength))
101 ProcessDashWidthAttribute(attribute, underlinedCharacterRun);
106 void OverrideNestedUnderlinedCharacterRuns(Vector<UnderlinedCharacterRun>& underlinedCharacterRuns)
108 // Handle nested tags
109 // The inner tag inherit the attributes of the outer tag and override them when defined in the inner tag.
111 // <u height='5.0f' color='blue'> outer tag before <u color='green'> inner tag </u> outer tag after </u>
112 // "outer tag before" and "outer tag after" have height = 5.0f and color = 'blue'
113 // "inner tag" has height = 5.0f and color = 'green'
115 if(underlinedCharacterRuns.Count() > 0u)
117 Vector<UnderlinedCharacterRun>::ConstIterator preIt = underlinedCharacterRuns.Begin();
119 Vector<UnderlinedCharacterRun>::Iterator it = underlinedCharacterRuns.Begin() + 1;
120 Vector<UnderlinedCharacterRun>::ConstIterator endIt = underlinedCharacterRuns.End();
124 const UnderlinedCharacterRun& run = *it;
125 const CharacterIndex& characterIndex = run.characterRun.characterIndex;
126 const Length& numberOfCharacters = run.characterRun.numberOfCharacters;
128 const UnderlinedCharacterRun& preRun = *preIt;
129 const CharacterIndex& preCharacterIndex = preRun.characterRun.characterIndex;
130 const Length& preNumberOfCharacters = preRun.characterRun.numberOfCharacters;
132 if((preCharacterIndex <= characterIndex) &&
133 ((characterIndex + numberOfCharacters) <= (preCharacterIndex + preNumberOfCharacters)))
135 it->properties.CopyIfNotDefined(preIt->properties);
146 } // namespace Toolkit