[macosx] Printing unicode chars with drawGlyphVector in Java 7.
Abhinay Reddyreddy
Abhinay.Reddyreddy at mathworks.com
Tue Jun 11 10:00:41 PDT 2013
Hi,
I found that drawGlyphVector method does not work properly for printing unicode characters (at-least Japanese), when used with NATIVE print dialogs on Mac OS X.
Changing the locale of the machine did not make any difference. I verified this used to work fine with Java 6.
Here's a test case and the attachment shows a picture of the
import java.awt.*;
import javax.swing.*;
import java.awt.print.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;
import java.awt.font.*;
public class PrintUnicodeTest implements Printable
{
public static int count = 0;
public void startTestCase()
{
PrinterJob pj = PrinterJob.getPrinterJob();
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
pras.add(DialogTypeSelection.NATIVE);
pj.setPrintable(this);
if (pj.printDialog(pras))
{
try{
pj.print(pras);
} catch (Exception e) { }
}
}
public int print(Graphics g, PageFormat pf, int pageNo) throws PrinterException
{
Graphics2D g2d = (Graphics2D)g;
if(pageNo > 0)
return Printable.NO_SUCH_PAGE;
else {
g2d.setColor(Color.blue);
Font fnt = new Font("Serif", Font.PLAIN, 24);
g2d.setFont(fnt);
String s = "¤é¥»»y.m";
int x = 100, y = 100;
GlyphVector glyphVec = g2d.getFont().createGlyphVector( g2d.getFontRenderContext(), "using shape fill: "+s);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// extract glyph shapes and draw ¡V this works fine.
Shape shape = glyphVec.getOutline();
g2d.translate(x, y);
g2d.fill(shape);
g2d.translate(-x, -y);
// use in-built drawString method ¡V this does not work because of bug 7183516
g.drawString("using drawString (sun Bug#7183516): "+s, x, y*2);
// use in-built drawGlyphVector method ¡V this the bug I am reporting.
GlyphVector glyphVec2 = g2d.getFont().createGlyphVector( g2d.getFontRenderContext(), "using drawGlyphVector: "+s);
g2d.drawGlyphVector(glyphVec2, (float)x, (float)y*3);
return Printable.PAGE_EXISTS;
}
}
public static void main (String []Args) {
PrintUnicodeTest st = new PrintUnicodeTest ();
st.startTestCase ();
}
}
I have submitted a bug(9003977). Let me know if anyone had luck printing non-english/roman characters with the native print dialog on Mac OS X.
Thanks,
Abhinay.
More information about the macosx-port-dev
mailing list