Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Swedish keyboard mapping table

This thread is locked; no one can reply to it. rss feed Print
Swedish keyboard mapping table
juan maluenda
Member #7,257
May 2006

Hi.
So my problem here is that i whant to use my dear swedish characters åäö in my game.
But for some reason they always appear as ^. Ive tryed several fonts that do contain the above stated characters but to no success ( made with TTF2PCX ).
Saw something about ranges but could not directly see how that could help me.

Appreciate all the help i can get!

J.

Johan Halmén
Member #1,550
September 2001

Guess I'm oldfashioned, but I use FontEd and Grabber and dat files. In FontEd I often fail to include åäö. I end up in a 7 bit PCX/BMP character table. I have to increase the range or include the range 80-ff. Then it works.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Years of thorough research have revealed that the red "x" that closes a window, really isn't red, but white on red background.

Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest.

Evert
Member #794
November 2000
avatar

You don't need a keyboard mapping table, you need a proper font. ^ is Allegro's default character for glyphs it cannot display.

miran
Member #2,407
June 2002

Use FontEd. Down in my sig. By default you only edit characters 32-127, that's the 7bit ASCII range. Then you add a range, it asks you for start and end indexes which you can leave at 128-255. This fills the font with the full 8bit ASCII table. You then proceed to edit the characters you're interested in, save the font as a .pcx or .tga and load it in your program directly or use grabber or dat to put it into a datafile.

--
sig used to be here

Riccard
Member #7,261
May 2006

I am working on the same game as Juan.

The thing is - we have doublechecked that the fonts we use has
support for the chars we are looking for to be displayed.

Even though these are in the used font - allegro still continues to display
the ^ sign whenever a åä or ö is used.

Is there some configuration needed or anything?
Is there a drawback with textout-functions for textoutputs?

Cheers
Riccard

Evert
Member #794
November 2000
avatar

Post the font and post a small sample programme.

juan maluenda
Member #7,257
May 2006

1#include "allegro.h"
2int main()
3{
4 allegro_init();
5 install_keyboard();
6
7 set_color_depth(32);
8 if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800, 640, 0, 0) != 0) {
9 if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) {
10 set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
11 allegro_message("Unable to set any graphic mode\n%s\n", allegro_error);
12 return 1;
13 }
14 }
15
16 BITMAP *buffer = create_bitmap(SCREEN_W, SCREEN_H);
17 
18 clear_to_color(buffer, makecol(0, 0, 0));
19
20 FONT *m_font = load_font("font.pcx", NULL, NULL);
21 char *name[] = { "FONT", NULL };
22 FONT *dat_font = load_dat_font("data.dat", NULL, name);
23
24 textprintf_ex(buffer, m_font, 140, 40, makecol(255,255,255), -1, "%s", "Not working: ÅÄÖ åäö");
25 textprintf_ex(buffer, m_font, 140, 100, makecol(255,255,255), -1, "%s", "Still Not working: ÅÄÖ åäö");
26 
27 blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
28
29 while(!keypressed()){
30 }
31
32 return 0;
33}
34END_OF_MAIN();

Looking at the font in grabber the range is dictated from 0x20 to 0xFF

GullRaDriel
Member #3,861
September 2003
avatar

Perhaps set_uformat(...) will help ?

Try adding set_uformat( U_ASCII ); before allegro_init();

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

miran
Member #2,407
June 2002

As Gulldi said, you need to set uformat to what you actually use. That is Allegro should use the same encoding as what you write. By default Allegro uses UTF-8 but you seem to be writing your strings in extended 8 bit ASCII. Either make Allegro use ASCII or you should switch to UTF-8. I suggest the second approach because it will give you a lot less trouble. To switch to UTF-8 just select UTF-8 in the enciding settings of your text editor.

EDIT: Attached is a screenshot of you program on my computer. I copied and pasted the code you posted into a text editor that supports UTF-8 and compiled. Works out of the box!

--
sig used to be here

GullRaDriel
Member #3,861
September 2003
avatar

OFF-TOPIC:

Miran said:

As Gulldi said

It seems that I am not the only one to have some problem with the Spell Check feature. Correct me if I am wrong, but the word replacement isn't working that good.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

juan maluenda
Member #7,257
May 2006

Thanks a million guys!
:D:D:D:D:D

miran
Member #2,407
June 2002

Sorry, but your name is impossible for me to remember. I know it starts with Gull and there's a d in there somewhere, but after that I'm lost. What does "GullRaDriel" mean by the way? And in what language? And how are you supposed to pronounce it? (Yes, I copied&pasted this time)

