source: josm/trunk/src/org/openstreetmap/josm/tools/FontsManager.java@ 7395

Last change on this file since 7395 was 7383, checked in by bastiK, 10 years ago

applied #10301 - extend display of maxspeed nodes (patch by Klumbumbus)
Include Droid Sans font in the JOSM binary distribution.
This unifies the font rendering on different platforms and allows geometric constructions with text (as demonstrated for maxspeed). Both regular and bold style are available.

  • Property svn:eol-style set to native
File size: 1.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.tools;
3
4import java.awt.Font;
5import java.awt.FontFormatException;
6import java.awt.GraphicsEnvironment;
7import java.io.IOException;
8import java.io.InputStream;
9import java.util.Arrays;
10import java.util.Collection;
11import java.util.Map;
12import org.openstreetmap.josm.io.CachedFile;
13
14public class FontsManager {
15
16 public static Map<String, Font> fonts;
17 public static Collection<String> includedFonts = Arrays.asList(
18 "DroidSans.ttf",
19 "DroidSans-Bold.ttf"
20 );
21
22 public static void initialize() {
23 GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
24 for (String fontFile : includedFonts) {
25 String url = "resource://data/fonts/"+fontFile;
26 try (InputStream i = new CachedFile(url).getInputStream())
27 {
28 Font f = Font.createFont(Font.TRUETYPE_FONT, i);
29 if (f == null) {
30 throw new RuntimeException("unable to load font: "+fontFile);
31 }
32 ge.registerFont(f);
33 } catch (IOException | FontFormatException ex) {
34 throw new RuntimeException(ex);
35 }
36 }
37 }
38}
Note: See TracBrowser for help on using the repository browser.