summarylogtreecommitdiffstats
path: root/xdg-basedir-compliant-fontconfig.patch
blob: 40d72f4b41e345b881a1f6de82021e0356505cbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
--- a/src/java.desktop/unix/classes/sun/font/FcFontConfiguration.java
+++ b/src/java.desktop/unix/classes/sun/font/FcFontConfiguration.java
@@ -352,7 +352,29 @@
             String userDir = System.getProperty("user.home");
             String version = System.getProperty("java.version");
             String fs = File.separator;
-            String dir = userDir+fs+".java"+fs+"fonts"+fs+version;
+            String dir;
+
+            /* On Linux systems, put the font config into 
+             * ${XDG_CONFIG_HOME:-$HOME/.config}/java/fonts in order to follow
+             * the XDG Base Directory Specification.
+             */
+            if (System.getProperty("os.name").equals("Linux")) {
+                /* assume homedir can be found, which the jvm already does */
+                String xdgDefaultConfigHome = System.getenv("HOME")+"/.config";
+                String xdgConfigHomeEnvVar = "XDG_CONFIG_HOME";
+                String xdgConfigDir;
+
+                String xdgSetConfigDir = System.getenv(xdgConfigHomeEnvVar);
+
+                if (xdgSetConfigDir == null)
+                    xdgConfigDir = xdgDefaultConfigHome;
+                else
+                    xdgConfigDir = xdgSetConfigDir;
+
+                dir = xdgConfigDir+"/java/fonts/"+version;
+            } else {
+                dir = userDir+fs+".java"+fs+"fonts"+fs+version;
+            }
             Locale locale = SunToolkit.getStartupLocale();
             String lang = locale.getLanguage();
             String country = locale.getCountry();