Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
josm/src/org/openstreetmap/josm/tools/FontsManager.java /
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
47 lines (41 sloc)
1.34 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // License: GPL. For details, see LICENSE file. | |
| package org.openstreetmap.josm.tools; | |
| import java.awt.Font; | |
| import java.awt.FontFormatException; | |
| import java.awt.GraphicsEnvironment; | |
| import java.io.IOException; | |
| import java.io.InputStream; | |
| import java.util.Arrays; | |
| import java.util.Collection; | |
| import org.openstreetmap.josm.io.CachedFile; | |
| /** | |
| * Custom fonts manager that provides some embedded fonts to ensure | |
| * a common rendering on different platforms. | |
| * @since 7383 | |
| */ | |
| public final class FontsManager { | |
| /** | |
| * List of fonts embedded into JOSM jar. | |
| */ | |
| public static final Collection<String> INCLUDED_FONTS = Arrays.asList( | |
| "DroidSans.ttf", | |
| "DroidSans-Bold.ttf" | |
| ); | |
| private FontsManager() { | |
| // Hide constructor for utility classes | |
| } | |
| /** | |
| * Initializes the fonts manager. | |
| */ | |
| public static void initialize() { | |
| GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); | |
| for (String fontFile : INCLUDED_FONTS) { | |
| String url = "resource://data/fonts/"+fontFile; | |
| try (InputStream i = new CachedFile(url).getInputStream()) { | |
| ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, i)); | |
| } catch (IOException | FontFormatException ex) { | |
| throw new RuntimeException(ex); | |
| } | |
| } | |
| } | |
| } |