Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FontRenderer.trimStringToWidth cuts at incorrect position #1276

Open
Johni0702 opened this issue Mar 11, 2018 · 1 comment
Open

FontRenderer.trimStringToWidth cuts at incorrect position #1276

Johni0702 opened this issue Mar 11, 2018 · 1 comment

Comments

@Johni0702
Copy link

This issue may be related to #845 but still occurs in versions where aforementioned bug does not.

Summary

The default font renderer cuts too early in trimStringToWidth(String,int) for certain inputs using certain resource packs (possibly related to HD fonts).

Example

String text = "30"
FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;

int width = fontRenderer.getStringWidth(text); // width is 12, same as in vanilla
fontRenderer.listFormattedStringToWidth(text, width + 1);
// ^ this, for comparison, works as expected: ["30"]
fontRenderer.trimStringToWidth(text, width);
// ^ expected "30" but is "3"
fontRenderer.trimStringToWidth(text, width + 1);
// ^ As expected: "30"

Environment

Minecraft: 1.12.2
Optifine: 1.12.2_HD_U_C9
Forge: build 2611
No other mods (IntelliJ Remote Debugging for testing)
Resource Pack used for the Example: PureBDcraft 256x MC112 (download link)

@sp614x
Copy link
Owner

sp614x commented Mar 19, 2018

Internally OptiFine uses float character widths to allow finer tuning of character spacing.
The string "30" in BDCraft font has width "12.25". It is rounded to 12 when returned from getStringWidth().
Solution A: Round down when comparing the width, then the string may be rendered a bit wider.
Solution B: Round up the width returned from getStringWidth(), then rendered width may be smaller.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants