diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-07-04 06:01:29 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-07-04 06:01:29 +1000 |
commit | a45d16b4ed2698361ff68c5502bcabfc908099a7 (patch) | |
tree | 58de4cdff77ed7d99ae354be711c7ec6843a058e /source/rendering/StarTextPainter.cpp | |
parent | 1d04c689ba3e9d8bb3602a7289fe5756aa8fb3fd (diff) |
Cache font directives
Diffstat (limited to 'source/rendering/StarTextPainter.cpp')
-rw-r--r-- | source/rendering/StarTextPainter.cpp | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/source/rendering/StarTextPainter.cpp b/source/rendering/StarTextPainter.cpp index d6078dc..3e6c618 100644 --- a/source/rendering/StarTextPainter.cpp +++ b/source/rendering/StarTextPainter.cpp @@ -402,8 +402,15 @@ void TextPainter::setFontColor(Vec4B color) { m_renderSettings.color = move(color); } -void TextPainter::setProcessingDirectives(String directives) { - m_renderSettings.directives = move(directives); +void TextPainter::setProcessingDirectives(StringView directives) { + m_renderSettings.directives = String(directives); + if (m_renderSettings.directives) { + m_renderSettings.directives.loadOperations(); + for (auto& entry : m_renderSettings.directives.shared->entries) { + if (auto border = entry.operation.ptr<BorderImageOperation>()) + border->includeTransparent = true; + } + } } void TextPainter::setFont(String const& font) { @@ -450,7 +457,7 @@ void TextPainter::applyCommands(StringView unsplitCommands) { } else if (command.beginsWith("directives=")) { // Honestly this is really stupid but I just couldn't help myself // Should probably limit in the future - m_renderSettings.directives = command.substr(11); + setProcessingDirectives(command.substr(11)); } else { // expects both #... sequences and plain old color names. Color c = Color(command); @@ -559,6 +566,8 @@ RectF TextPainter::doRenderGlyph(String::Char c, TextPositioning const& position else if (position.vAnchor == VerticalAnchor::TopAnchor) vOffset = -(float)m_fontSize; + Directives* directives = m_renderSettings.directives ? &m_renderSettings.directives : nullptr; + if (reallyRender) { if ((int)m_renderSettings.mode & (int)FontMode::Shadow) { Color shadow = Color::Black; @@ -571,17 +580,17 @@ RectF TextPainter::doRenderGlyph(String::Char c, TextPositioning const& position shadow.setAlpha(alphaU); //Kae: Draw only one shadow glyph instead of stacking two, alpha modified to appear perceptually the same as vanilla - renderGlyph(c, position.pos + Vec2F(hOffset, vOffset - 2), m_fontSize, 1, shadow.toRgba(), m_renderSettings.directives); + renderGlyph(c, position.pos + Vec2F(hOffset, vOffset - 2), m_fontSize, 1, shadow.toRgba(), directives); } - renderGlyph(c, position.pos + Vec2F(hOffset, vOffset), m_fontSize, 1, m_renderSettings.color, m_renderSettings.directives); + renderGlyph(c, position.pos + Vec2F(hOffset, vOffset), m_fontSize, 1, m_renderSettings.color, directives); } return RectF::withSize(position.pos + Vec2F(hOffset, vOffset), {(float)width, (int)m_fontSize}); } void TextPainter::renderGlyph(String::Char c, Vec2F const& screenPos, unsigned fontSize, - float scale, Vec4B const& color, String const& processingDirectives) { + float scale, Vec4B const& color, Directives const* processingDirectives) { if (!fontSize) return; |