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.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/markup-processor-strikethrough.h>
36 #include <dali-toolkit/internal/text/markup-processor-underline.h>
37 #include <dali-toolkit/internal/text/xhtml-entities.h>
47 // HTML-ISH tag and attribute constants.
48 // Note they must be lower case in order to make the comparison to work
49 // as the parser converts all the read tags to lower case.
50 const std::string XHTML_COLOR_TAG("color");
51 const std::string XHTML_FONT_TAG("font");
52 const std::string XHTML_B_TAG("b");
53 const std::string XHTML_I_TAG("i");
54 const std::string XHTML_U_TAG("u");
55 const std::string XHTML_SHADOW_TAG("shadow");
56 const std::string XHTML_GLOW_TAG("glow");
57 const std::string XHTML_OUTLINE_TAG("outline");
58 const std::string XHTML_ITEM_TAG("item");
59 const std::string XHTML_ANCHOR_TAG("a");
60 const std::string XHTML_BACKGROUND_TAG("background");
61 const std::string XHTML_SPAN_TAG("span");
62 const std::string XHTML_STRIKETHROUGH_TAG("s");
63 const std::string XHTML_PARAGRAPH_TAG("p");
65 const char LESS_THAN = '<';
66 const char GREATER_THAN = '>';
67 const char EQUAL = '=';
68 const char QUOTATION_MARK = '\'';
69 const char SLASH = '/';
70 const char BACK_SLASH = '\\';
71 const char AMPERSAND = '&';
72 const char HASH = '#';
73 const char SEMI_COLON = ';';
74 const char CHAR_ARRAY_END = '\0';
75 const char HEX_CODE = 'x';
77 const char WHITE_SPACE = 0x20; // ASCII value of the white space.
78 const char NEW_LINE = 0x0A; // ASCII value of the newline.
80 // Range 1 0x0u < XHTML_DECIMAL_ENTITY_RANGE <= 0xD7FFu
81 // Range 2 0xE000u < XHTML_DECIMAL_ENTITY_RANGE <= 0xFFFDu
82 // Range 3 0x10000u < XHTML_DECIMAL_ENTITY_RANGE <= 0x10FFFFu
83 const unsigned long XHTML_DECIMAL_ENTITY_RANGE[] = {0x0u, 0xD7FFu, 0xE000u, 0xFFFDu, 0x10000u, 0x10FFFFu};
85 const unsigned int MAX_NUM_OF_ATTRIBUTES = 5u; ///< The font tag has the 'family', 'size' 'weight', 'width' and 'slant' attrubutes.
86 const unsigned int DEFAULT_VECTOR_SIZE = 16u; ///< Default size of run vectors.
88 #if defined(DEBUG_ENABLED)
89 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_MARKUP_PROCESSOR");
92 typedef VectorBase::SizeType RunIndex;
95 * @brief Struct used to retrieve the style runs from the mark-up string.
97 template<typename StyleStackType>
100 Vector<StyleStackType> stack; ///< Use a vector as a style stack.
101 unsigned int topIndex; ///< Points the top of the stack.
107 stack.Resize(DEFAULT_VECTOR_SIZE);
110 void Push(StyleStackType item)
112 // Check if there is space inside the style stack.
113 const VectorBase::SizeType size = stack.Count();
116 // Resize the style stack.
117 stack.Resize(2u * size);
120 // Set the item in the top of the stack.
121 *(stack.Begin() + topIndex) = item;
123 // Reposition the pointer to the top of the stack.
129 // Pop the top of the stack.
131 return *(stack.Begin() + topIndex);
136 * @brief Struct used to retrieve spans from the mark-up string.
140 RunIndex colorRunIndex;
141 RunIndex fontRunIndex;
147 * @brief Initializes a font run description to its defaults.
149 * @param[in,out] fontRun The font description run to initialize.
151 void Initialize(FontDescriptionRun& fontRun)
153 fontRun.characterRun.characterIndex = 0u;
154 fontRun.characterRun.numberOfCharacters = 0u;
155 fontRun.familyName = NULL;
156 fontRun.familyLength = 0u;
157 fontRun.weight = TextAbstraction::FontWeight::NORMAL;
158 fontRun.width = TextAbstraction::FontWidth::NORMAL;
159 fontRun.slant = TextAbstraction::FontSlant::NORMAL;
161 fontRun.familyDefined = false;
162 fontRun.weightDefined = false;
163 fontRun.widthDefined = false;
164 fontRun.slantDefined = false;
165 fontRun.sizeDefined = false;
169 * @brief Initializes a color run description to its defaults.
171 * @param[in,out] colorRun The font description run to initialize.
173 void Initialize(ColorRun& colorRun)
175 colorRun.characterRun.characterIndex = 0u;
176 colorRun.characterRun.numberOfCharacters = 0u;
180 * @brief Initializes a underlined character run to its defaults.
182 * @param[in,out] underlinedCharacterRun The underelined character run to initialize.
184 void Initialize(UnderlinedCharacterRun& underlinedCharacterRun)
186 underlinedCharacterRun.characterRun.characterIndex = 0u;
187 underlinedCharacterRun.characterRun.numberOfCharacters = 0u;
191 * @brief Initializes a span to its defaults.
193 * @param[in,out] span The span to be initialized.
195 void Initialize(Span& span)
197 span.colorRunIndex = 0u;
198 span.isColorDefined = false;
199 span.fontRunIndex = 0u;
200 span.isFontDefined = false;
204 * @brief Initializes a strikethrough character run to its defaults.
206 * @param[in,out] strikethroughCharacterRun The strikethrough character run to initialize.
208 void Initialize(StrikethroughCharacterRun& strikethroughCharacterRun)
210 strikethroughCharacterRun.characterRun.characterIndex = 0u;
211 strikethroughCharacterRun.characterRun.numberOfCharacters = 0u;
212 strikethroughCharacterRun.isColorSet = false;
216 * @brief Initializes a bounded-paragraph character run to its defaults.
218 * @param[in,out] boundedParagraphRun The bounded paragraphRun run to initialize.
220 void Initialize(BoundedParagraphRun& boundedParagraphRun)
222 boundedParagraphRun.characterRun.characterIndex = 0u;
223 boundedParagraphRun.characterRun.numberOfCharacters = 0u;
227 * @brief Splits the tag string into the tag name and its attributes.
229 * The attributes are stored in a vector in the tag.
231 * @param[in,out] tag The tag.
233 void ParseAttributes(Tag& tag)
235 if(tag.buffer == NULL)
240 tag.attributes.Resize(MAX_NUM_OF_ATTRIBUTES);
242 // Find first the tag name.
243 bool isQuotationOpen = false;
245 const char* tagBuffer = tag.buffer;
246 const char* const tagEndBuffer = tagBuffer + tag.length;
248 for(; tagBuffer < tagEndBuffer; ++tagBuffer)
250 const char character = *tagBuffer;
251 if(WHITE_SPACE < character)
257 // Stops counting the length of the tag when a white space is found.
258 // @note a white space is the WHITE_SPACE character and anything below as 'tab', 'return' or 'control characters'.
262 SkipWhiteSpace(tagBuffer, tagEndBuffer);
264 // Find the attributes.
265 unsigned int attributeIndex = 0u;
266 const char* nameBuffer = NULL;
267 const char* valueBuffer = NULL;
268 Length nameLength = 0u;
269 Length valueLength = 0u;
271 bool addToNameValue = true;
272 Length numberOfWhiteSpace = 0u;
273 for(; tagBuffer < tagEndBuffer; ++tagBuffer)
275 const char character = *tagBuffer;
276 if((WHITE_SPACE >= character) && !isQuotationOpen)
278 if(NULL != valueBuffer)
280 // Remove white spaces at the end of the value.
281 valueLength -= numberOfWhiteSpace;
284 if((NULL != nameBuffer) && (NULL != valueBuffer))
286 // Every time a white space is found, a new attribute is created and stored in the attributes vector.
287 Attribute& attribute = *(tag.attributes.Begin() + attributeIndex);
290 attribute.nameBuffer = nameBuffer;
291 attribute.valueBuffer = valueBuffer;
292 attribute.nameLength = nameLength;
293 attribute.valueLength = valueLength;
300 addToNameValue = true; // next read characters will be added to the name.
303 else if(EQUAL == character) // '='
305 addToNameValue = false; // next read characters will be added to the value.
306 SkipWhiteSpace(tagBuffer, tagEndBuffer);
308 else if(QUOTATION_MARK == character) // '\''
310 // Do not add quotation marks to neither name nor value.
311 isQuotationOpen = !isQuotationOpen;
316 SkipWhiteSpace(tagBuffer, tagEndBuffer);
322 // Adds characters to the name or the value.
325 if(NULL == nameBuffer)
327 nameBuffer = tagBuffer;
335 if(WHITE_SPACE >= character)
337 ++numberOfWhiteSpace;
341 numberOfWhiteSpace = 0u;
344 if(NULL == valueBuffer)
346 valueBuffer = tagBuffer;
353 if(NULL != valueBuffer)
355 // Remove white spaces at the end of the value.
356 valueLength -= numberOfWhiteSpace;
359 if((NULL != nameBuffer) && (NULL != valueBuffer))
361 // Checks if the last attribute needs to be added.
362 Attribute& attribute = *(tag.attributes.Begin() + attributeIndex);
365 attribute.nameBuffer = nameBuffer;
366 attribute.valueBuffer = valueBuffer;
367 attribute.nameLength = nameLength;
368 attribute.valueLength = valueLength;
371 // Resize the vector of attributes.
372 tag.attributes.Resize(attributeIndex);
376 * @brief It parses a tag and its attributes if the given iterator @e it is pointing at a tag beginning.
378 * @param[in,out] markupStringBuffer The mark-up string buffer. It's a const iterator pointing the current character.
379 * @param[in] markupStringEndBuffer Pointer to one character after the end of the mark-up string buffer.
380 * @param[out] tag The tag with its attributes.
382 * @return @e true if the iterator @e it is pointing a mark-up tag. Otherwise @e false.
384 bool IsTag(const char*& markupStringBuffer,
385 const char* const markupStringEndBuffer,
389 bool isQuotationOpen = false;
390 bool attributesFound = false;
391 tag.isEndTag = false;
392 bool isPreviousLessThan = false;
393 bool isPreviousSlash = false;
395 const char character = *markupStringBuffer;
396 if(LESS_THAN == character) // '<'
400 isPreviousLessThan = true;
402 // if the iterator is pointing to a '<' character, then check if it's a mark-up tag is needed.
403 ++markupStringBuffer;
404 if(markupStringBuffer < markupStringEndBuffer)
406 SkipWhiteSpace(markupStringBuffer, markupStringEndBuffer);
408 for(; (!isTag) && (markupStringBuffer < markupStringEndBuffer); ++markupStringBuffer)
410 const char character = *markupStringBuffer;
412 if(!isQuotationOpen && (SLASH == character)) // '/'
414 if(isPreviousLessThan)
420 // if the tag has a '/' it may be an end tag.
421 isPreviousSlash = true;
424 isPreviousLessThan = false;
425 if((markupStringBuffer + 1u < markupStringEndBuffer) && (WHITE_SPACE >= *(markupStringBuffer + 1u)))
427 ++markupStringBuffer;
428 SkipWhiteSpace(markupStringBuffer, markupStringEndBuffer);
429 --markupStringBuffer;
432 else if(GREATER_THAN == character) // '>'
440 isPreviousSlash = false;
441 isPreviousLessThan = false;
443 else if(QUOTATION_MARK == character)
445 isQuotationOpen = !isQuotationOpen;
448 isPreviousSlash = false;
449 isPreviousLessThan = false;
451 else if(WHITE_SPACE >= character) // ' '
453 // If the tag contains white spaces then it may have attributes.
456 attributesFound = true;
462 if(NULL == tag.buffer)
464 tag.buffer = markupStringBuffer;
467 // If it's not any of the 'special' characters then just add it to the tag string.
470 isPreviousSlash = false;
471 isPreviousLessThan = false;
476 // If the tag string has white spaces, then parse the attributes is needed.
479 ParseAttributes(tag);
487 * @brief Returns length of XHTML entity by parsing the text. It also determines if it is XHTML entity or not.
489 * @param[in] markupStringBuffer The mark-up string buffer. It's a const iterator pointing the current character.
490 * @param[in] markupStringEndBuffer Pointing to end of mark-up string buffer.
492 * @return Length of markupText in case of XHTML entity otherwise return 0.
494 unsigned int GetXHTMLEntityLength(const char*& markupStringBuffer,
495 const char* const markupStringEndBuffer)
497 char character = *markupStringBuffer;
498 if(AMPERSAND == character) // '&'
500 // if the iterator is pointing to a '&' character, then check for ';' to find end to XHTML entity.
501 ++markupStringBuffer;
502 if(markupStringBuffer < markupStringEndBuffer)
504 unsigned int len = 1u;
505 for(; markupStringBuffer < markupStringEndBuffer; ++markupStringBuffer)
507 character = *markupStringBuffer;
509 if(SEMI_COLON == character) // ';'
511 // found end of XHTML entity
512 ++markupStringBuffer;
515 else if((AMPERSAND == character) || (BACK_SLASH == character) || (LESS_THAN == character))
526 * @brief It parses a XHTML string which has hex/decimal entity and fill its corresponging utf-8 string.
528 * @param[in] markupText The mark-up text buffer.
529 * @param[out] utf-8 text Corresponding to markup Text
531 * @return true if string is successfully parsed otherwise false
533 bool XHTMLNumericEntityToUtf8(const char* markupText, char* utf8)
537 if(NULL != markupText)
541 // check if hex or decimal entity
542 if((CHAR_ARRAY_END != *markupText) && (HEX_CODE == *markupText))
549 unsigned long l = strtoul(markupText, &end, (isHex ? 16 : 10)); // l contains UTF-32 code in case of correct XHTML entity
551 // check for valid XHTML numeric entities (between '#' or "#x" and ';')
552 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'
554 /* characters XML 1.1 permits */
555 if(((XHTML_DECIMAL_ENTITY_RANGE[0] < l) && (l <= XHTML_DECIMAL_ENTITY_RANGE[1])) ||
556 ((XHTML_DECIMAL_ENTITY_RANGE[2] <= l) && (l <= XHTML_DECIMAL_ENTITY_RANGE[3])) ||
557 ((XHTML_DECIMAL_ENTITY_RANGE[4] <= l) && (l <= XHTML_DECIMAL_ENTITY_RANGE[5])))
559 // Convert UTF32 code to UTF8
560 Utf32ToUtf8(reinterpret_cast<const uint32_t* const>(&l), 1, reinterpret_cast<uint8_t*>(utf8));
569 * @brief Processes a particular tag for the required run (color-run, font-run or underlined-character-run).
571 * @tparam RunType Whether ColorRun , FontDescriptionRun or UnderlinedCharacterRun
573 * @param[in/out] runsContainer The container containing all the runs
574 * @param[in/out] styleStack The style stack
575 * @param[in] tag The tag we are currently processing
576 * @param[in] characterIndex The current character index
577 * @param[in/out] runIndex The run index
578 * @param[in/out] tagReference The tagReference we should increment/decrement
579 * @param[in] parameterSettingFunction This function will be called to set run specific parameters
581 template<typename RunType>
582 void ProcessTagForRun(
583 Vector<RunType>& runsContainer,
584 StyleStack<RunIndex>& styleStack,
586 const CharacterIndex characterIndex,
589 std::function<void(const Tag&, RunType&)> parameterSettingFunction)
597 // Fill the run with the parameters.
598 run.characterRun.characterIndex = characterIndex;
599 parameterSettingFunction(tag, run);
601 // Push the run in the logical model.
602 runsContainer.PushBack(run);
604 // Push the index of the run into the stack.
605 styleStack.Push(runIndex);
607 // Point the next free run.
610 // Increase reference
617 // Pop the top of the stack and set the number of characters of the run.
618 RunType& run = *(runsContainer.Begin() + styleStack.Pop());
619 run.characterRun.numberOfCharacters = characterIndex - run.characterRun.characterIndex;
626 * @brief Processes the item tag
628 * @param[in/out] markupProcessData The markup process data
629 * @param[in] tag The current tag
630 * @param[in/out] characterIndex The current character index
633 MarkupProcessData& markupProcessData,
635 CharacterIndex& characterIndex)
639 // Create an embedded item instance.
641 item.characterIndex = characterIndex;
642 ProcessEmbeddedItem(tag, item);
644 markupProcessData.items.PushBack(item);
646 // Insert white space character that will be replaced by the item.
647 markupProcessData.markupProcessedText.append(1u, WHITE_SPACE);
653 * @brief Processes the paragraph-tag
655 * @param[in/out] markupProcessData The markup process data
656 * @param[in] tag The current tag
657 * @param[in] isEndBuffer Whether the end of buffer
658 * @param[in/out] characterIndex The current character index
660 void ProcessParagraphTag(
661 MarkupProcessData& markupProcessData,
664 CharacterIndex& characterIndex)
666 if((characterIndex > 0 &&
667 markupProcessData.markupProcessedText[characterIndex - 1u] != NEW_LINE) &&
668 (!(tag.isEndTag && isEndBuffer)))
670 // Insert new-line character at the start and end of paragraph.
671 markupProcessData.markupProcessedText.append(1u, NEW_LINE);
677 * @brief Processes the anchor tag
679 * @param[in/out] markupProcessData The markup process data
680 * @param[in] tag The current tag
681 * @param[in/out] characterIndex The current character index
683 void ProcessAnchorTag(
684 MarkupProcessData& markupProcessData,
686 CharacterIndex& characterIndex)
690 // Create an anchor instance.
692 anchor.startIndex = characterIndex;
693 anchor.endIndex = 0u;
694 ProcessAnchor(tag, anchor);
695 markupProcessData.anchors.PushBack(anchor);
700 unsigned int count = markupProcessData.anchors.Count();
703 markupProcessData.anchors[count - 1].endIndex = characterIndex;
709 * @brief Processes span tag for the color-run & font-run.
711 * @param[in] spanTag The tag we are currently processing
712 * @param[in/out] spanStack The spans stack
713 * @param[int/out] colorRuns The container containing all the color runs
714 * @param[int/out] fontRuns The container containing all the font description runs
715 * @param[in/out] colorRunIndex The color run index
716 * @param[in/out] fontRunIndex The font run index
717 * @param[in] characterIndex The current character index
718 * @param[in] tagReference The tagReference we should increment/decrement
720 void ProcessSpanForRun(
722 StyleStack<Span>& spanStack,
723 Vector<ColorRun>& colorRuns,
724 Vector<FontDescriptionRun>& fontRuns,
725 RunIndex& colorRunIndex,
726 RunIndex& fontRunIndex,
727 const CharacterIndex characterIndex,
730 if(!spanTag.isEndTag)
734 Initialize(colorRun);
736 FontDescriptionRun fontRun;
742 // Fill the run with the parameters.
743 colorRun.characterRun.characterIndex = characterIndex;
744 fontRun.characterRun.characterIndex = characterIndex;
746 span.colorRunIndex = colorRunIndex;
747 span.fontRunIndex = fontRunIndex;
749 ProcessSpanTag(spanTag, colorRun, fontRun, span.isColorDefined, span.isFontDefined);
751 // Push the span into the stack.
752 spanStack.Push(span);
754 // Point the next free run.
755 if(span.isColorDefined)
757 // Push the run in the logical model.
758 colorRuns.PushBack(colorRun);
762 if(span.isFontDefined)
764 // Push the run in the logical model.
765 fontRuns.PushBack(fontRun);
769 // Increase reference
776 // Pop the top of the stack and set the number of characters of the run.
777 Span span = spanStack.Pop();
779 if(span.isColorDefined)
781 ColorRun& colorRun = *(colorRuns.Begin() + span.colorRunIndex);
782 colorRun.characterRun.numberOfCharacters = characterIndex - colorRun.characterRun.characterIndex;
785 if(span.isFontDefined)
787 FontDescriptionRun& fontRun = *(fontRuns.Begin() + span.fontRunIndex);
788 fontRun.characterRun.numberOfCharacters = characterIndex - fontRun.characterRun.characterIndex;
797 * @brief Resizes the model's vectors
799 * @param[in/out] markupProcessData The markup process data
800 * @param[in] fontRunIndex The font run index
801 * @param[in] colorRunIndex The color run index
802 * @param[in] underlinedCharacterRunIndex The underlined character run index
803 * @param[in] backgroundRunIndex The background run index
804 * @param[in] boundedParagraphRunIndex The bounded paragraph run index
807 void ResizeModelVectors(MarkupProcessData& markupProcessData,
808 const RunIndex fontRunIndex,
809 const RunIndex colorRunIndex,
810 const RunIndex underlinedCharacterRunIndex,
811 const RunIndex backgroundRunIndex,
812 const RunIndex boundedParagraphRunIndex)
814 markupProcessData.fontRuns.Resize(fontRunIndex);
815 markupProcessData.colorRuns.Resize(colorRunIndex);
816 markupProcessData.underlinedCharacterRuns.Resize(underlinedCharacterRunIndex);
817 markupProcessData.backgroundColorRuns.Resize(backgroundRunIndex);
818 markupProcessData.boundedParagraphRuns.Resize(boundedParagraphRunIndex);
821 for(unsigned int i = 0; i < colorRunIndex; ++i)
823 ColorRun& run = markupProcessData.colorRuns[i];
824 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);
830 * @brief Processes the markup string buffer
832 * @param[in/out] markupProcessData The markup process data
833 * @param[in/out] markupStringBuffer The markup string buffer pointer
834 * @param[in] markupStringEndBuffer The markup string end buffer pointer
835 * @param[in/out] characterIndex The current character index
837 void ProcessMarkupStringBuffer(
838 MarkupProcessData& markupProcessData,
839 const char*& markupStringBuffer,
840 const char* const markupStringEndBuffer,
841 CharacterIndex& characterIndex)
843 unsigned char character = *markupStringBuffer;
844 const char* markupBuffer = markupStringBuffer;
845 unsigned char count = GetUtf8Length(character);
848 if((BACK_SLASH == character) && (markupStringBuffer + 1u < markupStringEndBuffer))
850 // Adding < , > or & special character.
851 const unsigned char nextCharacter = *(markupStringBuffer + 1u);
852 if((LESS_THAN == nextCharacter) || (GREATER_THAN == nextCharacter) || (AMPERSAND == nextCharacter))
854 character = nextCharacter;
855 ++markupStringBuffer;
857 count = GetUtf8Length(character);
858 markupBuffer = markupStringBuffer;
861 else // checking if contains XHTML entity or not
863 const unsigned int len = GetXHTMLEntityLength(markupStringBuffer, markupStringEndBuffer);
865 // Parse markupStringTxt if it contains XHTML Entity between '&' and ';'
868 char* entityCode = NULL;
872 // Checking if XHTML Numeric Entity
873 if(HASH == *(markupBuffer + 1u))
875 entityCode = &utf8[0];
876 // markupBuffer is currently pointing to '&'. By adding 2u to markupBuffer it will point to numeric string by skipping "&#'
877 result = XHTMLNumericEntityToUtf8((markupBuffer + 2u), entityCode);
879 else // Checking if XHTML Named Entity
881 entityCode = const_cast<char*>(NamedEntityToUtf8(markupBuffer, len));
882 result = (entityCode != NULL);
886 markupBuffer = entityCode; //utf8 text assigned to markupBuffer
887 character = markupBuffer[0];
891 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Not valid XHTML entity : (%.*s) \n", len, markupBuffer);
895 else // in case string conatins Start of XHTML Entity('&') but not its end character(';')
897 if(character == AMPERSAND)
900 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Not Well formed XHTML content \n");
905 if(markupBuffer != NULL)
907 const unsigned char numberOfBytes = GetUtf8Length(character);
908 markupProcessData.markupProcessedText.push_back(character);
910 for(unsigned char i = 1u; i < numberOfBytes; ++i)
913 markupProcessData.markupProcessedText.push_back(*markupBuffer);
917 markupStringBuffer += count;
923 void ProcessMarkupString(const std::string& markupString, MarkupProcessData& markupProcessData)
925 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "markupString: %s\n", markupString.c_str());
927 // Reserve space for the plain text.
928 const Length markupStringSize = markupString.size();
929 markupProcessData.markupProcessedText.reserve(markupStringSize);
931 // Stores a struct with the index to the first character of the run, the type of run and its parameters.
932 StyleStack<RunIndex> styleStack;
934 // Stores a struct with the index to the first character of the color run & color font for the span.
935 StyleStack<Span> spanStack;
937 // Points the next free position in the vector of runs.
938 RunIndex colorRunIndex = 0u;
939 RunIndex fontRunIndex = 0u;
940 RunIndex underlinedCharacterRunIndex = 0u;
941 RunIndex backgroundRunIndex = 0u;
942 RunIndex strikethroughCharacterRunIndex = 0u;
943 RunIndex boundedParagraphRunIndex = 0u;
945 // check tag reference
946 int colorTagReference = 0u;
947 int fontTagReference = 0u;
948 int iTagReference = 0u;
949 int bTagReference = 0u;
950 int uTagReference = 0u;
951 int backgroundTagReference = 0u;
952 int spanTagReference = 0u;
953 int sTagReference = 0u;
954 int pTagReference = 0u;
956 // Give an initial default value to the model's vectors.
957 markupProcessData.colorRuns.Reserve(DEFAULT_VECTOR_SIZE);
958 markupProcessData.fontRuns.Reserve(DEFAULT_VECTOR_SIZE);
959 markupProcessData.underlinedCharacterRuns.Reserve(DEFAULT_VECTOR_SIZE);
960 markupProcessData.backgroundColorRuns.Reserve(DEFAULT_VECTOR_SIZE);
962 // Get the mark-up string buffer.
963 const char* markupStringBuffer = markupString.c_str();
964 const char* const markupStringEndBuffer = markupStringBuffer + markupStringSize;
967 CharacterIndex characterIndex = 0u;
968 for(; markupStringBuffer < markupStringEndBuffer;)
970 tag.attributes.Clear();
971 if(IsTag(markupStringBuffer,
972 markupStringEndBuffer,
975 if(TokenComparison(XHTML_COLOR_TAG, tag.buffer, tag.length))
977 ProcessTagForRun<ColorRun>(
978 markupProcessData.colorRuns, styleStack, tag, characterIndex, colorRunIndex, colorTagReference, [](const Tag& tag, ColorRun& run) { ProcessColorTag(tag, run); });
980 else if(TokenComparison(XHTML_I_TAG, tag.buffer, tag.length))
982 ProcessTagForRun<FontDescriptionRun>(
983 markupProcessData.fontRuns, styleStack, tag, characterIndex, fontRunIndex, iTagReference, [](const Tag&, FontDescriptionRun& fontRun) {
984 fontRun.slant = TextAbstraction::FontSlant::ITALIC;
985 fontRun.slantDefined = true;
988 else if(TokenComparison(XHTML_U_TAG, tag.buffer, tag.length))
990 ProcessTagForRun<UnderlinedCharacterRun>(
991 markupProcessData.underlinedCharacterRuns, styleStack, tag, characterIndex, underlinedCharacterRunIndex, uTagReference, [](const Tag& tag, UnderlinedCharacterRun& run) { ProcessUnderlineTag(tag, run); });
993 else if(TokenComparison(XHTML_B_TAG, tag.buffer, tag.length))
995 ProcessTagForRun<FontDescriptionRun>(
996 markupProcessData.fontRuns, styleStack, tag, characterIndex, fontRunIndex, bTagReference, [](const Tag&, FontDescriptionRun& fontRun) {
997 fontRun.weight = TextAbstraction::FontWeight::BOLD;
998 fontRun.weightDefined = true;
1001 else if(TokenComparison(XHTML_FONT_TAG, tag.buffer, tag.length))
1003 ProcessTagForRun<FontDescriptionRun>(
1004 markupProcessData.fontRuns, styleStack, tag, characterIndex, fontRunIndex, fontTagReference, [](const Tag& tag, FontDescriptionRun& fontRun) { ProcessFontTag(tag, fontRun); });
1006 else if(TokenComparison(XHTML_ANCHOR_TAG, tag.buffer, tag.length))
1009 ProcessAnchorTag(markupProcessData, tag, characterIndex);
1011 ProcessTagForRun<ColorRun>(
1012 markupProcessData.colorRuns, styleStack, tag, characterIndex, colorRunIndex, colorTagReference, [](const Tag& tag, ColorRun& run) {
1013 run.color = Color::BLUE;
1014 ProcessColorTag(tag, run);
1017 ProcessTagForRun<UnderlinedCharacterRun>(
1018 markupProcessData.underlinedCharacterRuns, styleStack, tag, characterIndex, underlinedCharacterRunIndex, uTagReference, [](const Tag& tag, UnderlinedCharacterRun& run) {
1019 run.properties.color = Color::BLUE;
1020 run.properties.colorDefined = true;
1021 ProcessUnderlineTag(tag, run);
1023 } // <a href=https://www.tizen.org>tizen</a>
1024 else if(TokenComparison(XHTML_SHADOW_TAG, tag.buffer, tag.length))
1026 // TODO: If !tag.isEndTag, then create a new shadow run.
1027 // else Pop the top of the stack and set the number of characters of the run.
1028 } // <shadow></shadow>
1029 else if(TokenComparison(XHTML_GLOW_TAG, tag.buffer, tag.length))
1031 // TODO: If !tag.isEndTag, then create a new glow run.
1032 // else Pop the top of the stack and set the number of characters of the run.
1034 else if(TokenComparison(XHTML_OUTLINE_TAG, tag.buffer, tag.length))
1036 // TODO: If !tag.isEndTag, then create a new outline run.
1037 // else Pop the top of the stack and set the number of characters of the run.
1038 } // <outline></outline>
1039 else if(TokenComparison(XHTML_ITEM_TAG, tag.buffer, tag.length))
1041 ProcessItemTag(markupProcessData, tag, characterIndex);
1043 else if(TokenComparison(XHTML_BACKGROUND_TAG, tag.buffer, tag.length))
1045 ProcessTagForRun<ColorRun>(
1046 markupProcessData.backgroundColorRuns, styleStack, tag, characterIndex, backgroundRunIndex, backgroundTagReference, [](const Tag& tag, ColorRun& run) { ProcessBackground(tag, run); });
1048 else if(TokenComparison(XHTML_SPAN_TAG, tag.buffer, tag.length))
1050 ProcessSpanForRun(tag, spanStack, markupProcessData.colorRuns, markupProcessData.fontRuns, colorRunIndex, fontRunIndex, characterIndex, spanTagReference);
1052 else if(TokenComparison(XHTML_STRIKETHROUGH_TAG, tag.buffer, tag.length))
1054 ProcessTagForRun<StrikethroughCharacterRun>(
1055 markupProcessData.strikethroughCharacterRuns, styleStack, tag, characterIndex, strikethroughCharacterRunIndex, sTagReference, [](const Tag& tag, StrikethroughCharacterRun& run) { ProcessStrikethroughTag(tag, run); });
1057 else if(TokenComparison(XHTML_PARAGRAPH_TAG, tag.buffer, tag.length))
1059 ProcessParagraphTag(markupProcessData, tag, (markupStringBuffer == markupStringEndBuffer), characterIndex);
1060 ProcessTagForRun<BoundedParagraphRun>(
1061 markupProcessData.boundedParagraphRuns, styleStack, tag, characterIndex, boundedParagraphRunIndex, pTagReference, [](const Tag& tag, BoundedParagraphRun& run) {});
1063 } // end if( IsTag() )
1064 else if(markupStringBuffer < markupStringEndBuffer)
1066 ProcessMarkupStringBuffer(markupProcessData, markupStringBuffer, markupStringEndBuffer, characterIndex);
1070 // Resize the model's vectors.
1071 ResizeModelVectors(markupProcessData, fontRunIndex, colorRunIndex, underlinedCharacterRunIndex, backgroundRunIndex, boundedParagraphRunIndex);
1076 } // namespace Toolkit