Add FontLoaderImpl
This commit is contained in:
parent
72fcb570fa
commit
4fbd648eeb
1 changed files with 33 additions and 0 deletions
33
src/main/java/net/kemitix/fontface/FontLoaderImpl.java
Normal file
33
src/main/java/net/kemitix/fontface/FontLoaderImpl.java
Normal 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue