1

I have a Scala/Java service running on a JVM. This is a graphical application that renders images.

While it's running, I want to add fonts it can use. So I install the fonts, and all things work great. EXCEPT that I must restart the service in order for the fonts to work.

So, how to make the JVM load the new fonts I've installed without restarting it?

Luís Guilherme
  • 2,620
  • 6
  • 26
  • 41
  • How do you install the fonts? Assuming the fonts are bundled with your service/application you could load them directly instead of installing them? this way there is no need to restart the service. This other question may help: http://stackoverflow.com/questions/5652344/how-can-i-use-a-custom-font-in-java – sorifiend Jun 02 '15 at 03:26
  • @sorifiend, I get the fonts from the system (fc-cache, etc...) – Luís Guilherme Jun 02 '15 at 18:18

1 Answers1

0

I can only guess at what you need and give basic examples, before we can help much more you will need to give us more details or an example of how you are currently trying to install/load the font, and how you apply it to your rendered images.

Are you installing the font every time your application runs? This should not be the case, you can do everything from within Java.

Java loads most fonts by itself, so if you are using an already installed/existing font then you can load and use it the normal way, like this:

Font font = new Font("Dialog", Font.PLAIN, 12);
your2Dgraphics.setFont(font);
your2Dgraphics.drawString(String str, int x, int y)

If you want to load the fonts manually from within your program or another directory then you should be doing it like this:

GraphicsEnvironment graphicsEnviro = GraphicsEnvironment.getLocalGraphicsEnvironment();
graphicsEnviro.registerFont(Font.TRUETYPE_FONT, new File("myFontToLoad.ttf"));

Once when you start the program load the font into memory, so you do not have to load it from file every time you need to use it.


I recommend a quick read about fonts in Java, take a look here:

https://docs.oracle.com/javase/tutorial/2d/text/fonts.html

sorifiend
  • 5,927
  • 1
  • 28
  • 45