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

version» Context lines:

pike.git/src/modules/Image/font.c:1: - /* $Id: font.c,v 1.23 1997/12/28 09:29:32 hubbe Exp $ */ + /* $Id: font.c,v 1.24 1998/01/03 07:12:40 hubbe Exp $ */   #include <config.h>      #define SPACE_CHAR 'i'      /*   **! module Image   **! note - **! $Id: font.c,v 1.23 1997/12/28 09:29:32 hubbe Exp $ + **! $Id: font.c,v 1.24 1998/01/03 07:12:40 hubbe 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:87:    1 numchars*numchars entries, each a signed char with the kerning value    2 numchar entries, each with a list of kerning pairs, like this:    int len    len * (short char, short value)    */               #include "global.h" + #include "fdlib.h"      #include <sys/types.h>   #include <sys/stat.h>      #ifdef HAVE_FCNTL_H   #include <fcntl.h>   #endif      #ifdef HAVE_SYS_FCNTL_H   #include <sys/fcntl.h>
pike.git/src/modules/Image/font.c:205:    return this->charinfo[c].spacing*this->xspacing_scale;   }      static INLINE int char_width(struct font *this, unsigned char c)   {    if(c==0x20 || c==0x20+128) return 0;    return this->charinfo[c].width;   }      #ifndef HAVE_MMAP - static INLINE int my_read(int from, char *buf, int towrite) + static INLINE int my_read(int from, void *t, int towrite)   {    int res; -  while((res = read(from, buf, towrite)) < 0) +  while((res = fd_read(from, t, towrite)) < 0)    {    switch(errno)    {    case EAGAIN: case EINTR:    continue;       default:    res = 0;    return 0;    }    }    return res;   }   #endif      static INLINE long file_size(int fd)   {    struct stat tmp;    int res; -  if((!fstat(fd, &tmp)) && +  if((!fd_fstat(fd, &tmp)) &&    (tmp.st_mode & S_IFREG)) {    return res = tmp.st_size;    }    return -1;   }      static INLINE void write_char(struct _char *ci,    rgb_group *pos,    INT32 xsize,    INT32 height)
pike.git/src/modules/Image/font.c:293:    if (THIS)    {    free_font_struct(THIS);    THIS=NULL;    }    do    {   #ifdef FONT_DEBUG    fprintf(stderr,"FONT open '%s'\n",sp[-args].u.string->str);   #endif -  fd = open(sp[-args].u.string->str,O_RDONLY); +  fd = fd_open(sp[-args].u.string->str,fd_RDONLY,0);    } while(fd < 0 && errno == EINTR);       if (fd >= 0)    {    long size; -  struct font *new; +  struct font *new_font;       size = file_size(fd);    if (size > 0)    { -  new=THIS=(struct font *)xalloc(sizeof(struct font)); +  new_font=THIS=(struct font *)xalloc(sizeof(struct font));       THREADS_ALLOW();   #ifdef HAVE_MMAP -  new->mem = +  new_font->mem =    mmap(0,size,PROT_READ,MAP_SHARED,fd,0); -  new->mmaped_size=size; +  new_font->mmaped_size=size;   #else -  new->mem = malloc(size); -  if ((new->mem) && (!my_read(fd,new->mem,size))) { -  free(new->mem); -  new->mem = NULL; +  new_font->mem = malloc(size); + #ifdef FONT_DEBUG +  fprintf(stderr,"FONT Malloced %p (%d)\n",new_font->mem,size); + #endif +  if ((new_font->mem) && (!my_read(fd,new_font->mem,size))) { +  free(new_font->mem); +  new_font->mem = NULL;    }   #endif    THREADS_DISALLOW();       if (THIS->mem)    {    struct file_head    {    unsigned INT32 cookie;    unsigned INT32 version;
pike.git/src/modules/Image/font.c:359:    if (ntohl(fh->version)==1)    {    unsigned long i;      #ifdef FONT_DEBUG    fprintf(stderr,"FONT version 1\n");   #endif       THIS->chars=ntohl(fh->chars);    -  new=malloc(sizeof(struct font)+ +  new_font=malloc(sizeof(struct font)+    sizeof(struct _char)*(THIS->chars-1)); -  new->mem=THIS->mem; +  new_font->mem=THIS->mem;   #ifdef HAVE_MMAP -  new->mmaped_size=THIS->mmaped_size; +  new_font->mmaped_size=THIS->mmaped_size;   #endif -  new->chars=THIS->chars; -  new->xspacing_scale = 1.0; -  new->yspacing_scale = 1.0; -  new->justification = J_LEFT; +  new_font->chars=THIS->chars; +  new_font->xspacing_scale = 1.0; +  new_font->yspacing_scale = 1.0; +  new_font->justification = J_LEFT;    free(THIS); -  THIS=new; +  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    && ! ( ntohl(fh->o[i]) % 4) ) /* must be aligned */    {
pike.git/src/modules/Image/font.c:393:    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 */    {   #ifdef FONT_DEBUG    fprintf(stderr,"FONT failed on char %02xh %d '%c'\n",    i,i,i);   #endif -  free_font_struct(new); +  free_font_struct(new_font);    THIS=NULL;    pop_n_elems(args);    push_int(0);    return;    }       }    -  close(fd); +  fd_close(fd);    pop_n_elems(args);    THISOBJ->refs++;    push_object(THISOBJ); /* success */   #ifdef FONT_DEBUG    fprintf(stderr,"FONT successfully loaded\n");   #endif    return;    } /* wrong version */   #ifdef FONT_DEBUG    else fprintf(stderr,"FONT unknown version\n");
pike.git/src/modules/Image/font.c:428: Inside #if defined(FONT_DEBUG)
   } /* mem failure */   #ifdef FONT_DEBUG    else fprintf(stderr,"FONT mem failure\n");   #endif    free_font_struct(THIS);    THIS=NULL;    } /* size failure */   #ifdef FONT_DEBUG    else fprintf(stderr,"FONT size failure\n");   #endif -  close(fd); +  fd_close(fd);    } /* fd failure */   #ifdef FONT_DEBUG    else fprintf(stderr,"FONT fd failure\n");   #endif       pop_n_elems(args);    push_int(0);    return;   }