Slick Forums

Discuss the Slick 2D Library
It is currently Wed Jun 19, 2013 12:05 pm

All times are UTC




Post new topic Reply to topic  [ 37 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: True Type Fonts?
PostPosted: Sat Oct 03, 2009 9:44 pm 
Offline
Regular

Joined: Sun Oct 05, 2008 9:24 pm
Posts: 173
I keep getting warnings that TrueTypeFont is now deprecated:

Code:
The type TrueTypeFont is deprecated   Hud.java   /game/src    line 32   Java Problem


I'm using it the way the wiki suggestions: http://slick.cokeandcode.com/wiki/doku. ... nt_support

What is the "new and correct" way to use these?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 03, 2009 9:55 pm 
Offline
Regular
User avatar

Joined: Thu Dec 18, 2008 6:07 pm
Posts: 238
Location: Bournemouth, UK
See UnicodeFont.
Maybe kev should put in a valid @see tag in the javadoc!

_________________
- Gwinnell (irc.freenode.net, irc.chatspike.net)
- Game Jolt Moderator


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 05, 2009 2:26 am 
Offline
Regular

Joined: Sun Oct 05, 2008 9:24 pm
Posts: 173
hrm, doesn't seem to be working:

Code:
      font = new Font("Verdana", Font.PLAIN, 40);
      tfont = new UnicodeFont(font);
      tfont.drawString(0,0, message, Color.white);


displays nothing to screen. Gives no warnings or errors.

TrueTypeFont works just fine...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 13, 2009 12:38 am 
Offline
Regular

Joined: Sun Dec 07, 2008 5:22 am
Posts: 238
Location: Vancouver, BC, Canada
Nothing displays because you haven't loaded any glyphs yet.
Try:
Code:
    tfont.getEffects().add(new ColorEffect(java.awt.Color.white));
    tfont.addAsciiGlyphs();
    tfont.loadGlyphs();
    tfont.drawString(0,0, message, Color.white);
I'm not sure why exactly but you need to have at least one effect added before you can load glyphs.

_________________
If at first quads don't succeed tri tri again.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 13, 2009 1:32 am 
Offline
Regular

Joined: Sun Oct 05, 2008 9:24 pm
Posts: 173
Chronocide wrote:
Nothing displays because you haven't loaded any glyphs yet.
Try:
Code:
    tfont.getEffects().add(new ColorEffect(java.awt.Color.white));
    tfont.addAsciiGlyphs();
    tfont.loadGlyphs();
    tfont.drawString(0,0, message, Color.white);
I'm not sure why exactly but you need to have at least one effect added before you can load glyphs.

Thanks.

wiki updated: http://slick.cokeandcode.com/wiki/doku. ... ser_manual


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 24, 2009 5:10 am 
Offline
Oldbie

Joined: Tue Jun 17, 2008 5:11 pm
Posts: 336
I just ran into this issue. Why is the API so bad for the UnicodeFont class? I mean the TrueTypeFont was inconvenient but this is a joke! It fails to draw anything and there's no error, no warning, no documentation... Who would think to call this incantation to get the fonts to work??

We should have the class add the ASCII glyphs and a color effect at construction so that this issue doesn't come up. Users can override these settings if they want something else.

_________________
My website about game development http://anotherearlymorning.com


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 24, 2009 5:14 am 
Offline
Oldbie

Joined: Tue Jun 17, 2008 5:11 pm
Posts: 336
Sorry to double post but I have to vent a little more.

1. Why do I need to call getEffects.add instead of just addEffect? I would never guess that was how to set an effect on the font object, it just seems like bad form to have to call a getter to perform a set.
2. Why oh why does the color effect take a AWT color and not a Slick color?!?

_________________
My website about game development http://anotherearlymorning.com


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 24, 2009 5:24 am 
Offline
Regular

Joined: Sun Dec 07, 2008 5:22 am
Posts: 238
Location: Vancouver, BC, Canada
I agree with you manunderground. I mean I had to figure this stuff out on my own, and I asked all the exact same questions you did. It wasn't particularly hard but still. What really got me, and it only dawned on me after reading your posts, is that I have gotten so used to letting API's slap me around that it really seemed par for the course.

In summary the magic smoke going on inside UnicodeFont is great, but yeah, the magic incantations seem to require I make more blood sacrifices then usual.

_________________
If at first quads don't succeed tri tri again.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 24, 2009 7:16 am 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
Ok, less scary banter! :)

Can we make a list of what's wrong/complicated about it, with each usecase and what we'd like the API to look like for the most common cases?

I believe some of the issues here are to do with UnicodeFont being used in Hiero as well as at runtime. The idea was to make Hiero effects available at runtime, however it seems to have got somewhat lost in a non-intuitive API.

So.. lets fix it :)

Kev


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 24, 2009 4:37 pm 
Offline
Oldbie

Joined: Tue Jun 17, 2008 5:11 pm
Posts: 336
Here's a list of what I found to be wrong or inconsistent with the rest of Slick:

* The UnicodeFont constructor does not completely initialize the object, it requires that glyphs be loaded and at least one effect be applied
* Setting effects is done through a getter instead of directly through a setter
* There doesn't appear to be any easy way to remove effects, you may be able to go through the getter once again
* ColorEffect expects a AWT color object not a Slick color object
* Calling UnicodeFont.drawString and passing a color does not write the text with the new color, the old color effect is used
* Calling Graphics.setFont followed by Graphics.setColor does not correctly set the font's color

