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

Some custom fonts are sized at 2x.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P3 P3
    • 9
    • 7u21, 8, 9
    • client-libs
    • 2d
    • windows_7

      FULL PRODUCT VERSION :
      java version " 1.7.0_21 "
      Java(TM) SE Runtime Environment (build 1.7.0_21-b11)
      Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux 3.2.0-40-generic #64-Ubuntu SMP Mon Mar 25 21:22:10 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

        Bug also exhibits on OS X and Windows 7.

      A DESCRIPTION OF THE PROBLEM :
      When I load OpenDyslexic font using Font.createFont, it is displayed at 2x the specified point size. Also, when I install this font, it is also not sized correctly in Windows and Linux.

      Stackoverflow question: http://stackoverflow.com/questions/16596421/why-is-this-font-so-big-in-java

      REGRESSION. Last worked in version 7

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Save OpenDyslexic from http://opendyslexic.org/ to resources/.
      Load the font from file using Font.createFont.
      Use the font in a Swing application.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Font should appear at the correct size (e.g., 15pt m is 15px wide).
      ACTUAL -
      Font is displayed at twice the size (e.g. 15pt m is 29px wide).

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.BorderLayout;
      import java.awt.Component;
      import java.awt.Font;
      import java.awt.FontFormatException;
      import java.awt.GraphicsEnvironment;
      import java.io.IOException;
      import java.io.InputStream;
      import java.lang.reflect.InvocationTargetException;
      import java.util.Arrays;
      import java.util.HashSet;
      import java.util.Locale;

      import javax.swing.DefaultComboBoxModel;
      import javax.swing.DefaultListCellRenderer;
      import javax.swing.JComboBox;
      import javax.swing.JFrame;
      import javax.swing.JList;
      import javax.swing.JPanel;
      import javax.swing.JTextArea;
      import javax.swing.SwingUtilities;
      import javax.swing.WindowConstants;
      import javax.swing.event.ListDataEvent;
      import javax.swing.event.ListDataListener;

      public class FontFrame {
      /**
       * Register extra fonts from resources. If you already have it installed on
       * the computer, you can skip this.
       */
      private static void registerFonts() {
      String[] resources = {
       " OpenDyslexic-Regular.otf " ,
       " OpenDyslexic-Italic.otf " ,
       " OpenDyslexic-Bold.otf " ,
       " OpenDyslexic-BoldItalic.otf "
      };
      GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
      for (String filename: resources) {
      InputStream stream = FontFrame.class.getResourceAsStream( " resources/ " + filename);
      try {
      Font font = Font.createFont(Font.TRUETYPE_FONT, stream);
      ge.registerFont(font);
      } catch (FontFormatException | IOException e) {
      throw new IllegalStateException(e);
      }
      }
      }
      private static void createUI(boolean allFonts) {
      final JTextArea textArea = new JTextArea(
       " Font created to help dyslexic readers. " +
       " Bottom heavy and unique character shapes help " +
       " prevent letters and numbers from being confused. " );
      textArea.setWrapStyleWord(true);
      textArea.setLineWrap(true);
      final DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>();
      if (allFonts) {
      GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
      HashSet<Object> seenFamilies = new HashSet<>();
      Font[] fonts = ge.getAllFonts();
      for (Font font: fonts) {
      String familyName = font.getFamily(Locale.ENGLISH);
      if (seenFamilies.contains(familyName))
      continue;
      seenFamilies.add(familyName);
      model.addElement(familyName);
      }
      } else {
      model.addElement( " SansSerif " );
      model.addElement( " Waltograph " );
      model.addElement( " Waltograph UI " );
      model.addElement( " OpenDyslexic " );
      }

      final int fontSize = 15;
      textArea.setFont(new Font( " OpenDyslexic " , Font.PLAIN, fontSize));
      model.addListDataListener(new ListDataListener() {
      @Override public void intervalRemoved(ListDataEvent e) {}
      @Override public void intervalAdded(ListDataEvent e) {}
      @Override public void contentsChanged(ListDataEvent e) {
      if (e.getIndex0() == -1 && e.getIndex1() == -1) {
      SwingUtilities.invokeLater(new Runnable() { @Override public void run() {
      String selectedFamily = (String) model.getSelectedItem();
      Font font = new Font(selectedFamily, Font.PLAIN, fontSize);
      textArea.setFont(font);
      }});
      }
      }
      });
      JComboBox<String> familyChooser = new JComboBox<>(model);
      familyChooser.setMaximumRowCount(50);
      familyChooser.setRenderer(new DefaultListCellRenderer() {
      private static final long serialVersionUID = 1L;
      public Component getListCellRendererComponent(JList<?> list,
      Object value, int index, boolean isSelected,
      boolean cellHasFocus) {
      Component comp = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
      String familyName = (String) value;
      Font font = new Font(familyName, Font.PLAIN, fontSize);
      comp.setFont(font);
      return comp;
      }
      });

      JPanel jpanel = new JPanel();
      jpanel.setLayout(new BorderLayout());
      jpanel.add(familyChooser, BorderLayout.NORTH);
      jpanel.add(textArea, BorderLayout.CENTER);
      JFrame jframe = new JFrame();
      jframe.getContentPane().add(jpanel);
      jframe.setSize(300, 300);
      jframe.invalidate();
      jframe.setVisible(true);
      jframe.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
      }
      public static void main(String[] args) throws InvocationTargetException, InterruptedException {
      final boolean allFonts = Arrays.asList(args).contains( " --all " );
      final boolean noregister = Arrays.asList(args).contains( " --noregister " );
      System.out.format( " allFonts=%b, noregister=%b%n " , allFonts, noregister);
      if (! noregister)
      registerFonts();
      SwingUtilities.invokeAndWait(new Runnable() {
      @Override public void run() {
      createUI(allFonts);
      }
      });
      }
      }

      ---------- END SOURCE ----------

            psadhukhan Prasanta Sadhukhan
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: