X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Fmarkup-processor.cpp;h=197dff19a7814fb64fcea90541b44df5db62ee88;hp=b656aa46f6349b5a321c52a0ff5e32ceb381bf53;hb=22451f7abe0230b418d551d9eac0c685273e72f1;hpb=6970e395a31aae5e97be905e01e47fd49e043f94 diff --git a/dali-toolkit/internal/text/markup-processor.cpp b/dali-toolkit/internal/text/markup-processor.cpp index b656aa4..197dff1 100644 --- a/dali-toolkit/internal/text/markup-processor.cpp +++ b/dali-toolkit/internal/text/markup-processor.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,7 +31,10 @@ #include #include #include +#include #include +#include +#include #include namespace Dali @@ -57,6 +60,8 @@ const std::string XHTML_ITEM_TAG("item"); const std::string XHTML_ANCHOR_TAG("a"); const std::string XHTML_BACKGROUND_TAG("background"); const std::string XHTML_SPAN_TAG("span"); +const std::string XHTML_STRIKETHROUGH_TAG("s"); +const std::string XHTML_PARAGRAPH_TAG("p"); const char LESS_THAN = '<'; const char GREATER_THAN = '>'; @@ -71,13 +76,14 @@ const char CHAR_ARRAY_END = '\0'; const char HEX_CODE = 'x'; const char WHITE_SPACE = 0x20; // ASCII value of the white space. +const char NEW_LINE = 0x0A; // ASCII value of the newline. // Range 1 0x0u < XHTML_DECIMAL_ENTITY_RANGE <= 0xD7FFu // Range 2 0xE000u < XHTML_DECIMAL_ENTITY_RANGE <= 0xFFFDu // Range 3 0x10000u < XHTML_DECIMAL_ENTITY_RANGE <= 0x10FFFFu const unsigned long XHTML_DECIMAL_ENTITY_RANGE[] = {0x0u, 0xD7FFu, 0xE000u, 0xFFFDu, 0x10000u, 0x10FFFFu}; -const unsigned int MAX_NUM_OF_ATTRIBUTES = 5u; ///< The font tag has the 'family', 'size' 'weight', 'width' and 'slant' attrubutes. +const unsigned int MAX_NUM_OF_ATTRIBUTES = 11u; ///< The span tag has the 'font-family', 'font-size' 'font-weight', 'font-width', 'font-slant','text-color', 'u-color', 'u-height','u-type','u-dash-gap'and 'u-dash-width' attrubutes. const unsigned int DEFAULT_VECTOR_SIZE = 16u; ///< Default size of run vectors. #if defined(DEBUG_ENABLED) @@ -134,8 +140,10 @@ struct Span { RunIndex colorRunIndex; RunIndex fontRunIndex; + RunIndex underlinedCharacterRunIndex; bool isColorDefined; bool isFontDefined; + bool isUnderlinedCharacterDefined; }; /** @@ -189,10 +197,35 @@ void Initialize(UnderlinedCharacterRun& underlinedCharacterRun) */ void Initialize(Span& span) { - span.colorRunIndex = 0u; - span.isColorDefined = false; - span.fontRunIndex = 0u; - span.isFontDefined = false; + span.colorRunIndex = 0u; + span.isColorDefined = false; + span.fontRunIndex = 0u; + span.isFontDefined = false; + span.underlinedCharacterRunIndex = 0u; + span.isUnderlinedCharacterDefined = false; +} + +/** + * @brief Initializes a strikethrough character run to its defaults. + * + * @param[in,out] strikethroughCharacterRun The strikethrough character run to initialize. + */ +void Initialize(StrikethroughCharacterRun& strikethroughCharacterRun) +{ + strikethroughCharacterRun.characterRun.characterIndex = 0u; + strikethroughCharacterRun.characterRun.numberOfCharacters = 0u; + strikethroughCharacterRun.isColorSet = false; +} + +/** + * @brief Initializes a bounded-paragraph character run to its defaults. + * + * @param[in,out] boundedParagraphRun The bounded paragraphRun run to initialize. + */ +void Initialize(BoundedParagraphRun& boundedParagraphRun) +{ + boundedParagraphRun.characterRun.characterIndex = 0u; + boundedParagraphRun.characterRun.numberOfCharacters = 0u; } /** @@ -622,6 +655,30 @@ void ProcessItemTag( } /** + * @brief Processes the paragraph-tag + * + * @param[in/out] markupProcessData The markup process data + * @param[in] tag The current tag + * @param[in] isEndBuffer Whether the end of buffer + * @param[in/out] characterIndex The current character index + */ +void ProcessParagraphTag( + MarkupProcessData& markupProcessData, + const Tag tag, + bool isEndBuffer, + CharacterIndex& characterIndex) +{ + if((characterIndex > 0 && + markupProcessData.markupProcessedText[characterIndex - 1u] != NEW_LINE) && + (!(tag.isEndTag && isEndBuffer))) + { + // Insert new-line character at the start and end of paragraph. + markupProcessData.markupProcessedText.append(1u, NEW_LINE); + ++characterIndex; + } +} + +/** * @brief Processes the anchor tag * * @param[in/out] markupProcessData The markup process data @@ -666,14 +723,16 @@ void ProcessAnchorTag( * @param[in] tagReference The tagReference we should increment/decrement */ void ProcessSpanForRun( - const Tag& spanTag, - StyleStack& spanStack, - Vector& colorRuns, - Vector& fontRuns, - RunIndex& colorRunIndex, - RunIndex& fontRunIndex, - const CharacterIndex characterIndex, - int& tagReference) + const Tag& spanTag, + StyleStack& spanStack, + Vector& colorRuns, + Vector& fontRuns, + Vector& underlinedCharacterRuns, + RunIndex& colorRunIndex, + RunIndex& fontRunIndex, + RunIndex& underlinedCharacterRunIndex, + const CharacterIndex characterIndex, + int& tagReference) { if(!spanTag.isEndTag) { @@ -684,17 +743,22 @@ void ProcessSpanForRun( FontDescriptionRun fontRun; Initialize(fontRun); + UnderlinedCharacterRun underlinedCharacterRun; + Initialize(underlinedCharacterRun); + Span span; Initialize(span); // Fill the run with the parameters. - colorRun.characterRun.characterIndex = characterIndex; - fontRun.characterRun.characterIndex = characterIndex; + colorRun.characterRun.characterIndex = characterIndex; + fontRun.characterRun.characterIndex = characterIndex; + underlinedCharacterRun.characterRun.characterIndex = characterIndex; - span.colorRunIndex = colorRunIndex; - span.fontRunIndex = fontRunIndex; + span.colorRunIndex = colorRunIndex; + span.fontRunIndex = fontRunIndex; + span.underlinedCharacterRunIndex = underlinedCharacterRunIndex; - ProcessSpanTag(spanTag, colorRun, fontRun, span.isColorDefined, span.isFontDefined); + ProcessSpanTag(spanTag, colorRun, fontRun, underlinedCharacterRun, span.isColorDefined, span.isFontDefined, span.isUnderlinedCharacterDefined); // Push the span into the stack. spanStack.Push(span); @@ -714,6 +778,13 @@ void ProcessSpanForRun( ++fontRunIndex; } + if(span.isUnderlinedCharacterDefined) + { + // Push the run in the logical model. + underlinedCharacterRuns.PushBack(underlinedCharacterRun); + ++underlinedCharacterRunIndex; + } + // Increase reference ++tagReference; } @@ -736,6 +807,12 @@ void ProcessSpanForRun( fontRun.characterRun.numberOfCharacters = characterIndex - fontRun.characterRun.characterIndex; } + if(span.isUnderlinedCharacterDefined) + { + UnderlinedCharacterRun& underlinedCharacterRun = *(underlinedCharacterRuns.Begin() + span.underlinedCharacterRunIndex); + underlinedCharacterRun.characterRun.numberOfCharacters = characterIndex - underlinedCharacterRun.characterRun.characterIndex; + } + --tagReference; } } @@ -749,13 +826,21 @@ void ProcessSpanForRun( * @param[in] colorRunIndex The color run index * @param[in] underlinedCharacterRunIndex The underlined character run index * @param[in] backgroundRunIndex The background run index + * @param[in] boundedParagraphRunIndex The bounded paragraph run index + * */ -void ResizeModelVectors(MarkupProcessData& markupProcessData, const RunIndex fontRunIndex, const RunIndex colorRunIndex, const RunIndex underlinedCharacterRunIndex, const RunIndex backgroundRunIndex) +void ResizeModelVectors(MarkupProcessData& markupProcessData, + const RunIndex fontRunIndex, + const RunIndex colorRunIndex, + const RunIndex underlinedCharacterRunIndex, + const RunIndex backgroundRunIndex, + const RunIndex boundedParagraphRunIndex) { markupProcessData.fontRuns.Resize(fontRunIndex); markupProcessData.colorRuns.Resize(colorRunIndex); markupProcessData.underlinedCharacterRuns.Resize(underlinedCharacterRunIndex); markupProcessData.backgroundColorRuns.Resize(backgroundRunIndex); + markupProcessData.boundedParagraphRuns.Resize(boundedParagraphRunIndex); #ifdef DEBUG_ENABLED for(unsigned int i = 0; i < colorRunIndex; ++i) @@ -875,10 +960,12 @@ void ProcessMarkupString(const std::string& markupString, MarkupProcessData& mar StyleStack spanStack; // Points the next free position in the vector of runs. - RunIndex colorRunIndex = 0u; - RunIndex fontRunIndex = 0u; - RunIndex underlinedCharacterRunIndex = 0u; - RunIndex backgroundRunIndex = 0u; + RunIndex colorRunIndex = 0u; + RunIndex fontRunIndex = 0u; + RunIndex underlinedCharacterRunIndex = 0u; + RunIndex backgroundRunIndex = 0u; + RunIndex strikethroughCharacterRunIndex = 0u; + RunIndex boundedParagraphRunIndex = 0u; // check tag reference int colorTagReference = 0u; @@ -888,6 +975,8 @@ void ProcessMarkupString(const std::string& markupString, MarkupProcessData& mar int uTagReference = 0u; int backgroundTagReference = 0u; int spanTagReference = 0u; + int sTagReference = 0u; + int pTagReference = 0u; // Give an initial default value to the model's vectors. markupProcessData.colorRuns.Reserve(DEFAULT_VECTOR_SIZE); @@ -924,7 +1013,7 @@ void ProcessMarkupString(const std::string& markupString, MarkupProcessData& mar else if(TokenComparison(XHTML_U_TAG, tag.buffer, tag.length)) { ProcessTagForRun( - markupProcessData.underlinedCharacterRuns, styleStack, tag, characterIndex, underlinedCharacterRunIndex, uTagReference, [](const Tag& tag, UnderlinedCharacterRun& run) {}); + markupProcessData.underlinedCharacterRuns, styleStack, tag, characterIndex, underlinedCharacterRunIndex, uTagReference, [](const Tag& tag, UnderlinedCharacterRun& run) { ProcessUnderlineTag(tag, run); }); } // else if(TokenComparison(XHTML_B_TAG, tag.buffer, tag.length)) { @@ -949,7 +1038,13 @@ void ProcessMarkupString(const std::string& markupString, MarkupProcessData& mar run.color = Color::BLUE; ProcessColorTag(tag, run); }); - /* TODO - underline */ + /* Underline */ + ProcessTagForRun( + markupProcessData.underlinedCharacterRuns, styleStack, tag, characterIndex, underlinedCharacterRunIndex, uTagReference, [](const Tag& tag, UnderlinedCharacterRun& run) { + run.properties.color = Color::BLUE; + run.properties.colorDefined = true; + ProcessUnderlineTag(tag, run); + }); } // tizen else if(TokenComparison(XHTML_SHADOW_TAG, tag.buffer, tag.length)) { @@ -977,9 +1072,20 @@ void ProcessMarkupString(const std::string& markupString, MarkupProcessData& mar } else if(TokenComparison(XHTML_SPAN_TAG, tag.buffer, tag.length)) { - ProcessSpanForRun(tag, spanStack, markupProcessData.colorRuns, markupProcessData.fontRuns, colorRunIndex, fontRunIndex, characterIndex, spanTagReference); + ProcessSpanForRun(tag, spanStack, markupProcessData.colorRuns, markupProcessData.fontRuns, markupProcessData.underlinedCharacterRuns, colorRunIndex, fontRunIndex, underlinedCharacterRunIndex, characterIndex, spanTagReference); } - } // end if( IsTag() ) + else if(TokenComparison(XHTML_STRIKETHROUGH_TAG, tag.buffer, tag.length)) + { + ProcessTagForRun( + markupProcessData.strikethroughCharacterRuns, styleStack, tag, characterIndex, strikethroughCharacterRunIndex, sTagReference, [](const Tag& tag, StrikethroughCharacterRun& run) { ProcessStrikethroughTag(tag, run); }); + } // + else if(TokenComparison(XHTML_PARAGRAPH_TAG, tag.buffer, tag.length)) + { + ProcessParagraphTag(markupProcessData, tag, (markupStringBuffer == markupStringEndBuffer), characterIndex); + ProcessTagForRun( + markupProcessData.boundedParagraphRuns, styleStack, tag, characterIndex, boundedParagraphRunIndex, pTagReference, [](const Tag& tag, BoundedParagraphRun& run) { ProcessAttributesOfParagraphTag(tag, run); }); + } //

+ } // end if( IsTag() ) else if(markupStringBuffer < markupStringEndBuffer) { ProcessMarkupStringBuffer(markupProcessData, markupStringBuffer, markupStringEndBuffer, characterIndex); @@ -987,7 +1093,10 @@ void ProcessMarkupString(const std::string& markupString, MarkupProcessData& mar } // Resize the model's vectors. - ResizeModelVectors(markupProcessData, fontRunIndex, colorRunIndex, underlinedCharacterRunIndex, backgroundRunIndex); + ResizeModelVectors(markupProcessData, fontRunIndex, colorRunIndex, underlinedCharacterRunIndex, backgroundRunIndex, boundedParagraphRunIndex); + + // Handle the nested tags + OverrideNestedUnderlinedCharacterRuns(markupProcessData.underlinedCharacterRuns); } } // namespace Text