MCPcopy Create free account
hub / github.com/Teneted/Tenet / getWidth

Method getWidth

src/main/java/org/bukkit/map/MapFont.java:54–72  ·  view source on GitHub ↗

Get the width of the given text as it would be rendered using this font. @param text The text. @return The width in pixels.

(@NotNull String text)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 4

isValidMethod · 0.95
getWidthMethod · 0.65
getMethod · 0.65
lengthMethod · 0.45

Tested by

no test coverage detected