Make sure counter font is included/loaded

This commit is contained in:
Krazy
2017-06-22 02:42:34 +00:00
parent 6e891101ce
commit fd4419b9f4
3 changed files with 37 additions and 17 deletions

1
.gitattributes vendored
View File

@@ -1174,6 +1174,7 @@ forge-gui-desktop/src/main/java/forge/view/arcane/util/CardPanelMouseListener.ja
forge-gui-desktop/src/main/java/forge/view/arcane/util/OutlinedLabel.java -text forge-gui-desktop/src/main/java/forge/view/arcane/util/OutlinedLabel.java -text
forge-gui-desktop/src/main/java/forge/view/arcane/util/package-info.java -text forge-gui-desktop/src/main/java/forge/view/arcane/util/package-info.java -text
forge-gui-desktop/src/main/java/forge/view/package-info.java -text forge-gui-desktop/src/main/java/forge/view/package-info.java -text
forge-gui-desktop/src/main/resources/Roboto-Bold.ttf -text
forge-gui-desktop/src/test/java/forge/BoosterDraft1Test.java -text forge-gui-desktop/src/test/java/forge/BoosterDraft1Test.java -text
forge-gui-desktop/src/test/java/forge/BoosterDraftTest.java -text forge-gui-desktop/src/test/java/forge/BoosterDraftTest.java -text
forge-gui-desktop/src/test/java/forge/CardRankerTest.java -text forge-gui-desktop/src/test/java/forge/CardRankerTest.java -text

View File

@@ -43,6 +43,7 @@ import java.awt.event.ComponentEvent;
import java.awt.font.TextAttribute; import java.awt.font.TextAttribute;
import java.awt.geom.RoundRectangle2D; import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@@ -89,6 +90,36 @@ public class CardPanel extends SkinnedPanel implements CardContainer, IDisposabl
private boolean isSelected; private boolean isSelected;
private CachedCardImage cachedImage; private CachedCardImage cachedImage;
private static Font smallCounterFont;
private static Font largeCounterFont;
static {
try {
Font roboto = Font.createFont(Font.TRUETYPE_FONT, CardPanel.class.getClassLoader().getResourceAsStream("Roboto-Bold.ttf"));
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont(roboto);
Map<TextAttribute, Object> attributes = new HashMap<>();
attributes.put(TextAttribute.FAMILY, "Roboto Bold");
attributes.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
attributes.put(TextAttribute.SIZE, 11);
attributes.put(TextAttribute.KERNING, TextAttribute.KERNING_ON);
smallCounterFont = Font.getFont(attributes);
attributes.put(TextAttribute.SIZE, 15);
largeCounterFont = Font.getFont(attributes);
} catch (FontFormatException | IOException e) {
e.printStackTrace();
}
}
public CardPanel(final CMatchUI matchUI, final CardView card0) { public CardPanel(final CMatchUI matchUI, final CardView card0) {
this.matchUI = matchUI; this.matchUI = matchUI;
@@ -468,20 +499,8 @@ public class CardPanel extends SkinnedPanel implements CardContainer, IDisposabl
int currentCounter = 0; int currentCounter = 0;
Map<TextAttribute, Object> attributes = new HashMap<>(); FontMetrics smallFontMetrics = g.getFontMetrics(smallCounterFont);
FontMetrics largeFontMetrics = g.getFontMetrics(largeCounterFont);
attributes.put(TextAttribute.FAMILY, "Roboto Bold");
attributes.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
attributes.put(TextAttribute.SIZE, 11);
attributes.put(TextAttribute.KERNING, TextAttribute.KERNING_ON);
Font smallFont = Font.getFont(attributes);
attributes.put(TextAttribute.SIZE, 15);
Font largeFont = Font.getFont(attributes);
FontMetrics smallFontMetrics = g.getFontMetrics(smallFont);
FontMetrics largeFontMetrics = g.getFontMetrics(largeFont);
for (Map.Entry<CounterType, Integer> counterEntry : card.getCounters().entrySet()) { for (Map.Entry<CounterType, Integer> counterEntry : card.getCounters().entrySet()) {
@@ -511,11 +530,11 @@ public class CardPanel extends SkinnedPanel implements CardContainer, IDisposabl
Rectangle nameBounds = counterArea.getBounds(); Rectangle nameBounds = counterArea.getBounds();
nameBounds.x += 13; nameBounds.x += 13;
nameBounds.width = 48; nameBounds.width = 48;
drawVerticallyCenteredString(g, counter.getCounterOnCardDisplayName(), nameBounds, smallFont, smallFontMetrics); drawVerticallyCenteredString(g, counter.getCounterOnCardDisplayName(), nameBounds, smallCounterFont, smallFontMetrics);
Rectangle numberBounds = counterArea.getBounds(); Rectangle numberBounds = counterArea.getBounds();
numberBounds.x += 58; numberBounds.x += 58;
drawVerticallyCenteredString(g, String.valueOf(numberOfCounters), numberBounds, largeFont, largeFontMetrics); drawVerticallyCenteredString(g, String.valueOf(numberOfCounters), numberBounds, largeCounterFont, largeFontMetrics);
} }
@@ -534,7 +553,7 @@ public class CardPanel extends SkinnedPanel implements CardContainer, IDisposabl
Font oldFont = g.getFont(); Font oldFont = g.getFont();
int x = area.x; int x = area.x;
int y = area.y + (area.height - fontMetrics.getHeight()) / 2 + fontMetrics.getAscent(); int y = area.y + (area.height - fontMetrics.getHeight()) / 2 + fontMetrics.getAscent() + 1;
g.setFont(font); g.setFont(font);
g.drawString(text, x, y); g.drawString(text, x, y);

Binary file not shown.