From 4fbd648eeb43b5143bba87e5e63fe56d5b8d5769 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 18 Sep 2020 18:27:32 +0100 Subject: [PATCH] Add FontLoaderImpl --- .../net/kemitix/fontface/FontLoaderImpl.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/main/java/net/kemitix/fontface/FontLoaderImpl.java diff --git a/src/main/java/net/kemitix/fontface/FontLoaderImpl.java b/src/main/java/net/kemitix/fontface/FontLoaderImpl.java new file mode 100644 index 0000000..f60a34c --- /dev/null +++ b/src/main/java/net/kemitix/fontface/FontLoaderImpl.java @@ -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 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); + } + } + +}