Jump to content

Loading a custom font in script


Recommended Posts

Posted

Hey, how can I load a custom font into my script?

I've tried the following but to no success, what am I doing wrong?

 

  1. Create a resources folder in the same level as the src folder and mark it as a resources root directory + include the files in the JAR.
  2. place the font inside resources/fonts/Speedy.ttf 
  3. load the font with the following code:
    1.         try {
                  InputStream is = getClass().getClassLoader().getResourceAsStream("fonts/Speedy.ttf");
                  speedy = Font.createFont(Font.TRUETYPE_FONT, is);
              } catch (FontFormatException | IOException e) {
                  api.log(e.getMessage());
                  throw new RuntimeException();
              }
  4.  g.setFont(speedy);
  5. I get the following error:
    [INFO][Bot #1][08/11 10:39:08 em]: Stream closed
    [ERROR][08/11 10:39:08 em]: Uncaught exception!
    java.lang.RuntimeException: java.io.IOException: Stream closed
    	at com.psyfisher.ui.Paint.loadResources(Paint.java:72)
    	at com.psyfisher.ui.Paint.onStart(Paint.java:37)
    	at com.psyfisher.ui.Paint.<init>(Paint.java:31)
    	at com.psyfisher.PsyFisher.setRunning(PsyFisher.java:78)
    	at com.psyfisher.ui.Settings.lambda$createStartButton$0(Settings.java:124)
    	at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967)
    	at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308)
    	at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
    	at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
    	at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279)
    	at org.pushingpixels.substance.internal.utils.RolloverButtonListener.mouseReleased(RolloverButtonListener.java:108)
    	at java.desktop/java.awt.Component.processMouseEvent(Component.java:6635)
    	at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342)
    	at java.desktop/java.awt.Component.processEvent(Component.java:6400)
    	at java.desktop/java.awt.Container.processEvent(Container.java:2263)
    	at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5011)
    	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
    	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4843)
    	at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4918)
    	at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4547)
    	at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4488)
    	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307)
    	at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2772)
    	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4843)
    	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)
    	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
    	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
    	at java.base/java.security.AccessController.doPrivileged(Native Method)
    	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
    	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
    	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743)
    	at java.base/java.security.AccessController.doPrivileged(Native Method)
    	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
    	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
    	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
    	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:117)
    	at java.desktop/java.awt.WaitDispatchSupport$2.run(WaitDispatchSupport.java:190)
    	at java.desktop/java.awt.WaitDispatchSupport$4.run(WaitDispatchSupport.java:235)
    	at java.desktop/java.awt.WaitDispatchSupport$4.run(WaitDispatchSupport.java:233)
    	at java.base/java.security.AccessController.doPrivileged(Native Method)
    	at java.desktop/java.awt.WaitDispatchSupport.enter(WaitDispatchSupport.java:233)
    	at java.desktop/java.awt.Dialog.show(Dialog.java:1070)
    	at java.desktop/java.awt.Component.show(Component.java:1716)
    	at java.desktop/java.awt.Component.setVisible(Component.java:1663)
    	at java.desktop/java.awt.Window.setVisible(Window.java:1031)
    	at java.desktop/java.awt.Dialog.setVisible(Dialog.java:1005)
    	at com.psyfisher.ui.Settings.open(Settings.java:32)
    	at com.psyfisher.PsyFisher.lambda$initSettings$0(PsyFisher.java:58)
    	at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:303)
    	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
    	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
    	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
    	at java.base/java.security.AccessController.doPrivileged(Native Method)
    	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
    	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
    	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
    	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
    	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
    	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
    Caused by: java.io.IOException: Stream closed
    	at java.base/java.util.zip.InflaterInputStream.ensureOpen(InflaterInputStream.java:68)
    	at java.base/java.util.zip.InflaterInputStream.read(InflaterInputStream.java:143)
    	at java.base/java.io.FilterInputStream.read(FilterInputStream.java:107)
    	at java.desktop/java.awt.Font.createFont0(Font.java:1112)
    	at java.desktop/java.awt.Font.createFont(Font.java:1052)
    	at com.psyfisher.ui.Paint.loadResources(Paint.java:65)
    	... 62 more
Posted
5 hours ago, Explv said:

Try loading it from a URL instead, or put the font inside the OSBot/Data directory and load it from there.

Or, even better, download the font to the data directory, and then load it

Oh thanks! I'm quite new into this, how would I go about downloading the font to the data directory and then load it? Got any snippets for that? Thanks!! 🙂

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...