Card Rendering name & type line fixes

* Changed Name and Type line rendering to use Arial / Arial Narrow instead of Beleren. At small font sizes, those fonts are much more readable.

* The P/T box still uses the Beleren font, as the numbers in that font are quite readable even at small sizes.

* Changed the name / type lines to switch between Arial and Arial Narrow depending on whether there is space available using Arial or not.
This commit is contained in:
Mark Langen 2016-09-06 17:03:28 -06:00
parent 32fd253624
commit f9e088b51d

View file

@ -165,6 +165,7 @@ public class ModernCardRenderer extends CardRenderer {
protected int boxTextHeight; protected int boxTextHeight;
protected int boxTextOffset; protected int boxTextOffset;
protected Font boxTextFont; protected Font boxTextFont;
protected Font boxTextFontNarrow;
// How large is the P/T text, and how far is it down the boxes // How large is the P/T text, and how far is it down the boxes
protected int ptTextHeight; protected int ptTextHeight;
@ -211,11 +212,16 @@ public class ModernCardRenderer extends CardRenderer {
// Box text height // Box text height
boxTextHeight = getTextHeightForBoxHeight(boxHeight); boxTextHeight = getTextHeightForBoxHeight(boxHeight);
boxTextOffset = (boxHeight - boxTextHeight) / 2; boxTextOffset = (boxHeight - boxTextHeight) / 2;
boxTextFont = BASE_BELEREN_FONT.deriveFont(Font.PLAIN, boxTextHeight); // Not using Beleren for now because it looks bad at small font sizes. Maybe we want to in the future?
//boxTextFont = BASE_BELEREN_FONT.deriveFont(Font.PLAIN, boxTextHeight);
boxTextFont = new Font("Arial", Font.PLAIN, boxTextHeight);
boxTextFontNarrow = new Font("Arial Narrow", Font.PLAIN, boxTextHeight);
// Box text height // Box text height
ptTextHeight = getPTTextHeightForLineHeight(boxHeight); ptTextHeight = getPTTextHeightForLineHeight(boxHeight);
ptTextOffset = (boxHeight - ptTextHeight) / 2; ptTextOffset = (boxHeight - ptTextHeight) / 2;
// Beleren font does work well for numbers though
ptTextFont = BASE_BELEREN_FONT.deriveFont(Font.PLAIN, ptTextHeight); ptTextFont = BASE_BELEREN_FONT.deriveFont(Font.PLAIN, ptTextHeight);
} }
@ -417,7 +423,14 @@ public class ModernCardRenderer extends CardRenderer {
AttributedString str = new AttributedString(nameStr); AttributedString str = new AttributedString(nameStr);
str.addAttribute(TextAttribute.FONT, boxTextFont); str.addAttribute(TextAttribute.FONT, boxTextFont);
TextMeasurer measure = new TextMeasurer(str.getIterator(), g.getFontRenderContext()); TextMeasurer measure = new TextMeasurer(str.getIterator(), g.getFontRenderContext());
TextLayout layout = measure.getLayout(0, measure.getLineBreakIndex(0, availableWidth)); int breakIndex = measure.getLineBreakIndex(0, availableWidth);
if (breakIndex < nameStr.length()) {
str = new AttributedString(nameStr);
str.addAttribute(TextAttribute.FONT, boxTextFontNarrow);
measure = new TextMeasurer(str.getIterator(), g.getFontRenderContext());
breakIndex = measure.getLineBreakIndex(0, availableWidth);
}
TextLayout layout = measure.getLayout(0, breakIndex);
g.setColor(getBoxTextColor()); g.setColor(getBoxTextColor());
layout.draw(g, x, y + boxTextOffset + boxTextHeight - 1); layout.draw(g, x, y + boxTextOffset + boxTextHeight - 1);
@ -455,7 +468,14 @@ public class ModernCardRenderer extends CardRenderer {
AttributedString str = new AttributedString(types); AttributedString str = new AttributedString(types);
str.addAttribute(TextAttribute.FONT, boxTextFont); str.addAttribute(TextAttribute.FONT, boxTextFont);
TextMeasurer measure = new TextMeasurer(str.getIterator(), g.getFontRenderContext()); TextMeasurer measure = new TextMeasurer(str.getIterator(), g.getFontRenderContext());
TextLayout layout = measure.getLayout(0, measure.getLineBreakIndex(0, availableWidth)); int breakIndex = measure.getLineBreakIndex(0, availableWidth);
if (breakIndex < types.length()) {
str = new AttributedString(types);
str.addAttribute(TextAttribute.FONT, boxTextFontNarrow);
measure = new TextMeasurer(str.getIterator(), g.getFontRenderContext());
breakIndex = measure.getLineBreakIndex(0, availableWidth);
}
TextLayout layout = measure.getLayout(0, breakIndex);
g.setColor(getBoxTextColor()); g.setColor(getBoxTextColor());
layout.draw(g, x, y + boxTextOffset + boxTextHeight - 1); layout.draw(g, x, y + boxTextOffset + boxTextHeight - 1);
} }