Last change
on this file since 11073 was 9639, checked in by stoecker, 8 years ago |
fix possible resource leaks
|
-
Property svn:eol-style
set to
native
|
File size:
1.4 KB
|
Rev | Line | |
---|
[7383] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.tools;
|
---|
| 3 |
|
---|
| 4 | import java.awt.Font;
|
---|
| 5 | import java.awt.FontFormatException;
|
---|
| 6 | import java.awt.GraphicsEnvironment;
|
---|
| 7 | import java.io.IOException;
|
---|
| 8 | import java.io.InputStream;
|
---|
| 9 | import java.util.Arrays;
|
---|
| 10 | import java.util.Collection;
|
---|
[7402] | 11 |
|
---|
[7383] | 12 | import 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 | */
|
---|
[8419] | 19 | public final class FontsManager {
|
---|
[7383] | 20 |
|
---|
[7402] | 21 | /**
|
---|
| 22 | * List of fonts embedded into JOSM jar.
|
---|
| 23 | */
|
---|
[8882] | 24 | private 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;
|
---|
[9639] | 40 | try (CachedFile cf = new CachedFile(url); InputStream i = cf.getInputStream()) {
|
---|
[8308] | 41 | ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, i));
|
---|
[7383] | 42 | } catch (IOException | FontFormatException ex) {
|
---|
| 43 | throw new RuntimeException(ex);
|
---|
| 44 | }
|
---|
| 45 | }
|
---|
| 46 | }
|
---|
| 47 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.