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

version» Context lines:

pike.git/src/modules/Image/font.c:1: - /* $Id: font.c,v 1.39 1998/06/03 13:21:32 grubba Exp $ */ + /* $Id: font.c,v 1.40 1998/10/11 19:07:26 marcus Exp $ */   #include "global.h"   #include <config.h>      #define SPACE_CHAR 'i'      /*   **! module Image   **! note - **! $Id: font.c,v 1.39 1998/06/03 13:21:32 grubba Exp $ + **! $Id: font.c,v 1.40 1998/10/11 19:07:26 marcus 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:237:   }      static void exit_font_struct(struct object *obj)   {    free_font_struct(THIS);    THIS=NULL;   }      /***************** internals ***********************************/    - static INLINE int char_space(struct font *this, unsigned char c) + static INLINE int char_space(struct font *this, INT32 c)   {    if(c==0x20)    return (int)((float)(this->height*this->xspacing_scale)/4.5);    else if(c==0x20+128)    return (this->height*this->xspacing_scale)/18;    return this->charinfo[c].spacing*this->xspacing_scale;   }    - static INLINE int char_width(struct font *this, unsigned char c) + static INLINE int char_width(struct font *this, INT32 c)   {    if(c==0x20 || c==0x20+128) return 0;    return this->charinfo[c].width;   }      #ifndef HAVE_MMAP   static INLINE int my_read(int from, void *t, int towrite)   {    int res;    while((res = fd_read(from, t, towrite)) < 0)
pike.git/src/modules/Image/font.c:519:   **! One or more lines of text.   **! see also: text_extents, load, Image.image->paste_mask, Image.image->paste_alpha_color   */      void font_write(INT32 args)   {    struct object *o;    struct image *img;    INT32 xsize=0,i,maxwidth2,j;    int *width_of; -  unsigned char *to_write; +  p_wchar0 *to_write0; +  p_wchar1 *to_write1; +  p_wchar2 *to_write2;    int to_write_len; -  int c; +  INT32 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++;    }   
pike.git/src/modules/Image/font.c:544:    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 = max = 1; -  to_write = (unsigned char*)sp[j-args].u.string->str; +     to_write_len = sp[j-args].u.string->len; -  +  switch(sp[j-args].u.string->size_shift) +  { +  case 0: +  to_write0 = STR0(sp[j-args].u.string);    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+char_width(this,to_write0[i]) > max) +  max=xsize+char_width(this,to_write0[i]); +  xsize += char_space(this,to_write0[i]);    if (xsize > max) max=xsize;    } -  +  break; +  case 1: +  to_write1 = STR1(sp[j-args].u.string); +  for (i = 0; i < to_write_len; i++) +  { +  if (xsize+char_width(this,to_write1[i]) > max) +  max=xsize+char_width(this,to_write1[i]); +  xsize += char_space(this,to_write1[i]); +  if (xsize > max) max=xsize; +  } +  break; +  case 2: +  to_write2 = STR2(sp[j-args].u.string); +  for (i = 0; i < to_write_len; i++) +  { +  if (xsize+char_width(this,to_write2[i]) > max) +  max=xsize+char_width(this,to_write2[i]); +  xsize += char_space(this,to_write2[i]); +  if (xsize > max) max=xsize; +  } +  break; +  default: +  fatal("Illegal shift size!\n"); +  }    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);       if (!img) { free_object(o); free(width_of); error("Out of memory\n"); }       MEMSET(img->img,0,img->xsize*img->ysize*sizeof(rgb_group));       for (j=0; j<args; j++)    { -  to_write = (unsigned char *)sp[j-args].u.string->str; +     to_write_len = sp[j-args].u.string->len;    switch(this->justification)    {    case J_LEFT: xsize = 0; break;    case J_RIGHT: xsize = img->xsize-width_of[j]-1; break;    case J_CENTER: xsize = img->xsize/2-width_of[j]/2-1; break;    }    if(xsize<0) xsize=0;    -  +  switch(sp[j-args].u.string->size_shift) +  { +  case 0: +  to_write0 = STR0(sp[j-args].u.string);    THREADS_ALLOW();    for (i = 0; i < to_write_len; i++)    { -  c=*(to_write++); - /* if(c<0) fatal("IDI compiler\n");*/ +  c=*(to_write0++);    if (c < (INT32)this->chars)    {    if(char_width(this,c))    write_char(this->charinfo+c,    (img->img+xsize)+    (img->xsize*(int)(j*this->height*this->yspacing_scale)),    img->xsize,    this->height);    xsize += char_space(this, c);    }    }    THREADS_DISALLOW(); -  +  break; +  case 1: +  to_write1 = STR1(sp[j-args].u.string); +  THREADS_ALLOW(); +  for (i = 0; i < to_write_len; i++) +  { +  c=*(to_write1++); +  if (c < (INT32)this->chars) +  { +  if(char_width(this,c)) +  write_char(this->charinfo+c, +  (img->img+xsize)+ +  (img->xsize*(int)(j*this->height*this->yspacing_scale)), +  img->xsize, +  this->height); +  xsize += char_space(this, c);    } -  +  } +  THREADS_DISALLOW(); +  break; +  case 2: +  to_write2 = STR2(sp[j-args].u.string); +  THREADS_ALLOW(); +  for (i = 0; i < to_write_len; i++) +  { +  c=*(to_write2++); +  if (c < (INT32)this->chars) +  { +  if(char_width(this,c)) +  write_char(this->charinfo+c, +  (img->img+xsize)+ +  (img->xsize*(int)(j*this->height*this->yspacing_scale)), +  img->xsize, +  this->height); +  xsize += char_space(this, c); +  } +  } +  THREADS_DISALLOW(); +  break; +  default: +  fatal("Illegal shift size!\n"); +  } +  }    free(width_of);       pop_n_elems(args);    push_object(o);   }      /*   **! method int height()   **! returns font height   **! see also: baseline, text_extents
pike.git/src/modules/Image/font.c:650:       if (args==0)    {    push_string(make_shared_binary_string("",0));    args++;    }       for (j=0; j<args; j++)    {    int max; -  unsigned char *to_write; +  p_wchar0 *to_write0; +  p_wchar1 *to_write1; +  p_wchar2 *to_write2;    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; -  +  switch(sp[j-args].u.string->size_shift) +  { +  case 0: +  to_write0 = STR0(sp[j-args].u.string);    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+char_width(THIS,to_write0[i]) > max) +  max=xsize+char_width(THIS,to_write0[i]); +  xsize += char_space(THIS,to_write0[i]);    if (xsize > max) max=xsize;    } -  +  break; +  case 1: +  to_write1 = STR1(sp[j-args].u.string); +  for (i = 0; i < to_write_len; i++) +  { +  if (xsize+char_width(THIS,to_write1[i]) > max) +  max=xsize+char_width(THIS,to_write1[i]); +  xsize += char_space(THIS,to_write1[i]); +  if (xsize > max) max=xsize; +  } +  break; +  case 2: +  to_write2 = STR2(sp[j-args].u.string); +  for (i = 0; i < to_write_len; i++) +  { +  if (xsize+char_width(THIS,to_write2[i]) > max) +  max=xsize+char_width(THIS,to_write2[i]); +  xsize += char_space(THIS,to_write2[i]); +  if (xsize > max) max=xsize; +  } +  break; +  default: +  fatal("Illegal shift size!\n"); +  }    if (max>maxwidth2) maxwidth2=max;    }       pop_n_elems(args);    push_int(maxwidth2);    push_int(args * THIS->height * THIS->yspacing_scale);    f_aggregate(2);   }