TextComponent: Draw outline using one axis offset at a time

This commit prevents fonts with thin and angled glyphs from having gaps
between the characters and their outline by offsetting outline draws in
one direction exclusively.

(cherry picked from commit 8d1f028758)
This commit is contained in:
Jordan Atwood
2020-06-25 06:01:34 +02:00
committed by Lucwousin
parent 8eb9ea7e45
commit 36e86c6619

View File

@@ -47,7 +47,8 @@ public class TextComponent implements RenderableEntity
private String text;
private Point position = new Point();
private Color color = Color.WHITE;
private Color borderColor = Color.BLACK;
private boolean outline;
private boolean alpha; // Generates a lot of garbage!
@Override
public Dimension render(Graphics2D graphics)
@@ -71,8 +72,20 @@ public class TextComponent implements RenderableEntity
}
else
{
renderText(graphics, position.x, position.y, text, color, borderColor);
if (alpha)
{
drawAlpha(graphics, position.x, position.y, text, color);
}
else
{
drawOutline(graphics, text);
// actual text
graphics.setColor(color);
graphics.drawString(text, position.x, position.y);
}
}
return new Dimension(fontMetrics.stringWidth(text), fontMetrics.getHeight());
}