MinecraftFont.getWidth(" ") returns 2 when it should be 3.

    • Type: Bug
    • Resolution: Fixed
    • Priority: Minor
    • None
    • Affects Version/s: None
    • Environment:

      Not related to error.

    • This server is running CraftBukkit version git-Spigot-57bbdd8-dea4138 (MC: 1.16.3) (Implementing API version 1.16.3-R0.1-SNAPSHOT)
    • Yes

      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:
      pixels wide: 112
      space char is 2 pixels wide.

      The maximum pixel count for a line is 113.
      The screenshot below shows how the above test string actually renders in game.

      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.

        1. ticket4.png
          ticket4.png
          2 kB
        2. ticket3.png
          ticket3.png
          2 kB
        3. ticket2.png
          ticket2.png
          8 kB
        4. ticket1.PNG
          ticket1.PNG
          24 kB

          [SPIGOT-6213] MinecraftFont.getWidth(" ") returns 2 when it should be 3.

          Llm Dl added a comment -

          Llm Dl added a comment - To follow up this is where Bukkit is told it is 2 and not 3.

          Llm Dl added a comment -

          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.

          Llm Dl added a comment - 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.

          Black Hole added a comment -

          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.

          Black Hole added a comment - 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.

          Llm Dl added a comment -

          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.

          Llm Dl added a comment - 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.

          Black Hole added a comment -

          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.

          Black Hole added a comment - 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.

          Llm Dl added a comment -

          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.

          Llm Dl added a comment - 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.

          Black Hole added a comment -

          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.

          Black Hole added a comment - 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.

          Llm Dl added a comment -

          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.)

          Llm Dl added a comment - 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.)

          Black Hole added a comment -

          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.

          Black Hole added a comment - 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.

            Assignee:
            Unassigned
            Reporter:
            Llm Dl
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: