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

summaryrefslogtreecommitdiff
path: root/source/core
diff options
context:
space:
mode:
Diffstat (limited to 'source/core')
-rw-r--r--source/core/StarFont.cpp16
-rw-r--r--source/core/StarFont.hpp2
2 files changed, 15 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);
}
}
diff --git a/source/core/StarFont.hpp b/source/core/StarFont.hpp
index e4786b6..a3b3ced 100644
--- a/source/core/StarFont.hpp
+++ b/source/core/StarFont.hpp
@@ -27,6 +27,7 @@ public:
FontPtr clone() const;
void setPixelSize(unsigned pixelSize);
+ void setAlphaThreshold(uint8_t alphaThreshold = 0);
unsigned height() const;
unsigned width(String::Char c);
@@ -40,6 +41,7 @@ private:
FontImplPtr m_fontImpl;
ByteArrayConstPtr m_fontBuffer;
unsigned m_pixelSize;
+ uint8_t m_alphaThreshold;
HashMap<pair<String::Char, unsigned>, unsigned> m_widthCache;
};