Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Cyrillic fonts for allegro

Credits go to DanielH, Evert, gnolam, Kirr, Matt Smith, miran, and Thomas Fjellstrom for helping out!
This thread is locked; no one can reply to it. rss feed Print
 1   2   3 
Cyrillic fonts for allegro
Kirr
Member #5,060
September 2004
avatar

You would have much better chance to get help here if you include these things with your post:

1. Everything needed to reproduce the problem. Your program code (as short as possible), PCX/script/whatever else you use, steps you took with TTF2PCX and both TTF and PCX, as many details as possible. Also mention your OS and allegro version and anything else you think can be relevant.

2. What you expect your program to do, precisely.

3. What your program is actually doing, precisely.

Then, if someone is willing to help, he will at least have such chance, instead of guessing what you might have done wrong.

Quote:

miran I do not think that I am the first man using unicode.

Most people using unicode don't use codepages at all. Also using unicode does not imply using PCX fonts.

Quote:

And why when I used some already done PCX(from one site for beginers) it works?

What site? Did you try to say they work with the same code, that you posted here? Or with some other code? Or you mean something else? I guess the question is rather why your PCX don't work. Did you actually try Miran's suggestions?

Mark Knopfler said:

But in the communique you know he's gonna come clean
Think what he say, say what he mean
Maybe on Monday he got something to say
Communication
Communique
Communique

--
"Go to the NW of Stonemarket Plaza to the Blue Glyph Keeper Library door and enter."
- Lunabean's Thief Deadly Shadows Walkthrough, day eight

Nedjalko Milenkov
Member #5,394
January 2005

Kirr
Here is the full information about my problem

1. I came from Bulgaria and I want my programs to support cyrillic.
2. My Allegro lib is 4.0.3.0 .
3. I saw one example for unicode at http://agdn.pyrosoftware.net/main/showfile.php?request=7 . You can download the hole program from http://agdn.pyrosoftware.net/main/archive/unicode.zip .
4. When I tried it it works, but the font was too big. I wanted to make my own and to make it smaller.
5. I did some googling and found two programs ttf2pcx and Font Editor
6. I had a bad copy of the first program and at the beginning it does not works. Someone gave me the url of a working version.
7. I extracted from arial.ttf (Windows XP, SP2) the cyrillic ranges (0x410 - 0x44F) and tried to put the PCX in my data file. But again it does not work. Then Miran told me to use Font scripts, but after 1 hour of trying I found that my grabber do not work properly even with the Mirian`s example.
8. I tried all of your suggestion (thank you for the attention)
9. I`v posted a simple code. Here is once again:

1/* UltraBlocks ver.:0.1
2 * By the ultimate and unforgiven game TETRIS
3 * Coder Nedjalko Milenkov
4 * e-mail redspace[at]bg-webmaster.com
5 * Just wait to see the final version :)
6 * Whats new: The whole code :)
7 */
8
9#include <allegro.h>
10 
11#include "data.h"
12 
13DATAFILE *data;
14FONT *myfont;
15 
16//The MAIN FUNCTION
17int main(void){
18char buf[512];
19set_uformat(U_UNICODE);
20 
21 allegro_init();
22
23 install_keyboard();
24
25 set_color_depth(16);
26
27 if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0)!=0)
28 {
29 set_color_depth(15);
30 if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0)!=0){
31 allegro_message("Unable initialize graphics module\n%s\n", allegro_error);
32 return -1;
33 }
34 }
35
36
37 BITMAP *buffer=create_bitmap(SCREEN_W, SCREEN_H);
38
39 if(buffer==NULL){
40 allegro_message("Sorry, not enough memory.");
41 allegro_exit();
42 exit(2);
43 }
44
45 data=load_datafile(uconvert_ascii("arialcyr.dat", buf));
46
47 if (!data) {
48 allegro_message("Unable to load %s\n");
49 return -1;
50 }
51 
52//set_uformat( U_UTF8 );
53//set_uformat(U_ASCII_CP);
54 
55 
56
57 uconvert("Ïðîãðàìèðàíå", U_ASCII, buf, U_UNICODE, sizeof( buf ));
58
59 textprintf_centre(screen, data[0].dat, 300, 100, makecol( 255, 255, 255), buf);
60
61 //blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
62
63 readkey();
64
65 return 0;
66}
67END_OF_MAIN()

