-
Enhancement
-
Resolution: Duplicate
-
P4
-
None
-
6u10
-
x86
-
windows_vista
A DESCRIPTION OF THE REQUEST :
JTextComponent now uses TextComponentPrintable to print and control page breaks. The main benefit was to make sure lines of text did not get split between two different pages. It also provided rudimentary header / footer mechanism.
Unfortunately, this change relies on native fonts for the layout of the printed content. Specifically:
fm = sun.font.FontDesignMetrics.getMetrics(font, context)
While this change helps those who could not control printing before, it breaks code for those of us who had.
Prior to this change we could measure the size and placement of views to determine where to make page breaks. We could then use these measurements to control more sophisticated page breaks in html documents.
For example, we could examine placement of a section of text on a page to make sure critical sections of documents were kept together. (e.g., we could keep signature lines on the same page as important preceding text.) We called this feature conditional page breaks.
However, now that printing uses a different set of fonts, with different metrics, our old mechanisms could not reliably measure the document views for printing purposes.
JUSTIFICATION :
We temporarily solved our problem by using:
fm = sun.font.FontDesignMetrics.getMetrics(font, context)
However, when compiled, the compiler warns that this feature may be removed in the future.
We need a reliable and permanent interface that will allow us to accurately measure printed text, so we do not have to rewrite this (again) in the future.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
If Sun uses a different set of fonts to control printing, those same fonts should be accessible to everyone else, and we should be able to rely on them over time.
ACTUAL -
The fonts are accessible, but this accessibility does not appear to be permanent. If you change the fonts you use, make them available to us!
---------- BEGIN SOURCE ----------
there are numerous bug reports regarding spacing and sizing of printed fonts.
try to print a JEditorPage
1. using print(g2d) or rootView.paint(g2d, rect);
2. with html content that uses serif fonts and
3. has multiple consecutive words with bold text
You will see that the spaces between words disappear in some cases. For example, you might see THISISATITLE instead of THIS IS A TITLE.
The reason is that the Graphics2D fonts have different metrics than the native fonts that are now used for printing.
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
class MyClass extends JEditorPane implements Printable
{
print(....)
{
Graphics2D g2d = (Graphics2D)g;
context = g2d.getFontRenderContext();
...
}
public FontMetrics getFontMetrics(Font font)
{
// This access needs to be permanent
return sun.font.FontDesignMetrics.getMetrics(font, context);
}
}
JTextComponent now uses TextComponentPrintable to print and control page breaks. The main benefit was to make sure lines of text did not get split between two different pages. It also provided rudimentary header / footer mechanism.
Unfortunately, this change relies on native fonts for the layout of the printed content. Specifically:
fm = sun.font.FontDesignMetrics.getMetrics(font, context)
While this change helps those who could not control printing before, it breaks code for those of us who had.
Prior to this change we could measure the size and placement of views to determine where to make page breaks. We could then use these measurements to control more sophisticated page breaks in html documents.
For example, we could examine placement of a section of text on a page to make sure critical sections of documents were kept together. (e.g., we could keep signature lines on the same page as important preceding text.) We called this feature conditional page breaks.
However, now that printing uses a different set of fonts, with different metrics, our old mechanisms could not reliably measure the document views for printing purposes.
JUSTIFICATION :
We temporarily solved our problem by using:
fm = sun.font.FontDesignMetrics.getMetrics(font, context)
However, when compiled, the compiler warns that this feature may be removed in the future.
We need a reliable and permanent interface that will allow us to accurately measure printed text, so we do not have to rewrite this (again) in the future.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
If Sun uses a different set of fonts to control printing, those same fonts should be accessible to everyone else, and we should be able to rely on them over time.
ACTUAL -
The fonts are accessible, but this accessibility does not appear to be permanent. If you change the fonts you use, make them available to us!
---------- BEGIN SOURCE ----------
there are numerous bug reports regarding spacing and sizing of printed fonts.
try to print a JEditorPage
1. using print(g2d) or rootView.paint(g2d, rect);
2. with html content that uses serif fonts and
3. has multiple consecutive words with bold text
You will see that the spaces between words disappear in some cases. For example, you might see THISISATITLE instead of THIS IS A TITLE.
The reason is that the Graphics2D fonts have different metrics than the native fonts that are now used for printing.
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
class MyClass extends JEditorPane implements Printable
{
print(....)
{
Graphics2D g2d = (Graphics2D)g;
context = g2d.getFontRenderContext();
...
}
public FontMetrics getFontMetrics(Font font)
{
// This access needs to be permanent
return sun.font.FontDesignMetrics.getMetrics(font, context);
}
}
- duplicates
-
JDK-6784965 Printing JTable using Sans Serif 11pt is broken
- Open