From 48429c8158f80e1c242bd63ef10dd5f5ec5da696 Mon Sep 17 00:00:00 2001 From: BoilingTeapot <103682205+BoilingTeapot@users.noreply.github.com> Date: Thu, 12 Sep 2024 12:28:46 +0000 Subject: [PATCH] Prevent glyph clipping in LB fonts --- src/font.h | 4 ++-- src/profile/fonts.cpp | 3 +++ src/renderer/renderer.cpp | 14 +++++++++++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/font.h b/src/font.h index 81b10450..6411a272 100644 --- a/src/font.h +++ b/src/font.h @@ -60,6 +60,7 @@ class LBFont : public Font { float OutlineCellHeight; float OutlineCellWidth; + glm::vec2 ForegroundOffset; glm::vec2 OutlineOffset; void CalculateDefaultSizes() override { @@ -75,8 +76,7 @@ class LBFont : public Font { Sprite Glyph(uint16_t id) { uint8_t row = id / Columns; uint8_t col = id % Columns; - float width = AdvanceWidths[id]; - return Sprite(ForegroundSheet, col * CellWidth, row * CellHeight, width, + return Sprite(ForegroundSheet, col * CellWidth, row * CellHeight, CellWidth, CellHeight); } diff --git a/src/profile/fonts.cpp b/src/profile/fonts.cpp index 20c4358f..d260e9c4 100644 --- a/src/profile/fonts.cpp +++ b/src/profile/fonts.cpp @@ -36,6 +36,9 @@ void LoadFonts() { font->ForegroundSheet = EnsureGetMemberSpriteSheet("ForegroundSheet"); font->OutlineSheet = EnsureGetMemberSpriteSheet("OutlineSheet"); + if (!TryGetMemberVec2("ForegroundOffset", font->ForegroundOffset)) { + font->ForegroundOffset = glm::vec2(0.0f); + } font->OutlineOffset = EnsureGetMemberVec2("OutlineOffset"); break; diff --git a/src/renderer/renderer.cpp b/src/renderer/renderer.cpp index f61399e0..677d7c18 100644 --- a/src/renderer/renderer.cpp +++ b/src/renderer/renderer.cpp @@ -187,15 +187,23 @@ void BaseRenderer::DrawProcessedText_LBFont( } else { color.a *= text[i].Opacity; } + + float scaleX = text[i].DestRect.Width / font->BitmapEmWidth; + float scaleY = text[i].DestRect.Height / font->BitmapEmHeight; + + RectF foregroundDest = RectF( + text[i].DestRect.X + scaleX * font->ForegroundOffset.x, + text[i].DestRect.Y + scaleY * font->ForegroundOffset.y, + scaleX * font->CellWidth, scaleY * font->CellHeight); if (maskedSheet) { Sprite mask; mask.Sheet = *maskedSheet; - mask.Bounds = text[i].DestRect; + mask.Bounds = foregroundDest; DrawMaskedSpriteOverlay(font->Glyph(text[i].CharId), mask, - text[i].DestRect, color, color.a * 255, 256, + foregroundDest, color, color.a * 255, 256, false, 0, false); } else { - DrawSprite(font->Glyph(text[i].CharId), text[i].DestRect, color); + DrawSprite(font->Glyph(text[i].CharId), foregroundDest, color); } } }