Commits
eueln authored and turt2live committed 0bf83c077dc
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; |