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

version» Context lines:

pike.git/src/modules/Image/font.c:1: - /* $Id: font.c,v 1.16 1997/09/03 04:59:12 per Exp $ */ + /* $Id: font.c,v 1.17 1997/09/05 22:18:00 per Exp $ */   #include <config.h>      #define SPACE_CHAR 'i'      /*   **! module Image   **! note - **! $Id: font.c,v 1.16 1997/09/03 04:59:12 per Exp $<br> + **! $Id: font.c,v 1.17 1997/09/05 22:18:00 per Exp $<br>   **! 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:181:   }      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) + { +  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 my_read(int from, char *buf, int towrite) + static INLINE int char_width(struct font *this, unsigned char c)   { -  +  if(c==0x20 || c==0x20+128) return 0; +  return this->charinfo[c].width; + } +  +  + static INLINE int my_read(int from, char *buf, int towrite) + {    int res;    while((res = read(from, buf, towrite)) < 0)    {    switch(errno)    {    case EAGAIN: case EINTR:    continue;       default:    res = 0;    return 0;    }    }    return res;   }    - static inline long file_size(int fd) + static INLINE long file_size(int fd)   {    struct stat tmp;    int res;    if((!fstat(fd, &tmp)) &&    (tmp.st_mode & S_IFREG)) {    return res = tmp.st_size;    }    return -1;   }    - static inline void write_char(struct _char *ci, + static INLINE void write_char(struct _char *ci,    rgb_group *pos,    INT32 xsize,    INT32 height)   {    rgb_group *nl;    INT32 x,y;    unsigned char *p;    p=ci->pixels;       for (y=height; y>0; y--)
pike.git/src/modules/Image/font.c:426:      /*   **! 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   */ - static INLINE int char_space(struct font *this, unsigned char c) - { -  if(c==0x20) -  return this->charinfo[SPACE_CHAR].spacing*this->xspacing_scale; -  else if(c==0x20+128) -  return (this->charinfo['m'].spacing/16)*this->xspacing_scale; -  return this->charinfo[c].spacing*this->xspacing_scale; - } +     - static INLINE int char_width(struct font *this, unsigned char c) - { -  if(c==0x20) return 0; -  else if(c==0x20+128) return 0; -  return this->charinfo[c].width; - } -  -  +    void font_write(INT32 args)   {    struct object *o;    struct image *img; -  INT32 xsize=0,i,c,maxwidth2,j; +  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");       maxwidth2=0;       width_of=(int *)malloc((args+1)*sizeof(int));    if(!width_of) error("Out of memory\n");       for (j=0; j<args; j++)
pike.git/src/modules/Image/font.c:504:    {    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;       THREADS_ALLOW();    for (i = 0; i < to_write_len; i++)    { -  c=(unsigned char)*(to_write++); +  c=*(to_write++); + /* if(c<0) fatal("IDI compiler\n");*/    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();    }