From 081dd693ca57ef624342e729c5b27b2e5da98410 Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Mon, 3 Jul 2023 20:07:16 +1000 Subject: Add 1-px padding around font and round to fix jitter --- source/core/StarFont.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'source/core/StarFont.cpp') diff --git a/source/core/StarFont.cpp b/source/core/StarFont.cpp index 6adc4c3..2c0d6a7 100644 --- a/source/core/StarFont.cpp +++ b/source/core/StarFont.cpp @@ -101,23 +101,26 @@ std::pair Font::render(String::Char c) { FT_GlyphSlot slot = face->glyph; - unsigned int width = slot->bitmap.width; - unsigned int height = slot->bitmap.rows; + unsigned width = slot->bitmap.width; + unsigned height = slot->bitmap.rows; - Image image(width, height, PixelFormat::RGBA32); - for (int y = 0; y < height; ++y) { - unsigned char* p = slot->bitmap.buffer + y * slot->bitmap.pitch; - for (int x = 0; x < width; ++x) { + Image image(width + 2, height + 2, PixelFormat::RGBA32); + Vec4B white(255, 255, 255, 0); + image.fill(white); + + for (unsigned y = 0; y != height; ++y) { + 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) { - unsigned char val = *(p + x); - image.set(x, height - y - 1, Vec4B(255, 255, 255, val)); - } else { - image.set(x, height - y - 1, Vec4B(255, 255, 255, 0)); + if (uint8_t val = *(p + x)) { + white.setW(val); + image.set(x + 1, height - y, white); + } } } } - return { move(image), {slot->bitmap_left, (slot->bitmap_top - (int)height) + m_pixelSize / 4} }; + return { move(image), {slot->bitmap_left - 1, (slot->bitmap_top - height) + (m_pixelSize / 4) - 1} }; } } -- cgit v1.2.3