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

summaryrefslogtreecommitdiff
path: root/source/core/StarFont.cpp
diff options
context:
space:
mode:
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);
}
}