how do I use fnt_new? I can't get it to work.

Started by handsource-dyko, March 15, 2012, 08:28:06 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

handsource-dyko

Right now I'm testing fnt_new( <INT file> , <INT graph>, <INT charset> , <INT width> , <INT height> , <INT first> , <INT last> , <INT flags> ) for documentation and I'm having bad luck. I try to use bitmaps from an fpg file, but When I write a text, it doesn't display. I a tried a couple of different things but I'm puzzled. :(

What is a bit unclear to me, is the graph from an array? and the "first" and "last" parameters. Do I have to call this function in a loop or just once? The C code in libfont.c is a bit too hard for me.

A test sample would be helpfull. I attached two fpg files, the first one, has 152 characters in it, and the second one has 36 characters. The width and height are not constant. (Is that perhaps a couse???)

Bottom line: have I forgotten something?


This is my (not working) code ;D :


IMPORT "mod_say";
IMPORT "mod_debug";
IMPORT "mod_key";
IMPORT "mod_text";
IMPORT "mod_map";
IMPORT "mod_path";
IMPORT "mod_video";
IMPORT "mod_wm";
IMPORT "mod_draw";
IMPORT "mod_screen";




GLOBAL

   int file_id;          // the fileID of the fpg with the source graphics
   int font_id;          // the fileID of the font we're going to create
   int font_id_2[200];
   
   int graph_id[36];
   
   int width_info;       // the width of the current letter bitmap
   int height_info;      // the height of the current letter bitmap
   
   int char_count;       // the current letter bitmap
   int max_chars_in_fpg;

PROCESS main();

BEGIN

   x=100;
   y=100;

   set_mode(640,480,8);

   // load an fpg with glyps
   file_id=load_fpg("fonttest2.fpg");
   
   // check how many maps there exist in the loaded fpg file
   FOR (char_count=1; char_count<999; char_count+=1)
   
      IF (map_exists(file_id,char_count))       
         max_chars_in_fpg+=1;
         
         graph_id[char_count]=map_clone(file_id,char_count);
         
         graph=graph_id[char_count];
         frame(500);
         
         say("map count: "+max_chars_in_fpg);
      ELSE
         say("mapcode "+char_count+" does not exist");
      END
   END
   
   say("max_chars_in_fpg: "+max_chars_in_fpg);
   
   // create a new font
   font_id=fnt_new(0,graph_id[1],CHARSET_CP850,30,30,1,36,NFB_VARIABLEWIDTH);
   write(font_id,200,100,ALIGN_CENTER_LEFT,"0123456789");
   
   // fnt_new ( <INT file> , <INT graph>, <INT charset> , <INT width> , <INT height> , <INT first> , <INT last> , <INT flags> )
   
   FOR (char_count=1; char_count<max_chars_in_fpg; char_count+=1)
   
       // obtain data from the current "map"
       width_info=graphic_info(file_id,char_count,G_WIDTH);
       height_info=graphic_info(file_id,char_count,G_HEIGHT);
       
       say("char count: "+char_count+" width: "+width_info+" height: "+height_info);
       
       font_id_2[char_count]=fnt_new(file_id,char_count,CHARSET_CP850,width_info,height_info,1,max_chars_in_fpg,NFB_VARIABLEWIDTH);
       
       say("font_id_2["+char_count+"]="+char_count);
       
       // display the font
       write(font_id_2[char_count],100,100,ALIGN_CENTER_LEFT,"0123456789");
   END
   
   
   LOOP
      IF (key(_esc))
         BREAK;
      END
      FRAME;
   END
   
END





SplinterGU

font have charmaps... I have pending review this.
Download Lastest BennuGD Release: http://www.bennugd.org/node/2