00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 package com.realtime.crossfire.jxclient.skin.io;
00023
00024 import com.realtime.crossfire.jxclient.skin.source.JXCSkinSource;
00025 import java.awt.Font;
00026 import java.awt.FontFormatException;
00027 import java.io.IOException;
00028 import java.io.InputStream;
00029 import org.jetbrains.annotations.NotNull;
00030
00035 public class FontParser {
00036
00040 @NotNull
00041 private final JXCSkinSource skinSource;
00042
00047 public FontParser(@NotNull final JXCSkinSource skinSource) {
00048 this.skinSource = skinSource;
00049 }
00050
00057 @NotNull
00058 public Font getFont(@NotNull final String name) throws IOException {
00059 final String filename = "fonts/"+name+".ttf";
00060
00061 final Font font;
00062 try {
00063 final InputStream ttf = skinSource.getInputStream(filename);
00064 try {
00065 try {
00066 font = Font.createFont(Font.TRUETYPE_FONT, ttf);
00067 } catch (final FontFormatException ex) {
00068 throw new IOException(filename+": invalid font format: "+ex.getMessage());
00069 }
00070 } finally {
00071 ttf.close();
00072 }
00073 } catch (final IOException ex) {
00074 throw new IOException(skinSource.getURI(filename)+": i/o error: "+ex.getMessage());
00075 }
00076 return font;
00077 }
00078
00079 }