What is font format for fnt_load?

Started by EugeneP, October 25, 2010, 05:58:33 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

EugeneP

Асс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.

handsource-dyko

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.

EugeneP

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 :)

FreeYourMind


EugeneP

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.

Drumpi

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).
Hala, como con 1001 procesos sólo va a 9 FPS, vamos a meterle 32 veces más, a ver si revienta.
(Drumpi epic moment)

EugeneP

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.  :-\

EugeneP

This is what I want (full code attached in archive):



[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.

osk

Maybe Splinter is the one that could say anything here...

josebita

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

EugeneP

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.

josebita

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.

SplinterGU

#12
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.
Download Lastest BennuGD Release: http://www.bennugd.org/node/2

handsource-dyko

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.

panreyes

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