From 9020950d9016c268b4e4f65c1d1ce95296827446 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 18 Sep 2020 18:39:47 +0100 Subject: [PATCH] Merge FontLoaderImpl into FontLoader and make it a class --- .../java/net/kemitix/fontface/FontLoader.java | 31 ++++++++++++++--- .../net/kemitix/fontface/FontLoaderImpl.java | 33 ------------------- 2 files changed, 27 insertions(+), 37 deletions(-) delete mode 100644 src/main/java/net/kemitix/fontface/FontLoaderImpl.java diff --git a/src/main/java/net/kemitix/fontface/FontLoader.java b/src/main/java/net/kemitix/fontface/FontLoader.java index af6ad4b..e08527a 100644 --- a/src/main/java/net/kemitix/fontface/FontLoader.java +++ b/src/main/java/net/kemitix/fontface/FontLoader.java @@ -1,9 +1,32 @@ package net.kemitix.fontface; -import net.kemitix.fontface.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 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 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); } diff --git a/src/main/java/net/kemitix/fontface/FontLoaderImpl.java b/src/main/java/net/kemitix/fontface/FontLoaderImpl.java deleted file mode 100644 index f60a34c..0000000 --- a/src/main/java/net/kemitix/fontface/FontLoaderImpl.java +++ /dev/null @@ -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 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); - } - } - -}