Bennu Game Development

English Forums => Helpdesk => Topic started by: EugeneP on October 25, 2010, 05:58:33 AM

Title: What is font format for fnt_load?
Post by: EugeneP on October 25, 2010, 05:58:33 AM
Ассording to BennuWiki  fnt_load:
QuoteLoads a FNT file into memory as a font.

What is a FNT file? How can I create my font or convert existing fonts to this format?

P.S.
I have looked at existing apps using .FNT files. These were not Windows FNT as I could expect, and FontForge does not know this format.
Title: Re: What is font format for fnt_load?
Post by: handsource-dyko on October 25, 2010, 08:14:30 AM
Fnt fonts are bitmap type fonts, and they are specific to DIV/Fenix and Bennu.
It's non-standard, and it's format is similair to the map format, with some extra data.

They are 8-bit only, and use color palettes. The format originated for DIV gamesstudio.
There's on tool you can use to create them(fntedit 2006), and you can find it in bennupack.

However, you can also use true-type fonts with bennu, however this requires the use
of an additional lib, called mod_ttf. True type fonts are recommended if you want
flexibility and smooth font scaling. Fnt fonts however are a bit old, but can be textured.

Both formats have advantages and disadvantages, fnt fonts don't require an additional lib,
but don't scale nicely.
Title: Re: What is font format for fnt_load?
Post by: EugeneP on October 25, 2010, 08:33:44 AM
Thanks, this makes things clear.

mod_ttf is not good for me because it is not available on Wiz/Caanoo out if the box.

I probably implement loading some standard bitmap font by myself :)
Title: Re: What is font format for fnt_load?
Post by: FreeYourMind on October 25, 2010, 09:08:44 AM
Someone to do the port ? :)
Title: Re: What is font format for fnt_load?
Post by: EugeneP on October 25, 2010, 09:25:35 AM
A port to every platform? If someone have access to every platform :) No, I think it is possible implement reading PSF1/2 fonts by bennu itself.

Actually I don't like a current state when essential functionality (like networking or truetype or smpeg) is not available for every supported platform.
Title: Re: What is font format for fnt_load?
Post by: Drumpi on October 25, 2010, 10:51:35 PM
Sorry, but FNT it's more like FPG format than MAP format.
And is not only a 8bits format, you can use 1bit (with TEXT_COLOR function you can define this colour on 8/16/32 bits mode) and 16bits on Fenix, and 32 bits in Bennu too.

You can do them with FNTEdit (limited to old DIV 8bits FNT format) or with Bennu functions (maybe, with mod_ttf and bennu you can do a basic FNTEdit).
Title: Re: What is font format for fnt_load?
Post by: EugeneP on October 26, 2010, 07:13:27 AM
Agrrrrhhh!!!  >:( It looks like someone designed bennu especially to make native language support impossible!!!  :-\

I've wrote .psf font loader but I cannot create font with new_fnt / set_glyph because these functions does internal conversion from encoding I do not use to encoding I do not need. And there is no way to change this behaviour from bennu code.

libfont .c
[code language="c"]int gr_font_new()
{
...
    f->charset = CHARSET_CP850;
    f->bpp = 8;
    f->maxwidth = 0;
    f->maxheight = 0;
...
}[/code]

mod_map.c
[code language="c"]static int modmap_set_glyph( INSTANCE * my, int * params )
{
    FONT  * font = gr_font_get( params[0] );
    GRAPH * map  = bitmap_get( params[2], params[3] );
    unsigned char c = params[1];

    if ( font->charset == CHARSET_CP850 ) c = win_to_dos[c];
...
}[/code]

libtext.c
[code language="c"]
int gr_text_put( GRAPH * dest, REGION * clip, int fontid, int x, int y, const unsigned char * text )
{
    GRAPH * ch ;
    FONT   * f ;
    uint8_t  current_char;
    int flags ;
    int save8, save16, save32;

...

    while ( *text )
    {
        switch ( f->charset )
        {
            case CHARSET_ISO8859:
                current_char = dos_to_win[*text];
                break;

            case CHARSET_CP850:
                current_char = *text;
                break;

            default:
                current_char = 0;
                break;
        }

        ch = f->glyph[current_char].bitmap ;
        ...
     }
     ...
  }

}
[/code]

Newly created font is always marked cp850, there is no way we could change it (cp850 is "Western DOS", why DOS i wonder?). When we assign glyphs to this font we translate win->dos. OK, text in the source is win-encoded, the font is in cp850. Now we render the same text with the same font and... wait we have same win-encoded text and cp850 font! We should probably do win->dos translation once again, but no, we don't.

This system works wrong or I don't understand a thing.  :-\
Title: Re: What is font format for fnt_load?
Post by: EugeneP on October 26, 2010, 08:16:52 AM
This is what I want (full code attached in archive):

