[SPIGOT-6213] MinecraftFont.getWidth(" ") returns 2 when it should be 3. Created: 01/Nov/20 Updated: 03/Nov/20 Resolved: 03/Nov/20 |
|
Status: | Resolved |
Project: | Spigot |
Component/s: | None |
Affects Version/s: | None |
Fix Version/s: | None |
Type: | Bug | Priority: | Minor |
Reporter: | Llm Dl | Assignee: | Unassigned |
Resolution: | Fixed | Votes: | 0 |
Labels: | bukkit | ||
Environment: |
Not related to error. |
Attachments: |
![]() ![]() ![]() ![]() |
Version: | This server is running CraftBukkit version git-Spigot-57bbdd8-dea4138 (MC: 1.16.3) (Implementing API version 1.16.3-R0.1-SNAPSHOT) |
Guidelines Read: | Yes |
Description |
While making a book-parsing method I spent about a night and a morning trying to figure out why the line-wrapping was not working.
To reproduce: MinecraftFont font = new MinecraftFont(); System.out.println("pixels wide: " + font.getWidth("Homeblocks have an HP")); System.out.println("space char is " + font.getWidth(" ") + " pixels wide."); which will output: The maximum pixel count for a line is 113. The reference for the font shows the space character as having 3 pixels and I am inclined to believe them: https://minecraft.gamepedia.com/Language#Font after I added a pixel for every space to my line parser's lineWidth it worked perfectly. |
Comments |
Comment by Llm Dl [ 02/Nov/20 ] |
To follow up this is where Bukkit is told it is 2 and not 3. |
Comment by Llm Dl [ 01/Nov/20 ] |
I've gone and used the lower-cased "L" letter which is 2 pixels wide according to the above linked Font article. Using that l as a determination of what a pixel is on the font I've mocked up the gap in the " " section of the image attached. There's 3 pixels worth of space (and the buffer) between each space. |
Comment by Black Hole [ 01/Nov/20 ] |
You might want to draw a line that is 112 pixels wide and another one that is 115 pixels wide to confirm that you can't trust your eyes on this. |
Comment by Llm Dl [ 01/Nov/20 ] |
Here's "Homeblocks have an HP" written on a map. The spaces are not 2 pixels wide. The spaces between letters that are part of the same word are probably 2 pixels, but not the actual " " character. |
Comment by Black Hole [ 01/Nov/20 ] |
Just take your sample text "Homeblocks have an HP" and draw it on a map. It'll be exactly 112 pixels wide. Spaces are two pixels wide, because of the extra pixel between each character there will be a three pixel gap between characters separated by a space. |
Comment by Llm Dl [ 01/Nov/20 ] |
I took a look at it (I'd never needed to put text onto a Map before,) but it sure doesn't look like 2 pixels on the map either... I think if you take a look for yourself you'll see that a space is not 2 pixels in a book, a map, or on the actual font (found here, where it says they are 3 pixels.) Hence the bug report. If you have proof otherwise I'd love to see it. |
Comment by Black Hole [ 01/Nov/20 ] |
The text rendering on maps is done by Spigot using the very limited characters of the MinecraftFont class. So it will use 2 pixels there. |
Comment by Llm Dl [ 01/Nov/20 ] |
Yes, but the only way to tell what will really fit on a book page is to measure the pixels. Character count is not something you can use to parse what will fit in a book. I would imagine that the space character displayed on a map is also 3 pixels wide (and not 2 pixels wide like the API thinks.) |
Comment by Black Hole [ 01/Nov/20 ] |
The class MinecraftFont ist used for writing text to maps only. It doesn't promise to return the same results as the chat. For chat there is the class ChatPaginator, which don't take character width into account, only character count. |