You are not logged in.

#1 2021-04-20 17:10:10

alecmev
Member
Registered: 2020-11-02
Posts: 5

How to trick a Java app into using a different font?

Hi!

I'm packaging a Java/AWT application that's hardcoded to use Microsoft fonts.

I could just install them as a dependency, but there's a side effect: some websites now render Arial instead of my preferred sans, which is noticeable, since ttf-ms-fonts are fonts from XP days.

The application is built on JasperReports, and as you can see here, it checks whether a font is available or not by first listing all installed fonts, so the standard metric-compatible aliases don't do anything here.

Is there a way to trick this application into picking up another font, e.g. Arimo, and using it as if it were Arial? Preferably something Fontconfig-based, but I'm open for any ideas, e.g. symlinking TTF files, etc.

Thanks!

Last edited by alecmev (2021-04-20 17:10:38)

Offline

#2 2021-04-21 02:17:56

Ropid
Member
Registered: 2015-03-09
Posts: 1,069

Re: How to trick a Java app into using a different font?

You can override fontconfig's config for just one program with an environment variable "FONTCONFIG_FILE". Maybe you can somehow engineer a setup for this program that leaves the rest of the machine alone by using this FONTCONFIG_FILE env variable?

If I check the file "/etc/fonts/fonts.conf", there's a "<dir>" entry there that points fontconfig to the system's "/usr/share/fonts/". You could perhaps do your own version of that fonts.conf file that points to a location with Microsoft fonts before looking at the system's normal /usr location. Maybe a config like this here works:

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "urn:fontconfig:fonts.dtd">
<fontconfig>

    <dir>/your/programs/own/fonts/location</dir>

    <include>/etc/fonts/fonts.conf</include>

</fontconfig>

Last edited by Ropid (2021-04-21 02:20:31)

Offline

#3 2021-04-21 10:54:29

alecmev
Member
Registered: 2020-11-02
Posts: 5

Re: How to trick a Java app into using a different font?

Thanks Ropid! This could work, and I might give it a go when I revisit this package, but yeah, then it's on me to download the fonts, would be great to avoid that. Was hoping that maybe there's an easy way to tell Fontconfig "hey, take whatever sans-serif, and treat it as a whole new font called Arial, and show it in fc-list and whatnot".

Just in case, I finished it yesterday, with ttf-ms-fonts for now. Thankfully, I need to use it only once every quarter.

Offline

Board footer

Powered by FluxBB