#include <dali-toolkit/internal/text/markup-processor-span.h>
#include <dali-toolkit/internal/text/markup-processor-strikethrough.h>
#include <dali-toolkit/internal/text/markup-processor-underline.h>
+#include <dali-toolkit/internal/text/markup-tags-and-attributes.h>
#include <dali-toolkit/internal/text/xhtml-entities.h>
namespace Dali
{
namespace
{
-// HTML-ISH tag and attribute constants.
-// Note they must be lower case in order to make the comparison to work
-// as the parser converts all the read tags to lower case.
-const std::string XHTML_COLOR_TAG("color");
-const std::string XHTML_FONT_TAG("font");
-const std::string XHTML_B_TAG("b");
-const std::string XHTML_I_TAG("i");
-const std::string XHTML_U_TAG("u");
-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 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 std::string XHTML_CHARACTER_SPACING_TAG("char-spacing");
-
const char LESS_THAN = '<';
const char GREATER_THAN = '>';
const char EQUAL = '=';
// 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 = 13u; ///< 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', 'u-dash-width', 's-color' and 's-height' attrubutes.
+// The MAX_NUM_OF_ATTRIBUTES is the number of attributes in span tag "markup-processor-span.cpp". Because it contains the maximum number of attributes in all tags.
+const unsigned int MAX_NUM_OF_ATTRIBUTES = 14u; ///< 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', 'u-dash-width', 's-color', 's-height' and 'char-space-value' attrubutes.
const unsigned int DEFAULT_VECTOR_SIZE = 16u; ///< Default size of run vectors.
#if defined(DEBUG_ENABLED)
RunIndex underlinedCharacterRunIndex;
RunIndex backgroundColorRunIndex;
RunIndex strikethroughCharacterRunIndex;
+ RunIndex characterSpacingCharacterRunIndex;
bool isColorDefined;
bool isFontDefined;
bool isUnderlinedCharacterDefined;
bool isBackgroundColorDefined;
bool isStrikethroughDefined;
+ bool isCharacterSpacingDefined;
};
/**
*/
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;
span.backgroundColorRunIndex = 0u;
//strikethrough
span.strikethroughCharacterRunIndex = 0u;
span.isStrikethroughDefined = false;
+
+ //characterSpacing
+ span.characterSpacingCharacterRunIndex = 0u;
+ span.isCharacterSpacingDefined = false;
}
/**
* @param[in] tagReference The tagReference we should increment/decrement
*/
void ProcessSpanForRun(
- const Tag& spanTag,
- StyleStack<Span>& spanStack,
- Vector<ColorRun>& colorRuns,
- Vector<FontDescriptionRun>& fontRuns,
- Vector<UnderlinedCharacterRun>& underlinedCharacterRuns,
- Vector<ColorRun>& backgroundColorRuns,
- Vector<StrikethroughCharacterRun>& strikethroughCharacterRuns,
- RunIndex& colorRunIndex,
- RunIndex& fontRunIndex,
- RunIndex& underlinedCharacterRunIndex,
- RunIndex& backgroundColorRunIndex,
- RunIndex& strikethroughCharacterRunIndex,
- const CharacterIndex characterIndex,
- int& tagReference)
+ const Tag& spanTag,
+ StyleStack<Span>& spanStack,
+ Vector<ColorRun>& colorRuns,
+ Vector<FontDescriptionRun>& fontRuns,
+ Vector<UnderlinedCharacterRun>& underlinedCharacterRuns,
+ Vector<ColorRun>& backgroundColorRuns,
+ Vector<StrikethroughCharacterRun>& strikethroughCharacterRuns,
+ Vector<CharacterSpacingCharacterRun>& characterSpacingCharacterRuns,
+ RunIndex& colorRunIndex,
+ RunIndex& fontRunIndex,
+ RunIndex& underlinedCharacterRunIndex,
+ RunIndex& backgroundColorRunIndex,
+ RunIndex& strikethroughCharacterRunIndex,
+ RunIndex& characterSpacingCharacterRunIndex,
+ const CharacterIndex characterIndex,
+ int& tagReference)
{
if(!spanTag.isEndTag)
{
StrikethroughCharacterRun strikethroughCharacterRun;
Initialize(strikethroughCharacterRun);
+ CharacterSpacingCharacterRun characterSpacingCharacterRun;
+ Initialize(characterSpacingCharacterRun);
+
Span span;
Initialize(span);
// Fill the run with the parameters.
- colorRun.characterRun.characterIndex = characterIndex;
- fontRun.characterRun.characterIndex = characterIndex;
- underlinedCharacterRun.characterRun.characterIndex = characterIndex;
- backgroundColorRun.characterRun.characterIndex = characterIndex;
- strikethroughCharacterRun.characterRun.characterIndex = characterIndex;
-
- span.colorRunIndex = colorRunIndex;
- span.fontRunIndex = fontRunIndex;
- span.underlinedCharacterRunIndex = underlinedCharacterRunIndex;
- span.backgroundColorRunIndex = backgroundColorRunIndex;
- span.strikethroughCharacterRunIndex = strikethroughCharacterRunIndex;
+ colorRun.characterRun.characterIndex = characterIndex;
+ fontRun.characterRun.characterIndex = characterIndex;
+ underlinedCharacterRun.characterRun.characterIndex = characterIndex;
+ backgroundColorRun.characterRun.characterIndex = characterIndex;
+ strikethroughCharacterRun.characterRun.characterIndex = characterIndex;
+ characterSpacingCharacterRun.characterRun.characterIndex = characterIndex;
+
+ span.colorRunIndex = colorRunIndex;
+ span.fontRunIndex = fontRunIndex;
+ span.underlinedCharacterRunIndex = underlinedCharacterRunIndex;
+ span.backgroundColorRunIndex = backgroundColorRunIndex;
+ span.strikethroughCharacterRunIndex = strikethroughCharacterRunIndex;
+ span.characterSpacingCharacterRunIndex = characterSpacingCharacterRunIndex;
ProcessSpanTag(spanTag,
colorRun,
underlinedCharacterRun,
backgroundColorRun,
strikethroughCharacterRun,
+ characterSpacingCharacterRun,
span.isColorDefined,
span.isFontDefined,
span.isUnderlinedCharacterDefined,
span.isBackgroundColorDefined,
- span.isStrikethroughDefined);
+ span.isStrikethroughDefined,
+ span.isCharacterSpacingDefined);
// Push the span into the stack.
spanStack.Push(span);
++strikethroughCharacterRunIndex;
}
+ if(span.isCharacterSpacingDefined)
+ {
+ // Push the run in the logical model.
+ characterSpacingCharacterRuns.PushBack(characterSpacingCharacterRun);
+ ++characterSpacingCharacterRunIndex;
+ }
+
// Increase reference
++tagReference;
}
strikethroughCharacterRun.characterRun.numberOfCharacters = characterIndex - strikethroughCharacterRun.characterRun.characterIndex;
}
+ if(span.isCharacterSpacingDefined)
+ {
+ CharacterSpacingCharacterRun& characterSpacingCharacterRun = *(characterSpacingCharacterRuns.Begin() + span.characterSpacingCharacterRunIndex);
+ characterSpacingCharacterRun.characterRun.numberOfCharacters = characterIndex - characterSpacingCharacterRun.characterRun.characterIndex;
+ }
+
--tagReference;
}
}
markupProcessData.characterSpacingCharacterRuns.Resize(characterSpacingCharacterRunIndex);
#ifdef DEBUG_ENABLED
- for(unsigned int i = 0; i < colorRunIndex; ++i)
+ if(gLogFilter->IsEnabledFor(Debug::Verbose))
{
- ColorRun& run = markupProcessData.colorRuns[i];
- 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);
+ for(uint32_t i = 0; i < colorRunIndex; ++i)
+ {
+ ColorRun& run = markupProcessData.colorRuns[i];
+ 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);
+ }
}
#endif
}
markupStringEndBuffer,
tag))
{
- if(TokenComparison(XHTML_COLOR_TAG, tag.buffer, tag.length))
+ if(TokenComparison(MARKUP::TAG::COLOR, tag.buffer, tag.length))
{
ProcessTagForRun<ColorRun>(
markupProcessData.colorRuns, styleStack, tag, characterIndex, colorRunIndex, colorTagReference, [](const Tag& tag, ColorRun& run) { ProcessColorTag(tag, run); });
} // <color></color>
- else if(TokenComparison(XHTML_I_TAG, tag.buffer, tag.length))
+ else if(TokenComparison(MARKUP::TAG::ITALIC, tag.buffer, tag.length))
{
ProcessTagForRun<FontDescriptionRun>(
markupProcessData.fontRuns, styleStack, tag, characterIndex, fontRunIndex, iTagReference, [](const Tag&, FontDescriptionRun& fontRun) {
fontRun.slantDefined = true;
});
} // <i></i>
- else if(TokenComparison(XHTML_U_TAG, tag.buffer, tag.length))
+ else if(TokenComparison(MARKUP::TAG::UNDERLINE, tag.buffer, tag.length))
{
ProcessTagForRun<UnderlinedCharacterRun>(
markupProcessData.underlinedCharacterRuns, styleStack, tag, characterIndex, underlinedCharacterRunIndex, uTagReference, [](const Tag& tag, UnderlinedCharacterRun& run) { ProcessUnderlineTag(tag, run); });
} // <u></u>
- else if(TokenComparison(XHTML_B_TAG, tag.buffer, tag.length))
+ else if(TokenComparison(MARKUP::TAG::BOLD, tag.buffer, tag.length))
{
ProcessTagForRun<FontDescriptionRun>(
markupProcessData.fontRuns, styleStack, tag, characterIndex, fontRunIndex, bTagReference, [](const Tag&, FontDescriptionRun& fontRun) {
fontRun.weightDefined = true;
});
} // <b></b>
- else if(TokenComparison(XHTML_FONT_TAG, tag.buffer, tag.length))
+ else if(TokenComparison(MARKUP::TAG::FONT, tag.buffer, tag.length))
{
ProcessTagForRun<FontDescriptionRun>(
markupProcessData.fontRuns, styleStack, tag, characterIndex, fontRunIndex, fontTagReference, [](const Tag& tag, FontDescriptionRun& fontRun) { ProcessFontTag(tag, fontRun); });
} // <font></font>
- else if(TokenComparison(XHTML_ANCHOR_TAG, tag.buffer, tag.length))
+ else if(TokenComparison(MARKUP::TAG::ANCHOR, tag.buffer, tag.length))
{
/* Anchor */
ProcessAnchorTag(markupProcessData, tag, characterIndex);
ProcessUnderlineTag(tag, run);
});
} // <a href=https://www.tizen.org>tizen</a>
- else if(TokenComparison(XHTML_SHADOW_TAG, tag.buffer, tag.length))
+ else if(TokenComparison(MARKUP::TAG::SHADOW, tag.buffer, tag.length))
{
// TODO: If !tag.isEndTag, then create a new shadow run.
// else Pop the top of the stack and set the number of characters of the run.
} // <shadow></shadow>
- else if(TokenComparison(XHTML_GLOW_TAG, tag.buffer, tag.length))
+ else if(TokenComparison(MARKUP::TAG::GLOW, tag.buffer, tag.length))
{
// TODO: If !tag.isEndTag, then create a new glow run.
// else Pop the top of the stack and set the number of characters of the run.
} // <glow></glow>
- else if(TokenComparison(XHTML_OUTLINE_TAG, tag.buffer, tag.length))
+ else if(TokenComparison(MARKUP::TAG::OUTLINE, tag.buffer, tag.length))
{
// TODO: If !tag.isEndTag, then create a new outline run.
// else Pop the top of the stack and set the number of characters of the run.
} // <outline></outline>
- else if(TokenComparison(XHTML_ITEM_TAG, tag.buffer, tag.length))
+ else if(TokenComparison(MARKUP::TAG::EMBEDDED_ITEM, tag.buffer, tag.length))
{
ProcessItemTag(markupProcessData, tag, characterIndex);
}
- else if(TokenComparison(XHTML_BACKGROUND_TAG, tag.buffer, tag.length))
+ else if(TokenComparison(MARKUP::TAG::BACKGROUND, tag.buffer, tag.length))
{
ProcessTagForRun<ColorRun>(
markupProcessData.backgroundColorRuns, styleStack, tag, characterIndex, backgroundRunIndex, backgroundTagReference, [](const Tag& tag, ColorRun& run) { ProcessBackground(tag, run); });
}
- else if(TokenComparison(XHTML_SPAN_TAG, tag.buffer, tag.length))
+ else if(TokenComparison(MARKUP::TAG::SPAN, tag.buffer, tag.length))
{
ProcessSpanForRun(tag,
spanStack,
markupProcessData.underlinedCharacterRuns,
markupProcessData.backgroundColorRuns,
markupProcessData.strikethroughCharacterRuns,
+ markupProcessData.characterSpacingCharacterRuns,
colorRunIndex,
fontRunIndex,
underlinedCharacterRunIndex,
backgroundRunIndex,
strikethroughCharacterRunIndex,
+ characterSpacingCharacterRunIndex,
characterIndex,
spanTagReference);
}
- else if(TokenComparison(XHTML_STRIKETHROUGH_TAG, tag.buffer, tag.length))
+ else if(TokenComparison(MARKUP::TAG::STRIKETHROUGH, tag.buffer, tag.length))
{
ProcessTagForRun<StrikethroughCharacterRun>(
markupProcessData.strikethroughCharacterRuns, styleStack, tag, characterIndex, strikethroughCharacterRunIndex, sTagReference, [](const Tag& tag, StrikethroughCharacterRun& run) { ProcessStrikethroughTag(tag, run); });
} // <s></s>
- else if(TokenComparison(XHTML_PARAGRAPH_TAG, tag.buffer, tag.length))
+ else if(TokenComparison(MARKUP::TAG::PARAGRAPH, tag.buffer, tag.length))
{
ProcessParagraphTag(markupProcessData, tag, (markupStringBuffer == markupStringEndBuffer), characterIndex);
ProcessTagForRun<BoundedParagraphRun>(
markupProcessData.boundedParagraphRuns, styleStack, tag, characterIndex, boundedParagraphRunIndex, pTagReference, [](const Tag& tag, BoundedParagraphRun& run) { ProcessAttributesOfParagraphTag(tag, run); });
} // <p></p>
- else if(TokenComparison(XHTML_CHARACTER_SPACING_TAG, tag.buffer, tag.length))
+ else if(TokenComparison(MARKUP::TAG::CHARACTER_SPACING, tag.buffer, tag.length))
{
ProcessTagForRun<CharacterSpacingCharacterRun>(
markupProcessData.characterSpacingCharacterRuns, styleStack, tag, characterIndex, characterSpacingCharacterRunIndex, characterSpacingTagReference, [](const Tag& tag, CharacterSpacingCharacterRun& run) { ProcessCharacterSpacingTag(tag, run); });