Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/core/StarFont.cpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2023-08-04 23:47:52 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2023-08-04 23:47:52 +1000
commit2a204b384fc61b59aa6b2f9998c3af28013f7d17 (patch)
tree4c5ea83fe2936ae1b0cc02cd3fe411189b240882 /source/core/StarFont.cpp
parent65bacddc67942e8678626016960431cdecef2030 (diff)
Add optional alpha threshold option for fonts
Diffstat (limited to 'source/core/StarFont.cpp')
-rw-r--r--source/core/StarFont.cpp16
1 files changed, 13 insertions, 3 deletions
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<Image, Vec2I> 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);
}
}