Skip to main content

Print quality with "i18n" property on.

2 replies [Last post]

Could someone from SUN's team take a look at this? When I set "i18n" property to true and print the content of JEditorPane print output is bad. The kerning (space between characters) is different for different character pairs.

Best regards,

<br />
import java.awt.*;<br />
import java.awt.print.*;<br />
import javax.swing.*;<br />
import javax.swing.text.*;</p>
<p>public class PrintTest implements Printable {<br />
    private JEditorPane edit;</p>
<p>    public static void main(String args[]) throws Exception {<br />
        PrintTest pt = new PrintTest();<br />
        PrinterJob pj = PrinterJob.getPrinterJob();<br />
        pj.setPrintable(pt);<br />
        pj.print();<br />
    }<br />
    public PrintTest() {<br />
        edit=new JEditorPane();<br />
        edit.setEditorKit(new StyledEditorKit());<br />
        //new row enables float based painter<br />
        edit.getDocument().putProperty("i18n", Boolean.TRUE);</p>
<p>        MutableAttributeSet attrs=new SimpleAttributeSet();<br />
        StyleConstants.setFontFamily(attrs,"Times New Roman");<br />
<p>        try {<br />
            for (int i=8; i<=12; i++) {<br />
                StyleConstants.setFontSize(attrs, i);<br />
                edit.getDocument().insertString(0, "This is Times New Roman font test size="+i+"\n", attrs);<br />
            }<br />
        }<br />
        catch (Exception ex) {<br />
            ex.printStackTrace();<br />
        }<br />
<p>    public int print(Graphics g, PageFormat pageFormat, int pageIndex) {</p>
<p>        if (pageIndex != 0) {<br />
            return (NO_SUCH_PAGE);<br />
        }<br />
        else {</p>
<p>            disableDoubleBuffering(edit);<br />
<p>            ( (Graphics2D) g).setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);<br />
            ( (Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);<br />
            ( (Graphics2D) g).setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);</p>
<p>            ( (Graphics2D) g).setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);<br />
            ( (Graphics2D) g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);<br />
            edit.setSize(400,300);<br />
            edit.paint(g);<br />
<p>            return (PAGE_EXISTS);<br />
<p>    }</p>
<p>    public static void disableDoubleBuffering(Component c) {<br />
        RepaintManager currentManager = RepaintManager.currentManager(c);<br />
        currentManager.setDoubleBufferingEnabled(false);<br />
<p>    public static void enableDoubleBuffering(Component c) {<br />
        RepaintManager currentManager = RepaintManager.currentManager(c);<br />
        currentManager.setDoubleBufferingEnabled(true);<br />
    }<br />
}<br />

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2005-01-12
Points: 0

The same happens for :
AffineTransform xf = GraphicsEnvironment.
FontRenderContext frc = new FontRenderContext(xf, false, false);
//this frc is used in swing.text

String testString = "This is Times New Roman font test size=";
Font font;
TextLayout textLayout;
int y = 100;
for (int i = 12; i >= 8; i--,y += (textLayout.getBounds().getHeight() + 5)) {
font = new Font("Times New Roman",Font.PLAIN,i);
textLayout = new TextLayout(testString + i,font,frc);


There is a bug which is marked as fixed in Tiger.

Could you suggest any workaround? Will it work if I change the paint() method of GlyphPainter2 and use graphics.drawString() instead of textLayout.draw()