pike.git / src / modules / Image / font.c

version» Context lines:

pike.git/src/modules/Image/font.c:1:   #include <config.h>      /*   **! module Image   **! class font + **! + **! Short technical documentation on a font file: + **! struct file_head + **! { + **! unsigned INT32 cookie; - 0x464f4e54 + **! unsigned INT32 version; - 1 + **! unsigned INT32 chars; - number of chars + **! unsigned INT32 height; - height of font + **! unsigned INT32 baseline; - font baseline + **! unsigned INT32 o[1]; - position of char_head's + **! } *fh; + **! struct char_head + **! { + **! unsigned INT32 width; - width of this character + **! unsigned INT32 spacing; - spacing to next character + **! unsigned char data[1]; - pixmap data (1byte/pixel) + **! } *ch; + **!   */    - /* $Id: font.c,v 1.5 1997/04/03 07:00:17 mirar Exp $ */ + /* $Id: font.c,v 1.6 1997/04/09 01:49:47 mirar Exp $ */      #include "global.h"      #include <sys/types.h>   #include <sys/stat.h>      #ifdef HAVE_FCNTL_H   #include <fcntl.h>   #endif   
pike.git/src/modules/Image/font.c:159:    }    pos++;    p++;    }    pos=nl;    }   }      /***************** methods *************************************/    + /* + **! method object|int load(string filename) + **! Loads a font file to this font object. + **! returns zero upon failure, font object upon success + **! arg string filename + **! Font file + **! see also: write + */    -  +    void font_load(INT32 args)   {    int fd;       if (args<1    || sp[-args].type!=T_STRING)    error("font->read: illegal or wrong number of arguments\n");       if (THIS)    {
pike.git/src/modules/Image/font.c:326: Inside #if defined(FONT_DEBUG)
   } /* fd failure */   #ifdef FONT_DEBUG    else fprintf(stderr,"FONT fd failure\n");   #endif       pop_n_elems(args);    push_int(0);    return;   }    + /* + **! method object write(string text,...) + **! Writes some text; thus creating an image object + **! that can be used as mask or as a complete picture. + **! returns an <ref>Image::image</ref> object + **! arg string text, ... + **! One or more lines of text. + **! see also: text_extents, load, image::paste_mask, image::paste_alpha_color + */ +    void font_write(INT32 args)   {    struct object *o;    struct image *img;    INT32 xsize=0,i,maxwidth,c,maxwidth2,j;    int *width_of;       if (!THIS)    error("font->write: no font loaded\n");   
pike.git/src/modules/Image/font.c:407:    THIS->height);    xsize += THIS->charinfo[c].spacing*THIS->xspacing_scale;    }    }    }    free(width_of);    pop_n_elems(args);    push_object(o);   }    + /* + **! method int height() + **! returns font height + **! see also: baseline, text_extents + */ +    void font_height(INT32 args)   {    pop_n_elems(args);    if (THIS)    push_int(THIS->height);    else    push_int(0);   }    -  + /* + **! method text_extents(string text,...) + **! Calculate extents of a text-image, + **! that would be created by calling <ref>write</ref> + **! with the same arguments. + **! returns an array of width and height + **! arg string text, ... + **! One or more lines of text. + **! see also: write, height, baseline + */ +    void font_text_extents(INT32 args)   {    INT32 xsize,i,maxwidth,c,maxwidth2,j;       if (!THIS)    error("font->text_extents: no font loaded\n");       maxwidth2=0;       for (j=0; j<args; j++)
pike.git/src/modules/Image/font.c:447:    {    if (xsize + (signed long)THIS->charinfo[c].width > maxwidth)    maxwidth = xsize + THIS->charinfo[c].width;    xsize += THIS->charinfo[c].spacing*THIS->xspacing_scale;    }    }       if (xsize>maxwidth) maxwidth=xsize;    if (maxwidth>maxwidth2) maxwidth2=maxwidth;    } +  pop_n_elems(args);    push_int(maxwidth2);    push_int(args * THIS->height * THIS->yspacing_scale); -  +  f_aggregate(2);   }       -  +  + /* + **! method void set_xspacing_scale(float scale) + **! method void set_yspacing_scale(float scale) + **! Set spacing scale to write characters closer + **! or more far away. This does not change scale + **! of character, only the space between them. + **! arg float scale + **! what scale to use + */ +    void font_set_xspacing_scale(INT32 args)   {    if(!THIS) error("font->set_xspacing_scale(FLOAT): No font loaded.\n");    if(!args) error("font->set_xspacing_scale(FLOAT): No argument!\n");    if(sp[-args].type!=T_FLOAT)    error("font->set_xspacing_scale(FLOAT): Wrong type of argument!\n");       THIS->xspacing_scale = (double)sp[-args].u.float_number;   /*fprintf(stderr, "Setting xspacing to %f\n", THIS->xspacing_scale);*/    if(THIS->xspacing_scale < 0.0)
pike.git/src/modules/Image/font.c:481:    if(sp[-args].type!=T_FLOAT)    error("font->set_yspacing_scale(FLOAT): Wrong type of argument!\n");       THIS->yspacing_scale = (double)sp[-args].u.float_number;   /*fprintf(stderr, "Setting yspacing to %f\n", THIS->yspacing_scale);*/    if(THIS->yspacing_scale <= 0.0)    THIS->yspacing_scale=0.1;    pop_stack();   }    +  + /* + **! method int baseline() + **! returns font baseline (pixels from top) + **! see also: height, text_extents + */   void font_baseline(INT32 args)   {    pop_n_elems(args);    if (THIS)    push_int(THIS->baseline);    else    push_int(0);   }      void font_set_center(INT32 args)