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

version» Context lines:

pike.git/src/modules/Image/font.c:1: - /* $Id: font.c,v 1.48 1999/05/23 17:46:40 mirar Exp $ */ + /* $Id: font.c,v 1.49 1999/05/24 14:33:10 mirar Exp $ */   #include "global.h"   #include <config.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.48 1999/05/23 17:46:40 mirar Exp $ + **! $Id: font.c,v 1.49 1999/05/24 14:33:10 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:212:    unsigned char *pixels; /* character rectangle */    } charinfo [1]; /* many!! */   };      /***************** init & exit *********************************/      static INLINE void free_font_struct(struct font *font)   {    if (font)    { -  if (font->mem) +  if (font->mem && font->mem!=image_default_font)    {   #ifdef HAVE_MMAP    munmap(font->mem,font->mmaped_size);   #else    free(font->mem);   #endif    }    free(font);    }   }
pike.git/src/modules/Image/font.c:328:   **!   **! method void create(string filename)   **! Loads a font file to this font object.   **! Similar to <ref>load</ref>().   */      void font_load(INT32 args);      void font_create(INT32 args)   { -  if (args) -  { +     font_load(args);    pop_stack();   } - } +       void font_load(INT32 args)   {    int fd; -  +  size_t size;    -  if (args<1 -  || sp[-args].type!=T_STRING) -  error("font->read: illegal or wrong number of arguments\n"); -  +     if (THIS)    {    free_font_struct(THIS);    THIS=NULL;    } -  +  +  if (!args) +  { +  THIS=(struct font *)xalloc(sizeof(struct font)); +  THIS->mem=image_default_font; +  size=IMAGE_DEFAULT_FONT_SIZE; +  goto loading_default; +  } +  +  if (sp[-args].type!=T_STRING) +  error("font->read: illegal or wrong number of arguments\n"); +     do    {   #ifdef FONT_DEBUG    fprintf(stderr,"FONT open '%s'\n",sp[-args].u.string->str);   #endif    fd = fd_open(sp[-args].u.string->str,fd_RDONLY,0);    } while(fd < 0 && errno == EINTR);       if (fd >= 0)    { -  size_t size; +     struct font *new_font;       size = (size_t) file_size(fd);    if (size > 0)    {    new_font=THIS=(struct font *)xalloc(sizeof(struct font));       THREADS_ALLOW();   #ifdef HAVE_MMAP    new_font->mem =
pike.git/src/modules/Image/font.c:384:    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();    + loading_default: +     if (THIS->mem)    {    struct file_head    {    unsigned INT32 cookie;    unsigned INT32 version;    unsigned INT32 chars;    unsigned INT32 height;    unsigned INT32 baseline;    unsigned INT32 o[1];
pike.git/src/modules/Image/font.c:466:   #endif    free_font_struct(new_font);    THIS=NULL;    pop_n_elems(args);    push_int(0);    return;    }       }    +  if (!args) goto done; +     fd_close(fd);    pop_n_elems(args);    ref_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");   #endif    } /* wrong cookie */   #ifdef FONT_DEBUG    else fprintf(stderr,"FONT wrong cookie\n");   #endif -  +  if (!args) goto done; /* just in case */    } /* 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    fd_close(fd);    } /* fd failure */   #ifdef FONT_DEBUG    else fprintf(stderr,"FONT fd failure\n");   #endif    -  + done: +     pop_n_elems(args);    push_int(0);    return;   }      /*   **! 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
pike.git/src/modules/Image/font.c:881:   {    ADD_STORAGE(struct font*);       /* function(string:object|int) */    ADD_FUNCTION("load",font_load,tFunc(tStr,tOr(tObj,tInt)),0);       /* function(void|string:void) */    ADD_FUNCTION("create",font_create,tFunc(tOr(tVoid,tStr),tVoid),0);       /* function(string:object) */ -  ADD_FUNCTION("write",font_write,tFunc(tStr,tObj),0); +  ADD_FUNCTION("write",font_write,tFuncV(,tStr,tObj),0);       /* function(:int) */    ADD_FUNCTION("height",font_height,tFunc(,tInt),0);       /* function(:int) */    ADD_FUNCTION("baseline",font_baseline,tFunc(,tInt),0);       /* function(string ...:array(int)) */    ADD_FUNCTION("extents",font_text_extents,tFuncV(,tStr,tArr(tInt)),0);