The code does not work with the data file from the allegro unicode example and with the Mirian`s data file too, but when I write something like \x14\x04 it works. The problem is that I do not want to write like that :(.
Could anyone help me?

Kirr
Member #5,060
September 2004
avatar

OK, now it's better, although you still did not post your datafile, so I had to make that cyrillic font myself. After that and some modifications your code worked for me:

#include "data.h"

You did not post "data.h", so I just commented it out.

uconvert("Ïðîãðàìèðàíå", U_ASCII, buf, U_UNICODE, sizeof( buf ));

Here is your problem. First, when you copy/paste your source into forum reply box, its encoding may be changed. You'd better attach your source file as attachment to the post. I assume that this line has actually some cyrillic characters. So I typed cyrillic "Медитирoвать не надo." indtead of "Ïðîãðàìèðàíå".

Second. Cyrillic is not part of ASCII. You have to use U_ASCII_CP instead of U_ASCII in this function call.

And last, for U_ASCII_CP to work you should specify a cyrillic codepage for ALlegro with set_ucodepage. So, instead of that your one line I typed two lines:

set_ucodepage(cyrcodepage,0);
uconvert("Медитирoвать не надo.", U_ASCII_CP, buf, U_UNICODE, sizeof( buf ));

Of course, for this to work I had to type in a cyrillic codepage earlier:

const unsigned short cyrcodepage[256] = {
.....
};

Then everything worked and the program printed cyrillic text on screen.

One last thing:

Quote:

allegro_message("Unable to load %s\n");

There is not enough arguments in this call.

--
"Go to the NW of Stonemarket Plaza to the Blue Glyph Keeper Library door and enter."
- Lunabean's Thief Deadly Shadows Walkthrough, day eight

Nedjalko Milenkov
Member #5,394
January 2005

Seems there is a hope :).
Could you post the hole const unsigned short cyrcodepage[256] = {
.....
};
or rar of the your test program?
In this post is my non working example.

P.S. In the allegro manual there is no second argument in void allegro_message(const char *msg, ...);

Kirr
Member #5,060
September 2004
avatar

Actually MattSmith already mentioned in this thread that you need a codepage conversion table, and I posted a link to the codepage data. You could use it long time ago. Anyway, here you go, this is Windows-1251 codepage:

1const unsigned short cyrcodepage[256] = {
2 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,
3 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,
4 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,
5 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,
6 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,
7 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F,
8 0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,
9 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,
10 0x0402,0x0403,0x201A,0x0453,0x201E,0x2026,0x2020,0x2021,0x20AC,0x2030,0x0409,0x2039,0x040A,0x040C,0x040B,0x040F,
11 0x0452,0x2018,0x2019,0x201C,0x201D,0x2022,0x2013,0x2014,0x0020,0x2122,0x0459,0x203A,0x045A,0x045C,0x045B,0x045F,
12 0x00A0,0x040E,0x045E,0x0408,0x00A4,0x0490,0x00A6,0x00A7,0x0401,0x00A9,0x0404,0x00AB,0x00AC,0x00AD,0x00AE,0x0407,
13 0x00B0,0x00B1,0x0406,0x0456,0x0491,0x00B5,0x00B6,0x00B7,0x0451,0x2116,0x0454,0x00BB,0x0458,0x0405,0x0455,0x0457,
14 0x0410,0x0411,0x0412,0x0413,0x0414,0x0415,0x0416,0x0417,0x0418,0x0419,0x041A,0x041B,0x041C,0x041D,0x041E,0x041F,
15 0x0420,0x0421,0x0422,0x0423,0x0424,0x0425,0x0426,0x0427,0x0428,0x0429,0x042A,0x042B,0x042C,0x042D,0x042E,0x042F,
16 0x0430,0x0431,0x0432,0x0433,0x0434,0x0435,0x0436,0x0437,0x0438,0x0439,0x043A,0x043B,0x043C,0x043D,0x043E,0x043F,
17 0x0440,0x0441,0x0442,0x0443,0x0444,0x0445,0x0446,0x0447,0x0448,0x0449,0x044A,0x044B,0x044C,0x044D,0x044E,0x044F,
18};

Quote:

P.S. In the allegro manual there is no second argument in void allegro_message(const char *msg, ...);

allegro_message() uses same format with printf(). Please check printf() documentation.

--
"Go to the NW of Stonemarket Plaza to the Blue Glyph Keeper Library door and enter."
- Lunabean's Thief Deadly Shadows Walkthrough, day eight

Nedjalko Milenkov
Member #5,394
January 2005

Thanks to all for the help. It works!

Evert
Member #794
November 2000
avatar

Quote:

One last thing:

On a related note, don't call allegro_message() when you're in graphics mode. It will either not work or cause problems. You should call set_gfx_mode(GFX_TEXT, ...) before allegro_message() if you're in graphics mode.

 1   2   3 


Go to: