X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Fmarkup-processor.cpp;h=ea7f869588a7ee8d73203f56308dd91bfb12764d;hb=9161d9828d1a5bb3c7eaf83002863de84b23b751;hp=20a58256baf19f517e3d01c10af9de30d7ed84b5;hpb=b8da2e53925b9abb9fa362560069e8ca4aa62f81;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/text/markup-processor.cpp b/dali-toolkit/internal/text/markup-processor.cpp index 20a5825..ea7f869 100644 --- a/dali-toolkit/internal/text/markup-processor.cpp +++ b/dali-toolkit/internal/text/markup-processor.cpp @@ -25,6 +25,7 @@ // INTERNAL INCLUDES #include +#include #include #include #include @@ -51,6 +52,7 @@ const std::string XHTML_SHADOW_TAG("shadow"); const std::string XHTML_GLOW_TAG("glow"); const std::string XHTML_OUTLINE_TAG("outline"); const std::string XHTML_ITEM_TAG("item"); +const std::string XHTML_ANCHOR_TAG("a"); const char LESS_THAN = '<'; const char GREATER_THAN = '>'; @@ -154,6 +156,17 @@ void Initialize(ColorRun& colorRun) } /** + * @brief Initializes a underlined character run to its defaults. + * + * @param[in,out] underlinedCharacterRun The underelined character run to initialize. + */ +void Initialize(UnderlinedCharacterRun& underlinedCharacterRun) +{ + underlinedCharacterRun.characterRun.characterIndex = 0u; + underlinedCharacterRun.characterRun.numberOfCharacters = 0u; +} + +/** * @brief Splits the tag string into the tag name and its attributes. * * The attributes are stored in a vector in the tag. @@ -496,9 +509,9 @@ bool XHTMLNumericEntityToUtf8(const char* markupText, char* utf8) } /** - * @brief Processes a particular tag for the required run (color-run or font-run). + * @brief Processes a particular tag for the required run (color-run, font-run or underlined-character-run). * - * @tparam RunType Whether ColorRun or FontDescriptionRun + * @tparam RunType Whether ColorRun , FontDescriptionRun or UnderlinedCharacterRun * * @param[in/out] runsContainer The container containing all the runs * @param[in/out] styleStack The style stack @@ -580,16 +593,50 @@ void ProcessItemTag( } /** + * @brief Processes the anchor tag + * + * @param[in/out] markupProcessData The markup process data + * @param[in] tag The current tag + * @param[in/out] characterIndex The current character index + */ +void ProcessAnchorTag( + MarkupProcessData& markupProcessData, + const Tag tag, + CharacterIndex& characterIndex) +{ + if(!tag.isEndTag) + { + // Create an anchor instance. + Anchor anchor; + anchor.startIndex = characterIndex; + anchor.endIndex = 0u; + ProcessAnchor(tag, anchor); + markupProcessData.anchors.PushBack(anchor); + } + else + { + // Update end index. + unsigned int count = markupProcessData.anchors.Count(); + if(count > 0) + { + markupProcessData.anchors[count - 1].endIndex = characterIndex; + } + } +} + +/** * @brief Resizes the model's vectors * * @param[in/out] markupProcessData The markup process data * @param[in] fontRunIndex The font run index * @param[in] colorRunIndex The color run index + * @param[in] underlinedCharacterRunIndex The underlined character run index */ -void ResizeModelVectors(MarkupProcessData& markupProcessData, const StyleStack::RunIndex fontRunIndex, const StyleStack::RunIndex colorRunIndex) +void ResizeModelVectors(MarkupProcessData& markupProcessData, const StyleStack::RunIndex fontRunIndex, const StyleStack::RunIndex colorRunIndex, const StyleStack::RunIndex underlinedCharacterRunIndex) { markupProcessData.fontRuns.Resize(fontRunIndex); markupProcessData.colorRuns.Resize(colorRunIndex); + markupProcessData.underlinedCharacterRuns.Resize(underlinedCharacterRunIndex); #ifdef DEBUG_ENABLED for(unsigned int i = 0; i < colorRunIndex; ++i) @@ -706,18 +753,21 @@ void ProcessMarkupString(const std::string& markupString, MarkupProcessData& mar StyleStack styleStack; // Points the next free position in the vector of runs. - StyleStack::RunIndex colorRunIndex = 0u; - StyleStack::RunIndex fontRunIndex = 0u; + StyleStack::RunIndex colorRunIndex = 0u; + StyleStack::RunIndex fontRunIndex = 0u; + StyleStack::RunIndex underlinedCharacterRunIndex = 0u; // check tag reference int colorTagReference = 0u; int fontTagReference = 0u; int iTagReference = 0u; int bTagReference = 0u; + int uTagReference = 0u; // Give an initial default value to the model's vectors. markupProcessData.colorRuns.Reserve(DEFAULT_VECTOR_SIZE); markupProcessData.fontRuns.Reserve(DEFAULT_VECTOR_SIZE); + markupProcessData.underlinedCharacterRuns.Reserve(DEFAULT_VECTOR_SIZE); // Get the mark-up string buffer. const char* markupStringBuffer = markupString.c_str(); @@ -747,9 +797,9 @@ void ProcessMarkupString(const std::string& markupString, MarkupProcessData& mar } // else if(TokenComparison(XHTML_U_TAG, tag.buffer, tag.length)) { - // TODO: If !tag.isEndTag, then create a new underline run. - // else Pop the top of the stack and set the number of characters of the run. - } // + ProcessTagForRun( + markupProcessData.underlinedCharacterRuns, styleStack, tag, characterIndex, underlinedCharacterRunIndex, uTagReference, [](const Tag& tag, UnderlinedCharacterRun& run) { }); + } // else if(TokenComparison(XHTML_B_TAG, tag.buffer, tag.length)) { ProcessTagForRun( @@ -763,6 +813,18 @@ void ProcessMarkupString(const std::string& markupString, MarkupProcessData& mar ProcessTagForRun( markupProcessData.fontRuns, styleStack, tag, characterIndex, fontRunIndex, fontTagReference, [](const Tag& tag, FontDescriptionRun& fontRun) { ProcessFontTag(tag, fontRun); }); } // + else if(TokenComparison(XHTML_ANCHOR_TAG, tag.buffer, tag.length)) + { + /* Anchor */ + ProcessAnchorTag(markupProcessData, tag, characterIndex); + /* Color */ + ProcessTagForRun( + markupProcessData.colorRuns, styleStack, tag, characterIndex, colorRunIndex, colorTagReference, [](const Tag& tag, ColorRun& run) { + run.color = Color::BLUE; + ProcessColorTag(tag, run); + }); + /* TODO - underline */ + } // tizen else if(TokenComparison(XHTML_SHADOW_TAG, tag.buffer, tag.length)) { // TODO: If !tag.isEndTag, then create a new shadow run. @@ -790,7 +852,7 @@ void ProcessMarkupString(const std::string& markupString, MarkupProcessData& mar } // Resize the model's vectors. - ResizeModelVectors(markupProcessData, fontRunIndex, colorRunIndex); + ResizeModelVectors(markupProcessData, fontRunIndex, colorRunIndex, underlinedCharacterRunIndex); } } // namespace Text