United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6760148 Certain fonts are not correctly soft wrapped when using JTextComponent.print()
JDK-6760148 : Certain fonts are not correctly soft wrapped when using JTextComponent.print()

Details
Type:
Bug
Submit Date:
2008-10-16
Status:
Closed
Updated Date:
2012-10-01
Project Name:
JDK
Resolved Date:
2009-05-18
Component:
client-libs
OS:
generic
Sub-Component:
javax.swing
CPU:
generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
6u10
Fixed Versions:
6u14 (b03)

Related Reports
Backport:
Backport:
Relates:
Relates:
Relates:
Relates:
Relates:
Relates:

Sub Tasks

Description
When printing, the letters at the end of the line are sometimes truncated when soft wrap is activated. This happens for all platforms and all printers. It is also independent of configured printer magins/borders.
Interestingly the issue does not happen for all font sizes. There seems to be some mathematical miscalculation.
To reproduce, run the attached test program. Try various fonts. it looks that the issue
is present with sizes 6, 8, 11, 13, 15, und 17 while it is not with sizes 7, 9, 10, 12, 14, 16, 18, 19 and 20

                                    

Comments
EVALUATION

I reproduced this problem with font size #8
and made sure that it is not reproduced with font size #9
on Windows XP, anyway this looks like a platform independent problem

assigned to the text team
                                     
2008-11-10
EVALUATION

When fractional metrics are enabled on the FontRenderContext (as in the case of printing), the length of the rendered string, calcualted as a whole, may be different than the sum of the lenghts of the individual characters.

For some font sizes the lenght of the whole string is bigger, for some it is smaller.

Line breaking mechanism implemented in JTextArea finds breakpoints analyzing a string character-by-character. Character drawing mechanism, OTOH, draws the string as a whole. So, when the lenght of the string as a whole is bigger than the sum of the lenghts of the individual characters, a line gets clipped.

The solution is, when a breakpoint is found, to check that the lenght of the string-as-a-whole does not exceed the calculated breakpoint distance, and if it does, clip characters from the breakpoint until the lenght fits.
                                     
2009-01-20
SUGGESTED FIX

http://sa.sfbay.sun.com/projects/swing_data/6u14/6760148.0
                                     
2009-02-24



Hardware and Software, Engineered to Work Together