Added "Kochi Gothic" font.

- Provides cross-platform CJK support. (follow-up to 904a54d)

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2014-08-25 12:47:10 -04:00
parent 904a54df26
commit 51b50843e5
3 changed files with 42 additions and 37 deletions

BIN
res/kochi-gothic.ttf Normal file

Binary file not shown.

View File

@ -21,10 +21,8 @@ package itdelatrisu.opsu;
import itdelatrisu.opsu.states.Options; import itdelatrisu.opsu.states.Options;
import java.awt.Font; import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.io.File; import java.io.File;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
@ -44,6 +42,7 @@ import org.newdawn.slick.font.effects.ColorEffect;
import org.newdawn.slick.imageout.ImageOut; import org.newdawn.slick.imageout.ImageOut;
import org.newdawn.slick.state.StateBasedGame; import org.newdawn.slick.state.StateBasedGame;
import org.newdawn.slick.util.Log; import org.newdawn.slick.util.Log;
import org.newdawn.slick.util.ResourceLoader;
/** /**
* Contains miscellaneous utilities. * Contains miscellaneous utilities.
@ -126,7 +125,6 @@ public class Utils {
* @param game the game object * @param game the game object
* @throws SlickException * @throws SlickException
*/ */
@SuppressWarnings("unchecked")
public static void init(GameContainer container, StateBasedGame game) public static void init(GameContainer container, StateBasedGame game)
throws SlickException { throws SlickException {
Utils.container = container; Utils.container = container;
@ -164,40 +162,25 @@ public class Utils {
else else
fontBase = 15f; fontBase = 15f;
// TODO: cross-platform multilingual support try {
String fontName = ""; Font javaFont = Font.createFont(Font.TRUETYPE_FONT, ResourceLoader.getResourceAsStream(Options.FONT_NAME));
String[] fontNames = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); Font font = javaFont.deriveFont(Font.PLAIN, (int) (fontBase * 4 / 3));
if (Arrays.asList(fontNames).contains("Arial Unicode MS")) FONT_DEFAULT = new UnicodeFont(font);
fontName = "Arial Unicode MS"; FONT_BOLD = new UnicodeFont(font.deriveFont(Font.BOLD));
else FONT_XLARGE = new UnicodeFont(font.deriveFont(fontBase * 4));
fontName = "Lucida Sans Console"; FONT_LARGE = new UnicodeFont(font.deriveFont(fontBase * 2));
FONT_MEDIUM = new UnicodeFont(font.deriveFont(fontBase * 3 / 2));
Font font = new Font(fontName, Font.PLAIN, (int) (fontBase * 4 / 3)); FONT_SMALL = new UnicodeFont(font.deriveFont(fontBase));
FONT_DEFAULT = new UnicodeFont(font); ColorEffect colorEffect = new ColorEffect();
FONT_BOLD = new UnicodeFont(font.deriveFont(Font.BOLD)); loadFont(FONT_DEFAULT, 2, colorEffect);
FONT_XLARGE = new UnicodeFont(font.deriveFont(fontBase * 4)); loadFont(FONT_BOLD, 2, colorEffect);
FONT_LARGE = new UnicodeFont(font.deriveFont(fontBase * 2)); loadFont(FONT_XLARGE, 4, colorEffect);
FONT_MEDIUM = new UnicodeFont(font.deriveFont(fontBase * 3 / 2)); loadFont(FONT_LARGE, 4, colorEffect);
FONT_SMALL = new UnicodeFont(font.deriveFont(fontBase)); loadFont(FONT_MEDIUM, 3, colorEffect);
FONT_DEFAULT.addAsciiGlyphs(); loadFont(FONT_SMALL, 1, colorEffect);
FONT_BOLD.addAsciiGlyphs(); } catch (Exception e) {
FONT_XLARGE.addAsciiGlyphs(); Log.error("Failed to load fonts.", e);
FONT_LARGE.addAsciiGlyphs(); }
FONT_MEDIUM.addAsciiGlyphs();
FONT_SMALL.addAsciiGlyphs();
ColorEffect colorEffect = new ColorEffect();
FONT_DEFAULT.getEffects().add(colorEffect);
FONT_BOLD.getEffects().add(colorEffect);
FONT_XLARGE.getEffects().add(colorEffect);
FONT_LARGE.getEffects().add(colorEffect);
FONT_MEDIUM.getEffects().add(colorEffect);
FONT_SMALL.getEffects().add(colorEffect);
FONT_DEFAULT.loadGlyphs();
FONT_BOLD.loadGlyphs();
FONT_XLARGE.loadGlyphs();
FONT_LARGE.loadGlyphs();
FONT_MEDIUM.loadGlyphs();
FONT_SMALL.loadGlyphs();
// tab image // tab image
tab = new Image("selection-tab.png"); tab = new Image("selection-tab.png");
@ -502,6 +485,23 @@ public class Utils {
return true; return true;
} }
/**
* Loads a Unicode font.
* @param font the font to load
* @param padding the top and bottom padding
* @param colorEffect the ColorEffect
* @throws SlickException
*/
@SuppressWarnings("unchecked")
private static void loadFont(UnicodeFont font, int padding,
ColorEffect colorEffect) throws SlickException {
font.setPaddingTop(padding);
font.setPaddingBottom(padding);
font.addAsciiGlyphs();
font.getEffects().add(colorEffect);
font.loadGlyphs();
}
/** /**
* Adds and loads glyphs for an OsuFile's Unicode title and artist strings. * Adds and loads glyphs for an OsuFile's Unicode title and artist strings.
* @param osu the OsuFile * @param osu the OsuFile

View File

@ -78,6 +78,11 @@ public class Options extends BasicGameState {
"Songs/" "Songs/"
}; };
/**
* Font file name.
*/
public static final String FONT_NAME = "kochi-gothic.ttf";
/** /**
* The beatmap directory. * The beatmap directory.
*/ */