Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4319120

Successive strings overlap, possibly due to incorrect stringWidth() calc

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.3.0
    • client-libs
    • 2d
    • x86
    • windows_nt



      Name: krT82822 Date: 03/06/2000


      orig synopsis: "HTML printing: when changing style, successives strings are overlapping."

      28 Feb 2000, eval1127@eng -- bug # 4097833 is the 1.1.x/AWT (vs. Java2/2D) bug re. stringWidth() returning #'s that are too low (resulting in a cumulative width
      for a long string that is way too low)...I'm not sure whether this is just a downstream symptom.

      With build "T" (kestrel-rc1) on NT 4.0 SP6, the lowercase "B" at the end of this long string ends up in the middle of the string of uppercase "A"s.
      Under build "T" on Solaris, this example runs fine.

      ------------

      java version "1.3.0rc1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc1-T)
      Java HotSpot(TM) Client VM (build 1.3.0rc1-S, mixed mode)

      I have a JEditorPane document with sentences composed with different styles.

      When I'm printing this document, the successives fragments on the printer are
      overlapped. This overlapping is not the same if I'm using another environment,
      and I guess it would not be the same if I would use a different printer.

      The code below should print several 'A', followed by a 'B'. However, after
      launching it, the result on the printer is not the same as the result in the
      visible frame.

      I guess it's closely related to the bug 4097833.

      import java.awt.*;
      import java.awt.print.*;
      import javax.swing.*;
      import javax.swing.text.html.HTMLEditorKit;

      public class HtmlPrint implements Printable {

      JEditorPane pane;

      public HtmlPrint() {
      // init the printing
      PrinterJob pj = PrinterJob.getPrinterJob();
      PageFormat pf = pj.pageDialog(new PageFormat());

      // create the document
      JEditorPane printingPane = new JEditorPane();
      pane = printingPane;
      printingPane.setPreferredSize(new Dimension(500,200));
      printingPane.setEditorKitForContentType("html",new HTMLEditorKit());
      printingPane.setContentType("html");
      printingPane.setText(
      "<html><body>"+
      "<font size=3>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA</font>"+
      "<font size=0>B</font>"+
      "</body></html>");
      JFrame frame = new JFrame();
      frame.getContentPane().add(printingPane);
      frame.pack();
      frame.setVisible(true);

      // prepare the textview book
      Book book = new Book();
      book.append(this,pf);
      pj.setPageable(book);

      if (pj.printDialog()) {
      try {
      pj.print();
      } catch (PrinterException e) {
      System.err.println(e.getMessage());
      }
      }
      }

      public int print(Graphics g, PageFormat pf, int index) throws
      PrinterException {

      if (index > 0) return NO_SUCH_PAGE;

      g.translate((int)pf.getImageableX(), (int)pf.getImageableY());
      pane.paint(g);

      return PAGE_EXISTS;
      }

      public static void main(String[] args) {
      HtmlPrint test = new HtmlPrint();
      }
      }
      (Review ID: 101233)
      ======================================================================

            prr Philip Race
            kryansunw Kevin Ryan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: