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

version» Context lines:

pike.git/src/modules/Image/font.c:1: - /* $Id: font.c,v 1.61 2000/08/10 09:51:53 per Exp $ */ + /* $Id: font.c,v 1.62 2000/08/11 18:42:54 grubba Exp $ */   #include "global.h"      #define SPACE_CHAR 'i'      extern unsigned char * image_default_font;   #define IMAGE_DEFAULT_FONT_SIZE 30596      /*   **! module Image   **! note - **! $Id: font.c,v 1.61 2000/08/10 09:51:53 per Exp $ + **! $Id: font.c,v 1.62 2000/08/11 18:42:54 grubba 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:197:      struct font   {    unsigned long height; /* height of character rectangles */    unsigned long baseline; /* baseline of characters */   #ifdef HAVE_MMAP    unsigned long mmaped_size; /* if 0 - not mmaped: just free() mem */   #endif    void *mem; /* pointer to mmaped/malloced memory */    unsigned long chars; /* number of characters */ -  float xspacing_scale; /* Fraction of spacing to use */ -  float yspacing_scale; /* Fraction of spacing to use */ +  double xspacing_scale; /* Fraction of spacing to use */ +  double yspacing_scale; /* Fraction of spacing to use */    enum {    J_LEFT,    J_RIGHT,    J_CENTER    } justification;    struct _char    {    unsigned long width; /* character rectangle has this width in pixels */    unsigned long spacing; /* pixels to next character */    unsigned char *pixels; /* character rectangle */
pike.git/src/modules/Image/font.c:246:   {    free_font_struct(THIS);    THIS=NULL;   }      /***************** internals ***********************************/      static INLINE int char_space(struct font *this, INT32 c)   {    if(c==0x20) -  return (int)((double)(this->height*this->xspacing_scale)/4.5); +  return DOUBLE_TO_INT((double)(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, 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) + static INLINE int my_read(int from, void *t, size_t towrite)   {    int res;    while((res = fd_read(from, t, towrite)) < 0)    {    switch(errno)    {    case EAGAIN: case EINTR:    continue;       default:
pike.git/src/modules/Image/font.c:303:    INT32 x,y;    unsigned char *p;    p=ci->pixels;       for (y=height; y>0; y--)    {    nl=pos+xsize;    for (x=(INT32)ci->width; x>0; x--)    {    int r,c; -  if((c=255-*p)) +  if((c=255-*p)) {    if ((r=pos->r+c)>255)    pos->r=pos->g=pos->b=255;    else    pos->r=pos->g=pos->b=r; -  +  }    pos++;    p++;    }    pos=nl;    }   }      /***************** methods *************************************/      /*
pike.git/src/modules/Image/font.c:466:    new_font->yspacing_scale = 1.0;    new_font->justification = J_LEFT;    free(THIS);    THIS=new_font;       THIS->height=ntohl(fh->height);    THIS->baseline=ntohl(fh->baseline);       for (i=0; i<THIS->chars; i++)    { -  if (i*sizeof(INT32)<(unsigned long)size -  && ntohl(fh->o[i])<(unsigned long)size +  if (i*sizeof(INT32)<(size_t)size +  && ntohl(fh->o[i])<(size_t)size    && ! ( ntohl(fh->o[i]) % 4) ) /* must be aligned */    {    ch=(struct char_head*)    ((char *)(THIS->mem)+ntohl(fh->o[i]));    THIS->charinfo[i].width = ntohl(ch->width);    THIS->charinfo[i].spacing = ntohl(ch->spacing);    THIS->charinfo[i].pixels = ch->data;    }    else /* illegal <tm> offset or illegal align */    {
pike.git/src/modules/Image/font.c:554:      void font_write(INT32 args)   {    struct object *o;    struct image *img;    INT32 xsize=0,i,maxwidth2,j;    int *width_of;    p_wchar0 *to_write0;    p_wchar1 *to_write1;    p_wchar2 *to_write2; -  int to_write_len; +  ptrdiff_t to_write_len;    INT32 c;    struct font *this = (*(struct font **)(Pike_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:632:    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; +  img->ysize = DOUBLE_TO_INT(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); resource_error(NULL,0,0,"memory",0,"Out of memory.\n"); }       MEMSET(img->img,0,img->xsize*img->ysize*sizeof(rgb_group));       for (j=0; j<args; j++)
pike.git/src/modules/Image/font.c:768:    push_string(make_shared_binary_string("",0));    args++;    }       for (j=0; j<args; j++)    {    int max;    p_wchar0 *to_write0;    p_wchar1 *to_write1;    p_wchar2 *to_write2; -  int to_write_len; +  ptrdiff_t to_write_len;    if (sp[j-args].type!=T_STRING)    bad_arg_error("font->write",sp-args,args,0,"",sp-args,    "Bad arguments to font->write()\n");       xsize = max = 1;    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);