Merge branch 'feature/strikethrough'
This commit is contained in:
commit
ef1b9d6b20
2 changed files with 42 additions and 6 deletions
|
@ -260,10 +260,17 @@ void Text::ensureGeometryUpdate() const
|
|||
// Compute values related to the text style
|
||||
bool bold = (m_style & Bold) != 0;
|
||||
bool underlined = (m_style & Underlined) != 0;
|
||||
bool strikeThrough = (m_style & StrikeThrough) != 0;
|
||||
float italic = (m_style & Italic) ? 0.208f : 0.f; // 12 degrees
|
||||
float underlineOffset = static_cast<float>(m_font->getUnderlinePosition(m_characterSize));
|
||||
float underlineThickness = static_cast<float>(m_font->getUnderlineThickness(m_characterSize));
|
||||
|
||||
// Compute the location of the strike through dynamically
|
||||
// We use the center point of the lowercase 'x' glyph as the reference
|
||||
// We reuse the underline thickness as the thickness of the strike through as well
|
||||
IntRect xBounds = m_font->getGlyph(L'x', m_characterSize, bold).bounds;
|
||||
float strikeThroughOffset = static_cast<float>(xBounds.top) + static_cast<float>(xBounds.height) / 2.f;
|
||||
|
||||
// Precompute the variables needed by the algorithm
|
||||
float hspace = static_cast<float>(m_font->getGlyph(L' ', m_characterSize, bold).advance);
|
||||
float vspace = static_cast<float>(m_font->getLineSpacing(m_characterSize));
|
||||
|
@ -298,6 +305,20 @@ void Text::ensureGeometryUpdate() const
|
|||
m_vertices.append(Vertex(Vector2f(x, bottom), m_color, Vector2f(1, 1)));
|
||||
}
|
||||
|
||||
// If we're using the strike through style and there's a new line, draw a line across all characters
|
||||
if (strikeThrough && (curChar == L'\n'))
|
||||
{
|
||||
float top = y + strikeThroughOffset;
|
||||
float bottom = top + underlineThickness;
|
||||
|
||||
m_vertices.append(Vertex(Vector2f(0, top), m_color, Vector2f(1, 1)));
|
||||
m_vertices.append(Vertex(Vector2f(x, top), m_color, Vector2f(1, 1)));
|
||||
m_vertices.append(Vertex(Vector2f(0, bottom), m_color, Vector2f(1, 1)));
|
||||
m_vertices.append(Vertex(Vector2f(0, bottom), m_color, Vector2f(1, 1)));
|
||||
m_vertices.append(Vertex(Vector2f(x, top), m_color, Vector2f(1, 1)));
|
||||
m_vertices.append(Vertex(Vector2f(x, bottom), m_color, Vector2f(1, 1)));
|
||||
}
|
||||
|
||||
// Handle special characters
|
||||
if ((curChar == ' ') || (curChar == '\t') || (curChar == '\n'))
|
||||
{
|
||||
|
@ -365,6 +386,20 @@ void Text::ensureGeometryUpdate() const
|
|||
m_vertices.append(Vertex(Vector2f(x, bottom), m_color, Vector2f(1, 1)));
|
||||
}
|
||||
|
||||
// If we're using the strike through style, add the last line across all characters
|
||||
if (strikeThrough)
|
||||
{
|
||||
float top = y + strikeThroughOffset;
|
||||
float bottom = top + underlineThickness;
|
||||
|
||||
m_vertices.append(Vertex(Vector2f(0, top), m_color, Vector2f(1, 1)));
|
||||
m_vertices.append(Vertex(Vector2f(x, top), m_color, Vector2f(1, 1)));
|
||||
m_vertices.append(Vertex(Vector2f(0, bottom), m_color, Vector2f(1, 1)));
|
||||
m_vertices.append(Vertex(Vector2f(0, bottom), m_color, Vector2f(1, 1)));
|
||||
m_vertices.append(Vertex(Vector2f(x, top), m_color, Vector2f(1, 1)));
|
||||
m_vertices.append(Vertex(Vector2f(x, bottom), m_color, Vector2f(1, 1)));
|
||||
}
|
||||
|
||||
// Update the bounding rectangle
|
||||
m_bounds.left = minX;
|
||||
m_bounds.top = minY;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue