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