mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-11 10:12:06 -07:00
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. By: eueln <euelnd@gmail.com>
This commit is contained in:
@@ -52,10 +52,16 @@ public class MapFont {
|
|||||||
throw new IllegalArgumentException("text contains invalid characters");
|
throw new IllegalArgumentException("text contains invalid characters");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (text.length() == 0){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int result = 0;
|
int result = 0;
|
||||||
for (int i = 0; i < text.length(); ++i) {
|
for (int i = 0; i < text.length(); ++i) {
|
||||||
result += chars.get(text.charAt(i)).getWidth();
|
result += chars.get(text.charAt(i)).getWidth();
|
||||||
}
|
}
|
||||||
|
result += text.length() - 1; // Account for 1px spacing between characters
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user