title: Printing Mathematical Symbols in Java Gives Wrong Output
body: <p>I am trying to print using the TextLayout class.  When I print some mathematical symbols, I get odd behavior.</p>
  
  <p>The image below shows the results from printing the strings "First + 2" and "First \u222A 2" to a PDF file.  When the 'union' symbol (\u222A) is printed, it looks like characters following the symbol overwrite characters before the symbol.</p>
  
  <p><img src="https://i.stack.imgur.com/MWwqD.png" alt="enter image description here"></p>
  
  <p>Here is the test code that prints a string that does not contain \u222A and another string that does:</p>
  
  <pre><code>public class PrintTest {
  
  public static void main(String[] args) {
      PrinterJob pj = PrinterJob.getPrinterJob();
  
      pj.setPrintable(new Printable() {
          public int print(Graphics g, PageFormat pf, int pageIndex) {
              if (pageIndex != 0) return NO_SUCH_PAGE;
  
              Graphics2D g2 = (Graphics2D) g;
              Font font = new Font("SansSerif", Font.PLAIN, 10);
  
              // Draw string with + char
              TextLayout layout = new TextLayout("First + 2", font, g2
                      .getFontRenderContext());
              layout.draw(g2, 40, 80);
  
              // Draw string with union character
              layout = new TextLayout("First \u222A 2", font, g2
                      .getFontRenderContext());
              layout.draw(g2, 40, 100);
  
              return PAGE_EXISTS;
          }
      });
  
      if (pj.printDialog()) {
          try {
              pj.print();
          } catch (PrinterException e) {
              System.out.println(e.getMessage());
          }
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I am running java 1.7.0_17 on Windows 7 &amp; 8, and have tested this on several printers, including printing to PDF.  All tests show the same problem.  I get the same results with 'union', 'intersection' and 'exclusion' symbols.</p>
  
  <p>I am really stuck here.  Any help would be greatly appreciated.</p>
  
  <p>UPDATE: The problem seems to occur when using logical fonts.  I tested with all of the installed logical fonts ('Dialog', 'DialogInput', 'Monospaced, 'SansSerif' and 'Serif') and got the same problem.  When I tested with physical fonts that support these symbols ('Lucida Sans' and 'Arial Unicode MS') I got the desired output.</p>
  
  <p><img src="https://i.stack.imgur.com/ujUiq.png" alt="enter image description here"></p>
  
  <p>This resolves the immediate issue for me since I'm not tied to using logical fonts.</p>