Merge FontLoaderImpl into FontLoader and make it a class

This commit is contained in:
Paul Campbell 2020-09-18 18:39:47 +01:00
parent 4800f7720a
commit 9020950d90
2 changed files with 27 additions and 37 deletions

View file

@ -1,9 +1,32 @@
package net.kemitix.fontface; package net.kemitix.fontface;
import net.kemitix.fontface.FontFace;
import java.awt.*; 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 FontLoader {
private static final Logger LOGGER =
Logger.getLogger(
FontLoader.class.getName());
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);
}
}
public interface FontLoader {
Font loadFont(FontFace fontFace);
} }

View file

@ -1,33 +0,0 @@
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);
}
}
}