2 * Copyright (c) 2021 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.h>
22 #include <dali/integration-api/debug.h>
23 #include <climits> // for ULONG_MAX
27 #include <dali-toolkit/internal/text/character-set-conversion.h>
28 #include <dali-toolkit/internal/text/markup-processor-anchor.h>
29 #include <dali-toolkit/internal/text/markup-processor-background.h>
30 #include <dali-toolkit/internal/text/markup-processor-color.h>
31 #include <dali-toolkit/internal/text/markup-processor-embedded-item.h>
32 #include <dali-toolkit/internal/text/markup-processor-font.h>
33 #include <dali-toolkit/internal/text/markup-processor-helper-functions.h>
34 #include <dali-toolkit/internal/text/markup-processor-span.h>
35 #include <dali-toolkit/internal/text/xhtml-entities.h>
45 // HTML-ISH tag and attribute constants.
46 // Note they must be lower case in order to make the comparison to work
47 // as the parser converts all the read tags to lower case.
48 const std::string XHTML_COLOR_TAG("color");
49 const std::string XHTML_FONT_TAG("font");
50 const std::string XHTML_B_TAG("b");
51 const std::string XHTML_I_TAG("i");
52 const std::string XHTML_U_TAG("u");
53 const std::string XHTML_SHADOW_TAG("shadow");
54 const std::string XHTML_GLOW_TAG("glow");
55 const std::string XHTML_OUTLINE_TAG("outline");
56 const std::string XHTML_ITEM_TAG("item");
57 const std::string XHTML_ANCHOR_TAG("a");
58 const std::string XHTML_BACKGROUND_TAG("background");
59 const std::string XHTML_SPAN_TAG("span");
61 const char LESS_THAN = '<';
62 const char GREATER_THAN = '>';
63 const char EQUAL = '=';
64 const char QUOTATION_MARK = '\'';
65 const char SLASH = '/';
66 const char BACK_SLASH = '\\';
67 const char AMPERSAND = '&';
68 const char HASH = '#';
69 const char SEMI_COLON = ';';
70 const char CHAR_ARRAY_END = '\0';
71 const char HEX_CODE = 'x';
73 const char WHITE_SPACE = 0x20; // ASCII value of the white space.
75 // Range 1 0x0u < XHTML_DECIMAL_ENTITY_RANGE <= 0xD7FFu
76 // Range 2 0xE000u < XHTML_DECIMAL_ENTITY_RANGE <= 0xFFFDu
77 // Range 3 0x10000u < XHTML_DECIMAL_ENTITY_RANGE <= 0x10FFFFu
78 const unsigned long XHTML_DECIMAL_ENTITY_RANGE[] = {0x0u, 0xD7FFu, 0xE000u, 0xFFFDu, 0x10000u, 0x10FFFFu};
80 const unsigned int MAX_NUM_OF_ATTRIBUTES = 5u; ///< The font tag has the 'family', 'size' 'weight', 'width' and 'slant' attrubutes.
81 const unsigned int DEFAULT_VECTOR_SIZE = 16u; ///< Default size of run vectors.
83 #if defined(DEBUG_ENABLED)
84 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_MARKUP_PROCESSOR");
87 typedef VectorBase::SizeType RunIndex;
90 * @brief Struct used to retrieve the style runs from the mark-up string.
92 template<typename StyleStackType>
95 Vector<StyleStackType> stack; ///< Use a vector as a style stack.
96 unsigned int topIndex; ///< Points the top of the stack.
102 stack.Resize(DEFAULT_VECTOR_SIZE);
105 void Push(StyleStackType item)
107 // Check if there is space inside the style stack.
108 const VectorBase::SizeType size = stack.Count();
111 // Resize the style stack.
112 stack.Resize(2u * size);
115 // Set the item in the top of the stack.
116 *(stack.Begin() + topIndex) = item;
118 // Reposition the pointer to the top of the stack.
124 // Pop the top of the stack.
126 return *(stack.Begin() + topIndex);
131 * @brief Struct used to retrieve spans from the mark-up string.
135 RunIndex colorRunIndex;
136 RunIndex fontRunIndex;
142 * @brief Initializes a font run description to its defaults.
144 * @param[in,out] fontRun The font description run to initialize.
146 void Initialize(FontDescriptionRun& fontRun)
148 fontRun.characterRun.characterIndex = 0u;
149 fontRun.characterRun.numberOfCharacters = 0u;
150 fontRun.familyName = NULL;
151 fontRun.familyLength = 0u;
152 fontRun.weight = TextAbstraction::FontWeight::NORMAL;
153 fontRun.width = TextAbstraction::FontWidth::NORMAL;
154 fontRun.slant = TextAbstraction::FontSlant::NORMAL;
156 fontRun.familyDefined = false;
157 fontRun.weightDefined = false;
158 fontRun.widthDefined = false;
159 fontRun.slantDefined = false;
160 fontRun.sizeDefined = false;
164 * @brief Initializes a color run description to its defaults.
166 * @param[in,out] colorRun The font description run to initialize.
168 void Initialize(ColorRun& colorRun)
170 colorRun.characterRun.characterIndex = 0u;
171 colorRun.characterRun.numberOfCharacters = 0u;
175 * @brief Initializes a underlined character run to its defaults.
177 * @param[in,out] underlinedCharacterRun The underelined character run to initialize.
179 void Initialize(UnderlinedCharacterRun& underlinedCharacterRun)
181 underlinedCharacterRun.characterRun.characterIndex = 0u;
182 underlinedCharacterRun.characterRun.numberOfCharacters = 0u;
186 * @brief Initializes a span to its defaults.
188 * @param[in,out] span The span to be initialized.
190 void Initialize(Span& span)
192 span.colorRunIndex = 0u;
193 span.isColorDefined = false;
194 span.fontRunIndex = 0u;
195 span.isFontDefined = false;
199 * @brief Splits the tag string into the tag name and its attributes.
201 * The attributes are stored in a vector in the tag.
203 * @param[in,out] tag The tag.
205 void ParseAttributes(Tag& tag)
207 if(tag.buffer == NULL)
212 tag.attributes.Resize(MAX_NUM_OF_ATTRIBUTES);
214 // Find first the tag name.
215 bool isQuotationOpen = false;
217 const char* tagBuffer = tag.buffer;
218 const char* const tagEndBuffer = tagBuffer + tag.length;
220 for(; tagBuffer < tagEndBuffer; ++tagBuffer)
222 const char character = *tagBuffer;
223 if(WHITE_SPACE < character)
229 // Stops counting the length of the tag when a white space is found.
230 // @note a white space is the WHITE_SPACE character and anything below as 'tab', 'return' or 'control characters'.
234 SkipWhiteSpace(tagBuffer, tagEndBuffer);
236 // Find the attributes.
237 unsigned int attributeIndex = 0u;
238 const char* nameBuffer = NULL;
239 const char* valueBuffer = NULL;
240 Length nameLength = 0u;
241 Length valueLength = 0u;
243 bool addToNameValue = true;
244 Length numberOfWhiteSpace = 0u;
245 for(; tagBuffer < tagEndBuffer; ++tagBuffer)
247 const char character = *tagBuffer;
248 if((WHITE_SPACE >= character) && !isQuotationOpen)
250 if(NULL != valueBuffer)
252 // Remove white spaces at the end of the value.
253 valueLength -= numberOfWhiteSpace;
256 if((NULL != nameBuffer) && (NULL != valueBuffer))
258 // Every time a white space is found, a new attribute is created and stored in the attributes vector.
259 Attribute& attribute = *(tag.attributes.Begin() + attributeIndex);
262 attribute.nameBuffer = nameBuffer;
263 attribute.valueBuffer = valueBuffer;
264 attribute.nameLength = nameLength;
265 attribute.valueLength = valueLength;
272 addToNameValue = true; // next read characters will be added to the name.
275 else if(EQUAL == character) // '='
277 addToNameValue = false; // next read characters will be added to the value.
278 SkipWhiteSpace(tagBuffer, tagEndBuffer);
280 else if(QUOTATION_MARK == character) // '\''
282 // Do not add quotation marks to neither name nor value.
283 isQuotationOpen = !isQuotationOpen;
288 SkipWhiteSpace(tagBuffer, tagEndBuffer);
294 // Adds characters to the name or the value.
297 if(NULL == nameBuffer)
299 nameBuffer = tagBuffer;
307 if(WHITE_SPACE >= character)
309 ++numberOfWhiteSpace;
313 numberOfWhiteSpace = 0u;
316 if(NULL == valueBuffer)
318 valueBuffer = tagBuffer;
325 if(NULL != valueBuffer)
327 // Remove white spaces at the end of the value.
328 valueLength -= numberOfWhiteSpace;
331 if((NULL != nameBuffer) && (NULL != valueBuffer))
333 // Checks if the last attribute needs to be added.
334 Attribute& attribute = *(tag.attributes.Begin() + attributeIndex);
337 attribute.nameBuffer = nameBuffer;
338 attribute.valueBuffer = valueBuffer;
339 attribute.nameLength = nameLength;
340 attribute.valueLength = valueLength;
343 // Resize the vector of attributes.
344 tag.attributes.Resize(attributeIndex);
348 * @brief It parses a tag and its attributes if the given iterator @e it is pointing at a tag beginning.
350 * @param[in,out] markupStringBuffer The mark-up string buffer. It's a const iterator pointing the current character.
351 * @param[in] markupStringEndBuffer Pointer to one character after the end of the mark-up string buffer.
352 * @param[out] tag The tag with its attributes.
354 * @return @e true if the iterator @e it is pointing a mark-up tag. Otherwise @e false.
356 bool IsTag(const char*& markupStringBuffer,
357 const char* const markupStringEndBuffer,
361 bool isQuotationOpen = false;
362 bool attributesFound = false;
363 tag.isEndTag = false;
364 bool isPreviousLessThan = false;
365 bool isPreviousSlash = false;
367 const char character = *markupStringBuffer;
368 if(LESS_THAN == character) // '<'
372 isPreviousLessThan = true;
374 // if the iterator is pointing to a '<' character, then check if it's a mark-up tag is needed.
375 ++markupStringBuffer;
376 if(markupStringBuffer < markupStringEndBuffer)
378 SkipWhiteSpace(markupStringBuffer, markupStringEndBuffer);
380 for(; (!isTag) && (markupStringBuffer < markupStringEndBuffer); ++markupStringBuffer)
382 const char character = *markupStringBuffer;
384 if(!isQuotationOpen && (SLASH == character)) // '/'
386 if(isPreviousLessThan)
392 // if the tag has a '/' it may be an end tag.
393 isPreviousSlash = true;
396 isPreviousLessThan = false;
397 if((markupStringBuffer + 1u < markupStringEndBuffer) && (WHITE_SPACE >= *(markupStringBuffer + 1u)))
399 ++markupStringBuffer;
400 SkipWhiteSpace(markupStringBuffer, markupStringEndBuffer);
401 --markupStringBuffer;
404 else if(GREATER_THAN == character) // '>'
412 isPreviousSlash = false;
413 isPreviousLessThan = false;
415 else if(QUOTATION_MARK == character)
417 isQuotationOpen = !isQuotationOpen;
420 isPreviousSlash = false;
421 isPreviousLessThan = false;
423 else if(WHITE_SPACE >= character) // ' '
425 // If the tag contains white spaces then it may have attributes.
428 attributesFound = true;
434 if(NULL == tag.buffer)
436 tag.buffer = markupStringBuffer;
439 // If it's not any of the 'special' characters then just add it to the tag string.
442 isPreviousSlash = false;
443 isPreviousLessThan = false;
448 // If the tag string has white spaces, then parse the attributes is needed.
451 ParseAttributes(tag);
459 * @brief Returns length of XHTML entity by parsing the text. It also determines if it is XHTML entity or not.
461 * @param[in] markupStringBuffer The mark-up string buffer. It's a const iterator pointing the current character.
462 * @param[in] markupStringEndBuffer Pointing to end of mark-up string buffer.
464 * @return Length of markupText in case of XHTML entity otherwise return 0.
466 unsigned int GetXHTMLEntityLength(const char*& markupStringBuffer,
467 const char* const markupStringEndBuffer)
469 char character = *markupStringBuffer;
470 if(AMPERSAND == character) // '&'
472 // if the iterator is pointing to a '&' character, then check for ';' to find end to XHTML entity.
473 ++markupStringBuffer;
474 if(markupStringBuffer < markupStringEndBuffer)
476 unsigned int len = 1u;
477 for(; markupStringBuffer < markupStringEndBuffer; ++markupStringBuffer)
479 character = *markupStringBuffer;
481 if(SEMI_COLON == character) // ';'
483 // found end of XHTML entity
484 ++markupStringBuffer;
487 else if((AMPERSAND == character) || (BACK_SLASH == character) || (LESS_THAN == character))
498 * @brief It parses a XHTML string which has hex/decimal entity and fill its corresponging utf-8 string.
500 * @param[in] markupText The mark-up text buffer.
501 * @param[out] utf-8 text Corresponding to markup Text
503 * @return true if string is successfully parsed otherwise false
505 bool XHTMLNumericEntityToUtf8(const char* markupText, char* utf8)
509 if(NULL != markupText)
513 // check if hex or decimal entity
514 if((CHAR_ARRAY_END != *markupText) && (HEX_CODE == *markupText))
521 unsigned long l = strtoul(markupText, &end, (isHex ? 16 : 10)); // l contains UTF-32 code in case of correct XHTML entity
523 // check for valid XHTML numeric entities (between '#' or "#x" and ';')
524 if((l > 0) && (l < ULONG_MAX) && (*end == SEMI_COLON)) // in case wrong XHTML entity is set eg. "abcdefs;" in that case *end will be 'a'
526 /* characters XML 1.1 permits */
527 if(((XHTML_DECIMAL_ENTITY_RANGE[0] < l) && (l <= XHTML_DECIMAL_ENTITY_RANGE[1])) ||
528 ((XHTML_DECIMAL_ENTITY_RANGE[2] <= l) && (l <= XHTML_DECIMAL_ENTITY_RANGE[3])) ||
529 ((XHTML_DECIMAL_ENTITY_RANGE[4] <= l) && (l <= XHTML_DECIMAL_ENTITY_RANGE[5])))
531 // Convert UTF32 code to UTF8
532 Utf32ToUtf8(reinterpret_cast<const uint32_t* const>(&l), 1, reinterpret_cast<uint8_t*>(utf8));
541 * @brief Processes a particular tag for the required run (color-run, font-run or underlined-character-run).
543 * @tparam RunType Whether ColorRun , FontDescriptionRun or UnderlinedCharacterRun
545 * @param[in/out] runsContainer The container containing all the runs
546 * @param[in/out] styleStack The style stack
547 * @param[in] tag The tag we are currently processing
548 * @param[in] characterIndex The current character index
549 * @param[in/out] runIndex The run index
550 * @param[in/out] tagReference The tagReference we should increment/decrement
551 * @param[in] parameterSettingFunction This function will be called to set run specific parameters
553 template<typename RunType>
554 void ProcessTagForRun(
555 Vector<RunType>& runsContainer,
556 StyleStack<RunIndex>& styleStack,
558 const CharacterIndex characterIndex,
561 std::function<void(const Tag&, RunType&)> parameterSettingFunction)
569 // Fill the run with the parameters.
570 run.characterRun.characterIndex = characterIndex;
571 parameterSettingFunction(tag, run);
573 // Push the run in the logical model.
574 runsContainer.PushBack(run);
576 // Push the index of the run into the stack.
577 styleStack.Push(runIndex);
579 // Point the next free run.
582 // Increase reference
589 // Pop the top of the stack and set the number of characters of the run.
590 RunType& run = *(runsContainer.Begin() + styleStack.Pop());
591 run.characterRun.numberOfCharacters = characterIndex - run.characterRun.characterIndex;
598 * @brief Processes the item tag
600 * @param[in/out] markupProcessData The markup process data
601 * @param[in] tag The current tag
602 * @param[in/out] characterIndex The current character index
605 MarkupProcessData& markupProcessData,
607 CharacterIndex& characterIndex)
611 // Create an embedded item instance.
613 item.characterIndex = characterIndex;
614 ProcessEmbeddedItem(tag, item);
616 markupProcessData.items.PushBack(item);
618 // Insert white space character that will be replaced by the item.
619 markupProcessData.markupProcessedText.append(1u, WHITE_SPACE);
625 * @brief Processes the anchor tag
627 * @param[in/out] markupProcessData The markup process data
628 * @param[in] tag The current tag
629 * @param[in/out] characterIndex The current character index
631 void ProcessAnchorTag(
632 MarkupProcessData& markupProcessData,
634 CharacterIndex& characterIndex)
638 // Create an anchor instance.
640 anchor.startIndex = characterIndex;
641 anchor.endIndex = 0u;
642 ProcessAnchor(tag, anchor);
643 markupProcessData.anchors.PushBack(anchor);
648 unsigned int count = markupProcessData.anchors.Count();
651 markupProcessData.anchors[count - 1].endIndex = characterIndex;
657 * @brief Processes span tag for the color-run & font-run.
659 * @param[in] spanTag The tag we are currently processing
660 * @param[in/out] spanStack The spans stack
661 * @param[int/out] colorRuns The container containing all the color runs
662 * @param[int/out] fontRuns The container containing all the font description runs
663 * @param[in/out] colorRunIndex The color run index
664 * @param[in/out] fontRunIndex The font run index
665 * @param[in] characterIndex The current character index
666 * @param[in] tagReference The tagReference we should increment/decrement
668 void ProcessSpanForRun(
670 StyleStack<Span>& spanStack,
671 Vector<ColorRun>& colorRuns,
672 Vector<FontDescriptionRun>& fontRuns,
673 RunIndex& colorRunIndex,
674 RunIndex& fontRunIndex,
675 const CharacterIndex characterIndex,
678 if(!spanTag.isEndTag)
682 Initialize(colorRun);
684 FontDescriptionRun fontRun;
690 // Fill the run with the parameters.
691 colorRun.characterRun.characterIndex = characterIndex;
692 fontRun.characterRun.characterIndex = characterIndex;
694 span.colorRunIndex = colorRunIndex;
695 span.fontRunIndex = fontRunIndex;
697 ProcessSpanTag(spanTag, colorRun, fontRun, span.isColorDefined, span.isFontDefined);
699 // Push the span into the stack.
700 spanStack.Push(span);
702 // Point the next free run.
703 if(span.isColorDefined)
705 // Push the run in the logical model.
706 colorRuns.PushBack(colorRun);
710 if(span.isFontDefined)
712 // Push the run in the logical model.
713 fontRuns.PushBack(fontRun);
717 // Increase reference
724 // Pop the top of the stack and set the number of characters of the run.
725 Span span = spanStack.Pop();
727 if(span.isColorDefined)
729 ColorRun& colorRun = *(colorRuns.Begin() + span.colorRunIndex);
730 colorRun.characterRun.numberOfCharacters = characterIndex - colorRun.characterRun.characterIndex;
733 if(span.isFontDefined)
735 FontDescriptionRun& fontRun = *(fontRuns.Begin() + span.fontRunIndex);
736 fontRun.characterRun.numberOfCharacters = characterIndex - fontRun.characterRun.characterIndex;
745 * @brief Resizes the model's vectors
747 * @param[in/out] markupProcessData The markup process data
748 * @param[in] fontRunIndex The font run index
749 * @param[in] colorRunIndex The color run index
750 * @param[in] underlinedCharacterRunIndex The underlined character run index
751 * @param[in] backgroundRunIndex The background run index
753 void ResizeModelVectors(MarkupProcessData& markupProcessData, const RunIndex fontRunIndex, const RunIndex colorRunIndex, const RunIndex underlinedCharacterRunIndex, const RunIndex backgroundRunIndex)
755 markupProcessData.fontRuns.Resize(fontRunIndex);
756 markupProcessData.colorRuns.Resize(colorRunIndex);
757 markupProcessData.underlinedCharacterRuns.Resize(underlinedCharacterRunIndex);
758 markupProcessData.backgroundColorRuns.Resize(backgroundRunIndex);
761 for(unsigned int i = 0; i < colorRunIndex; ++i)
763 ColorRun& run = markupProcessData.colorRuns[i];
764 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "run[%d] index: %d, length: %d, color %f,%f,%f,%f\n", i, run.characterRun.characterIndex, run.characterRun.numberOfCharacters, run.color.r, run.color.g, run.color.b, run.color.a);
770 * @brief Processes the markup string buffer
772 * @param[in/out] markupProcessData The markup process data
773 * @param[in/out] markupStringBuffer The markup string buffer pointer
774 * @param[in] markupStringEndBuffer The markup string end buffer pointer
775 * @param[in/out] characterIndex The current character index
777 void ProcessMarkupStringBuffer(
778 MarkupProcessData& markupProcessData,
779 const char*& markupStringBuffer,
780 const char* const markupStringEndBuffer,
781 CharacterIndex& characterIndex)
783 unsigned char character = *markupStringBuffer;
784 const char* markupBuffer = markupStringBuffer;
785 unsigned char count = GetUtf8Length(character);
788 if((BACK_SLASH == character) && (markupStringBuffer + 1u < markupStringEndBuffer))
790 // Adding < , > or & special character.
791 const unsigned char nextCharacter = *(markupStringBuffer + 1u);
792 if((LESS_THAN == nextCharacter) || (GREATER_THAN == nextCharacter) || (AMPERSAND == nextCharacter))
794 character = nextCharacter;
795 ++markupStringBuffer;
797 count = GetUtf8Length(character);
798 markupBuffer = markupStringBuffer;
801 else // checking if contains XHTML entity or not
803 const unsigned int len = GetXHTMLEntityLength(markupStringBuffer, markupStringEndBuffer);
805 // Parse markupStringTxt if it contains XHTML Entity between '&' and ';'
808 char* entityCode = NULL;
812 // Checking if XHTML Numeric Entity
813 if(HASH == *(markupBuffer + 1u))
815 entityCode = &utf8[0];
816 // markupBuffer is currently pointing to '&'. By adding 2u to markupBuffer it will point to numeric string by skipping "&#'
817 result = XHTMLNumericEntityToUtf8((markupBuffer + 2u), entityCode);
819 else // Checking if XHTML Named Entity
821 entityCode = const_cast<char*>(NamedEntityToUtf8(markupBuffer, len));
822 result = (entityCode != NULL);
826 markupBuffer = entityCode; //utf8 text assigned to markupBuffer
827 character = markupBuffer[0];
831 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Not valid XHTML entity : (%.*s) \n", len, markupBuffer);
835 else // in case string conatins Start of XHTML Entity('&') but not its end character(';')
837 if(character == AMPERSAND)
840 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Not Well formed XHTML content \n");
845 if(markupBuffer != NULL)
847 const unsigned char numberOfBytes = GetUtf8Length(character);
848 markupProcessData.markupProcessedText.push_back(character);
850 for(unsigned char i = 1u; i < numberOfBytes; ++i)
853 markupProcessData.markupProcessedText.push_back(*markupBuffer);
857 markupStringBuffer += count;
863 void ProcessMarkupString(const std::string& markupString, MarkupProcessData& markupProcessData)
865 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "markupString: %s\n", markupString.c_str());
867 // Reserve space for the plain text.
868 const Length markupStringSize = markupString.size();
869 markupProcessData.markupProcessedText.reserve(markupStringSize);
871 // Stores a struct with the index to the first character of the run, the type of run and its parameters.
872 StyleStack<RunIndex> styleStack;
874 // Stores a struct with the index to the first character of the color run & color font for the span.
875 StyleStack<Span> spanStack;
877 // Points the next free position in the vector of runs.
878 RunIndex colorRunIndex = 0u;
879 RunIndex fontRunIndex = 0u;
880 RunIndex underlinedCharacterRunIndex = 0u;
881 RunIndex backgroundRunIndex = 0u;
883 // check tag reference
884 int colorTagReference = 0u;
885 int fontTagReference = 0u;
886 int iTagReference = 0u;
887 int bTagReference = 0u;
888 int uTagReference = 0u;
889 int backgroundTagReference = 0u;
890 int spanTagReference = 0u;
892 // Give an initial default value to the model's vectors.
893 markupProcessData.colorRuns.Reserve(DEFAULT_VECTOR_SIZE);
894 markupProcessData.fontRuns.Reserve(DEFAULT_VECTOR_SIZE);
895 markupProcessData.underlinedCharacterRuns.Reserve(DEFAULT_VECTOR_SIZE);
896 markupProcessData.backgroundColorRuns.Reserve(DEFAULT_VECTOR_SIZE);
898 // Get the mark-up string buffer.
899 const char* markupStringBuffer = markupString.c_str();
900 const char* const markupStringEndBuffer = markupStringBuffer + markupStringSize;
903 CharacterIndex characterIndex = 0u;
904 for(; markupStringBuffer < markupStringEndBuffer;)
906 tag.attributes.Clear();
907 if(IsTag(markupStringBuffer,
908 markupStringEndBuffer,
911 if(TokenComparison(XHTML_COLOR_TAG, tag.buffer, tag.length))
913 ProcessTagForRun<ColorRun>(
914 markupProcessData.colorRuns, styleStack, tag, characterIndex, colorRunIndex, colorTagReference, [](const Tag& tag, ColorRun& run) { ProcessColorTag(tag, run); });
916 else if(TokenComparison(XHTML_I_TAG, tag.buffer, tag.length))
918 ProcessTagForRun<FontDescriptionRun>(
919 markupProcessData.fontRuns, styleStack, tag, characterIndex, fontRunIndex, iTagReference, [](const Tag&, FontDescriptionRun& fontRun) {
920 fontRun.slant = TextAbstraction::FontSlant::ITALIC;
921 fontRun.slantDefined = true;
924 else if(TokenComparison(XHTML_U_TAG, tag.buffer, tag.length))
926 ProcessTagForRun<UnderlinedCharacterRun>(
927 markupProcessData.underlinedCharacterRuns, styleStack, tag, characterIndex, underlinedCharacterRunIndex, uTagReference, [](const Tag& tag, UnderlinedCharacterRun& run) {});
929 else if(TokenComparison(XHTML_B_TAG, tag.buffer, tag.length))
931 ProcessTagForRun<FontDescriptionRun>(
932 markupProcessData.fontRuns, styleStack, tag, characterIndex, fontRunIndex, bTagReference, [](const Tag&, FontDescriptionRun& fontRun) {
933 fontRun.weight = TextAbstraction::FontWeight::BOLD;
934 fontRun.weightDefined = true;
937 else if(TokenComparison(XHTML_FONT_TAG, tag.buffer, tag.length))
939 ProcessTagForRun<FontDescriptionRun>(
940 markupProcessData.fontRuns, styleStack, tag, characterIndex, fontRunIndex, fontTagReference, [](const Tag& tag, FontDescriptionRun& fontRun) { ProcessFontTag(tag, fontRun); });
942 else if(TokenComparison(XHTML_ANCHOR_TAG, tag.buffer, tag.length))
945 ProcessAnchorTag(markupProcessData, tag, characterIndex);
947 ProcessTagForRun<ColorRun>(
948 markupProcessData.colorRuns, styleStack, tag, characterIndex, colorRunIndex, colorTagReference, [](const Tag& tag, ColorRun& run) {
949 run.color = Color::BLUE;
950 ProcessColorTag(tag, run);
952 /* TODO - underline */
953 } // <a href=https://www.tizen.org>tizen</a>
954 else if(TokenComparison(XHTML_SHADOW_TAG, tag.buffer, tag.length))
956 // TODO: If !tag.isEndTag, then create a new shadow run.
957 // else Pop the top of the stack and set the number of characters of the run.
958 } // <shadow></shadow>
959 else if(TokenComparison(XHTML_GLOW_TAG, tag.buffer, tag.length))
961 // TODO: If !tag.isEndTag, then create a new glow run.
962 // else Pop the top of the stack and set the number of characters of the run.
964 else if(TokenComparison(XHTML_OUTLINE_TAG, tag.buffer, tag.length))
966 // TODO: If !tag.isEndTag, then create a new outline run.
967 // else Pop the top of the stack and set the number of characters of the run.
968 } // <outline></outline>
969 else if(TokenComparison(XHTML_ITEM_TAG, tag.buffer, tag.length))
971 ProcessItemTag(markupProcessData, tag, characterIndex);
973 else if(TokenComparison(XHTML_BACKGROUND_TAG, tag.buffer, tag.length))
975 ProcessTagForRun<ColorRun>(
976 markupProcessData.backgroundColorRuns, styleStack, tag, characterIndex, backgroundRunIndex, backgroundTagReference, [](const Tag& tag, ColorRun& run) { ProcessBackground(tag, run); });
978 else if(TokenComparison(XHTML_SPAN_TAG, tag.buffer, tag.length))
980 ProcessSpanForRun(tag, spanStack, markupProcessData.colorRuns, markupProcessData.fontRuns, colorRunIndex, fontRunIndex, characterIndex, spanTagReference);
982 } // end if( IsTag() )
983 else if(markupStringBuffer < markupStringEndBuffer)
985 ProcessMarkupStringBuffer(markupProcessData, markupStringBuffer, markupStringEndBuffer, characterIndex);
989 // Resize the model's vectors.
990 ResizeModelVectors(markupProcessData, fontRunIndex, colorRunIndex, underlinedCharacterRunIndex, backgroundRunIndex);
995 } // namespace Toolkit