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
Nedjalko Milenkov
Member #5,394
January 2005

I was trying to use the unicode, but it needs spec. fonts. I do not have a cyryllic font. Could anyone give me? I searchd in google, but the tools which I found don not work (ttf2pcx and FontEditor).

Kirr
Member #5,060
September 2004
avatar

--
"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

The url does not help me :(. These are ttf fonts and I am searching fonts for Allegro in pcx, bmp or data file format.

miran
Member #2,407
June 2002

All the basic MS fonts that come with XP (Arial, Times, etc) have cyrillic characters in them. And they do work with both ttf2pcx and the FontEditor, you just need to know what you're doing. Hint: ranges...

--
sig used to be here

Nedjalko Milenkov
Member #5,394
January 2005

After playing with the ranges I found cyrillic from 1024 to 2048 (betwen). I saved the file in fontx.pcx. Loaded it at the grabber and detects 1120 glyphs! After loading the font and puting some text to the screen it show rectan. Why? Should I edit the range and how?

Evert
Member #794
November 2000
avatar

Or use Glyph Keeper to use the TrueType fonts directly.

EDIT: for font ranges, see Allegro's manual: [url http://alleg.sourceforge.net/onlinedocs/en/index017.html#load_txt_font].
Feel free to ask if you need more information.

(That link is for 4.1.18. If you use 4.0.3, the load_font() family of functions doesn't exist. But the information is still accurate, you'll just have to use the grabber and datafiles to load the font. Or upgrade;))

miran
Member #2,407
June 2002

I don't remember exactly where the cyrillic fonts are but there was a thread with this exact question not very long ago. You might want to do a search.

In FontEditor all you have to do is this: select your colours (if you want multicolour font), load the font, add the range with the cyrillic characters and save as a pcx file. Then you must write a multi-range font script. Take a look at the unifont that comes with Allegro in the examples directory. Basically that will be just a normal text file that will look like this:

unifont.pcx 0x0020 0x007F
- 0x0400 0x047F

Then when you load the font in your code, you load the txt file instead of the pcx. Again check the unicode example...

EDIT: That took me a long time to write ::)

--
sig used to be here

Nedjalko Milenkov
Member #5,394
January 2005

I checked the unicode example and see only \x14\x04 king of stuff. I know that that is the real unicode, but I prefer to write instead of code :). I found an example which works fine, but the cyrillic font is too big. I manage to isolate the eng. and cyr. from arial in 0x20-0x07F (eng) and 0x80 - 0xFF(CYR), but when I write something it takes the empty symbols in the file instead showing the cyr. Any Ideas how to correct?

miran
Member #2,407
June 2002

Did you call set_uformat() before allegro_init()? Or whatever it's called.

--
sig used to be here

Nedjalko Milenkov
Member #5,394
January 2005

miran Yes I run set_uformat( U_UTF8 ); buf after allegro_init();

miran
Member #2,407
June 2002

What does the manual say about that? Last time I checked it recommended you do it before allegro_init()...

--
sig used to be here

gnolam
Member #2,030
March 2002
avatar

And is your text input unicode as well? I know from personal experience that Cyrillic encoding is a bitch due to the many conflicting encoding standards...

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

miran
Member #2,407
June 2002

Oh I just noticed, you're trying to use a Unicode font with extended 8bit ASCII strings. That simply won't work. Either you make or get a font with 8bit ASCII encoding or you format your strings into real 16bit Unicode...

--
sig used to be here

Matt Smith
Member #783
November 2000

I would hack a Unicode->CodePage export func into Miran's font editor :D

Has anyone tested what happens when you feed UTF-8 strings through gcc? I expect it will choke.

When you use Allegro's printing functions, they expect UTF-8 by default, so you should set it to 8-bit ASCII with set_uformat(U_ASCII_CP); first. You still need a Cyrillic CodePage font, to match the one in your code editor. (I was wary about using codepages in C code but all the compilers seem to accept it.)

