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

Character widths for some ligatures calculated incorrectly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.3.0
    • client-libs
    • 2d
    • x86
    • windows_98



      Name: yyT116575 Date: 11/06/2000


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


      This problem is reproducable on several windows platforms using several
      different HP-4 class laser printers (one was non-postscript), so I do not think
      it is dependent on a particular computer's setup.

      The problem seems to relate to the Serif font (or "Times New Roman"). It must
      have something to do with ligatures because the problem centers mostly on ff.
      Any time a word contains ff, the FontMetric miscalculates the string width. In a
      screen context it seems to calculate the double-f glyph width (which is what the
      screen uses), then sends that to the printer, which prints two normal f's,
      chewing up what should have been an inter-word space.

      Here is a program to reproduce the problem.

      (I cannot change fonts for my application, so that quick-fix is out.)

      PrinterProblem.java:


      import java.awt.*;
      import java.awt.print.*;
      import java.awt.font.*;


        public class PrinterProblem implements Printable, Pageable {

          PageFormat pf = null;
          Paper [] ppr = null;
          private PrinterJob pjob = null;
          FontMetrics fm = null;
          Font normalPlain = null;
          
          public void sendToPrinter() {
              int i = 1;
              ppr = new Paper[i];

              pjob = PrinterJob.getPrinterJob();
              if (pjob != null) {
                pf = pjob.defaultPage();
                  for (int k = 0; k < i; k++) {
                  ppr[k] = pf.getPaper();
                  // 72 points per inch, 0.25" margins with 2 points shaved off
                  // either end for lines
                  ppr[k].setImageableArea(16.0,16.0,580.0,760.0);
                  pf.setPaper(ppr[k]);
                }
                pjob.setPrintable(this,pf); // the canvas does the rendering
                pjob.setPageable(this); // tells print dialog how many pages
                boolean doPrint = pjob.printDialog();

                if (doPrint)
                {
                    try {
                      pjob.print();
                      }
                    catch (PrinterException pe) {
                      System.out.println("Print job went bad.\n"+pe);
                    }
                 }
              }
          }


           public int print(Graphics g, PageFormat pf, int pageIndex) throws
                                                                   PrinterException
        {
          String str1 = "ott";
          String str2 = "stay";
          String str3 = "off";
          String str4 = "oll";
          String str5 = "ff";
          String str6 = "the";
          int len;

          normalPlain = new Font("Serif",Font.PLAIN|Font.TRUETYPE_FONT,10);
          g.setFont(normalPlain);
          fm = g.getFontMetrics(g.getFont());
          g.setColor(Color.black);

          g.drawString(str2,100,100);
          g.drawString(str3,100+fm.stringWidth(str2)+3,100);
          g.drawString(str6,100+fm.stringWidth(str2)+3+fm.stringWidth(str3)+3,100);
            
          g.drawString(str2,100,200);
          g.drawString(str4,100+fm.stringWidth(str2)+3,200);
          g.drawString(str6,100+fm.stringWidth(str2)+3+fm.stringWidth(str4)+3,200);
              
          g.drawString(str2,100,300);
          g.drawString(str5,100+fm.stringWidth(str2)+3,300);
          g.drawString(str6,100+fm.stringWidth(str2)+3+fm.stringWidth(str5)+3,300);
              
          g.drawString(str2,100,400);
          g.drawString(str1,100+fm.stringWidth(str2)+3,400);
          g.drawString(str6,100+fm.stringWidth(str2)+3+fm.stringWidth(str1)+3,400);

          return Printable.PAGE_EXISTS;
        }


        public PageFormat getPageFormat(int pageIndex) throws
                                IndexOutOfBoundsException {
          return pf;
        }

        public Printable getPrintable(int pageIndex) throws IndexOutOfBoundsException
       {
          return this;
        }

          public int getNumberOfPages() {
              return 1;
          }

        
       public static void main(String[] args) {
         PrinterProblem prob = new PrinterProblem();
         prob.sendToPrinter();
         System.exit(0);
       }
      }









      By the way .... a wider textfield would be nice. I edited out some comments that
      didn't make the linewraps gracefully.
      (Review ID: 109832)
      ======================================================================

            prr Philip Race
            yyoungsunw Yung-ching Young (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: