646016cdf1e2dfd539bcb649b9afb0203cf2336a
[jalview.git] / test / jalview / gui / FontChooserTest.java
1 package jalview.gui;
2
3 import java.awt.Canvas;
4 import java.awt.Font;
5 import java.awt.FontMetrics;
6
7 import org.testng.annotations.Test;
8
9 public class FontChooserTest
10 {
11
12   /**
13    * Not a real test as it runs no methods on FontChooser and makes no
14    * assertions, but this method writes to sysout the names of any (currently
15    * available, plain) fonts and point sizes that would be rejected by Jalview's
16    * FontChooser as having an I-width of less than 1.0.
17    */
18   @Test
19   public void dumpInvalidFonts()
20   {
21     String[] fonts = java.awt.GraphicsEnvironment
22             .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
23     final Canvas canvas = new Canvas();
24     for (int pointSize = 1;; pointSize++)
25     {
26       System.out.println(System.lineSeparator()
27               + "Plain fonts with sub-pixel width at " + pointSize + "pt:");
28       if (pointSize == 1)
29       {
30         System.out.println("All except:");
31       }
32       int badCount = 0;
33       for (String fontname : fonts)
34       {
35         Font newFont = new Font(fontname, Font.PLAIN, pointSize);
36         FontMetrics fontm = canvas.getFontMetrics(newFont);
37         double iw = fontm.getStringBounds("I", null).getWidth();
38         final boolean tooSmall = iw < 1d;
39         if (tooSmall)
40         {
41           badCount++;
42         }
43         if ((pointSize > 1 && tooSmall) || (pointSize == 1 && !tooSmall))
44         {
45           System.out.println(fontname);
46         }
47       }
48       if (badCount == 0)
49       {
50         break;
51       }
52     }
53   }
54
55 }