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

Last change on this file since 8241 was 7402, checked in by Don-vip, 10 years ago

fix some Sonar issues

  • Property svn:eol-style set to native
File size: 1.5 KB
RevLine 
[7383]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;
[7402]11
[7383]12import org.openstreetmap.josm.io.CachedFile;
13
[7402]14/**
15 * Custom fonts manager that provides some embedded fonts to ensure
16 * a common rendering on different platforms.
17 * @since 7383
18 */
[7383]19public class FontsManager {
20
[7402]21 /**
22 * List of fonts embedded into JOSM jar.
23 */
24 public static final Collection<String> INCLUDED_FONTS = Arrays.asList(
[7383]25 "DroidSans.ttf",
26 "DroidSans-Bold.ttf"
27 );
[7402]28
29 private FontsManager() {
30 // Hide constructor for utility classes
31 }
32
33 /**
34 * Initializes the fonts manager.
35 */
[7383]36 public static void initialize() {
37 GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
[7402]38 for (String fontFile : INCLUDED_FONTS) {
[7383]39 String url = "resource://data/fonts/"+fontFile;
[7402]40 try (InputStream i = new CachedFile(url).getInputStream()) {
[7383]41 Font f = Font.createFont(Font.TRUETYPE_FONT, i);
42 if (f == null) {
43 throw new RuntimeException("unable to load font: "+fontFile);
44 }
45 ge.registerFont(f);
46 } catch (IOException | FontFormatException ex) {
47 throw new RuntimeException(ex);
48 }
49 }
50 }
51}
Note: See TracBrowser for help on using the repository browser.