Slick Forums

Discuss the Slick 2D Library
It is currently Wed May 22, 2013 11:07 pm

All times are UTC




Post new topic Reply to topic  [ 15 posts ] 
Author Message
PostPosted: Mon Sep 14, 2009 9:06 pm 
Offline

Joined: Wed Jan 07, 2009 9:20 pm
Posts: 41
Hello,

I notice that when using fonts in italic, some of the top-right pixels get cut off in some letters and characters.

Here is a sample app to demonstrate the problem:

Code:
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.Font;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.TrueTypeFont;

public class FontTestGame extends BasicGame {
   private static Font font;

   private FontTestGame() throws SlickException {
      super("Font Tester");
   }
   
   public static void main(String[] args) throws SlickException {
      FontTestGame game = new FontTestGame();
      AppGameContainer container = new AppGameContainer(game, 640, 480, false);
      container.setSmoothDeltas(true);
         container.setVSync(true);
         container.setTargetFrameRate(60);
      container.start();
   }

   @Override
    public void init(GameContainer arg0) throws SlickException {
      font = new TrueTypeFont(new java.awt.Font("Arial", java.awt.Font.ITALIC, 26), true);
    }
   
   @Override
    public void update(GameContainer arg0, int arg1) throws SlickException {
    }
   
   public void render(GameContainer container, Graphics graphics) throws SlickException {
      graphics.setFont(font);
       graphics.drawString("Capital P, V and Y seem to suffer the most from this!", 30, 30);
    }
}


As you'll see from running it, P, V and Y are all missing a few pixels in the top-right; other characters do it too, but I thought these were the most obvious.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 14, 2009 11:01 pm 
Offline
Game Developer
User avatar

Joined: Sun May 25, 2008 9:45 am
Posts: 578
UnicodeFont has all the functionality of TrueTypeFont, plus more. More info here:
http://slick.javaunlimited.net/viewtopi ... 1189#11189

Kev, maybe we should remove TrueTypeFont?

_________________
SingSong Karaoke - http://singthegame.com


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 15, 2009 1:14 pm 
Offline

Joined: Wed Jan 07, 2009 9:20 pm
Posts: 41
Well I've tried replacing it with UnicodeFont but it's not working so far:

Code:
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.Color;
import org.newdawn.slick.Font;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.UnicodeFont;

public class FontTestGame extends BasicGame {
   private static Font font;

   private FontTestGame() throws SlickException {
      super("Font Tester");
   }
   
   public static void main(String[] args) throws SlickException {
      FontTestGame game = new FontTestGame();
      AppGameContainer container = new AppGameContainer(game, 640, 480, false);
      container.setSmoothDeltas(true);
         container.setVSync(true);
         container.setTargetFrameRate(60);
      container.start();
   }

   @Override
    public void init(GameContainer arg0) throws SlickException {
      font = new UnicodeFont(new java.awt.Font("Arial", java.awt.Font.ITALIC, 26));
    }
   
   @Override
    public void update(GameContainer arg0, int arg1) throws SlickException {
    }
   
   public void render(GameContainer container, Graphics graphics) throws SlickException {
      graphics.setFont(font);
      graphics.setColor(Color.white);
       graphics.drawString("Capital P, V and Y seem to suffer the most from this!", 30, 30);
      
      font.drawString(30, 80, "Does this work?");
    }
}


When I run this, nothing gets displayed at all. I tried rendering from the graphics and font itself, but neither is working, at least not on OS X.

I also tried using the UnicodeFont(String, int, boolean, boolean) constructor instead of the one with a java.awt.Font, but that one would crash immediately saying it couldn't find the font. I see that in the UnicodeFontTest class, a complete windows path is being specified to load the font (which also crashes for me on OS X).

Shouldn't the constructor using a String parameter perform the same lookup as java.awt.Font to find its TTF? Seems like that would be the most convenient variant to use.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 15, 2009 8:02 pm 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
Any progress on this. Unicode font test still seems to be working.

Kev


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 15, 2009 9:48 pm 
Offline

Joined: Wed Jan 07, 2009 9:20 pm
Posts: 41
I'm guessing UnicodeFontTest only works under Windows but not other OSes due to this line:

Code:
      unicodeFont = new UnicodeFont("c:/windows/fonts/arial.ttf", 48, false, false);


Shouldn't it be able to find the right path by itself so that the user code is not OS-dependent?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 16, 2009 5:59 am 
Offline
Game Developer
User avatar

Joined: Sun May 25, 2008 9:45 am
Posts: 578
You can either load a TTF font file yourself, or use java.awt.Font to find a system supplied font. You are right though, the test shouldn't have a Windows path in it!

Try this:

