Add Font manager (#165)
Convert existing plugins which load fonts to use it
This commit is contained in:
@@ -25,7 +25,6 @@
|
||||
package net.runelite.client.plugins.devtools;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.ImageIcon;
|
||||
import net.runelite.api.widgets.Widget;
|
||||
@@ -33,6 +32,7 @@ import net.runelite.api.widgets.Widget;
|
||||
import net.runelite.client.RuneLite;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.ui.ClientUI;
|
||||
import net.runelite.client.ui.FontManager;
|
||||
import net.runelite.client.ui.NavigationButton;
|
||||
import net.runelite.client.ui.overlay.Overlay;
|
||||
|
||||
@@ -68,11 +68,8 @@ public class DevTools extends Plugin
|
||||
|
||||
ui.getPluginToolbar().addNavigation(navButton);
|
||||
|
||||
font = Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("/runescape.ttf"));
|
||||
|
||||
font = font.deriveFont(Font.BOLD, 16);
|
||||
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
ge.registerFont(font);
|
||||
font = FontManager.getRunescapeFont()
|
||||
.deriveFont(Font.BOLD, 16);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -26,8 +26,8 @@
|
||||
package net.runelite.client.plugins.fpsinfo;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.ui.FontManager;
|
||||
import net.runelite.client.ui.overlay.Overlay;
|
||||
|
||||
public class FPS extends Plugin
|
||||
@@ -39,10 +39,8 @@ public class FPS extends Plugin
|
||||
@Override
|
||||
protected void startUp() throws Exception
|
||||
{
|
||||
font = Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("/runescape.ttf"));
|
||||
font = font.deriveFont(Font.BOLD, 16);
|
||||
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
ge.registerFont(font);
|
||||
font = FontManager.getRunescapeFont()
|
||||
.deriveFont(Font.BOLD, 16);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
package net.runelite.client.plugins.implings;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import java.awt.Font;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import net.runelite.client.RuneLite;
|
||||
import net.runelite.client.events.ConfigChanged;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
@@ -43,16 +41,9 @@ public class Implings extends Plugin
|
||||
|
||||
private final ImplingsOverlay overlay = new ImplingsOverlay(this);
|
||||
|
||||
private Font font;
|
||||
|
||||
@Override
|
||||
protected void startUp() throws Exception
|
||||
{
|
||||
font = Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("/runescape.ttf"));
|
||||
font = font.deriveFont(Font.BOLD, 16);
|
||||
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
ge.registerFont(font);
|
||||
|
||||
// Initialize overlay config
|
||||
overlay.updateConfig();
|
||||
}
|
||||
|
||||
@@ -24,13 +24,12 @@
|
||||
*/
|
||||
package net.runelite.client.plugins.jewelrycount;
|
||||
|
||||
import java.awt.Font;
|
||||
import net.runelite.client.RuneLite;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.ui.FontManager;
|
||||
import net.runelite.client.ui.overlay.Overlay;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
|
||||
public class JewelryCount extends Plugin
|
||||
{
|
||||
private final JewelryCountConfig config = RuneLite.getRunelite().getConfigManager().getConfig(JewelryCountConfig.class);
|
||||
@@ -47,10 +46,8 @@ public class JewelryCount extends Plugin
|
||||
@Override
|
||||
protected void startUp() throws Exception
|
||||
{
|
||||
font = Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("/runescape_small.ttf"));
|
||||
font = font.deriveFont(Font.PLAIN, 16);
|
||||
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
ge.registerFont(font);
|
||||
font = FontManager.getRunescapeSmallFont()
|
||||
.deriveFont(Font.PLAIN, 16);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -25,8 +25,8 @@
|
||||
package net.runelite.client.plugins.pestcontrol;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.ui.FontManager;
|
||||
import net.runelite.client.ui.overlay.Overlay;
|
||||
|
||||
public class PestControl extends Plugin
|
||||
@@ -38,10 +38,8 @@ public class PestControl extends Plugin
|
||||
@Override
|
||||
protected void startUp() throws Exception
|
||||
{
|
||||
font = Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("/runescape.ttf"));
|
||||
font = font.deriveFont(Font.BOLD, 16);
|
||||
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
ge.registerFont(font);
|
||||
font = FontManager.getRunescapeFont()
|
||||
.deriveFont(Font.BOLD, 16);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -26,11 +26,8 @@ package net.runelite.client.plugins.runepouch;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.font.TextAttribute;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Map;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.GameState;
|
||||
import net.runelite.api.ItemID;
|
||||
@@ -40,6 +37,7 @@ import net.runelite.api.widgets.Widget;
|
||||
import net.runelite.api.widgets.WidgetInfo;
|
||||
import net.runelite.api.widgets.WidgetItem;
|
||||
import net.runelite.client.RuneLite;
|
||||
import net.runelite.client.ui.FontManager;
|
||||
import net.runelite.client.ui.overlay.Overlay;
|
||||
import net.runelite.client.ui.overlay.OverlayPosition;
|
||||
import net.runelite.client.ui.overlay.OverlayUtil;
|
||||
@@ -83,14 +81,7 @@ public class RunepouchOverlay extends Overlay
|
||||
return null;
|
||||
}
|
||||
|
||||
Font font = graphics.getFont();
|
||||
if (font.getSize() != 10)
|
||||
{
|
||||
Map attributes = font.getAttributes();
|
||||
attributes.put(TextAttribute.SIZE, 10);
|
||||
font = Font.getFont(attributes);
|
||||
graphics.setFont(font);
|
||||
}
|
||||
graphics.setFont(FontManager.getRunescapeSmallFont());
|
||||
|
||||
for (WidgetItem item : inventoryWidget.getWidgetItems())
|
||||
{
|
||||
|
||||
@@ -34,8 +34,6 @@ import net.runelite.client.events.GameStateChanged;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.ui.ClientUI;
|
||||
import net.runelite.client.ui.NavigationButton;
|
||||
import java.awt.Font;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import net.runelite.client.task.Schedule;
|
||||
|
||||
@@ -59,11 +57,6 @@ public class XPTracker extends Plugin
|
||||
|
||||
navButton.getButton().setText("XP");
|
||||
ui.getPluginToolbar().addNavigation(navButton);
|
||||
|
||||
Font font = Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("/runescape.ttf"));
|
||||
font = font.deriveFont(Font.BOLD, 16);
|
||||
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
ge.registerFont(font);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Tyler <https://github.com/tylerthardy>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.runelite.client.ui;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.FontFormatException;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.io.IOException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class FontManager
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(FontManager.class);
|
||||
|
||||
private static final Font runescapeFont;
|
||||
private static final Font runescapeSmallFont;
|
||||
|
||||
static
|
||||
{
|
||||
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
|
||||
try
|
||||
{
|
||||
runescapeFont = Font.createFont(Font.TRUETYPE_FONT,
|
||||
FontManager.class.getResourceAsStream("runescape.ttf"))
|
||||
.deriveFont(Font.PLAIN, 16);
|
||||
ge.registerFont(runescapeFont);
|
||||
|
||||
runescapeSmallFont = Font.createFont(Font.TRUETYPE_FONT,
|
||||
FontManager.class.getResourceAsStream("runescape_small.ttf"))
|
||||
.deriveFont(Font.PLAIN, 16);
|
||||
ge.registerFont(runescapeSmallFont);
|
||||
}
|
||||
catch (FontFormatException ex)
|
||||
{
|
||||
throw new RuntimeException("Font loaded, but format incorrect.", ex);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
throw new RuntimeException("Font file not found.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static Font getRunescapeFont()
|
||||
{
|
||||
return runescapeFont;
|
||||
}
|
||||
|
||||
public static Font getRunescapeSmallFont()
|
||||
{
|
||||
return runescapeSmallFont;
|
||||
}
|
||||
}
|
||||
45
runelite-client/src/test/java/net/runelite/cache/ui/FontManagerTest.java
vendored
Normal file
45
runelite-client/src/test/java/net/runelite/cache/ui/FontManagerTest.java
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Tyler <https://github.com/tylerthardy>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.runelite.cache.ui;
|
||||
|
||||
import net.runelite.client.ui.FontManager;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import org.junit.Test;
|
||||
|
||||
public class FontManagerTest
|
||||
{
|
||||
@Test
|
||||
public void getRunescapeFont()
|
||||
{
|
||||
assertNotNull(FontManager.getRunescapeFont());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRunescapeSmallFont()
|
||||
{
|
||||
assertNotNull(FontManager.getRunescapeSmallFont());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user