Font derivation, plus ConcurrentModificationException on font load
Jeff Hain
jeffhain at rocketmail.com
Sun Dec 7 22:54:45 UTC 2014
Hello.
Currently discovering JavaFX (using 1.8.0_25-b18),I saw that there is no way to "derive" a font, as could be done in AWT.
In AWT, if you load "FreeMono.ttf", you get a non-bold font by default, but using
font.deriveFont(font.BOLD, 1.0f) you can obtain a bold version of it.
In JavaFX, there is no way to obtain a bold version of "FreeMono.ttf".The best you can do is to load "FreeMonoBold.ttf" and then callFont.load("FreeMono", FontWeight.BOLD, 1.0), but the resulting lookis quite different than AWT's bold FreeMono.ttf.
===> Are there plans to add font derivation in JavaFX, so that fonts of various styles can be obtained from a same ".ttf" file, or will it stay as this?
Now code to reproduce a bug :
### BEGIN
import javafx.scene.text.Font;
public class JavaFXCMEOnFontReload {
public static void main(String[] args) {
/*
* java.runtime.version=1.8.0_25-b18
*/
// download: http://www.fonts2u.com/download/free-monospaced.font
final String urlStr = "file:src/bugz/FreeMono.ttf";
final String initialFontFamily = "AngsanaUPC";
System.out.println("font(" + initialFontFamily + ")...");
Font.font(initialFontFamily);
for (int k=0;k<2;k++) {
System.out.println("loadFont(" + urlStr + ")...");
final Font font = Font.loadFont(urlStr, 1.0);
if (font == null) {
throw new AssertionError("could not load " + urlStr);
}
System.out.println("font(" + font.getFamily() + ")...");
Font.font(font.getFamily());
}
}
}
### END
Output:font(AngsanaUPC)...
loadFont(file:src/bugz/FreeMono.ttf)...
font(FreeMono)...
loadFont(file:src/bugz/FreeMono.ttf)...
Exception in thread "main" java.util.ConcurrentModificationException
at java.util.HashMap$HashIterator.nextNode(HashMap.java:1429)
at java.util.HashMap$KeyIterator.next(HashMap.java:1453)
at com.sun.javafx.font.PrismFontFactory.removeEmbeddedFont(PrismFontFactory.java:1550)
at com.sun.javafx.font.PrismFontFactory.loadEmbeddedFont(PrismFontFactory.java:1644)
at com.sun.javafx.font.PrismFontFactory.loadEmbeddedFont(PrismFontFactory.java:1525)
at com.sun.javafx.font.PrismFontLoader.loadFont(PrismFontLoader.java:99)
at javafx.scene.text.Font.loadFont(Font.java:400)
at bugz.JavaFXCMEOnFontReload.main(JavaFXCMEOnFontReload.java:18)
-Jeff
More information about the openjfx-dev
mailing list