A solution for IDEA crash when trying to change editor font in Ubuntu 6.06
Tuesday, 23. May 2006, 01:46:56
Idea crahes when I trying to change editor font in my ubuntu 6.06. My system uses jdk 1.5.06. I searched the web with google and found a solution in this page. Ubuntu maybe changed something that will cause this problem. Some font rendering have problem. You can test your system, get the problem fonts and remove them. Then your idea will work well. This test application will print informations on screen. When it abort, the last font is the problem font.
There are two problem fonts in my system. They are Rekha.ttf and aakar-medium.ttf in my Ubuntu and they are both in /usr/share/fonts/truetype/ttf-gujarati-fonts directory.
import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
public class FontTest {
public static void main(String[] args) {
final JFrame frame = new JFrame("Font test window");
frame.setSize(800, 600);
frame.getContentPane().setLayout(new BorderLayout());
final JLabel label = new JLabel("The quick brown fox jumped over the lazy dog's back!" +
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" +
"@#$%^&*()_+-=,./<>?'\";:[{]}\\|`~");
label.setFont(label.getFont().deriveFont(16.0f));
frame.getContentPane().add(label, BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
try {
final Font[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
for (int i = 0; i < fonts.length; i++) {
final int idx = i;
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
final Font font = fonts[idx];
final String name = font.getName();
System.out.println("Checking Font: " + name);
final boolean t1 = testChars(font, 'a', 'z');
final boolean t2 = testChars(font, 'A', 'Z');
final boolean t3 = testChars(font, '0', '9');
System.out.println("Executing canDisplayUpTo...");
final boolean t4 = font.canDisplayUpTo("The quick brown fox jumped over the lazy dog's back!@#$%^&*()_+-=,./<>?'\";:[{]}\\|`~") == -1;
System.out.println("Executing printTest...");
printTest(frame, label, font);
if (t1 && t2 && t3 && t4) {
System.out.println(" OK.");
} else {
System.out.println();
}
}
});
}
System.out.println("Finished");
System.exit(0);
} catch(Exception e) {
throw new RuntimeException(e);
}
}
private static boolean testChars(final Font font, final int start, final int end)
{
System.out.println("testChars('" + (char)start + "', '" + (char)end + "')");
boolean ret = true;
for(int i = start;i <= end;i++) {
if(!font.canDisplay((char)i)) {
ret = false;
}
}
return ret;
}
private static void printTest(final JFrame frame, final JLabel label, final Font font)
{
System.out.println("Entering printTest.");
final Font derived = font.deriveFont(16.0f);
System.out.println("Derived font");
label.setFont(derived);
System.out.println("Set font");
frame.repaint();
System.out.println("Repainted and leaving printTest.");
}
}






