Add 1-px padding around font and round to fix jitter
This commit is contained in:
parent
809744c300
commit
081dd693ca
@ -101,23 +101,26 @@ std::pair<Image, Vec2I> Font::render(String::Char c) {
|
|||||||
|
|
||||||
FT_GlyphSlot slot = face->glyph;
|
FT_GlyphSlot slot = face->glyph;
|
||||||
|
|
||||||
unsigned int width = slot->bitmap.width;
|
unsigned width = slot->bitmap.width;
|
||||||
unsigned int height = slot->bitmap.rows;
|
unsigned height = slot->bitmap.rows;
|
||||||
|
|
||||||
Image image(width, height, PixelFormat::RGBA32);
|
Image image(width + 2, height + 2, PixelFormat::RGBA32);
|
||||||
for (int y = 0; y < height; ++y) {
|
Vec4B white(255, 255, 255, 0);
|
||||||
unsigned char* p = slot->bitmap.buffer + y * slot->bitmap.pitch;
|
image.fill(white);
|
||||||
for (int x = 0; x < width; ++x) {
|
|
||||||
|
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) {
|
if (x >= 0 && y >= 0 && x < width && y < height) {
|
||||||
unsigned char val = *(p + x);
|
if (uint8_t val = *(p + x)) {
|
||||||
image.set(x, height - y - 1, Vec4B(255, 255, 255, val));
|
white.setW(val);
|
||||||
} else {
|
image.set(x + 1, height - y, white);
|
||||||
image.set(x, height - y - 1, Vec4B(255, 255, 255, 0));
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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} };
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -587,7 +587,7 @@ void TextPainter::renderGlyph(String::Char c, Vec2F const& screenPos, unsigned f
|
|||||||
|
|
||||||
const FontTextureGroup::GlyphTexture& glyphTexture = m_fontTextureGroup.glyphTexture(c, fontSize, processingDirectives);
|
const FontTextureGroup::GlyphTexture& glyphTexture = m_fontTextureGroup.glyphTexture(c, fontSize, processingDirectives);
|
||||||
Vec2F offset = glyphTexture.offset * scale;
|
Vec2F offset = glyphTexture.offset * scale;
|
||||||
m_renderer->immediatePrimitives().emplace_back(std::in_place_type_t<RenderQuad>(), glyphTexture.texture, screenPos + offset, scale, color, 0.0f);
|
m_renderer->immediatePrimitives().emplace_back(std::in_place_type_t<RenderQuad>(), glyphTexture.texture, Vec2F::round(screenPos + offset), scale, color, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user