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

version» Context lines:

pike.git/src/modules/Image/font.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: font.c,v 1.83 2004/03/05 23:04:02 nilsson Exp $ + || $Id: font.c,v 1.84 2004/05/19 00:10:10 nilsson Exp $   */      #include "global.h"      #define SPACE_CHAR 'i'      extern const unsigned char image_default_font[];   #define IMAGE_DEFAULT_FONT_SIZE 30596      
pike.git/src/modules/Image/font.c:117:   #endif      #include <errno.h>      #include "stralloc.h"   #include "object.h"   #include "interpret.h"   #include "svalue.h"   #include "threads.h"   #include "builtin_functions.h" + #include "module_support.h"      #include "image.h"   #ifdef HAVE_UNISTD_H   #include <unistd.h>   #endif   #ifdef HAVE_MMAP   #include <sys/mman.h>   #endif      #include "dmalloc.h"
pike.git/src/modules/Image/font.c:411:    unsigned long i;      #ifdef FONT_DEBUG    fprintf(stderr,"FONT version 1\n");   #endif       THIS->chars=ntohl(fh->chars);       new_font=malloc(sizeof(struct font)+    sizeof(struct _char)*(THIS->chars-1)); +  if(!new_font) { +  free(THIS); +  SIMPLE_OUT_OF_MEMORY_ERROR(0,0); +  }    new_font->mem=THIS->mem;   #ifdef HAVE_MMAP    new_font->mmaped_size=THIS->mmaped_size;   #endif    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_font;
pike.git/src/modules/Image/font.c:517:    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;    ptrdiff_t to_write_len;    INT32 c;    struct font *this = (*(struct font **)(Pike_fp->current_storage)); +  ONERROR err; +     if (!this)    Pike_error("font->write: no font loaded\n");       if (args==0)    { -  push_string(make_shared_binary_string("",0)); -  args++; +  push_text(""); +  args=1;    }       maxwidth2=1;    -  width_of=(int *)malloc((args+1)*sizeof(int)); -  if(!width_of) resource_error(NULL,0,0,"memory",0,"Out of memory.\n"); +  width_of=(int *)xalloc((args+1)*sizeof(int)); +  SET_ONERROR(err, free, width_of);       for (j=0; j<args; j++)    {    int max;    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;
pike.git/src/modules/Image/font.c:600:    img->xsize = maxwidth2;    if(args>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"); } +  if (!img->img) { +  free_object(o); +  SIMPLE_OUT_OF_MEMORY_ERROR("write", +  img->xsize*img->ysize*sizeof(rgb_group)+1); +  }       MEMSET(img->img,0,img->xsize*img->ysize*sizeof(rgb_group));       for (j=0; j<args; j++)    {    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;
pike.git/src/modules/Image/font.c:687:    this->height);    xsize += char_space(this, c);    }    }    /* THREADS_DISALLOW(); */    break;    default:    Pike_fatal("Illegal shift size!\n");    }    } +  UNSET_ONERROR(err);    free(width_of);       pop_n_elems(args);    push_object(o);   }      /*! @decl int height()    *! Returns the font height.    *!    *! @seealso
pike.git/src/modules/Image/font.c:737:   void font_text_extents(INT32 args)   {    INT32 xsize,i,maxwidth2,j;       if (!THIS) Pike_error("font->text_extents: no font loaded\n");       maxwidth2=0;       if (args==0)    { -  push_string(make_shared_binary_string("",0)); -  args++; +  push_text(""); +  args=1;    }       for (j=0; j<args; j++)    {    int max;    p_wchar0 *to_write0;    p_wchar1 *to_write1;    p_wchar2 *to_write2;    ptrdiff_t to_write_len;    if (sp[j-args].type!=T_STRING)
pike.git/src/modules/Image/font.c:809:   /*! @decl void set_xspacing_scale(float scale)    *! @decl void set_yspacing_scale(float scale)    *!    *! Set spacing scale to write characters closer    *! or more far away. This does not change scale    *! of character, only the space between them.    */      void font_set_xspacing_scale(INT32 args)   { -  if(!THIS) Pike_error("font->set_xspacing_scale(FLOAT): No font loaded.\n"); -  if(!args) Pike_error("font->set_xspacing_scale(FLOAT): No argument!\n"); -  if(sp[-args].type!=T_FLOAT) -  Pike_error("font->set_xspacing_scale(FLOAT): Wrong type of argument!\n"); +  FLOAT_TYPE f;    -  THIS->xspacing_scale = (double)sp[-args].u.float_number; - /*fprintf(stderr, "Setting xspacing to %f\n", THIS->xspacing_scale);*/ -  if(THIS->xspacing_scale < 0.0) -  THIS->xspacing_scale=0.1; -  pop_stack(); +  if(!THIS) Pike_error("font->set_xspacing_scale(): No font loaded.\n"); +  get_all_args("set_xspaxing_scale", args, "%f", &f); +  +  if(f < 0.0) f=0.1; +  THIS->xspacing_scale = (double)f; +  pop_n_elems(args);   }         void font_set_yspacing_scale(INT32 args)   { -  if(!THIS) Pike_error("font->set_yspacing_scale(FLOAT): No font loaded.\n"); -  if(!args) Pike_error("font->set_yspacing_scale(FLOAT): No argument!\n"); -  if(sp[-args].type!=T_FLOAT) -  Pike_error("font->set_yspacing_scale(FLOAT): Wrong type of argument!\n"); +  FLOAT_TYPE f;    -  THIS->yspacing_scale = (double)sp[-args].u.float_number; - /*fprintf(stderr, "Setting yspacing to %f\n", THIS->yspacing_scale);*/ -  if(THIS->yspacing_scale <= 0.0) -  THIS->yspacing_scale=0.1; -  pop_stack(); +  if(!THIS) Pike_error("font->set_yspacing_scale(): No font loaded.\n"); +  get_all_args("set_yspacing_scale", args, "%f", &f); +  +  if(f <= 0.0) f=0.1; +  THIS->yspacing_scale = (double)f; +  pop_n_elems(args);   }         /*! @decl int baseline()    *!    *! Returns font baseline (pixels from top)    *!    *! @seealso    *! @[height], @[text_extents]    */