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

version» Context lines:

pike.git/src/modules/Image/font.c:1: - /* $Id: font.c,v 1.35 1998/04/24 13:50:21 mirar Exp $ */ + /* $Id: font.c,v 1.36 1998/05/04 11:49:57 mirar Exp $ */   #include "global.h"   #include <config.h>      #define SPACE_CHAR 'i'      /*   **! module Image   **! note - **! $Id: font.c,v 1.35 1998/04/24 13:50:21 mirar Exp $ + **! $Id: font.c,v 1.36 1998/05/04 11:49:57 mirar Exp $   **! class font   **!   **! note   **! Short technical documentation on a font file:   **! This object adds the text-drawing and -creation   **! capabilities of the <ref>Image</ref> module.   **!   **! For simple usage, see   **! <ref>write</ref> and <ref>load</ref>.   **!
pike.git/src/modules/Image/font.c:319:      /***************** 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 + **! + **! method void create(string filename) + **! Loads a font file to this font object. + **! Similar to <ref>load</ref>().   */         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");
pike.git/src/modules/Image/font.c:512:    struct image *img;    INT32 xsize=0,i,maxwidth2,j;    int *width_of;    unsigned char *to_write;    int to_write_len;    int c;    struct font *this = (*(struct font **)(fp->current_storage));    if (!this)    error("font->write: no font loaded\n");    +  if (args==0) +  { +  push_string(make_shared_binary_string("",0)); +  args++; +  } +     maxwidth2=1;       width_of=(int *)malloc((args+1)*sizeof(int));    if(!width_of) error("Out of memory\n");       for (j=0; j<args; j++)    { -  +  int max;    if (sp[j-args].type!=T_STRING)    error("font->write: illegal argument(s)\n");    -  xsize = 0; +  xsize = max = 1;    to_write = (unsigned char*)sp[j-args].u.string->str;    to_write_len = sp[j-args].u.string->len;    for (i = 0; i < to_write_len; i++) -  +  { +  if (xsize+char_width(this,to_write[i]) > max) +  max=xsize+char_width(this,to_write[i]);    xsize += char_space(this,to_write[i]); -  xsize += char_width(this,to_write[to_write_len-1])-char_space(this,to_write[to_write_len-1]); -  width_of[j]=xsize; -  if (xsize>maxwidth2) maxwidth2=xsize; +  if (xsize > max) max=xsize;    } -  +  width_of[j]=max; +  if (max>maxwidth2) maxwidth2=max; +  }       o = clone_object(image_program,0);    img = ((struct image*)o->storage);    img->xsize = maxwidth2;    if(args>1)    img->ysize = this->height+((double)this->height*(double)(args-1)*(double)this->yspacing_scale)+1;    else    img->ysize = this->height;    img->rgb.r=img->rgb.g=img->rgb.b=255;    img->img=malloc(img->xsize*img->ysize*sizeof(rgb_group)+1);
pike.git/src/modules/Image/font.c:616:   */      void font_text_extents(INT32 args)   {    INT32 xsize,i,maxwidth2,j;       if (!THIS) error("font->text_extents: no font loaded\n");       maxwidth2=0;    +  if (args==0) +  { +  push_string(make_shared_binary_string("",0)); +  args++; +  } +     for (j=0; j<args; j++)    { -  if (sp[j-args].type!=T_STRING) error("font->text_extents: illegal argument(s)\n"); -  xsize = 0; -  for (i = 0; i < sp[j-args].u.string->len; i++) -  xsize += char_space(THIS, (unsigned char)sp[j-args].u.string->str[i]); -  xsize +=char_width(THIS,(unsigned char)sp[j-args].u.string->str[i-1]) -  -char_space(THIS,(unsigned char)sp[j-args].u.string->str[i-1]); -  if (xsize>maxwidth2) maxwidth2=xsize; +  int max; +  unsigned char *to_write; +  int to_write_len; +  if (sp[j-args].type!=T_STRING) +  error("font->write: illegal argument(s)\n"); +  +  xsize = max = 1; +  to_write = (unsigned char*)sp[j-args].u.string->str; +  to_write_len = sp[j-args].u.string->len; +  for (i = 0; i < to_write_len; i++) +  { +  if (xsize+char_width(THIS,to_write[i]) > max) +  max=xsize+char_width(THIS,to_write[i]); +  xsize += char_space(THIS,to_write[i]); +  if (xsize > max) max=xsize;    } -  +  if (max>maxwidth2) maxwidth2=max; +  } +     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)
pike.git/src/modules/Image/font.c:726:   */      void init_font_programs(void)   {    start_new_program();    add_storage(sizeof(struct font*));       add_function("load",font_load,    "function(string:object|int)",0);    +  add_function("create",font_load, +  "function(string:object|int)",0); +     add_function("write",font_write,    "function(string:object)",0);       add_function("height",font_height,    "function(:int)",0);       add_function("baseline",font_baseline,    "function(:int)",0);       add_function("extents",font_text_extents,