This site requires JavaScript, please enable it in your browser!
Greenfoot back
GregC246
GregC246 wrote ...

2012/9/10

Fonts

GregC246 GregC246

2012/9/10

#
Any way to get custom fonts to work with a web applet?
GregC246 GregC246

2012/9/11

#
Bump
groengeel groengeel

2012/9/11

#
I'm not good enough at this to get you a full working example. But I'm guessing you're looking in these directions: Check setFont() method in GreenfootImage: http://www.greenfoot.org/files/javadoc/ There I found it's using java.awt.Font, after Googling I found this: http://www.java2s.com/Tutorial/Java/0261__2D-Graphics/javaawtFont.htm I just hope this helps. If you fix it, please post your answer here.. ;-)
GregC246 GregC246

2012/9/11

#
Thanks for replying. My problem isn't getting fonts to work, though, it is getting the font file. Since the web applets are a .jar file (the files of which can't be used in setFont()) and I can't use external resources (because it's a web app), I'm stuck as to how to actually get the file. I might be able to get it to work.
GregC246 GregC246

2012/9/12

#
Got it to work using input streams rather than a "File".
font = new Font("q",0,0);
        String path = Glo.class.getProtectionDomain().getCodeSource().getLocation().getPath();
        InputStream is = Glo.class.getResourceAsStream("resources/Vdj.ttf");
        Font uniFont = null;
           try {
            //font = Font.createFont(0,new File(+"resources\\Vdj.ttf"));//  "File" does not work with .jars
            uniFont=Font.createFont(Font.TRUETYPE_FONT,is);
         }
        catch(java.awt.FontFormatException r){
            System.err.println("FontFormatException: " + r.getMessage());

        }
        catch(java.io.IOException r){
            System.err.println("FontFormatException: " + r.getMessage());

        }
       font = uniFont.deriveFont(24f);
groengeel groengeel

2012/9/12

#
Cool!
You need to login to post a reply.