Skip to content

Commit

Permalink
Cache resolved fonts. Resolves #149
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Mar 11, 2022
1 parent 615e8da commit 071219d
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import org.kordamp.ikonli.AbstractIkonResolver;
import org.kordamp.ikonli.IkonHandler;

import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.Set;

Expand All @@ -32,14 +34,16 @@ public class IkonResolver extends AbstractIkonResolver {
private static final IkonResolver INSTANCE;
private static final Set<IkonHandler> HANDLERS = new LinkedHashSet<>();
private static final Set<IkonHandler> CUSTOM_HANDLERS = new LinkedHashSet<>();
private static final Map<String, Font> FONTS = new LinkedHashMap<>();

static {
INSTANCE = new IkonResolver();

ServiceLoader<IkonHandler> loader = resolveServiceLoader();
for (IkonHandler handler : loader) {
HANDLERS.add(handler);
handler.setFont(Font.loadFont(handler.getFontResource().toExternalForm(), 16));
String fontResource = handler.getFontResource().toExternalForm();
handler.setFont(FONTS.computeIfAbsent(fontResource, key -> Font.loadFont(key, 16)));
}
}

Expand Down

0 comments on commit 071219d

Please sign in to comment.