font directives bwahahaha
This commit is contained in:
parent
8dce334931
commit
ee296e3381
@ -34,14 +34,21 @@ const FontTextureGroup::GlyphTexture& FontTextureGroup::glyphTexture(String::Cha
|
||||
m_font->setPixelSize(size);
|
||||
Image image = m_font->render(c);
|
||||
if (!processingDirectives.empty()) {
|
||||
Vec2F preSize = Vec2F(image.size());
|
||||
auto imageOperations = parseImageOperations(processingDirectives);
|
||||
for (auto& imageOp : imageOperations) {
|
||||
if (auto border = imageOp.ptr<BorderImageOperation>())
|
||||
border->includeTransparent = true;
|
||||
try {
|
||||
Vec2F preSize = Vec2F(image.size());
|
||||
auto imageOperations = parseImageOperations(processingDirectives);
|
||||
for (auto& imageOp : imageOperations) {
|
||||
if (auto border = imageOp.ptr<BorderImageOperation>())
|
||||
border->includeTransparent = true;
|
||||
}
|
||||
image = processImageOperations(imageOperations, image);
|
||||
res.first->second.processingOffset = preSize - Vec2F(image.size());
|
||||
}
|
||||
catch (StarException&) {
|
||||
image.forEachPixel([](unsigned x, unsigned y, Vec4B& pixel) {
|
||||
pixel = ((x + y) % 2 == 0) ? Vec4B(255, 0, 255, pixel[3]) : Vec4B(0, 0, 0, pixel[3]);
|
||||
});
|
||||
}
|
||||
image = processImageOperations(imageOperations, image);
|
||||
res.first->second.processingOffset = preSize - Vec2F(image.size());
|
||||
}
|
||||
else
|
||||
res.first->second.processingOffset = Vec2F();
|
||||
|
@ -268,7 +268,7 @@ void TextPainter::setFontColor(Vec4B color) {
|
||||
}
|
||||
|
||||
void TextPainter::setProcessingDirectives(String directives) {
|
||||
m_processingDirectives = move(directives);
|
||||
m_renderSettings.directives = move(directives);
|
||||
}
|
||||
|
||||
void TextPainter::setFont(String const& font) {
|
||||
@ -361,6 +361,10 @@ RectF TextPainter::doRenderLine(String const& s, TextPositioning const& position
|
||||
m_renderSettings.mode = (FontMode)((int)m_renderSettings.mode & (-1 ^ (int)FontMode::Shadow));
|
||||
} else if (command.beginsWith("font=")) {
|
||||
m_renderSettings.font = command.substr(5);
|
||||
} 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);
|
||||
} else {
|
||||
// expects both #... sequences and plain old color names.
|
||||
Color c = jsonToColor(command);
|
||||
@ -411,10 +415,10 @@ 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_processingDirectives);
|
||||
renderGlyph(c, position.pos + Vec2F(hOffset, vOffset - 2), m_fontSize, 1, shadow.toRgba(), m_renderSettings.directives);
|
||||
}
|
||||
|
||||
renderGlyph(c, position.pos + Vec2F(hOffset, vOffset), m_fontSize, 1, m_renderSettings.color, m_processingDirectives);
|
||||
renderGlyph(c, position.pos + Vec2F(hOffset, vOffset), m_fontSize, 1, m_renderSettings.color, m_renderSettings.directives);
|
||||
}
|
||||
|
||||
return RectF::withSize(position.pos + Vec2F(hOffset, vOffset), {(float)width, (int)m_fontSize});
|
||||
|
@ -84,6 +84,7 @@ private:
|
||||
FontMode mode;
|
||||
Vec4B color;
|
||||
String font;
|
||||
String directives;
|
||||
};
|
||||
|
||||
RectF doRenderText(String const& s, TextPositioning const& position, bool reallyRender, unsigned* charLimit);
|
||||
@ -104,8 +105,6 @@ private:
|
||||
String m_splitIgnore;
|
||||
String m_splitForce;
|
||||
String m_nonRenderedCharacters;
|
||||
|
||||
String m_processingDirectives;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user