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:
parent
904a54df26
commit
51b50843e5
BIN
res/kochi-gothic.ttf
Normal file
BIN
res/kochi-gothic.ttf
Normal file
Binary file not shown.
|
@ -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"))
|
|
||||||
fontName = "Arial Unicode MS";
|
|
||||||
else
|
|
||||||
fontName = "Lucida Sans Console";
|
|
||||||
|
|
||||||
Font font = new Font(fontName, Font.PLAIN, (int) (fontBase * 4 / 3));
|
|
||||||
FONT_DEFAULT = new UnicodeFont(font);
|
FONT_DEFAULT = new UnicodeFont(font);
|
||||||
FONT_BOLD = new UnicodeFont(font.deriveFont(Font.BOLD));
|
FONT_BOLD = new UnicodeFont(font.deriveFont(Font.BOLD));
|
||||||
FONT_XLARGE = new UnicodeFont(font.deriveFont(fontBase * 4));
|
FONT_XLARGE = new UnicodeFont(font.deriveFont(fontBase * 4));
|
||||||
FONT_LARGE = new UnicodeFont(font.deriveFont(fontBase * 2));
|
FONT_LARGE = new UnicodeFont(font.deriveFont(fontBase * 2));
|
||||||
FONT_MEDIUM = new UnicodeFont(font.deriveFont(fontBase * 3 / 2));
|
FONT_MEDIUM = new UnicodeFont(font.deriveFont(fontBase * 3 / 2));
|
||||||
FONT_SMALL = new UnicodeFont(font.deriveFont(fontBase));
|
FONT_SMALL = new UnicodeFont(font.deriveFont(fontBase));
|
||||||
FONT_DEFAULT.addAsciiGlyphs();
|
|
||||||
FONT_BOLD.addAsciiGlyphs();
|
|
||||||
FONT_XLARGE.addAsciiGlyphs();
|
|
||||||
FONT_LARGE.addAsciiGlyphs();
|
|
||||||
FONT_MEDIUM.addAsciiGlyphs();
|
|
||||||
FONT_SMALL.addAsciiGlyphs();
|
|
||||||
ColorEffect colorEffect = new ColorEffect();
|
ColorEffect colorEffect = new ColorEffect();
|
||||||
FONT_DEFAULT.getEffects().add(colorEffect);
|
loadFont(FONT_DEFAULT, 2, colorEffect);
|
||||||
FONT_BOLD.getEffects().add(colorEffect);
|
loadFont(FONT_BOLD, 2, colorEffect);
|
||||||
FONT_XLARGE.getEffects().add(colorEffect);
|
loadFont(FONT_XLARGE, 4, colorEffect);
|
||||||
FONT_LARGE.getEffects().add(colorEffect);
|
loadFont(FONT_LARGE, 4, colorEffect);
|
||||||
FONT_MEDIUM.getEffects().add(colorEffect);
|
loadFont(FONT_MEDIUM, 3, colorEffect);
|
||||||
FONT_SMALL.getEffects().add(colorEffect);
|
loadFont(FONT_SMALL, 1, colorEffect);
|
||||||
FONT_DEFAULT.loadGlyphs();
|
} catch (Exception e) {
|
||||||
FONT_BOLD.loadGlyphs();
|
Log.error("Failed to load fonts.", e);
|
||||||
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
|
||||||
|
|
|
@ -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.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue
Block a user