The manual says it should work with ASCII-8 strings and a Unicode font, provided the tables are set up right with void set_ucodepage(const unsigned short *table, const unsigned short *extras);

Nedjalko Milenkov
Member #5,394
January 2005

What a big mess :o. Could anyone post some nice example, because I do not understand how to put it all together. I readed the manual for the ten time, but still having some problems.

Evert
Member #794
November 2000
avatar

Quote:

What does the manual say about that? Last time I checked it recommended you do it before allegro_init()...

You should, if you only intend to use a single encoding ever. I'm not actually sure if there will be problems if you set it later, but I assume not, since Allegro also allows you to switch encodings on the fly.

This part of Allegro is pretty ugly, by the way.

Matt Smith
Member #783
November 2000

The first thing you need to establish is which code page you are using. DOS had the old IBM code pages (Russian was 866) and Windows has 1251 (Slavic) and 1257 (Baltic). There is also iso 8859-5 etc.

Then, you have to hope somebody has made the codepage tables for your chosen encoding, or make it yourself like this

1const unsigned short cp_cyrillic[256]={
2 0,
3 1,
4 ...
5 127, /* first 128 chars map to ASCII */
6 n, /* unicode-16 char (wchar) of codepage char 128 */
7 ...
8};
9 
10char string[] = "Dos Vedanya, Tanya"; <- in Cyrillic codepage
11 
12set_ucodepage(cp_cyrillic, NULL);
13set_uformat(U_ASCII_CP);
14 
15unifont = load_font("unifont.fnt"); /* new function in 4.2 :o) */
16
17textout_ex(screen, unifont, string,x,y,black,white);

Kirr
Member #5,060
September 2004
avatar

Here is a table for converting cp-1251 into Unicode.

But I don't suggest working with codepage through all your program. It's better to convert your strings to Unicode (for ex. UTF-16) in the startup of your program. Some libs, like ICU have this conversion functions, but it is trivial anyway, so I suggest to just code it.

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

DanielH
Member #934
January 2001
avatar

Nedjalko, look at my unicode example. It comes with a cyrillic font and prints Russian-English pairs.

Nedjalko Milenkov
Member #5,394
January 2005

MattSmith

Quote:

Then, you have to hope somebody has made the codepage tables for your chosen encoding, or make it yourself like this

-> I searched, but do not find some already defined. And if I deside to write it, should I write only number or? Because from your example it seems, that only positions or?

Kirr

Quote:

Here is a table for converting cp-1251 into Unicode.

-> I saw the table, but it only describes the position. I think that I should do the writing :(.

DanielH

Quote:

Nedjalko, look at my unicode example. It comes with a cyrillic font and prints Russian-English pairs.

-> Actually everything began with it :). But the font is too big. How can I resize it, or do you have another cyr. font? And how did you do it?

DanielH
Member #934
January 2001
avatar

I used TTF2PCX to make the font. You just have to supply the min and max characters of the cyrillic font. Now that I think of it, I was using a font that only had cyrillic characters.

Nedjalko Milenkov
Member #5,394
January 2005

I tried Monochrome from 0x20 to 0x7F and saved it as PCX, but the PCX was empty :(.

DanielH
Member #934
January 2001
avatar

You have a bad ttf2pcx. Download Matt's

http://www.allegro.cc/misc/ttf2pcx.zip

Here's what you do. Create a font with characters from 0x20 to 0xff
Create another font from 0x410 to 0x44f. Then combine them. copy paste the second one in to the lower portion of the first.

Nedjalko Milenkov
Member #5,394
January 2005

10x. I`v extracted the fonts fon 0x20 to 0x44F and the cyricllic font is fon 0x400 to 0x44F. How can I tell the grabber to extract
testfont.pcx 0x20 0x7F
testfont.pcx 0x400 0x44F
? This lines do not work :(

DanielH
Member #934
January 2001
avatar

What are you talking about? You have to use ttf2pcx and use a paint program to combine them.

 1   2   3 


Go to: