Discussions
Categories
- 385.5K All Categories
- 5.1K Data
- 2.5K Big Data Appliance
- 2.5K Data Science
- 453.4K Databases
- 223.2K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 47 Multilingual Engine
- 606 MySQL Community Space
- 486 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3.2K ORDS, SODA & JSON in the Database
- 585 SQLcl
- 4K SQL Developer Data Modeler
- 188K SQL & PL/SQL
- 21.5K SQL Developer
- 46 Data Integration
- 46 GoldenGate
- 298.4K Development
- 4 Application Development
- 20 Developer Projects
- 166 Programming Languages
- 295K Development Tools
- 150 DevOps
- 3.1K QA/Testing
- 646.7K Java
- 37 Java Learning Subscription
- 37.1K Database Connectivity
- 201 Java Community Process
- 108 Java 25
- 22.2K Java APIs
- 138.3K Java Development Tools
- 165.4K Java EE (Java Enterprise Edition)
- 22 Java Essentials
- 176 Java 8 Questions
- 86K Java Programming
- 82 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 208 Java User Groups
- 25 JavaScript - Nashorn
- Programs
- 667 LiveLabs
- 41 Workshops
- 10.3K Software
- 6.7K Berkeley DB Family
- 3.6K JHeadstart
- 6K Other Languages
- 2.3K Chinese
- 207 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 474 Portuguese
Additional CR when printing unicode character

Jörg
Member Posts: 1,301
Hello,
the following code prints two lines on a printer. The second line contains an escaped unicode character. When running the example code I can't even see the unicode character on the paper; but in my original application it is visible. So this is not the problem. But always an additional carriage return is inserted after the unicode character, thus overprinting the beginning of the line with the remaining text. This did not occur in java 6 if I remember correctly. Is there any workaround for this?
Regards
J.
the following code prints two lines on a printer. The second line contains an escaped unicode character. When running the example code I can't even see the unicode character on the paper; but in my original application it is visible. So this is not the problem. But always an additional carriage return is inserted after the unicode character, thus overprinting the beginning of the line with the remaining text. This did not occur in java 6 if I remember correctly. Is there any workaround for this?
Regards
J.
import java.awt.*; import java.awt.event.*; import java.awt.print.*; import javax.swing.*; public class HelloWorldPrinter implements Printable, ActionListener { public int print(Graphics g, PageFormat pf, int page) throws PrinterException { if (page > 0) return NO_SUCH_PAGE; Graphics2D g2d = (Graphics2D)g; g2d.translate(pf.getImageableX(), pf.getImageableY()); g.drawString("Hello world!", 100, 100); g.drawString("Now the line with a unicode \u2259 character.", 100, 120); return PAGE_EXISTS; } public void actionPerformed(ActionEvent e) { PrinterJob job = PrinterJob.getPrinterJob(); job.setPrintable(this); boolean ok = job.printDialog(); if (ok) { try { job.print(); } catch (PrinterException ex) { System.out.println(ex); } } } public static void main(String args[]) { // UIManager.put("swing.boldMetal", Boolean.FALSE); JFrame f = new JFrame("Hello World Printer"); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); JButton printButton = new JButton("Print"); printButton.addActionListener(new HelloWorldPrinter()); f.add("Center", printButton); f.pack(); f.setVisible(true); } }
Answers
-
I don't see this problem using 1.7.0_09 on Ubuntu 11.04 . Though I don't like the implications, it seems likely to me that on your system the Font being used does not have a Glyph for the \u2259 character . If I am right then the solution is to find a font that does support the \u2259 character.
-
Hello Sabre,
thank you for testing. Of course it's good news that you don't see any overprinting, but unfortunately that doesn't help me on my site (Win7 64-Bit, java 1.7.0_09).
Since I can see the character in my original application as I wrote, I made up the following test case and met a strange behaviour. I can make my desired unicode character appear without any overprinting as long as I don't use any other character in the string below 2000(16).
Kindly run the following code. It prints a line of unicode characters starting with my desired one.
Then change iConstant in makeTextLine() to any value below 0x2000. At my site this results in overprinting.
Does it also happen at yours?import java.awt.*; import java.awt.event.*; import java.awt.print.*; import javax.swing.*; public class UnicodeTest extends JFrame implements Printable { String text= "Test line with unicode \u2259 character."; public UnicodeTest() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(350, 200); text= makeTextLine(); JLabel lb= new JLabel("<html>Printing started...<br>"+text); add(lb); setVisible(true); PrinterJob printerJob= PrinterJob.getPrinterJob(); printerJob.setPrintable(this); try { printerJob.print(); } catch (PrinterException e) { System.out.println("PrinterException: "+e); } } public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new UnicodeTest(); } }); } public String makeTextLine() { StringBuilder sb= new StringBuilder(); int iStartValue= 0x2259; int iConstant= 0x2020; // Tested with 0x100, 200, 400, 800, 1000, 2000. for (int i=iStartValue; i<iStartValue+30; i++) { sb.append((char)i); sb.append((char)iConstant); } return sb.toString(); } public int print(Graphics g, PageFormat pf, int page) throws PrinterException { if (page > 0) return NO_SUCH_PAGE; Graphics2D g2d = (Graphics2D)g; g2d.translate(pf.getImageableX(), pf.getImageableY()); g2d.setFont(new Font("Dialog", Font.PLAIN, 12)); g.drawString(text, 50, 40); return PAGE_EXISTS; } }
-
Did you look for a font that does display those characters?
-
I could and can see it with the ordinary "Dialog" Font. So I didn't look for another.
-
Jörg wrote:I could be wrong but the only cause for this that I can envisage is if there is a Font problem. To decide whether I am right or wrong you need to try several different fonts that have glyphs for the offending characters. If ALL of these still cause the CR effect then you can confidently raise a bug report but of course unless you can afford to wait for a long time for the fix you will still have to find a work-around.
I could and can see it with the ordinary "Dialog" Font. So I didn't look for another. -
You are right, it is - also - a font problem. For I replaced now the "Dialog" by "Arial" and by "Courier New" and in both cases overprinting doesn't happen any more, even if I use a capital A as constant character between the high ranking unicodes. Still the glyph must be defined also in "Dialog" font, how else could it appear correctly on the JLabel or if I replace the "A" by a character of 0x2000 or above?
And specifying one of the "Arial" or "Courier New" fonts doesn't solve the problem either. For if I use my original string "Test line with unicode \u2259 character.", the unicode character is printed as a square which normally signals that the glyph is not defined. But the string assembled in the StringBuilder printed everything correctly and is thus a prove that the glyph is defined.
Very strange all this.
This discussion has been closed.