Code:
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.UnicodeFont;
import org.newdawn.slick.font.effects.ColorEffect;

public class FontTestGame extends BasicGame {
   private static UnicodeFont font;

   private FontTestGame () throws SlickException {
      super("Font Tester");
   }

   public static void main (String[] args) throws SlickException {
      FontTestGame game = new FontTestGame();
      AppGameContainer container = new AppGameContainer(game, 640, 480, false);
      container.setSmoothDeltas(true);
      container.setVSync(true);
      container.setTargetFrameRate(60);
      container.start();
   }

   public void init (GameContainer container) throws SlickException {
      font = new UnicodeFont(new java.awt.Font("Arial", java.awt.Font.ITALIC, 26));

      // Fonts are drawn using org.newdawn.slick.font.effects.Effect. Without at least one effect, nothing is drawn.
      // If you use a .hiero file saved with the Hiero tool, then you don't need to add effects programmatically.
      // This is a simple effect that just fills in the glyphs with a color.
      // White lets us tint the font to any color at runtime.
      font.getEffects().add(new ColorEffect(java.awt.Color.white));

      // A TrueType font can contain 65536 glyphs. We don't want to load all possible glyphs up front!
      // This code adds the glyphs in the ASCII range (32 to 255) then tells the font to load them.
      font.addAsciiGlyphs();
      font.loadGlyphs();
   }

   public void update (GameContainer container, int delta) throws SlickException {
   }

   public void render (GameContainer container, Graphics g) throws SlickException {
      g.setFont(font);
      g.setColor(Color.white);
      g.drawString("Capital P, V and Y seem to suffer the most from this!", 30, 30);

      font.drawString(30, 80, "Does this work?", Color.red); // Text tinted red.

      // If a font is asked to draw glyphs it does not have loaded, they are added to the font.
      // Calling this in the game loop causes any unloaded glyphs to be loaded on the fly.
      font.loadGlyphs(5);
      // If you only need ASCII, you can preload all the glyphs and don't need this in the game loop.
      // On the fly loading is required when you can't know all glyphs needed up front.
      // Eg, imagine someone typing Chinese charatcers into a text box.
   }
}

_________________
SingSong Karaoke - http://singthegame.com


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 16, 2009 12:31 pm 
Offline

Joined: Wed Jan 07, 2009 9:20 pm
Posts: 41
Thanks Nate, this last example does the trick.

However, the FPS system display is somehow jumbled up.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 17, 2009 9:15 am 
Offline
Game Developer
User avatar

Joined: Sun May 25, 2008 9:45 am
Posts: 578
Running the exact code I posted? The FPS display is working fine for me with that, on XP.

_________________
SingSong Karaoke - http://singthegame.com


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 17, 2009 12:27 pm 
Offline

Joined: Wed Jan 07, 2009 9:20 pm
Posts: 41
Yes, running this exact code in OS X, the FPS display gets jumbled up.

I am having similar issues after changing the fonts in my game to Unicode. A few images in a few screens now appear jumbled up or not at all. It appears to be random, but it's not, since it's always the same images on the same screens that suffer from this. Looks like possibly a memory leak going on somewhere. I'll try and gather more accurate info with some more testing.

The good news at least is that this fixes my original issue with fonts being cutoff. I also the texts now take a bit more horizontal space as a result, though, but I am going to deal with that for a better looking text.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 17, 2009 2:39 pm 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
Have you got the latest build? There were lots of issues with display lists/caches getting overwritten in fonts a while ago.

Kev


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 17, 2009 5:46 pm 
Offline

Joined: Wed Jan 07, 2009 9:20 pm
Posts: 41
Well I am using the "official" 0.3, plus the music patches I have proposed in the other thread. If there have been changes since, I could indeed try updating and see if it makes a difference.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 17, 2009 5:55 pm 
Offline
Game Developer
User avatar

Joined: Sun Nov 12, 2006 8:40 pm
Posts: 574
theres been tons of fixes since the 0.3 release, better to get the full distribution or download library version of slick as that is usually more close to the svn version.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 17, 2009 5:59 pm 
Offline

Joined: Wed Jan 07, 2009 9:20 pm
Posts: 41
Well I just got the latest SVN version as I was creating a patch for the music fixes, so I'll give that a try tonight when I'm back on my Mac.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 18, 2009 12:39 am 
Offline

Joined: Wed Jan 07, 2009 9:20 pm
Posts: 41
That was it. The weird visual bugs are gone using the latest Slick from SVN and UnicodeFont. Thanks, guys!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 18, 2009 10:00 am 
Offline
Game Developer
User avatar

Joined: Sun May 25, 2008 9:45 am
Posts: 578
Sweet! :)

_________________
SingSong Karaoke - http://singthegame.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group