(http://forum.bennugd.org/index.php?action=dlattach;topic=1737.0;attach=1559)

[code language="bennu"]
#include "psf-fonts.inc.prg"

function write_to_map_psf( PSF_FONT *font, int map, int x, int y, string text )
local
   int g, i, l;
end
begin
 
 l = len( text );
 
 for( i=0; i<l; i++)
   g = ascii_to_map_psf( font, asc( text ) );
   map_put( file, map, g , x, y );
   x += font.width;
   map_unload( file, g );
 end;
   
end

local
 PSF_FONT psf;
 int code, font, map, f,  i;
 string text, fontfile;
end
begin

 f=fopen("text.cp1251","rt");
 text = fgets(f);
 fclose(f);
 
 fontfile = argv[argc-1];
 fontfile = "ter-c14b.psf";

 set_mode(640, 480, 32);
 say ( "File: " + fontfile );
 say ( "Exit code: " + read_psf( &psf, fontfile ) );
 
 read_encoding( &psf, "encodings/microsoft-cp1251.enc" );

 write_to_map_psf( &psf, 0, 30, 100,  "Latin ASCII text");
 write_to_map_psf( &psf, 0, 30, 120,  text);

/*  
 font = fnt_new(8);
 for( code=0; code<=255; code++)
   say("code "+code);
   map = ascii_to_map_psf( &psf, code );
   glyph_set ( font , code , file , map );
   map_unload( file, map );
 end;
 
 write(font, 30, 150, 0, "Latin ASCII text");
 write(font, 30, 180, 0, text);
*/

 while( !key(_esc) ) frame; end;
end[/code]

If you uncomment block creating font, you either get garbage text either bennu crash in set_glyph.
Title: Re: What is font format for fnt_load?
Post by: osk on October 26, 2010, 09:46:04 AM
Maybe Splinter is the one that could say anything here...
Title: Re: What is font format for fnt_load?
Post by: josebita on October 26, 2010, 10:46:16 AM
Just had a quick look at your code, but Bennu internally uses the CP850 charset, which is basically english plus some spanish characters (ñ, ç...).

I had to deal with this problem for my karaoke game, too.
For dealing with charsets different from the standard one, you can use my mod_iconv (it's available in my PPA, if you're using Debian/Ubuntu/similar) but for rendering text.... it's more complicated.
If you only want your program to work on Linux, you can use mod_pango (http://forum.bennugd.org/index.php?topic=394.0). It's also available in my PPA and works great with all kinds of charsets -it must be fed with UTF8 text, but you can convert pretty much and charset to UTF8 with mod_iconv- and it expands greatly Bennu's font rendering system (you can manage text properties pretty much as you would in HTML).
The biggest downside of mod_pango is that it's very difficult to compile and set up on non-linux systems.
Title: Re: What is font format for fnt_load?
Post by: EugeneP on October 26, 2010, 11:38:08 AM
2 josebita

Thanks for advices, but I want to make a single .dcb which could be used on any supported platform from Linux to Wii. This aim prevents me from using any binary modules.


Actually I have few interdependent problems:

1) I want to make locales for non-Latin languages ( Russian, Georgian, Bulgarian, Greek - take one you like )

2) I want ( and need for p.1 ) to use custom fonts. ( for example I want to write a cross-platform book reader )

3) For the reasons of portability I cannot use 3-d party binary modules.

Bennu's text renderer can't work with non-Latin characters at all. The only solution I could invent is writing font managing and text rendering system on Bennu itself.

If the state of Bennu's text renderer bothers only me then ok, by now I know how to help myself. If rendering non-Latin characters is important then Bennu's text rendering system need to be reworked.
Title: Re: What is font format for fnt_load?
Post by: josebita on October 26, 2010, 12:35:02 PM
Quote from: EugeneP on October 26, 2010, 11:38:08 AM
2 josebita

Thanks for advices, but I want to make a single .dcb which could be used on any supported platform from Linux to Wii. This aim prevents me from using any binary modules.


Actually I have few interdependent problems:

1) I want to make locales for non-Latin languages ( Russian, Georgian, Bulgarian, Greek - take one you like )

2) I want ( and need for p.1 ) to use custom fonts. ( for example I want to write a cross-platform book reader )

3) For the reasons of portability I cannot use 3-d party binary modules.

Bennu's text renderer can't work with non-Latin characters at all. The only solution I could invent is writing font managing and text rendering system on Bennu itself.

If the state of Bennu's text renderer bothers only me then ok, by now I know how to help myself. If rendering non-Latin characters is important then Bennu's text rendering system need to be reworked.
Then your only option is to create your own custom text rendering system using bitmap fonts.

