Fnt new

From Bennu Wiki
Jump to: navigation, search


Definition

INT fnt_new ( <INT depth> )


Creates a new font with a certain color depth. There exists three variants of this function:

- INT fnt_new ( <INT depth> )

- INT fnt_new ( <INT charset> , <INT depth> )

- INT fnt_new ( <INT file> , <INT graph>, <INT charset> , <INT width> , <INT height> , <INT first> , <INT last> , <INT flags> )

- The first variant is a simple version wich uses the systemfont and the CP850 character set.

- The second version allows the user to select a different characterset.

- The third function allows custom fonts to made, from bitmaps in memory. It is similair to DIV gamestudio's font generator. In this variant, the depth cannot be set.

The previous name new_fnt() is deprecated.

Parameters

INT charset - The color characterset of the font, CHARSET_ISO8859 or CHARSET_CP850.
INT depth - The color depth of the glyphs of the font.
INT file - The fileID of the file wich contains the bitmaps with the letters.
INT graph - The graphID of the bitmap wich contains the character set.
INT width - The width of the glyph.
INT height - The height of the glyph.
INT first - The first character.
INT last - The last character.
INT flags - The kind of glyph width, NFB_VARIABLEWIDTH or NFB_FIXEDWIDTH.

Returns

INT : FontID

-1 - Error: could not create font.
>=0 - The FontID.

Errors

Insufficient memory - There is insufficient memory available. This error doesn't occur often.
Too many fonts - There are too many fonts loaded (255).


Example

IMPORT "mod_video";
IMPORT "mod_wm";
IMPORT "mod_text";
IMPORT "mod_map";
IMPORT "mod_key";

GLOBAL
   int a;
   int b;
   int c;
   
   int graph_id;
   
   int font_id1;
   int font_id2;

PROCESS main();    
    
BEGIN

    set_mode(640,480);
    
    graph_id=png_load("font.png");
    
    // new font, variable width
    font_id1=fnt_new(0,graph_id,CHARSET_ISO8859,16,16,0,255,NFB_VARIABLEWIDTH);
    
    write_int(font_id1,0,0,0,&a);
    write_int(font_id1,0,20,0,&b);
    write_int(font_id1,0,40,0,&c);
    write(font_id1,0,60,0,"hello world!");

    
    // new font, fixed width
    font_id2=fnt_new(0,graph_id,CHARSET_ISO8859,16,16,0,255,NFB_FIXEDWIDTH); 
    
    write_int(font_id2,0,100,0,&a);
    write_int(font_id2,0,120,0,&b);
    write_int(font_id2,0,140,0,&c);
    write(font_id2,0,160,0,"hello world!");
    
    
    
    // write texts in standard system font
    write_int(0,320,0,0,&a);
    write_int(0,320,20,0,&b);
    write_int(0,320,40,0,&c);
    write(0,320,60,0,"hello world!");

    WHILE (NOT key(_ESC) AND NOT exit_status)
    
        a++;
        b--;
        c*=2;
        
        IF (c==0) 
           c=1; 
        END
        
        FRAME;
    END
END

Used in example: Png_load(), Write(), Write_int()


Notes

If only one argument is used, the CP850 character set is used. The charactermap is a bitmap, with the characters arranged in a grid. See this post


Mod_map
Globals None
Imported:
FullscreenGraphmodeM7ScalemodeScaleresolutionScaleresolutionaspectratioScaleresolutionorientation
Constants BCLEARCHARSETCP850CHARSETISO8859GANIMATIONSPEEDGANIMATIONSTEPGANIMATIONSTEPSGCENTERXGCENTERYGDEPTHGFRAMESGHEIGHTGPITCHGWIDEGWIDTHGXCENTERGYCENTERNFBFIXEDWIDTHNFBVARIABLEWIDTH
Imported:
BABLENDBALPHABHMIRRORBNOCOLORKEYBSBLENDBTRANSLUCENTBVMIRRORDOUBLEBUFFERHWSURFACEM1024X768M1280X1024M320X200M320X240M320X400M360X240M376X282M400X300M512X384M640X400M640X480M800X600MODE16BITSMODE16BPPMODE2XSCALEMODE8BITSMODE8BPPMODEDOUBLEBUFFERMODEFRAMELESSMODEFULLSCREENMODEHARDWAREMODEMODALMODEWAITVSYNCMODEWINDOW
Functions Bdfload()Centerset()Colorfind()Colorsget()Colorsset()Fade()Fadeoff()Fadeon()Fntload()Fntnew()Fntsave()Fntunload()Fpgadd()Fpgdel()Fpgexists()Fpgload()Fpgnew()Fpgsave()Fpgunload()Getpixel()Glyphget()Glyphset()Graphicinfo()Graphicset()Mapblockcopy()Mapbuffer()Mapclear()Mapclone()Mapdel()Mapexists()Mapgetpixel()Mapinfo()Mapinfoget()Mapinfoset()Mapload()Mapname()Mapnew()Mapput()Mapputpixel()Mapsave()Mapsetname()Mapunload()Mapxput()Mapxputnp()Palclone()Paldel()Palget()Palload()Palmapassign()Palmapgetid()Palmapremove()Palnew()Palrefresh()Palsave()Palset()Palunload()Paletteconvert()Paletteroll()Pcxload()Pngload()Pngsave()Pointget()Pointset()Putpixel()Rgb()Rgbget()Rgba()Rgbaget()