Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4242645
Votes 109
Synopsis line spacing constraint in ParagraphView
Category java:classes_swing
Reported Against 1.1.7 , 1.3.1 , merlin-beta , kestrel-beta
Release Fixed 1.4.0_02, 1.4.1(hopper) (Bug ID:2117702)
State 10-Fix Delivered, Needs Verification, bug
Priority: 4-Low
Related Bugs 4493953
Submit Date 31-MAY-1999
Description




These are lines from ParagraphView.java in javax.swing.text 
package ( swing 1.1 ). This constraint does not allow me to
specify a line spacing of 0.5 and have it work. This should be
removed
	// Adjust for line spacing
	if(lineSpacing > 1) {
	    float height = row.getPreferredSpan(View.Y_AXIS);
	    float addition = (height * lineSpacing) - height;
	    if(addition > 0) {
		row.setInsets(row.getTopInset(), row.getLeftInset(),
			      (short) addition, row.getRightInset());
	    }
	}
(Review ID: 53458) 
======================================================================




java version "1.3beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3beta-O)
Java(TM) HotSpot Client VM (build 1.3beta-O, mixed mode)


javax.swing.text.ParagraphView does not implement linespacing correctly. The
bug lies in ParagraphView.createRow:

ParagraphView.createRow():
[cut]
	// Adjust for line spacing
	if(lineSpacing > 1) {
	    float height = row.getPreferredSpan(View.Y_AXIS);
	    float addition = (height * lineSpacing) - height;
	    if(addition > 0) {
		row.setInsets(row.getTopInset(), row.getLeftInset(),
			      (short) addition, row.getRightInset());
	    }
[cut]

The problem is that, at the time the row is created, it contains no text and
therefore returns zero for its getPreferredSpan(), meaning that the addition
variable always gets set to zero.

Solution 1. One quick solution on the Swing code side would be to store a
linespacing variable in the ParagraphView.Row class, and override getMinimumSpan
(), getPreferredSpan(), and getMaximumSpan() be multiplied by this LineSpacing
variable before the value is returned. This has the drawback of actually making
each row higher, instead of providing space between the rows, though. This is
partly a technicality.

Solution 2. A better solution would be to add a TileSpanMultiplier variable (or
something similar) to FlowView, which means that ParagraphView, when setting
its linespacing, would actually call FlowView.setTileSpanMultiplier
(lineSpacing) inside ParagraphView.setPropertiesFromAttributes(). This way,
FlowView.FlowStrategy could be modified to insert the above code inside
FlowView.FlowStrategy.layout():

	int next = layoutRow(fv, rowIndex, p0);	//existing
	if (row.getViewCount() == 0) {	//existing
	    row.append(createView(fv, p0, Integer.MAX_VALUE,
rowIndex));  //existing
	    next = row.getEndOffset();	//existing
	}	//existing
	//<--move code from ParagraphView.createRow() to here

**Problem lurking in the background**
However, I don't understand how the ParagraphView.createRow() code compiles in
the first place: it calls row.setInsets(), row.getTopInset(), etc. which are
all protected inside CompositeView (from which ParagraphView.Row derives).
Perhaps since Row is an internal class, this should still be visible; in any
case, JBuilder 3 does not compile it. (In fact, to make matters worse, copying
ParagraphView.Row into a derived MyParagraph.MyParagraphRow causes JBuilder 3
to throw a null pointer exception when compiling
MyParagraphView.MyParagraphRow.getAlignment() {...switch(justification)...} --
perhaps because justification is private in the parent class (ParagraphView) of
the class in which MyParagraphRow resides (MyParagraphView).)
(Review ID: 98867)
======================================================================
Work Around




None that I know of
======================================================================




Override ParagraphView and create a ParagraphView.Row. Give
MyParagraphView.MyParagraphRow a linespacing variable, and override
getMinimumSpan(), getPreferredSpan(), and getMaximumSpan() inside
MyParagraphView.MyParagraphRow to use this variable as a multiplier.

Note that since ParagraphView.Row is declared as having package visibility,
you'll have to create an entire new MyParagraphView.MyRow with the code copied
from ParagraphView.Row. Furthermore, since ParagraphView.justification is
declared private with no public accessor methods (this is getting to be *quite*
a consistent problem in Swing), you'll have to add your own justification
variable in MyParagraphView, override
MyParagraphView.setPropertiesFromAttributes() to set it correctly, provide an
accessor method for it, and then modify MyParagraphView.MyRow.getAlignment() to
use MyParagraphView.getJustification() instead of the private
ParagraphView.justification variable.
(Review ID: 98867)
======================================================================
Evaluation
The property was intended to be a size in points, not a percentage.  It is 
currently implemented incorrectly.  This is actually a bug, not an rfe.
  xxxxx@xxxxx   2000-03-22

=========================
Users want to have lineSpacing as a percentage. 

It did not work because in createRow the actual
height of the row is not known.

We can override ParagraphView.Row.getBottomInset

  xxxxx@xxxxx   2002-01-31
------------------
LineSpacing 0 means no additional spacing is needed
LineSpacing 1 means additional spacing is 100% of the original height
LineSpacing -0.5 means the height of the row is 50% of the original height
  xxxxx@xxxxx   2002-02-01 
-------------------
See description to bugId 4493953 for test case
  xxxxx@xxxxx   2002-03-06
Comments
  
  Include a link with my name & email   

Submitted On 06-DEC-2000
wmr4
the artificial limitation of the space in between text 
lines to be ignored if you try to set it less than 1 is a 
real problem.  We had to write a special printing piece 
because the line spacing is so large that the letters we 
were printing were not acceptable for business.  


Submitted On 25-MAY-2001
Garroyo
fix it


Submitted On 20-FEB-2002
idk
by default lineSpacing is 0. And it represents
"no spasing in the paragraph at all"
You might have spaces between paragraphs not between lines
in the paragraph


Submitted On 20-FEB-2002
cowwoc
Your idea of lineSpacing "percentages" is a bad one. My
application specifically requires *no* inter-line spacing
what-so-ever. I make use of ASCII "box characters" to draw
tables and that's impossible to do if there is any line
spacing at all.

Using your idea of lineSpacing by percentage, how can one
represent "no spacing at all"?


Submitted On 22-FEB-2002
idk
>I make use of ASCII "box characters" to draw  
>tables and that's 

You need to use some special font for that. Otherwise you
would have spaces anyway. 
That "invisible border" is a font property. Swing is using
Font.height to get the line height. In case Font.height is
bigger than actual height you'll get that border. 


Submitted On 01-MAR-2002
avery1701
This bug needs to be reopened for the 1.4 final release. 
The code in ParagraphView is exactly the same as stated above.



PLEASE NOTE: JDK6 is formerly known as Project Mustang