I also think the font rendering/handling system is very poor, but that's what we have, right now.
Title: Re: What is font format for fnt_load?
Post by: SplinterGU on October 26, 2010, 01:26:48 PM
the code that handles the display of texts is the legacy of Fenix in the majority, only made fixes and performance improvements, it's need a uptade? is true, but for now there is.

you can do the thing that all people do when there aren't different encoding handling natively, which is to replace some characters that you don't used in your font for which you need. you can see this in lot of apps, in olds DOS games, in some phone mobiles, etc.
Title: Re: What is font format for fnt_load?
Post by: handsource-dyko on October 26, 2010, 02:36:36 PM
Non latin character sets are a pain. Japanse users had specially modified
versions of Dos and more powerfull graphics hardware in onder to deal with
their character set. Your avarage dos machine couldn't handle it.

Not to mention that some languages read from right to left (arabic and japanese)
instead of left to right. However, latin alphabet is more efficient, with 26 + some
extra characters for spanish, french and scandinavian languages you can spell
every word and accent. The Chinese need like 1600 characters to express words
in their language. I'm not sure about arab characters.

The solution is asia was to use latin characters on computers, and spell the words
phonetically.
Title: Re: What is font format for fnt_load?
Post by: panreyes on October 26, 2010, 03:01:42 PM
Maybe we should start thinking on creating a new fnt system :)

Or something. I love TTF but I hate mod_ttf being a third party module...
Title: Re: What is font format for fnt_load?
Post by: josebita on October 26, 2010, 03:20:26 PM
Not exactly what you're talking about, but I believe it's related:
I believe I've said this earlier, but I'd be happy to give copyright to Splinter or relicense as needed my mod_iconv library (or mod_vlc or any library Splinter finds useful) if he found it useful to integrate it into BennuGD.

Also, I've found out that iconv is not really needed to compile or use mod_iconv as SDL provides all the needed functionality, so it should be just as portable as BennuGD.
Title: Re: What is font format for fnt_load?
Post by: SplinterGU on October 26, 2010, 04:44:27 PM
for josebita:

Joseba, seria bueno si me podes pasar algun sample y alguna introduccion a tu mod_iconv, para analizarlo y ver la posibilidad de incluirlo en bennugd como modulo oficial, desconozco si hay posibilidad de que esto pueda integrarse nativamente sin que nadie tenga que llamar a las funciones iconv para hacer la conversion, pero si es posible y sabes como seria la cosa me gustaria escuchar que me podes decir al respecto.
gracias.
Title: Re: What is font format for fnt_load?
Post by: EugeneP on October 26, 2010, 04:48:37 PM
Well, the zip attached to my post is actually draft of custom font system. It'll be ready in a few days :)

Integrating mod_ttf would be good. Making warps around SDL_ttf functions would be even better. (just pass string directly to TTF_RenderUTF8)
Title: Re: What is font format for fnt_load?
Post by: Drumpi on October 26, 2010, 06:40:04 PM
There are some features on FNT format that you can't change if you use NEW_FNT, this is why i want to make my own FNT editor (I did a FNT bpp edit, all in bennu code, using maps and creating FNT files from scratch).
FNT support 2 charcodes only, so if you want to play with more, mod_fnt isn't enough. Mod_fnt is a basic library, we cannot write from right to left nor up to down, rotate or scale text...

FNT format is free, you can see it on wiki (or maybe i will have it around here) and can do them with file functions. It's easy, really.
DIV-likes never were good enough to work with text, but this is why we are here an Bennu is open source ;)

For asian characters, they use a reduced set of them, but when tehy write on PC, if two or more characters can join in existing one, the CPU change them to their correct character, so no need to get a 1600 keys keyboard :D :D :D
Title: Re: What is font format for fnt_load?
Post by: EugeneP on October 27, 2010, 07:37:46 PM
Ok, this is solution of my initial problem in bennu.
Library can load PSF ver.1 fonts, assign an encoding and render 8-bit text lines.
(http://forum.bennugd.org/index.php?action=dlattach;topic=1737.0;attach=1563)
Title: Re: What is font format for fnt_load?
Post by: josebita on October 27, 2010, 07:46:47 PM
Great looking!

This might be really useful for the next version of my karaoke!
Title: Re: What is font format for fnt_load?
Post by: SplinterGU on October 27, 2010, 10:13:38 PM
excelente! karma++!
Title: Re: What is font format for fnt_load?
Post by: EugeneP on October 28, 2010, 03:36:07 AM
2 josebita
This exactly code is result of one sleepless night. It's more like proof of concept than real thing. I would recommend you wait for week or two till I release my cursed Pong :) It would contain tested and polished font & localization system.