Skip to content

Commit

Permalink
Prevent glyph clipping in LB fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
BoilingTeapot committed Sep 12, 2024
1 parent 6b668f5 commit 48429c8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/font.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class LBFont : public Font {
float OutlineCellHeight;
float OutlineCellWidth;

glm::vec2 ForegroundOffset;
glm::vec2 OutlineOffset;

void CalculateDefaultSizes() override {
Expand All @@ -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);
}

Expand Down
3 changes: 3 additions & 0 deletions src/profile/fonts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 11 additions & 3 deletions src/renderer/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down

0 comments on commit 48429c8

Please sign in to comment.