Sign in to follow this  
ahw

[java] fancy ASCII art in Java

Recommended Posts

Hi there, I have been looking around, reading the docs, but I am still a bit confused, so I thought I would ask to get more explanations, hopefully. So I am trying to write a roguelike map generator in Java, but I thought I would try to do it in a Component, rather than use the console. You see, I want to use the old extended ASCII characters, you know, those you see in BBS and other ASCII Art stuff, like the 50% gray block, the table corners characters, and so on. So I check out the cool Font2D Application from the latest SDK of Java 2 (not the 1.5 beta, though). I can SEE the characters there, I can even read the code 0x0175, but when I then try to display it, it gives me a "w" with and accent on top, or some other weird character... So I ended up using a GlyphVector and some unicode code and managed to display my fancy characters. My question is, first : What s a Glyph ? I mean, what's the difference between writing a String which contains the code u0175, and writing a Glyph using the SAME freaking code. BUT if I use drawString it doesnt work ?! I m confused. Also, is there an easier way to do this (keeping in mind I want to work in a GUI, not in the console), where I could use to good old IBM extended ASCII codes (not the Microsoft extended set, BTW), rather than Unicode codes ? I have a feeling that there is something in the doc, but I am am a bit lost about the whole codepage thingie. Anyone ASCII art lover knows about this stuff ? Maybe just a good link ? (I was hoping Jave would have links, but no)

Share this post


Link to post
Share on other sites
When you use drawString, this is a method call on a Graphics object. If you look at the API docs for Graphics you will see a method called setFont. You need to change the font from the default in your paint method before you draw your string.

Share this post


Link to post
Share on other sites
thanks for the answer but I am afraid that's only the tip of the iceberg you are seeing there.

I work with the Monospaced font (since I need monospacing for emulating console display).

My problem is in figuring out what to send to the function (whichever it is) so that it displays the character I expect (which are the blocks and array lines from the IBM extended ASCII set).

I think I have to use Unicode anyway, but I was hoping someone could tell me of a simpler method...

Anyone ?

Share this post


Link to post
Share on other sites
If you have a font that uses the IBM character set and it is monospaced, then you do not have a problem. You set that font to be the one used in the Graphics class, then you figure out the coords to use for your drawString method. Calling drawString with a monospaced font will draw it monospaced. You will then only need to figure out your vertical spacing. Typically the getHeight method of the FontMetrics class will be the proper spacing.

Share this post


Link to post
Share on other sites
Well,thanks for the help anyway Jester, I think my problem is that I am messing with more than one thing at once.
Just gotta have to stick with it until I figure it out :-P
At least there is some great documentation.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I might be off-topic here, but...
Have you considered using a flat char-tile-map (image that contains char tiles)?

As far as I understood, you want to make a terminal-look-alike turn based game (so the fps is not an issue).
You also might want to make a WISIWTG (What I see is what they get :) game. That is, WISIWTG in any computer.

I mean, if you even touch the Font/Glyph/etc. stuff with the 8-mile pole, you just might end up with cross-platform/cross-config problems.
IMHO

Share this post


Link to post
Share on other sites

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

Sign in to follow this