Crossfire JXClient, Trunk
FontParser.java
Go to the documentation of this file.
1 /*
2  * This file is part of JXClient, the Fullscreen Java Crossfire Client.
3  *
4  * JXClient is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * JXClient is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with JXClient; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * Copyright (C) 2005-2008 Yann Chachkoff
19  * Copyright (C) 2006-2017,2019-2023 Andreas Kirschbaum
20  * Copyright (C) 2010-2012,2014-2018,2020-2023 Nicolas Weeger
21  */
22 
23 package com.realtime.crossfire.jxclient.skin.io;
24 
26 import java.awt.Font;
27 import java.awt.FontFormatException;
28 import java.io.IOException;
29 import java.io.InputStream;
30 import org.jetbrains.annotations.NotNull;
31 
36 public class FontParser {
37 
41  @NotNull
42  private final JXCSkinSource skinSource;
43 
48  public FontParser(@NotNull final JXCSkinSource skinSource) {
49  this.skinSource = skinSource;
50  }
51 
58  @NotNull
59  public Font getFont(@NotNull final String name) throws IOException {
60  final String filename = "fonts/"+name+".ttf";
61 
62  final Font font;
63  try {
64  try (InputStream ttf = skinSource.getInputStream(filename)) {
65  try {
66  font = Font.createFont(Font.TRUETYPE_FONT, ttf);
67  } catch (final FontFormatException ex) {
68  throw new IOException(filename+": invalid font format: "+ex.getMessage(), ex);
69  }
70  }
71  } catch (final IOException ex) {
72  throw new IOException(skinSource.getURI(filename)+": i/o error: "+ex.getMessage(), ex);
73  }
74  return font;
75  }
76 
77 }
com.realtime.crossfire.jxclient
com.realtime.crossfire.jxclient.skin
com.realtime.crossfire.jxclient.skin.source
Definition: AbstractJXCSkinSource.java:23
com.realtime.crossfire.jxclient.skin.source.JXCSkinSource.getInputStream
InputStream getInputStream(@NotNull String name)
com.realtime.crossfire.jxclient.skin.io.FontParser.FontParser
FontParser(@NotNull final JXCSkinSource skinSource)
Definition: FontParser.java:48
com.realtime.crossfire.jxclient.skin.source.JXCSkinSource
Definition: JXCSkinSource.java:34
com.realtime.crossfire.jxclient.skin.source.JXCSkinSource.getURI
String getURI(@NotNull String name)
com.realtime.crossfire
com.realtime
com
com.realtime.crossfire.jxclient.skin.io.FontParser.getFont
Font getFont(@NotNull final String name)
Definition: FontParser.java:59
com.realtime.crossfire.jxclient.skin.io.FontParser
Definition: FontParser.java:36
com.realtime.crossfire.jxclient.skin.io.FontParser.skinSource
final JXCSkinSource skinSource
Definition: FontParser.java:42