Skip to content

Commit

Permalink
Improve text centering accuracy
Browse files Browse the repository at this point in the history
  • Loading branch information
Hammie committed Nov 27, 2023
1 parent 2ec1507 commit 8489c0a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/libs/renderer/src/s_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2906,7 +2906,7 @@ int32_t DX9RENDER::ExtPrint(int32_t nFontNum, uint32_t foreColor, uint32_t backC
switch (wAlign)
{
case PR_ALIGN_CENTER:
x -= static_cast<int32_t>((pFont->GetStringWidth(Buff_4k, {.scale = fScale}) + 1L) / 2L);
x -= static_cast<int32_t>(pFont->GetStringWidth(Buff_4k, {.scale = fScale}) / 2);
break;
case PR_ALIGN_RIGHT:
x -= static_cast<int32_t>(pFont->GetStringWidth(Buff_4k, {.scale = fScale}));
Expand Down
6 changes: 5 additions & 1 deletion src/libs/renderer/src/storm/bmfont/bmfont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ size_t BmFont::GetStringWidth(const std::string_view &text, const FontPrintOverr
previous = codepoint;
}

return static_cast<int32_t>(xoffset);
return std::lround(xoffset);
}

size_t BmFont::GetHeight() const
Expand Down Expand Up @@ -290,6 +290,10 @@ BmFont::UpdateVertexBufferResult BmFont::UpdateVertexBuffer(float x, float y, co
{
char32_t codepoint = utf8::Utf8ToCodepoint(text.data() + i);

if (codepoint == 10 || codepoint == 13) {
continue;
}

const BmCharacter *character = GetCharacter(codepoint);

if (character == nullptr) {
Expand Down

0 comments on commit 8489c0a

Please sign in to comment.