Add FontLoaderImpl

This commit is contained in:
Paul Campbell 2020-09-18 18:27:32 +01:00
parent 72fcb570fa
commit 4fbd648eeb

View file

@ -0,0 +1,33 @@
package net.kemitix.fontface;
import java.awt.*;
import java.awt.font.TextAttribute;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
public class FontLoaderImpl implements FontLoader {
private static final Logger LOGGER =
Logger.getLogger(
FontLoaderImpl.class.getName());
@Override
public Font loadFont(final FontFace fontFace) {
URI fontUri = fontFace.getFontLocation();
LOGGER.info(String.format("Loading %s", fontUri));
final Map<TextAttribute, Object> map = new HashMap<>();
//map.put(TextAttribute.LIGATURES, TextAttribute.LIGATURES_ON);
map.put(TextAttribute.KERNING, TextAttribute.KERNING_ON);
try {
return Font.createFont(Font.TRUETYPE_FONT, new File(fontUri))
.deriveFont(map);
} catch (final FontFormatException | IOException e) {
throw new FatalFontFaceError("Font load error", e);
}
}
}