EDIT:

Quote:

Thanks a million guys!
:D:D:D:D:D

So did you use the U_ASCII thing or did you do it like it's supposed to be done?

--
sig used to be here

GullRaDriel
Member #3,861
September 2003
avatar

Just call me Gull, It will be enough.

The full story for this nick is long, but shorter, I was a Ra family member on a mmorpg named TheFourthComing, and the Ra family was from the Driel one's.
'Gull' comes from a book, Heroic-fantasy one. ( A magic-l'assemblée book, from wizard of the coast)

I keep it so long for the sake of ...hum... I dunno, but I like it.

The language... Hmmm... Say it as you would read it. I would not hear it, so it does not matter ;-)

To end, Gull is propably a Russian or east country firstname.

EDIT: Nice to see it working, and can you say us what you did ?

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

juan maluenda
Member #7,257
May 2006

Well i added set_uformat( U_ASCII ); to the beggining and that worked nicely.
Im currently investigating the UTF-8 option, to be honest i do not fully follow with what you mean with "text editor".
My friend made the font, so im unshure what program he used.
We are coding in Dev-C but im am unable to find (for the moment) any options for changing to UTF-8.

miran
Member #2,407
June 2002

Quote:

Im currently investigating the UTF-8 option, to be honest i do not fully follow with what you mean with "text editor".
My friend made the font, so im unshure what program he used.
We are coding in Dev-C but im am unable to find (for the moment) any options for changing to UTF-8.

The font is good, the problem is with how you write text. If you look at your source code file with a hex editor or something like that, you will see that all the characters are coded with values between 32 and 127 (decimal) except for the Swedish characters which are encoded with values between 128 and 255. If this works for you, then good, but if you later decide to add support for other languages, this is very likely to break completely as there are many different 8 bit encodings out there, almost like one for each language. So by using U_ASCII you're limiting yourself to just a few languages.

If you want to do it the proper way you must encode your text with UTF-8. In this encoding all normal English characters stay the same as with 7bit ASCII, but characters above 127 are encoded as 2, 3 or 4 bytes (there are well defined rules for that). In practice this means that all you need to do is select UTF-8 in your editor. Now I don't know where that can be set in Dev-C++ or if it can even be done, but I'm attaching a screenshot of Kate (the editor I've been using lately). Sorry, because it's translated, but it should at least give you an idea of what I mean. In most decent editors there's a similar menu under File|Encoding or Tools|Encoding or something...

EDIT: By the way, the font you're using is plain old Arial which is completely unsuitable for most games. I think you should use something prettier. :)

--
sig used to be here

Milan Mimica
Member #3,877
September 2003
avatar

Doesn't ANSI C require the source code to be in ASCII?

miran
Member #2,407
June 2002

It's possible. If that's a problem (it isn't for me), you should put all your strings in separate txt files encoded in UTF-8. You should do that anyway if you want your program to be extensible...

--
sig used to be here

Evert
Member #794
November 2000
avatar

Quote:

Doesn't ANSI C require the source code to be in ASCII?

Yes. That's why Allegro's exunicod example uses escaped octal characters for the unicode text.

LennyLen
Member #5,313
December 2004
avatar

Quote:

The full story for this nick is long, but shorter, I was a Ra family member on a mmorpg named TheFourthComing, and the Ra family was from the Driel one's.
'Gull' comes from a book, Heroic-fantasy one. ( A magic-l'assemblée book, from wizard of the coast)

I keep it so long for the sake of ...hum... I dunno, but I like it.

The language... Hmmm... Say it as you would read it. I would not hear it, so it does not matter ;-)

To end, Gull is propably a Russian or east country firstname.

Everytime I see your name, I think Galadriel.

GullRaDriel
Member #3,861
September 2003
avatar

Héhé, please just think to Gull instead of a woman name ;-p

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

LennyLen
Member #5,313
December 2004
avatar

{"name":"seagull038ly.jpg","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/0\/f06f3e41a143c10e5760738d3b4d225b.jpg","w":600,"h":400,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/0\/f06f3e41a143c10e5760738d3b4d225b"}seagull038ly.jpg

GullRaDriel
Member #3,861
September 2003
avatar

I do not catch the joke here ???

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Evert
Member #794
November 2000
avatar

It's a picture of a gull.

GullRaDriel
Member #3,861
September 2003
avatar

Gul is also a minister somewhere. Happy to see I am also a Gull. But it does not really matter as I am not really a Gull ;-)

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Go to: