From 68fd5adfbf14798f22dd68c52c302f6b0b4f3556 Mon Sep 17 00:00:00 2001 From: mdb Date: Mon, 4 Apr 2005 20:11:54 +0000 Subject: [PATCH] Attempt to work around the Mac text layout bug. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1630 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../src/java/com/samskivert/swing/Label.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/projects/samskivert/src/java/com/samskivert/swing/Label.java b/projects/samskivert/src/java/com/samskivert/swing/Label.java index 2a3cec3b..636eb203 100644 --- a/projects/samskivert/src/java/com/samskivert/swing/Label.java +++ b/projects/samskivert/src/java/com/samskivert/swing/Label.java @@ -42,6 +42,7 @@ import java.util.HashMap; import javax.swing.SwingConstants; import com.samskivert.Log; +import com.samskivert.util.RunAnywhere; import com.samskivert.util.StringUtil; import com.samskivert.util.Tuple; @@ -321,7 +322,7 @@ public class Label implements SwingConstants, LabelStyleConstants // languages, anyway) if (_constraints.width == -1) { TextLayout layout = new TextLayout(textIterator(gfx), frc); - Rectangle2D bounds = layout.getBounds(); + Rectangle2D bounds = getBounds(layout); int lines = 1; double width = getWidth(bounds)/lines; @@ -343,7 +344,7 @@ public class Label implements SwingConstants, LabelStyleConstants } TextLayout layout = new TextLayout(textIterator(gfx), frc); - Rectangle2D bounds = layout.getBounds(); + Rectangle2D bounds = getBounds(layout); int lines = Math.round(targetHeight / getHeight(layout)); if (lines > 1) { int targetWidth = (int)Math.round(getWidth(bounds) / lines); @@ -372,7 +373,7 @@ public class Label implements SwingConstants, LabelStyleConstants // then layout on one line and call it good if (layouts == null) { TextLayout layout = new TextLayout(textIterator(gfx), frc); - Rectangle2D bounds = layout.getBounds(); + Rectangle2D bounds = getBounds(layout); // for some reason JDK1.3 on Linux chokes on setSize(double,double) _size.setSize(Math.ceil(getWidth(bounds)), Math.ceil(getHeight(layout))); @@ -427,7 +428,7 @@ public class Label implements SwingConstants, LabelStyleConstants if (layout == null) { break; } - Rectangle2D bounds = layout.getBounds(); + Rectangle2D bounds = getBounds(layout); width = Math.max(width, getWidth(bounds)); height += getHeight(layout); layouts.add(new Tuple(layout, bounds)); @@ -568,6 +569,19 @@ public class Label implements SwingConstants, LabelStyleConstants return width; } + /** + * Gets the bounds of the supplied text layout in a way that works + * around the various befuckeries that currently happen on the Mac. + */ + protected Rectangle2D getBounds (TextLayout layout) + { + if (RunAnywhere.isMacOS()) { + return layout.getOutline(null).getBounds(); + } else { + return layout.getBounds(); + } + } + /** * Computes the height based on the leading, ascent and descent rather * than what the layout reports via getBounds() which