From 2a204b384fc61b59aa6b2f9998c3af28013f7d17 Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Fri, 4 Aug 2023 23:47:52 +1000 Subject: Add optional alpha threshold option for fonts --- source/core/StarFont.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'source/core/StarFont.cpp') diff --git a/source/core/StarFont.cpp b/source/core/StarFont.cpp index 8b531a0..89503ed 100644 --- a/source/core/StarFont.cpp +++ b/source/core/StarFont.cpp @@ -51,7 +51,7 @@ FontPtr Font::loadTrueTypeFont(ByteArrayConstPtr const& bytes, unsigned pixelSiz return font; } -Font::Font() : m_pixelSize(0) {} +Font::Font() : m_pixelSize(0), m_alphaThreshold(0) {} FontPtr Font::clone() const { return Font::loadTrueTypeFont(m_fontBuffer, m_pixelSize); @@ -70,6 +70,10 @@ void Font::setPixelSize(unsigned pixelSize) { m_pixelSize = pixelSize; } +void Font::setAlphaThreshold(uint8_t alphaThreshold) { + m_alphaThreshold = alphaThreshold; +} + unsigned Font::height() const { return m_pixelSize; } @@ -112,8 +116,14 @@ std::pair Font::render(String::Char c) { uint8_t* p = slot->bitmap.buffer + y * slot->bitmap.pitch; for (unsigned x = 0; x != width; ++x) { if (x >= 0 && y >= 0 && x < width && y < height) { - if (uint8_t val = *(p + x)) { - white.setW(val); + uint8_t value = *(p + x); + if (m_alphaThreshold) { + if (value >= m_alphaThreshold) { + white[3] = 255; + image.set(x + 1, height - y, white); + } + } else if (value) { + white[3] = value; image.set(x + 1, height - y, white); } } -- cgit v1.2.3