- Timestamp:
- 2015-02-04T15:03:54+01:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/PlatformHookWindows.java
r7834 r8006 29 29 30 30 import java.awt.GraphicsEnvironment; 31 import java.io.BufferedWriter; 31 32 import java.io.File; 33 import java.io.FileInputStream; 32 34 import java.io.IOException; 35 import java.io.OutputStream; 36 import java.io.OutputStreamWriter; 37 import java.io.Writer; 38 import java.nio.file.FileSystems; 39 import java.nio.file.Files; 40 import java.nio.file.Path; 33 41 import java.security.InvalidKeyException; 34 42 import java.security.KeyFactory; … … 43 51 import java.security.spec.X509EncodedKeySpec; 44 52 import java.util.ArrayList; 53 import java.util.Arrays; 45 54 import java.util.Collection; 46 55 import java.util.Enumeration; 56 import java.util.List; 57 import java.util.Properties; 47 58 48 59 import javax.swing.JOptionPane; 49 50 60 import org.openstreetmap.josm.Main; 51 61 … … 85 95 private static final String WINDOWS_ROOT = "Windows-ROOT"; 86 96 97 @Override 98 public void preStartupHook() { 99 extendFontconfig(); 100 } 101 102 /** 103 * Add more fallback fonts to the Java runtime, in order to get wider 104 * unicode support. 105 * 106 * The font configuration in Java doesn't include some Indic scripts, 107 * even though MS Windows ships with fonts that cover these unicode 108 * ranges. 109 * 110 * To fix this, the fontconfig.properties template is copied to the JOSM 111 * cache folder. Then, the additional entries are added to the font 112 * configuration. Finally the system property "sun.awt.fontconfig" is set 113 * to the customized fontconfig.properties file. 114 * 115 * This is a crude hack, but better than no font display at all for these 116 * languages. 117 * There is no guarantee, that the template file 118 * ($JAVA_HOME/lib/fontconfig.properties.src) matches the default 119 * configuration (which is in a binary format). 120 * Furthermore, the system property "sun.awt.fontconfig" is undocumented and 121 * may no longer work in future versions of Java. 122 */ 123 protected void extendFontconfig() { 124 String customFontconfigFile = Main.pref.get("fontconfig.properties", null); 125 if (customFontconfigFile != null) { 126 Utils.updateSystemProperty("sun.awt.fontconfig", customFontconfigFile); 127 return; 128 } 129 if (!Main.pref.getBoolean("font.extended-unicode", true)) 130 return; 131 String javaLibPath = System.getProperty("java.home") + File.separator + "lib"; 132 Path templateFile = FileSystems.getDefault().getPath(javaLibPath, "fontconfig.properties.src"); 133 if (!Files.isReadable(templateFile)) { 134 Main.warn("extended unicode - unable to find font config template file "+templateFile.toString()); 135 return; 136 } 137 try { 138 Properties props = new Properties(); 139 props.load(new FileInputStream(templateFile.toFile())); 140 byte[] content = Files.readAllBytes(templateFile); 141 File cachePath = Main.pref.getCacheDirectory(); 142 Path fontconfigFile = cachePath.toPath().resolve("fontconfig.properties"); 143 OutputStream os = Files.newOutputStream(fontconfigFile); 144 os.write(content); 145 try (Writer w = new BufferedWriter(new OutputStreamWriter(os))) { 146 Collection<Collection<String>> def = new ArrayList<>(); 147 def.add(Arrays.asList("devanagari", "", "")); // just include in fallback list 148 // no font definition needed 149 // all of the following fonts are available in Win XP and later 150 def.add(Arrays.asList("gujarati", "Shruti", "SHRUTI.TTF")); 151 def.add(Arrays.asList("kannada", "Tunga", "TUNGA.TTF")); 152 def.add(Arrays.asList("gurmuhi", "Raavi", "RAAVI.TTF")); 153 def.add(Arrays.asList("tamil", "Latha", "LATHA.TTF")); 154 def.add(Arrays.asList("telugu", "Gautami", "GAUTAMI.TTF")); 155 def.add(Arrays.asList("bengali", "Vrinda", "VRINDA.TTF")); 156 Collection<Collection<String>> additions = 157 Main.pref.getArray("font.extended-unicode.added-items", def); 158 w.append("\n\n# Added by JOSM to extend unicode coverage of Java font support:\n\n"); 159 List<String> allCharSubsets = new ArrayList<>(); 160 for (Collection<String> entry: additions) { 161 List<String> lentry = new ArrayList<>(entry); 162 String charSubset = lentry.get(0); 163 allCharSubsets.add(charSubset); 164 String platformFontName = lentry.get(1); 165 if ("".equals(platformFontName)) { 166 continue; 167 } 168 String key = "allfonts." + charSubset; 169 String value = platformFontName; 170 String prevValue = props.getProperty(key); 171 if (prevValue != null && !prevValue.equals(value)) { 172 Main.warn("extended unicode - overriding " + key + "=" + prevValue + " with " + value); 173 } 174 w.append(key + "=" + value + "\n"); 175 } 176 w.append("\n"); 177 for (Collection<String> entry: additions) { 178 List<String> lentry = new ArrayList<>(entry); 179 String platformFontName = lentry.get(1); 180 String fontFile = lentry.get(2); 181 if ("".equals(platformFontName) || "".equals(fontFile)) { 182 continue; 183 } 184 String key = "filename." + platformFontName; 185 String value = fontFile; 186 String prevValue = props.getProperty(key); 187 if (prevValue != null && !prevValue.equals(value)) { 188 Main.warn("extended unicode - overriding " + key + "=" + prevValue + " with " + value); 189 } 190 w.append(key + "=" + value + "\n"); 191 } 192 w.append("\n"); 193 String fallback = props.getProperty("sequence.fallback"); 194 if (fallback != null) { 195 w.append("sequence.fallback=" + fallback + "," + Utils.join(",", allCharSubsets) + "\n"); 196 } else { 197 w.append("sequence.fallback=" + Utils.join(",", allCharSubsets) + "\n"); 198 } 199 } 200 Utils.updateSystemProperty("sun.awt.fontconfig", fontconfigFile.toString()); 201 } catch (IOException ex) { 202 Main.error(ex); 203 } 204 } 205 87 206 @Override 88 207 public void openUrl(String url) throws IOException {
Note:
See TracChangeset
for help on using the changeset viewer.