From 36e86c6619b9d7537ed0dc2a505296d17403258a Mon Sep 17 00:00:00 2001 From: Jordan Atwood Date: Thu, 25 Jun 2020 06:01:34 +0200 Subject: [PATCH 1/2] 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 8d1f0287587722b3055bf6c196ec836bcdc45296) --- .../ui/overlay/components/TextComponent.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/ui/overlay/components/TextComponent.java b/runelite-client/src/main/java/net/runelite/client/ui/overlay/components/TextComponent.java index 77375541bc..cac5c61e2b 100644 --- a/runelite-client/src/main/java/net/runelite/client/ui/overlay/components/TextComponent.java +++ b/runelite-client/src/main/java/net/runelite/client/ui/overlay/components/TextComponent.java @@ -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()); } From d80f6a211c75bb5242c4b72fbbd3dba1353b5bc5 Mon Sep 17 00:00:00 2001 From: Lucwousin Date: Fri, 26 Jun 2020 22:29:31 +0200 Subject: [PATCH 2/2] Make blending TextComponent alpha not default --- .../ui/overlay/components/TextComponent.java | 41 ++++++++++++++++--- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/ui/overlay/components/TextComponent.java b/runelite-client/src/main/java/net/runelite/client/ui/overlay/components/TextComponent.java index cac5c61e2b..35c68343f0 100644 --- a/runelite-client/src/main/java/net/runelite/client/ui/overlay/components/TextComponent.java +++ b/runelite-client/src/main/java/net/runelite/client/ui/overlay/components/TextComponent.java @@ -60,12 +60,23 @@ public class TextComponent implements RenderableEntity final String[] parts = COL_TAG_PATTERN_W_LOOKAHEAD.split(text); int x = position.x; - for (String textSplitOnCol : parts) + for (String part : parts) { - final String textWithoutCol = Text.removeTags(textSplitOnCol); - final String colColor = textSplitOnCol.substring(textSplitOnCol.indexOf("=") + 1, textSplitOnCol.indexOf(">")); + final String textWithoutCol = Text.removeTags(part); + final String colColor = part.substring(part.indexOf('=') + 1, part.indexOf('>')); + final Color col = Color.decode("#" + colColor); + if (alpha) + { + drawAlpha(graphics, x, position.y, part, col); + } + else + { + drawOutline(graphics, textWithoutCol); - renderText(graphics, x, position.y, textWithoutCol, Color.decode("#" + colColor), borderColor); + // actual text + graphics.setColor(col); + graphics.drawString(textWithoutCol, x, position.y); + } x += fontMetrics.stringWidth(textWithoutCol); } @@ -89,7 +100,25 @@ public class TextComponent implements RenderableEntity return new Dimension(fontMetrics.stringWidth(text), fontMetrics.getHeight()); } - private void renderText(Graphics2D graphics, int x, int y, String text, Color color, Color border) + private void drawOutline(Graphics2D graphics, String str) + { + graphics.setColor(Color.BLACK); + + if (outline) + { + graphics.drawString(str, position.x, position.y + 1); + graphics.drawString(str, position.x, position.y - 1); + graphics.drawString(str, position.x + 1, position.y); + graphics.drawString(str, position.x - 1, position.y); + } + else + { + // shadow + graphics.drawString(str, position.x + 1, position.y + 1); + } + } + + private void drawAlpha(Graphics2D graphics, int x, int y, String text, Color color) { // remember previous composite Composite originalComposite = graphics.getComposite(); @@ -102,7 +131,7 @@ public class TextComponent implements RenderableEntity Shape shape = vector.getOutline(x, y); // draw text border - graphics.setColor(border); + graphics.setColor(Color.BLACK); graphics.fill(stroke); // replace the pixels instead of overlaying