//ABC have strikethrough
DALI_TEST_EQUALS(strikethroughRuns[0u].glyphRun.glyphIndex, 0u, TEST_LOCATION);
DALI_TEST_EQUALS(strikethroughRuns[0u].glyphRun.numberOfGlyphs, 3u, TEST_LOCATION);
- DALI_TEST_CHECK(!strikethroughRuns[0u].isColorSet);
+ DALI_TEST_CHECK(!strikethroughRuns[0u].properties.colorDefined);
//GH have strikethrough
DALI_TEST_EQUALS(strikethroughRuns[1u].glyphRun.glyphIndex, 5u, TEST_LOCATION);
DALI_TEST_EQUALS(strikethroughRuns[1u].glyphRun.numberOfGlyphs, 2u, TEST_LOCATION);
- DALI_TEST_CHECK(strikethroughRuns[1u].isColorSet);
+ DALI_TEST_CHECK(strikethroughRuns[1u].properties.colorDefined);
END_TEST;
}
//ABC have strikethrough
DALI_TEST_EQUALS(strikethroughRuns[0u].glyphRun.glyphIndex, 0u, TEST_LOCATION);
DALI_TEST_EQUALS(strikethroughRuns[0u].glyphRun.numberOfGlyphs, 3u, TEST_LOCATION);
- DALI_TEST_CHECK(!strikethroughRuns[0u].isColorSet);
+ DALI_TEST_CHECK(!strikethroughRuns[0u].properties.colorDefined);
//GH have strikethrough
DALI_TEST_EQUALS(strikethroughRuns[1u].glyphRun.glyphIndex, 5u, TEST_LOCATION);
DALI_TEST_EQUALS(strikethroughRuns[1u].glyphRun.numberOfGlyphs, 2u, TEST_LOCATION);
- DALI_TEST_CHECK(strikethroughRuns[1u].isColorSet);
+ DALI_TEST_CHECK(strikethroughRuns[1u].properties.colorDefined);
END_TEST;
}
//ABC have strikethrough
DALI_TEST_EQUALS(strikethroughRuns[0u].glyphRun.glyphIndex, 0u, TEST_LOCATION);
DALI_TEST_EQUALS(strikethroughRuns[0u].glyphRun.numberOfGlyphs, 3u, TEST_LOCATION);
- DALI_TEST_CHECK(strikethroughRuns[0u].isColorSet);
- DALI_TEST_EQUALS(strikethroughRuns[0u].color.r, 1u, TEST_LOCATION);
- DALI_TEST_EQUALS(strikethroughRuns[0u].color.g, 0u, TEST_LOCATION);
- DALI_TEST_EQUALS(strikethroughRuns[0u].color.b, 0u, TEST_LOCATION);
+ DALI_TEST_CHECK(strikethroughRuns[0u].properties.colorDefined);
+ DALI_TEST_EQUALS(strikethroughRuns[0u].properties.color.r, 1u, TEST_LOCATION);
+ DALI_TEST_EQUALS(strikethroughRuns[0u].properties.color.g, 0u, TEST_LOCATION);
+ DALI_TEST_EQUALS(strikethroughRuns[0u].properties.color.b, 0u, TEST_LOCATION);
//GH have strikethrough
DALI_TEST_EQUALS(strikethroughRuns[1u].glyphRun.glyphIndex, 5u, TEST_LOCATION);
DALI_TEST_EQUALS(strikethroughRuns[1u].glyphRun.numberOfGlyphs, 2u, TEST_LOCATION);
- DALI_TEST_CHECK(strikethroughRuns[1u].isColorSet);
- DALI_TEST_EQUALS(strikethroughRuns[1u].color.r, 0u, TEST_LOCATION);
- DALI_TEST_EQUALS(strikethroughRuns[1u].color.g, 1u, TEST_LOCATION);
- DALI_TEST_EQUALS(strikethroughRuns[1u].color.b, 0u, TEST_LOCATION);
+ DALI_TEST_CHECK(strikethroughRuns[1u].properties.colorDefined);
+ DALI_TEST_EQUALS(strikethroughRuns[1u].properties.color.r, 0u, TEST_LOCATION);
+ DALI_TEST_EQUALS(strikethroughRuns[1u].properties.color.g, 1u, TEST_LOCATION);
+ DALI_TEST_EQUALS(strikethroughRuns[1u].properties.color.b, 0u, TEST_LOCATION);
END_TEST;
}
const std::string XHTML_COLOR_ATTRIBUTE("color");
}
+void ProcessColorAttribute(const Attribute& attribute, StrikethroughCharacterRun& strikethroughRun)
+
+{
+ ColorStringToVector4(attribute.valueBuffer, attribute.valueLength, strikethroughRun.properties.color);
+ strikethroughRun.properties.colorDefined = true;
+}
+
void ProcessStrikethroughTag(const Tag& tag, StrikethroughCharacterRun& strikethroughRun)
{
for(Vector<Attribute>::ConstIterator it = tag.attributes.Begin(),
const Attribute& attribute(*it);
if(TokenComparison(XHTML_COLOR_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
{
- strikethroughRun.isColorSet = true;
- ColorStringToVector4(attribute.valueBuffer, attribute.valueLength, strikethroughRun.color);
+ ProcessColorAttribute(attribute, strikethroughRun);
}
}
}
namespace Text
{
struct Tag;
+struct Attribute;
struct StrikethroughCharacterRun;
/**
+ * @brief Fill the strikethrough character run with the color attribute value.
+ *
+ * @param[in] attribute the color attribute.
+ * @param[out] strikethroughCharacterRun The strikethrough character run
+ */
+void ProcessColorAttribute(const Attribute& attribute, StrikethroughCharacterRun& strikethroughCharacterRun);
+
+/**
* @brief Retrieves the strikethrough run info from the tag and sets it to the strikethrough run.
*
* @param[in] tag The strikethrough tag and its attributes.
{
strikethroughCharacterRun.characterRun.characterIndex = 0u;
strikethroughCharacterRun.characterRun.numberOfCharacters = 0u;
- strikethroughCharacterRun.isColorSet = false;
+ strikethroughCharacterRun.properties.colorDefined = false;
}
/**
mQuadVertexFormat["aColor"] = Property::VECTOR4;
}
- bool
- doGlyphHaveStrikethrough(GlyphIndex index,
- const Vector<StrikethroughGlyphRun>& strikethroughRuns,
- Vector4& strikethroughColor)
- {
- for(Vector<StrikethroughGlyphRun>::ConstIterator it = strikethroughRuns.Begin(),
- endIt = strikethroughRuns.End();
- it != endIt;
- ++it)
- {
- const StrikethroughGlyphRun& run = *it;
-
- if((run.glyphRun.glyphIndex <= index) && (index < run.glyphRun.glyphIndex + run.glyphRun.numberOfGlyphs))
- {
- if(run.isColorSet)
- {
- strikethroughColor = run.color;
- }
-
- return true;
- }
- }
-
- return false;
- }
void CacheGlyph(const GlyphInfo& glyph, FontId lastFontId, const AtlasGlyphManager::GlyphStyle& style, AtlasManager::AtlasSlot& slot)
{
const Size& defaultTextAtlasSize = mFontClient.GetDefaultTextAtlasSize(); //Retrieve default size of text-atlas-block from font-client.
vertex.mColor = color;
}
+ // Since Free Type font doesn't contain the strikethrough-position property,
+ // strikethrough position will be calculated by moving the underline position upwards by half the value of the line height.
+ float strikethroughStartingYPosition = (position.y + glyph.yBearing + currentUnderlinePosition) - ((glyph.height) * HALF);
+
// Find an existing mesh data object to attach to ( or create a new one, if we can't find one using the same atlas)
StitchTextMesh(meshContainer,
newMesh,
currentlineThickness,
slot,
underlineChunkId,
- position.y + (glyph.height * HALF),
+ strikethroughStartingYPosition,
strikethroughChunkId);
}
const Length* hyphenIndices = view.GetHyphenIndices();
const Length hyphensCount = view.GetHyphensCount();
const bool strikethroughEnabled = view.IsStrikethroughEnabled();
- const Vector4& strikethroughColor(view.GetStrikethroughColor());
- const float strikethroughHeight = view.GetStrikethroughHeight();
- Vector4 currentStrikethroughColor;
const float characterSpacing(view.GetCharacterSpacing());
// Elided text info. Indices according to elided text.
strikethroughRuns.Resize(numberOfStrikethroughRuns);
view.GetStrikethroughRuns(strikethroughRuns.Begin(), 0u, numberOfStrikethroughRuns);
- bool thereAreUnderlinedGlyphs = false;
- bool strikethroughGlyphsExist = false;
+ const StrikethroughStyleProperties viewStrikethroughProperties{view.GetStrikethroughColor(),
+ view.GetStrikethroughHeight(),
+ true,
+ true};
+
+ float maxStrikethroughHeight = viewStrikethroughProperties.height;
- float currentUnderlinePosition = ZERO;
- float currentStrikethroughHeight = strikethroughHeight;
- float maxStrikethroughHeight = currentStrikethroughHeight;
- FontId lastFontId = 0;
- Style style = STYLE_NORMAL;
+ FontId lastFontId = 0;
+ Style style = STYLE_NORMAL;
+ float currentUnderlinePosition = ZERO;
+ bool thereAreUnderlinedGlyphs = false;
+ bool thereAreStrikethroughGlyphs = false;
if(fabsf(shadowOffset.x) > Math::MACHINE_EPSILON_1 || fabsf(shadowOffset.y) > Math::MACHINE_EPSILON_1)
{
std::map<uint32_t, UnderlineStyleProperties> mapUnderlineChunkIdWithProperties; // mapping underlineChunkId with UnderlineStyleProperties to get properties of underlined chunk
UnderlineStyleProperties preUnderlineProperties = viewUnderlineProperties; // the previous UnderlineStyleProperties
- uint32_t strikethroughChunkId = 0u; // give id for each chunk.
- bool isPrevGlyphStrikethrough = false; // status of strikethrough for previous glyph.
+ //For septated strikethrough chunks. (this is for Markup case)
+ uint32_t strikethroughChunkId = 0u; // give id for each chunk.
+ bool isPreStrikethrough = false; // status of strikethrough for previous glyph.
+ std::map<uint32_t, StrikethroughStyleProperties> mapStrikethroughChunkIdWithProperties; // mapping strikethroughChunkId with StrikethroughStyleProperties to get properties of strikethrough chunk
+ StrikethroughStyleProperties preStrikethroughProperties = viewStrikethroughProperties; // the previous StrikethroughStyleProperties
+
const Character* textBuffer = view.GetTextBuffer();
float calculatedAdvance = 0.f;
const Vector<CharacterIndex>& glyphToCharacterMap = view.GetGlyphsToCharacters();
float currentUnderlineHeight = currentUnderlineProperties.height;
thereAreUnderlinedGlyphs = thereAreUnderlinedGlyphs || isGlyphUnderlined;
- currentStrikethroughColor = strikethroughColor;
- const bool isStrikethroughGlyph = strikethroughEnabled || doGlyphHaveStrikethrough(i, strikethroughRuns, currentStrikethroughColor);
- strikethroughGlyphsExist = strikethroughGlyphsExist || isStrikethroughGlyph;
+ Vector<StrikethroughGlyphRun>::ConstIterator currentStrikethroughGlyphRunIt = strikethroughRuns.End();
+ const bool isGlyphStrikethrough = strikethroughEnabled || IsGlyphStrikethrough(i, strikethroughRuns, currentStrikethroughGlyphRunIt);
+ const StrikethroughStyleProperties currentStrikethroughProperties = GetCurrentStrikethroughProperties(isGlyphStrikethrough, strikethroughRuns, currentStrikethroughGlyphRunIt, viewStrikethroughProperties);
+ float currentStrikethroughHeight = GetCurrentStrikethroughHeight(strikethroughRuns, currentStrikethroughGlyphRunIt, viewStrikethroughProperties.height);
+ thereAreStrikethroughGlyphs = thereAreStrikethroughGlyphs || isGlyphStrikethrough;
// No operation for white space
if(glyph.width && glyph.height)
{
// Check and update decorative-lines informations
- if((isGlyphUnderlined || isStrikethroughGlyph) &&
- ((glyph.fontId != lastDecorativeLinesFontId) || !(currentUnderlineProperties.IsHeightEqualTo(preUnderlineProperties))))
+ if(isGlyphUnderlined || isGlyphStrikethrough)
{
bool isDecorativeLinesFontIdUpdated = false;
// Are we still using the same fontId as previous
isDecorativeLinesFontIdUpdated = true;
fontClient.GetFontMetrics(lastDecorativeLinesFontId, lastDecorativeLinesFontMetrics);
- if(isStrikethroughGlyph || isGlyphUnderlined)
+ if(isGlyphStrikethrough || isGlyphUnderlined)
{
//The currentUnderlinePosition will be used for both Underline and/or Strikethrough
currentUnderlinePosition = FetchUnderlinePositionFromFontMetrics(lastDecorativeLinesFontMetrics);
CalcualteUnderlineHeight(lastDecorativeLinesFontMetrics, currentUnderlineHeight, maxUnderlineHeight);
}
- if(isDecorativeLinesFontIdUpdated && isStrikethroughGlyph)
+ if(isGlyphStrikethrough && (isDecorativeLinesFontIdUpdated || !(currentStrikethroughProperties.IsHeightEqualTo(preStrikethroughProperties))))
{
+ //If the Strikethrough Height is changed then we need to recalculate height.
+ if(!(currentStrikethroughProperties.IsHeightEqualTo(preStrikethroughProperties)))
+ {
+ maxStrikethroughHeight = currentStrikethroughHeight;
+ }
+
CalcualteStrikethroughHeight(currentStrikethroughHeight, maxStrikethroughHeight);
}
} // decorative-lines
false,
0u);
- if(isStrikethroughGlyph)
+ if(isGlyphStrikethrough)
{
+ //The new strikethrough chunk. Add new id if they are not consecutive indices (this is for Markup case)
+ // Examples: "Hello <s>World</s> Hello <s>World</s>", "<s>World</s> Hello <s>World</s>", "<s> World</s> Hello <s>World</s>"
+ if((!isPreStrikethrough) || (preStrikethroughProperties != currentStrikethroughProperties))
+ {
+ strikethroughChunkId++;
+ mapStrikethroughChunkIdWithProperties.insert(std::pair<uint32_t, StrikethroughStyleProperties>(strikethroughChunkId, currentStrikethroughProperties));
+ }
+
GenerateMesh(glyph,
positionPlusOutlineOffset,
color,
NO_OUTLINE,
slot,
- strikethroughGlyphsExist,
+ isGlyphStrikethrough,
0.0f,
maxStrikethroughHeight,
meshContainer,
strikethroughChunkId);
}
+ //Keep status of Strikethrough for previous glyph to check consecutive indices
+ isPreStrikethrough = isGlyphStrikethrough;
+ preStrikethroughProperties = currentStrikethroughProperties;
+
lastFontId = glyph.fontId; // Prevents searching for existing blocksizes when string of the same fontId.
}
false,
0u);
}
-
- if(isPrevGlyphStrikethrough && !isStrikethroughGlyph)
- {
- strikethroughChunkId++;
- }
-
- isPrevGlyphStrikethrough = isStrikethroughGlyph;
}
if(addHyphen)
GenerateUnderlines(meshContainer, extents, viewUnderlineProperties, mapUnderlineChunkIdWithProperties);
}
- if(strikethroughGlyphsExist)
+ if(thereAreStrikethroughGlyphs)
{
// Check to see if any of the text needs a strikethrough
- GenerateStrikethrough(meshContainer, strikethroughExtents, currentStrikethroughColor);
+ GenerateStrikethrough(meshContainer, strikethroughExtents, viewStrikethroughProperties, mapStrikethroughChunkIdWithProperties);
}
// For each MeshData object, create a mesh actor and add to the renderable actor
}
}
- void GenerateStrikethrough(std::vector<MeshRecord>& meshRecords,
- Vector<Extent>& extents,
- const Vector4& strikethroughColor)
+ void GenerateStrikethrough(std::vector<MeshRecord>& meshRecords,
+ Vector<Extent>& extents,
+ const StrikethroughStyleProperties& viewStrikethroughProperties,
+ const std::map<uint32_t, StrikethroughStyleProperties>& mapStrikethroughChunkIdWithProperties)
{
AtlasManager::Mesh2D newMesh;
unsigned short faceIndex = 0;
uint32_t index = eIt->mMeshRecordIndex;
Vector2 uv = mGlyphManager.GetAtlasSize(meshRecords[index].mAtlasId);
+ auto pairStrikethroughChunkIdWithProperties = mapStrikethroughChunkIdWithProperties.find(eIt->mStrikethroughChunkId);
+
+ const StrikethroughStyleProperties strikethroughProperties = (pairStrikethroughChunkIdWithProperties == mapStrikethroughChunkIdWithProperties.end())
+ ? viewStrikethroughProperties
+ : pairStrikethroughChunkIdWithProperties->second;
+
+ const Vector4& strikethroughColor = strikethroughProperties.colorDefined ? strikethroughProperties.color : viewStrikethroughProperties.color;
+
// Make sure we don't hit texture edge for single pixel texture ( filled pixel is in top left of every atlas )
float u = HALF / uv.x;
float v = HALF / uv.y;
{
namespace Text
{
-/// Helper method to fetch the underline metrics for the specified font glyph
+bool IsGlyphStrikethrough(GlyphIndex index,
+ const Vector<StrikethroughGlyphRun>& strikethroughRuns,
+ Vector<StrikethroughGlyphRun>::ConstIterator& currentStrikethroughGlyphRunIt)
+{
+ for(Vector<StrikethroughGlyphRun>::ConstIterator it = strikethroughRuns.Begin(),
+ endIt = strikethroughRuns.End();
+ it != endIt;
+ ++it)
+ {
+ const StrikethroughGlyphRun& run = *it;
+
+ if((run.glyphRun.glyphIndex <= index) && (index < run.glyphRun.glyphIndex + run.glyphRun.numberOfGlyphs))
+ {
+ currentStrikethroughGlyphRunIt = it;
+ return true;
+ }
+ }
+
+ return false;
+}
+
+float GetCurrentStrikethroughHeight(const Vector<StrikethroughGlyphRun>& strikethroughRuns,
+ Vector<StrikethroughGlyphRun>::ConstIterator currentStrikethroughGlyphRunIt,
+ const float strikethroughHeight)
+{
+ if(currentStrikethroughGlyphRunIt == strikethroughRuns.End())
+ {
+ return strikethroughHeight;
+ }
+
+ const StrikethroughGlyphRun& strikethroughGlyphRun = *currentStrikethroughGlyphRunIt;
+ return (strikethroughGlyphRun.properties.heightDefined ? strikethroughGlyphRun.properties.height : strikethroughHeight);
+}
+
+StrikethroughStyleProperties GetCurrentStrikethroughProperties(const bool& isGlyphStrikethrough,
+ const Vector<StrikethroughGlyphRun>& strikethroughRuns,
+ Vector<StrikethroughGlyphRun>::ConstIterator currentStrikethroughGlyphRunIt,
+ const StrikethroughStyleProperties& commonStrikethroughProperties)
+{
+ return (isGlyphStrikethrough && (currentStrikethroughGlyphRunIt != strikethroughRuns.End()))
+ ? currentStrikethroughGlyphRunIt->properties
+ : commonStrikethroughProperties;
+}
+
+/// Helper method to fetch the strikethrough metrics for the specified font glyph
void CalcualteStrikethroughHeight(float& currentStrikethroughHeight, float& maxStrikethroughHeight)
{
//Height of strikethrough represents the thickness of line.
#include <dali/public-api/common/dali-vector.h>
// INTERNAL INCLUDES
-#include <dali-toolkit/internal/text/underlined-glyph-run.h>
+#include <dali-toolkit/internal/text/strikethrough-glyph-run.h>
#include <dali/devel-api/text-abstraction/text-abstraction-definitions.h>
namespace Dali
namespace Text
{
/**
- * @brief Calculate the current underline height and update maximum underline height
+ * @brief Whether the glyph at index is strikethrough or not. If true then return iterator to the run containes index.
+ *
+ * @param[in] index the index of glyph.
+ * @param[in] strikethroughRuns the strikethrough runs.
+ * @param[out] currentStrikethroughGlyphRunIt the iterator of current strikethrough glyph run.
+ *
+ * @return true if glyph at index is strikethrough
+ */
+bool IsGlyphStrikethrough(GlyphIndex index,
+ const Vector<StrikethroughGlyphRun>& strikethroughRuns,
+ Vector<StrikethroughGlyphRun>::ConstIterator& currentStrikethroughGlyphRunIt);
+
+/**
+ * @brief Check the current strikethrough glyph run iterator if not empty and its height is defined then return ts height. Otherwise return the common strikethrough height.
+ *
+ * @param[in] strikethroughRuns the strikethrough runs.
+ * @param[in] currentStrikethroughGlyphRunIt the iterator of current strikethrough glyph run.
+ * @param[in] strikethroughHeight the common strikethrough height.
+ *
+ * @return the determined strikethrough height
+ */
+float GetCurrentStrikethroughHeight(const Vector<StrikethroughGlyphRun>& strikethroughRuns,
+ Vector<StrikethroughGlyphRun>::ConstIterator currentStrikethroughGlyphRunIt,
+ const float strikethroughHeight);
+
+/**
+ * @brief Check the current strikethrough glyph run iterator if not empty and isGlyphStrikethrough is true then return its StrikethroughProperties. Otherwise return the common strikethrough properties.
+ *
+ * @param[in] isGlyphStrikethrough whether the glyph is strikethrough.
+ * @param[in] strikethroughRuns the strikethrough runs.
+ * @param[in] currentStrikethroughGlyphRunIt the iterator of current strikethrough glyph run.
+ * @param[in] commonStrikethroughProperties the common strikethrough properties.
+ *
+ * @return the determined strikethrough properties
+ */
+StrikethroughStyleProperties GetCurrentStrikethroughProperties(const bool& isGlyphStrikethrough,
+ const Vector<StrikethroughGlyphRun>& strikethroughRuns,
+ Vector<StrikethroughGlyphRun>::ConstIterator currentStrikethroughGlyphRunIt,
+ const StrikethroughStyleProperties& commonStrikethroughProperties);
+
+/**
+ * @brief Calculate the current strikethrough height and update maximum strikethrough height
*
* @param[inout] currentStrikethroughHeight the current strikethrough height.
* @param[inout] maxStrikethroughHeight the maximum strikethrough height.
}
}
-bool doGlyphHaveStrikethrough(GlyphIndex index,
- const Vector<StrikethroughGlyphRun>& strikethroughRuns,
- Vector4& strikethroughColor)
-{
- for(Vector<StrikethroughGlyphRun>::ConstIterator it = strikethroughRuns.Begin(),
- endIt = strikethroughRuns.End();
- it != endIt;
- ++it)
- {
- const StrikethroughGlyphRun& run = *it;
-
- if((run.glyphRun.glyphIndex <= index) && (index < run.glyphRun.glyphIndex + run.glyphRun.numberOfGlyphs))
- {
- if(run.isColorSet)
- {
- strikethroughColor = run.color;
- }
-
- return true;
- }
- }
-
- return false;
-}
-
/// Draws the specified color to the pixel buffer
void WriteColorToPixelBuffer(
GlyphData& glyphData,
}
/// Draws the specified strikethrough color to the buffer
-void DrawStrikethrough(
- const Vector4& strikethroughColor,
- const unsigned int bufferWidth,
- const unsigned int bufferHeight,
- GlyphData& glyphData,
- const float baseline,
- const LineRun& line,
- const float maxStrikethroughHeight,
- const float lineExtentLeft,
- const float lineExtentRight,
- float strikethroughStartingYPosition)
+void DrawStrikethrough(const unsigned int bufferWidth,
+ const unsigned int bufferHeight,
+ GlyphData& glyphData,
+ const float baseline,
+ const float strikethroughStartingYPosition,
+ const float maxStrikethroughHeight,
+ const float lineExtentLeft,
+ const float lineExtentRight,
+ const StrikethroughStyleProperties& commonStrikethroughProperties,
+ const StrikethroughStyleProperties& currentStrikethroughProperties,
+ const LineRun& line)
{
+ const Vector4& strikethroughColor = currentStrikethroughProperties.colorDefined ? currentStrikethroughProperties.color : commonStrikethroughProperties.color;
+
uint32_t* bitmapBuffer = reinterpret_cast<uint32_t*>(glyphData.bitmapBuffer.GetBuffer());
for(unsigned int y = strikethroughStartingYPosition; y < strikethroughStartingYPosition + maxStrikethroughHeight; y++)
// Whether to use the default color.
const bool useDefaultColor = (NULL == colorsBuffer);
const Vector4& defaultColor = mModel->GetDefaultColor();
- Vector4 currentStrikethroughColor;
// Create and initialize the pixel buffer.
GlyphData glyphData;
}
}
- const bool underlineEnabled = mModel->IsUnderlineEnabled();
- const bool strikethroughEnabled = mModel->IsStrikethroughEnabled();
- const Vector4& strikethroughColor = mModel->GetStrikethroughColor();
- const float strikethroughHeight = mModel->GetStrikethroughHeight();
- const float characterSpacing = mModel->GetCharacterSpacing();
+ const bool underlineEnabled = mModel->IsUnderlineEnabled();
+ const bool strikethroughEnabled = mModel->IsStrikethroughEnabled();
+ const float characterSpacing = mModel->GetCharacterSpacing();
// Aggregate underline-style-properties from mModel
const UnderlineStyleProperties modelUnderlineProperties{mModel->GetUnderlineType(),
true,
true};
+ // Aggregate strikethrough-style-properties from mModel
+ const StrikethroughStyleProperties modelStrikethroughProperties{mModel->GetStrikethroughColor(),
+ mModel->GetStrikethroughHeight(),
+ true,
+ true};
+
// Get the underline runs.
const Length numberOfUnderlineRuns = mModel->GetNumberOfUnderlineRuns();
Vector<UnderlinedGlyphRun> underlineRuns;
strikethroughRuns.Resize(numberOfStrikethroughRuns);
mModel->GetStrikethroughRuns(strikethroughRuns.Begin(), 0u, numberOfStrikethroughRuns);
- bool thereAreUnderlinedGlyphs = false;
- bool strikethroughGlyphsExist = false;
+ bool thereAreUnderlinedGlyphs = false;
+ bool thereAreStrikethroughGlyphs = false;
float currentUnderlinePosition = 0.0f;
float currentUnderlineHeight = modelUnderlineProperties.height;
float maxUnderlineHeight = currentUnderlineHeight;
auto currentUnderlineProperties = modelUnderlineProperties;
- float currentStrikethroughHeight = strikethroughHeight;
+ float currentStrikethroughHeight = modelStrikethroughProperties.height;
float maxStrikethroughHeight = currentStrikethroughHeight;
+ auto currentStrikethroughProperties = modelStrikethroughProperties;
float strikethroughStartingYPosition = 0.0f;
FontId lastFontId = 0;
currentUnderlineHeight = currentUnderlineProperties.height;
thereAreUnderlinedGlyphs = thereAreUnderlinedGlyphs || underlineGlyph;
- currentStrikethroughColor = strikethroughColor;
- const bool strikethroughGlyph = strikethroughEnabled || doGlyphHaveStrikethrough(glyphIndex, strikethroughRuns, currentStrikethroughColor);
- strikethroughGlyphsExist = strikethroughGlyphsExist || strikethroughGlyph;
+ Vector<StrikethroughGlyphRun>::ConstIterator currentStrikethroughGlyphRunIt = strikethroughRuns.End();
+ const bool strikethroughGlyph = strikethroughEnabled || IsGlyphStrikethrough(glyphIndex, strikethroughRuns, currentStrikethroughGlyphRunIt);
+ currentStrikethroughProperties = GetCurrentStrikethroughProperties(strikethroughGlyph, strikethroughRuns, currentStrikethroughGlyphRunIt, modelStrikethroughProperties);
+ currentStrikethroughHeight = GetCurrentStrikethroughHeight(strikethroughRuns, currentStrikethroughGlyphRunIt, modelStrikethroughProperties.height);
+ thereAreStrikethroughGlyphs = thereAreStrikethroughGlyphs || strikethroughGlyph;
// Are we still using the same fontId as previous
if((glyphInfo->fontId != lastFontId) && (strikethroughGlyph || underlineGlyph))
}
// Draw the strikethrough from the leftmost glyph to the rightmost glyph
- if(strikethroughGlyphsExist && style == Typesetter::STYLE_STRIKETHROUGH)
+ if(thereAreStrikethroughGlyphs && style == Typesetter::STYLE_STRIKETHROUGH)
{
//TODO : The currently implemented strikethrough creates a strikethrough on the line level. We need to create different strikethroughs the case of glyphs with different sizes.
strikethroughStartingYPosition = (glyphData.verticalOffset + baseline + currentUnderlinePosition) - ((line.ascender) * HALF); // Since Free Type font doesn't contain the strikethrough-position property, strikethrough position will be calculated by moving the underline position upwards by half the value of the line height.
- DrawStrikethrough(currentStrikethroughColor, bufferWidth, bufferHeight, glyphData, baseline, line, maxStrikethroughHeight, lineExtentLeft, lineExtentRight, strikethroughStartingYPosition);
+ DrawStrikethrough(bufferWidth, bufferHeight, glyphData, baseline, strikethroughStartingYPosition, maxStrikethroughHeight, lineExtentLeft, lineExtentRight, modelStrikethroughProperties, currentStrikethroughProperties, line);
}
// Increases the vertical offset with the line's descender.
// INTERNAL INCLUDES
#include <dali-toolkit/internal/text/character-run.h>
+#include <dali-toolkit/internal/text/strikethrough-style-properties.h>
namespace Dali
{
*/
struct StrikethroughCharacterRun
{
- CharacterRun characterRun; ///< The initial character index and the number of characters of the run.
- Vector4 color; ///< The color of strikethrough.
- bool isColorSet; ///< If the color of strikethrough is set.
+ /**
+ * Default constructor to set the default values of bitfields
+ */
+ StrikethroughCharacterRun()
+ : characterRun{},
+ properties{}
+ {
+ }
+
+ CharacterRun characterRun; ///< The initial character index and the number of characters of the run.
+ StrikethroughStyleProperties properties; /// The properties of strikethrough style
};
} // namespace Text
// INTERNAL INCLUDES
#include <dali-toolkit/internal/text/glyph-run.h>
+#include <dali-toolkit/internal/text/strikethrough-style-properties.h>
namespace Dali
{
*/
struct StrikethroughGlyphRun
{
- GlyphRun glyphRun; ///< The initial glyph index and the number of glyphs in the run.
- Vector4 color; ///< The color of strikethrough.
- bool isColorSet; ///< If the color of strikethrough is set.
+ /**
+ * Default constructor to set the default values of bitfields
+ */
+ StrikethroughGlyphRun()
+ : glyphRun{},
+ properties{}
+ {
+ }
+
+ GlyphRun glyphRun; ///< The initial glyph index and the number of glyphs in the run.
+ StrikethroughStyleProperties properties; /// The properties of strikethrough style
};
} // namespace Text
--- /dev/null
+#ifndef DALI_TOOLKIT_TEXT_STRIKETHROUGH_STYLE_PROPERTIES_H
+#define DALI_TOOLKIT_TEXT_STRIKETHROUGH_STYLE_PROPERTIES_H
+
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/math/vector4.h>
+
+namespace Dali
+{
+namespace Toolkit
+{
+namespace Text
+{
+/**
+ * @brief Properties of strikethrough style.
+ */
+struct StrikethroughStyleProperties
+{
+ // Constructors
+
+ /**
+ * Default constructor to set the default values of bitfields
+ */
+ StrikethroughStyleProperties()
+ : color{Color::BLACK},
+ height{0u},
+ colorDefined{false},
+ heightDefined{false}
+ {
+ }
+
+ StrikethroughStyleProperties(Vector4 color,
+ float height,
+ bool colorDefined,
+ bool heightDefined)
+ : color{color},
+ height{height},
+ colorDefined{colorDefined},
+ heightDefined{heightDefined}
+
+ {
+ }
+
+ // Overloading operators
+
+ bool operator==(const StrikethroughStyleProperties& other) const
+ {
+ //The property is similar when both are not defined or when both are defined and have the same value.
+ return ((!colorDefined && !other.colorDefined) || ((colorDefined && other.colorDefined) && (color == other.color))) &&
+ ((!heightDefined && !other.heightDefined) || ((heightDefined && other.heightDefined) && (height == other.height)));
+ }
+
+ bool operator!=(const StrikethroughStyleProperties& other) const
+ {
+ return !(*this == other);
+ }
+
+ bool IsHeightEqualTo(const StrikethroughStyleProperties& other) const
+ {
+ return ((!heightDefined && !other.heightDefined) || ((heightDefined && other.heightDefined) && (height == other.height)));
+ }
+
+ //Attributes
+ Vector4 color; ///< The color of strikethrough.
+ float height; ///< The height of strikethrough.
+
+ bool colorDefined : 1; ///< Whether the color is defined.
+ bool heightDefined : 1; ///< Whether the height is defined.
+};
+
+} // namespace Text
+
+} // namespace Toolkit
+
+} // namespace Dali
+
+#endif // DALI_TOOLKIT_TEXT_STRIKETHROUGH_STYLE_PROPERTIES_H
}
StrikethroughGlyphRun strikethroughGlyphRun;
- strikethroughGlyphRun.color = it->color;
- strikethroughGlyphRun.isColorSet = it->isColorSet;
+ strikethroughGlyphRun.properties = it->properties;
strikethroughGlyphRun.glyphRun.glyphIndex = charactersToGlyph[characterIndex];
strikethroughGlyphRun.glyphRun.numberOfGlyphs = glyphsPerCharacter[characterIndex];