Commits

eueln authored and turt2live committed 0bf83c077dc
Account for spacing in MapFont#getWidth(). Fixes BUKKIT-4089

Prior to this commit MapFont#getWidth() did not account for the 1px spacing inserted by CraftMapCanvas#drawText(). This commit adds the consideration of the 1px spacing per character while taking care to not consider the last character as it will not have a 1px space behind it. This commit also ensures the method will not check a 0-length String.
No tags

src/main/java/org/bukkit/map/MapFont.java

Modified
45 45 * font.
46 46 *
47 47 * @param text The text.
48 48 * @return The width in pixels.
49 49 */
50 50 public int getWidth(String text) {
51 51 if (!isValid(text)) {
52 52 throw new IllegalArgumentException("text contains invalid characters");
53 53 }
54 54
55 + if (text.length() == 0){
56 + return 0;
57 + }
58 +
55 59 int result = 0;
56 60 for (int i = 0; i < text.length(); ++i) {
57 61 result += chars.get(text.charAt(i)).getWidth();
58 62 }
63 + result += text.length() - 1; // Account for 1px spacing between characters
64 +
59 65 return result;
60 66 }
61 67
62 68 /**
63 69 * Get the height of this font.
64 70 *
65 71 * @return The height of the font.
66 72 */
67 73 public int getHeight() {
68 74 return height;

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut