Use the width, the whole width and nothing but the width.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@936 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: Label.java,v 1.27 2002/11/12 06:37:37 mdb Exp $
|
// $Id: Label.java,v 1.28 2002/11/13 23:14:57 mdb Exp $
|
||||||
//
|
//
|
||||||
// samskivert library - useful routines for java programs
|
// samskivert library - useful routines for java programs
|
||||||
// Copyright (C) 2002 Michael Bayne
|
// Copyright (C) 2002 Michael Bayne
|
||||||
@@ -292,13 +292,13 @@ public class Label implements SwingConstants, LabelStyleConstants
|
|||||||
Rectangle2D bounds = layout.getBounds();
|
Rectangle2D bounds = layout.getBounds();
|
||||||
|
|
||||||
int lines = 1;
|
int lines = 1;
|
||||||
double width = bounds.getWidth()/lines;
|
double width = getWidth(bounds)/lines;
|
||||||
double height = bounds.getHeight()*lines;
|
double height = getHeight(layout)*lines;
|
||||||
double delta = Math.abs(width/height - GOLDEN_RATIO);
|
double delta = Math.abs(width/height - GOLDEN_RATIO);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
width = bounds.getWidth() / (lines+1);
|
width = getWidth(bounds) / (lines+1);
|
||||||
double nheight = bounds.getHeight() * (lines+1);
|
double nheight = getHeight(layout) * (lines+1);
|
||||||
double ndelta = Math.abs(width/nheight - GOLDEN_RATIO);
|
double ndelta = Math.abs(width/nheight - GOLDEN_RATIO);
|
||||||
if (delta <= ndelta) {
|
if (delta <= ndelta) {
|
||||||
break;
|
break;
|
||||||
@@ -314,7 +314,7 @@ public class Label implements SwingConstants, LabelStyleConstants
|
|||||||
Rectangle2D bounds = layout.getBounds();
|
Rectangle2D bounds = layout.getBounds();
|
||||||
int lines = Math.round(targetHeight / getHeight(layout));
|
int lines = Math.round(targetHeight / getHeight(layout));
|
||||||
if (lines > 1) {
|
if (lines > 1) {
|
||||||
int targetWidth = (int)Math.round(bounds.getWidth() / lines);
|
int targetWidth = (int)Math.round(getWidth(bounds) / lines);
|
||||||
|
|
||||||
// attempt to lay the text out in the specified width,
|
// attempt to lay the text out in the specified width,
|
||||||
// incrementing by 10% each time; limit our attempts to 10
|
// incrementing by 10% each time; limit our attempts to 10
|
||||||
@@ -342,7 +342,7 @@ public class Label implements SwingConstants, LabelStyleConstants
|
|||||||
TextLayout layout = new TextLayout(textIterator(gfx), frc);
|
TextLayout layout = new TextLayout(textIterator(gfx), frc);
|
||||||
Rectangle2D bounds = layout.getBounds();
|
Rectangle2D bounds = layout.getBounds();
|
||||||
// for some reason JDK1.3 on Linux chokes on setSize(double,double)
|
// for some reason JDK1.3 on Linux chokes on setSize(double,double)
|
||||||
_size.setSize(Math.ceil(bounds.getWidth()),
|
_size.setSize(Math.ceil(getWidth(bounds)),
|
||||||
Math.ceil(getHeight(layout)));
|
Math.ceil(getHeight(layout)));
|
||||||
layouts = new ArrayList();
|
layouts = new ArrayList();
|
||||||
layouts.add(new Tuple(layout, bounds));
|
layouts.add(new Tuple(layout, bounds));
|
||||||
@@ -413,7 +413,7 @@ public class Label implements SwingConstants, LabelStyleConstants
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Rectangle2D bounds = layout.getBounds();
|
Rectangle2D bounds = layout.getBounds();
|
||||||
width = Math.max(width, bounds.getX() + bounds.getWidth());
|
width = Math.max(width, getWidth(bounds));
|
||||||
height += getHeight(layout);
|
height += getHeight(layout);
|
||||||
layouts.add(new Tuple(layout, bounds));
|
layouts.add(new Tuple(layout, bounds));
|
||||||
}
|
}
|
||||||
@@ -483,8 +483,7 @@ public class Label implements SwingConstants, LabelStyleConstants
|
|||||||
Rectangle2D lbounds = _lbounds[i];
|
Rectangle2D lbounds = _lbounds[i];
|
||||||
y += layout.getAscent();
|
y += layout.getAscent();
|
||||||
|
|
||||||
float extra = (float)(_size.width - lbounds.getWidth() -
|
float extra = (float)(_size.width - getWidth(lbounds));
|
||||||
lbounds.getX());
|
|
||||||
switch (_style) {
|
switch (_style) {
|
||||||
case OUTLINE:
|
case OUTLINE:
|
||||||
// if we're outlining, we really have two pixels less space
|
// if we're outlining, we really have two pixels less space
|
||||||
@@ -565,6 +564,15 @@ public class Label implements SwingConstants, LabelStyleConstants
|
|||||||
return text.getIterator();
|
return text.getIterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Computes the total width of a {@link TextLayout} given bounds
|
||||||
|
* returned from a call to {@link TextLayout#getBounds}.
|
||||||
|
*/
|
||||||
|
protected static double getWidth (Rectangle2D laybounds)
|
||||||
|
{
|
||||||
|
return laybounds.getX() + laybounds.getWidth();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Computes the height based on the leading, ascent and descent rather
|
* Computes the height based on the leading, ascent and descent rather
|
||||||
* than what the layout reports via <code>getBounds()</code> which
|
* than what the layout reports via <code>getBounds()</code> which
|
||||||
|
|||||||
Reference in New Issue
Block a user