From 2eccc70c9809f54f20ed9de373e56dc959ec7519 Mon Sep 17 00:00:00 2001 From: "ray.j.greenwell" Date: Fri, 30 Jan 2009 22:34:31 +0000 Subject: [PATCH] Patch from Dave Hoover to improve outlining when used with small text and antialiasing. git-svn-id: https://samskivert.googlecode.com/svn/trunk@2523 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- src/java/com/samskivert/swing/Label.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/java/com/samskivert/swing/Label.java b/src/java/com/samskivert/swing/Label.java index f309671d..99df6b2d 100644 --- a/src/java/com/samskivert/swing/Label.java +++ b/src/java/com/samskivert/swing/Label.java @@ -25,6 +25,7 @@ import java.awt.Component; import java.awt.Dimension; import java.awt.Font; import java.awt.Graphics2D; +import java.awt.RenderingHints; import java.awt.font.TextLayout; import java.awt.font.FontRenderContext; @@ -537,6 +538,11 @@ public class Label implements SwingConstants, LabelStyleConstants gfx.setColor(_textColor); } + // We're going to do a couple things differently if we're antialiased + RenderingHints hints = gfx.getRenderingHints(); + boolean antialiased = hints.containsKey(RenderingHints.KEY_ANTIALIASING) || + hints.containsKey(RenderingHints.KEY_TEXT_ANTIALIASING); + // render our text for (int i = 0; i < _layouts.length; i++) { TextLayout layout = _layouts[i]; @@ -568,6 +574,10 @@ public class Label implements SwingConstants, LabelStyleConstants textColor = gfx.getColor(); gfx.setColor(_alternateColor); _mainDraw = false; + if (antialiased) { + // We need to fill in the actual spot we'll be drawing on top of if antialiased + layout.draw(gfx, rx + 1, y + 1); + } layout.draw(gfx, rx, y); layout.draw(gfx, rx, y + 1); layout.draw(gfx, rx, y + 2); @@ -579,6 +589,11 @@ public class Label implements SwingConstants, LabelStyleConstants _mainDraw = true; gfx.setColor(textColor); layout.draw(gfx, rx + 1, y + 1); + if (antialiased) { + // If antialiased, draw a second time to make sure our letters are nice and + // solid looking on top of the outline + layout.draw(gfx, rx + 1, y + 1); + } } else if ((_style & SHADOW) != 0) { textColor = gfx.getColor();