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.getStringWidth returns wrong width #845

Closed
Johni0702 opened this issue Aug 16, 2017 · 3 comments
Closed

FontRenderer.getStringWidth returns wrong width #845

Johni0702 opened this issue Aug 16, 2017 · 3 comments

Comments

@Johni0702
Copy link

Note: This is almost certainly the same as #396, however that thread suggests various causes/symptoms that I cannot reproduce and has been close half a year ago.

Summary

The default font renderer returns values from getStringWidth(String) that are smaller than expected for certain inputs using certain resource packs (with HD fonts).

Example

String text = "Login to ReplayMod.com"
FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj;

int width = fontRenderer.getStringWidth(text); // width is 100 but probably should be 101
fontRenderer.listFormattedStringToWidth(text, width);
// ^ expected ["Login to ReplayMod.com"] but is ["Login to", "ReplayMod.com"]
fontRenderer.listFormattedStringToWidth(text, width + 1);
// ^ as expected ["Login to ReplayMod.com"]

width = fontRenderer.getStringWidth("*"); // width is 4 but probably should be 5
fontRenderer.listFormattedStringToWidth("*", width + 1);
// ^ As expected ["*"]
fontRenderer.listFormattedStringToWidth("*", width);
// ^ Throws StackOverflowException

Environment

Minecraft: 1.11.2
Optifine: 1.11.2_HD_U_C3
Forge: build 2366
No other mods (IntelliJ Remote Debugging for testing)
Resource Pack used for the Example: http://www.minecraftforum.net/forums/mapping-and-modding/resource-packs/1242763-conquest-wip-weekly-updates

@sp614x
Copy link
Owner

sp614x commented Oct 2, 2017

The given example works correctly with the default resource pack.

@Johni0702
Copy link
Author

Yes, as mentioned, this only happens with some resource packs (those with HD fonts or possibly only a subset of those).

@sp614x
Copy link
Owner

sp614x commented Oct 2, 2017

Updated preview C6 for 1.12.2

  • fixed string width calculation for HD fonts

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