-
Java Font Mapping
Java offers a way to map fonts to a logical representation, for this a fontconfig.properites file is used during JVM startup. Is it possible to load an alternate fontconfig.properties during Runtime or to change the mapping without using too much lines of code?
-
Re: Java Font Mapping
Please don't double post the same question to the forums. Your other post has been removed.
-
Re: Java Font Mapping
-
Re: Java Font Mapping
Well that's not exactly what i'm looking for. There are several documented ways which explain the installation of fonts or change the logical font mapping depending on the operating system. If you have a look at the FontConfiguration Source Code you will find some more undocumented options e.g. force use of a specific fontconfig.properties file, but all those mechanisms are configured before runtime. Of course there is a coding style way to create and install fonts during runtime but i'm interested on changing the global fonts mapping via loading a specific fontconfig.properties file during runtime. Since the runtime system has to process the fontconfig.properties file itself there must be some kind of undocumented mechanism to handle this problem.
-
Re: Java Font Mapping
I reviewed the sun.awt.FontConfiguration and sun.java2d.GraphicsEnvironment and found a lot of methods that could be usefull, especially the ones in the FontConfiguration class. There is no way to cast to the appropriate implementation type so i did some reflection code to get access to the implemented methods:
try {
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
Method getFontConf = env.getClass().getMethod("getFontConfiguration");
Object fontConfig = getFontConf.invoke(env);
Method loadProperties = fontConfig.getClass().getMethod("loadProperties", InputStream.class);
loadProperties.invoke(fontConfig, fontConfig.getClass().getResourceAsStream("/fontconfig.properties"));
} catch (Exception e) {
e.printStackTrace();
}
There is no usefull documentation in the source only coding comments and just a simple loadProperties method call doesn't cover the trick at all. There must be a sequence of method calls that can be used to initizalize the fonts specified in the mapping.