Some of these issues are just inconvenient. Others seem like a bug. The following code will not do what you'd expect, for instance:

Code:
    tfont.getEffects().add(new ColorEffect(java.awt.Color.white));
    tfont.addAsciiGlyphs();
    tfont.loadGlyphs();
    tfont.drawString(0,0, message, Color.black); // will still draw white

_________________
My website about game development http://anotherearlymorning.com


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 24, 2009 8:16 pm 
Offline
Regular

Joined: Sun Dec 07, 2008 5:22 am
Posts: 238
Location: Vancouver, BC, Canada
Well I would have saved myself a lot of time if the following would work.
Code:
Font f = new UnicodeFont("fontName.ttf",36);
g.setFont(f);
g.drawString();

It's quite possibly the most common use case. I have a font file, I have I size I want to use, and I want it to work. Ideally I don't even want to bother with boolean args for italics or bold. With most of my fonts it's a separate font file anyway.

That being said I don't want to be forced to include the ASCII glyphs if I'm localizing for Korea. If that's the case I wouldn't mind going through a bit more cognitive friction to do something more complex.
Code:
//false means don't load ASCII
UnicodeFont f = new UnicodeFont("fontName.ttf",36, false);
f.addGlyphs(0hAC00, D7A3);
g.setFont(f);
g.drawString();


I don't understand why I need to load the glyphs with a separate method though. Is there a reason that can't be done in add? Probably, but I would like to know what that is.

With effects I've never use them, other than the required one. But addEffect(), and removeEffect() methods would seem much more intuitive to me.

Anyway this just represents what would have been more intuitive for me. UnicodeFont is way better than the old font classes as far as results go, but I get the feeling a lot of people are avoiding it for the simpler to use TrueTypeFont which is a shame.

I final thing to make things more complicated. Manunderground, your code works exactly as it should for me; It draws the string in black.

_________________
If at first quads don't succeed tri tri again.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 24, 2009 8:31 pm 
Offline
Oldbie

Joined: Tue Jun 17, 2008 5:11 pm
Posts: 336
Quote:
I final thing to make things more complicated. Manunderground, your code works exactly as it should for me; It draws the string in black.


Weird, I will have to go double check what I did. As for default values why not have two constructors:

Code:
Font font = new UnicodeFont("path/to/Font.ttf", 36); // loads ascii
Font font = new UnicodeFont("path/to/Font.ttf", 36, Glyphs.SomeLanguage); // loads designated glyphs instead of ascii


That way you nail the common case and can easily handle internationalization. Also, I'd like to see something similar for a color effect. My only concern is what happens if two color effects applied?

Really, I think that the constructor should initialize the font such that it's ready to use. In this case that may mean picking some default glyphs and a color, which seems reasonable.

If we find it impossible to make the UnicodeFont class simpler to use -- say that we need all these options set and there are no reasonable defaults -- then it may make sense to create a new class, similar to TrueTypeFont, which provides more limited functionality but with an easier API. AsciiFont maybe.

_________________
My website about game development http://anotherearlymorning.com


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 05, 2010 10:05 pm 
Offline
Regular
User avatar

Joined: Thu Dec 18, 2008 6:07 pm
Posts: 238
Location: Bournemouth, UK
I agree with manunderground and chronocide here. I just stumbled upon the "nothing was rendered" issue and luckily found this thread. :)

_________________
- Gwinnell (irc.freenode.net, irc.chatspike.net)
- Game Jolt Moderator


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 05, 2010 11:33 pm 
Offline
Regular

Joined: Sun Dec 07, 2008 5:22 am
Posts: 238
Location: Vancouver, BC, Canada
As much as I like to complain, being proactive about it might be better.
When an API becomes broken or deficient the solution is to wrap it. Looking at the use cases that manunderground and I have posted, creating a wrapper class to implement them seems straight forward enough, and it seems that there is enough demand to warrant something to that affect.
Does that sound like a reasonable solution?
What are some other use cases and how would people like to interface with the UnicodeFont class?

_________________
If at first quads don't succeed tri tri again.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 13, 2010 12:05 pm 
Offline

Joined: Wed Jan 13, 2010 11:57 am
Posts: 3
Even when using all what's said here i cant get UnicodeFont to draw anything, nether on graphics context, nor on screen directly, nether from system font i.e "Verdana", nor from ttf file. I'm using linux maybe this might be problem? Anyone of you tried/used UnicodeFont on linux?
my code for loading font looks approximately like this:
Code:
Font font=new Font( "Verdana", Font.PLAIN, 40 );
uFont = new UnicodeFont(font, 20, false, false);
uFont.addAsciiGlyphs();
uFont.getEffects().add(new ColorEffect(java.awt.Color.WHITE));
uFont.loadGlyphs();

where i call addAsciiGlyphs (before/after adding effect) doesnt matter.
i try to draw directly with uFont.drawString(....) or using graphics.setFont
graphics.drawString, and i get nothing in any way. Any suggestions?
(However TrueTypeFont worked/s fine)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 37 posts ]  Go to page 1, 2, 3  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


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