Example #1
0
static void setup_callbacks( struct source *src )
{
  struct pf_source *s = (struct pf_source *)src;
  if( !s->str )
  {
    ref_push_object( s->cb_obj );
    apply( s->obj, "set_read_callback", 1 );
    pop_stack();
    ref_push_object( s->cb_obj );
    apply( s->obj, "set_close_callback", 1 );
    pop_stack();
  }
}
Example #2
0
/*! @decl string _sprintf()
 */
static void f_path_element_sprintf(INT32 args)
{
  INT_TYPE mode;
  struct mapping *opts;
  cairo_path_data_t* data = THIS->element;

  get_all_args("_sprintf", args, "%i%m", &mode, &opts);
  pop_n_elems (args);
  if (mode == 'O')
    {
      switch (data->header.type)
        {
        case CAIRO_PATH_MOVE_TO:
          push_constant_text ("%O(CAIRO_PATH_MOVE_TO(%f,%f))");
          ref_push_object(Pike_fp->current_object);
          f_object_program (1);
          push_float(data[1].point.x); push_float(data[1].point.y);
          f_sprintf(4);
          break;
        case CAIRO_PATH_LINE_TO:
          push_constant_text ("%O(CAIRO_PATH_LINE_TO(%f,%f))");
          ref_push_object(Pike_fp->current_object);
          f_object_program (1);
          push_float(data[1].point.x); push_float(data[1].point.y);
          f_sprintf(4);
          break;
        case CAIRO_PATH_CURVE_TO:
          push_constant_text ("%O(CAIRO_PATH_CURVE_TO(%f,%f,%f,%f,%f))");
          ref_push_object(Pike_fp->current_object);
          f_object_program (1);
          push_float(data[1].point.x); push_float(data[1].point.y);
          push_float(data[2].point.x); push_float(data[2].point.y);
          push_float(data[3].point.x); push_float(data[3].point.y);
          f_sprintf(8);
          break;
        case CAIRO_PATH_CLOSE_PATH:
          push_constant_text ("%O(CAIRO_PATH_CLOSE_PATH()");
          ref_push_object(Pike_fp->current_object);
          f_object_program (1);
          f_sprintf(2);
          break;
        default:
          push_undefined();
          return;
        }
    }
  else
    push_undefined();
}
Example #3
0
static void image_ttf_faceinstance_set_height(INT32 args)
{
   struct image_ttf_face_struct *face_s;
   struct image_ttf_faceinstance_struct *face_i=THISi;
   int h=0;

   if (!args)
      Pike_error("Image.TTF.FaceInstance->set_height(): missing arguments\n");

   if (sp[-args].type==T_INT)
      h = sp[-args].u.integer*64;
   else if (sp[-args].type==T_FLOAT)
      h = DOUBLE_TO_INT(sp[-args].u.float_number*64);
   else
      Pike_error("Image.TTF.FaceInstance->set_height(): illegal argument 1\n");
   if (h<1) h=1;

   if (!(face_s=(struct image_ttf_face_struct*)
	 get_storage(THISi->faceobj,image_ttf_face_program)))
      Pike_error("Image.TTF.FaceInstance->write(): lost Face\n");

   ttf_instance_setc(face_s,face_i,h,"Image.TTF.FaceInstance->set_height()");

   pop_n_elems(args);
   ref_push_object(THISOBJ);
}
Example #4
0
/*! @decl int value()
 *! Return the current path element that the iterator is pointing at.
 */
static void f_path_iterator_value(INT32 args)
{
  struct cairo_mod_path* pw;
  struct object* o;
  struct cairo_mod_path_element* pew;
  cairo_path_t* path;
  cairo_path_data_t* data = NULL;
  int j,i;

  pw = (struct cairo_mod_path*)get_storage(THIS->path_obj, cairo_mod_path_program);
  path = pw->path;

  for (i=0, j=0; i<path->num_data; i+= path->data[i].header.length, j++)
    {
      if (j == THIS->idx)
        {
          data = &path->data[i];
          break;
        }
    }

  if (!data)
    {
      
    }
    
  o = clone_object(cairo_mod_path_element_program, 0);
  pew = (struct cairo_mod_path_element*)get_storage(o, cairo_mod_path_element_program);
  pew->path_obj = THIS->path_obj;
  add_ref(THIS->path_obj);
  pew->element = data;
  ref_push_object(o);
}
Example #5
0
static void image_ttf_face_make(INT32 args)
{
   pop_n_elems(args);

   ref_push_object(THISOBJ);
   push_object(clone_object(image_ttf_faceinstance_program,1));
}
Example #6
0
/*! @decl void `+=(int step)
 *! Move @tt{step@} steps forward in the path.
 */
static void f_path_iterator_add_self(INT32 args)
{
  int i;
  get_all_args("`+=", args, "%d", &i);
  THIS->idx += i;
  pop_n_elems(args);
  ref_push_object(Pike_fp->current_object);
}
Example #7
0
static void image_ttf_face_flush(INT32 args)
{
   int res;
   pop_n_elems(args);

   if ((res=TT_Flush_Face(THISf->face)))
      my_tt_error("Image.TTF.Face->flush()","",res);

   ref_push_object(THISOBJ);
}
Example #8
0
void image_polyfill(INT32 args)
{
    struct vertex *v;
    double *buf;
    ONERROR err;

    if (!THIS->img)
        Pike_error("Image.Image->polyfill: no image\n");

    buf=xalloc(sizeof(double)*(THIS->xsize+1));
    SET_ONERROR(err, free, buf);

    v=polyfill_begin();

    while (args)
    {
        struct vertex *v_tmp;

        if (sp[-1].type!=T_ARRAY)
        {
            polyfill_free(v);
            SIMPLE_BAD_ARG_ERROR("Image.Image->polyfill", args,
                                 "array(int|float)");
        }
        if ((v_tmp=polyfill_add(&v, sp[-1].u.array, args,
                                "Image.Image->polyfill()"))) {
            v = v_tmp;
        } else {
            polyfill_free(v);
            Pike_error("Image.Image->polyfill: Bad argument %d, bad vertex\n", args);
        }
        args--;
        pop_stack();
    }

    if (!v) {
        free(buf);
        return; /* no vertices */
    }

    polyfill_some(THIS,v,buf);

    polyfill_free(v);

    UNSET_ONERROR(err);
    free(buf);

    ref_push_object(THISOBJ);
}
Example #9
0
void pgtk2_return_this(int n) {
  pop_n_elems(n);
  ref_push_object(Pike_fp->current_object);
}
Example #10
0
void pgtk2_ref_push_object(struct object *o) {
  ref_push_object(o);
}
Example #11
0
static void image_xbm__decode( INT32 args )
{
  struct array *fg = NULL;
  struct array *bg = NULL;
  int invert=0, ele;
  struct pike_string *data;
  struct object *i=NULL, *a;
  get_all_args( "Image.XBM.decode", args, "%S", &data );


  if (args>1)
  {
    if (Pike_sp[1-args].type!=PIKE_T_MAPPING)
      Pike_error("Image.XBM._decode: illegal argument 2\n");
      
    push_svalue(Pike_sp+1-args);
    ref_push_string(param_fg); 
    f_index(2);
    if(!UNSAFE_IS_ZERO(Pike_sp-1))
    {
      if(Pike_sp[-1].type != PIKE_T_ARRAY || Pike_sp[-1].u.array->size != 3)
        Pike_error("Wrong type for foreground. Should be array(int(0..255))"
              " with 3 elements\n");
      for(ele=0; ele<3; ele++)
        if(Pike_sp[-1].u.array->item[ele].type != PIKE_T_INT
           ||Pike_sp[-1].u.array->item[ele].u.integer < 0
           ||Pike_sp[-1].u.array->item[ele].u.integer > 255)
          Pike_error("Wrong type for foreground. Should be array(int(0..255))"
                " with 3 elements\n");
      fg = Pike_sp[-1].u.array;
    }
    Pike_sp--;

    push_svalue(Pike_sp+1-args);
    ref_push_string(param_bg);
    f_index(2);
    if(!UNSAFE_IS_ZERO(Pike_sp-1))
    {
      if(Pike_sp[-1].type != PIKE_T_ARRAY || Pike_sp[-1].u.array->size != 3)
        Pike_error("Wrong type for background. Should be array(int(0..255))"
              " with 3 elements\n");
      for(ele=0; ele<3; ele++)
        if(Pike_sp[-1].u.array->item[ele].type != PIKE_T_INT
           ||Pike_sp[-1].u.array->item[ele].u.integer < 0
           ||Pike_sp[-1].u.array->item[ele].u.integer > 255)
          Pike_error("Wrong type for background. Should be array(int(0..255))"
                " with 3 elements\n");
      bg = Pike_sp[-1].u.array;
    }
    Pike_sp--;
    
    push_svalue(Pike_sp+1-args);
    ref_push_string(param_invert);
    f_index(2);
    invert = !UNSAFE_IS_ZERO(Pike_sp-1);
    Pike_sp--;
  }

  a = load_xbm( data );

  if(!fg)
  {
    if(invert)
    {
      apply(a, "invert", 0);
      i = (struct object *)debug_malloc_pass(Pike_sp[-1].u.object);
      Pike_sp--;
    }
    else
    {
      i = a;
      add_ref(a);
    }
  } else {
    if(!bg)
    {
      push_int(255);
      push_int(255);
      push_int(255);
      f_aggregate(3);
      bg = (struct array *)debug_malloc_pass(Pike_sp[-1].u.array);
      Pike_sp--;
    }
    if(invert)
    {
      struct array *tmp = fg;
      fg = bg;
      bg = fg;
    }
    apply(a, "xsize", 0);
    apply(a, "ysize", 0);
    push_int( bg->item[0].u.integer );
    push_int( bg->item[1].u.integer );
    push_int( bg->item[2].u.integer );
    i = clone_object( image_program, 5 );
    ref_push_object( i );
    push_int( fg->item[0].u.integer );
    push_int( fg->item[1].u.integer );
    push_int( fg->item[2].u.integer );

    apply( i, "paste_alpha_color", 4 );
  }
  
  pop_n_elems(args);
  push_constant_text( "alpha" );
  push_object( a );
    push_constant_text( "image" );
  if(i)
    push_object( i );
  else
    push_int( 0 );
  f_aggregate_mapping(4);
}
Example #12
0
/*! @decl Pike.Backend query_backend()
 *!
 *! Return the backend used for the accept callback.
 *!
 *! @seealso
 *!   @[set_backend]
 */
static void port_query_backend (INT32 args)
{
  pop_n_elems (args);
  ref_push_object (get_backend_obj (THIS->box.backend ? THIS->box.backend :
				    default_backend));
}
Example #13
0
static void image_ttf_faceinstance_ponder(INT32 args)
{
   int *sstr;
   int len,i,res,base=0;
   struct image_ttf_face_struct *face_s;
   struct image_ttf_faceinstance_struct *face_i=THISi;

   int xmin=1000,xmax=-1000,pos=0;

   if (!(face_s=(struct image_ttf_face_struct*)
	 get_storage(THISi->faceobj,image_ttf_face_program)))
      Pike_error("Image.TTF.FaceInstance->ponder(): lost Face\n");

   if (args && sp[-1].type==T_INT)
   {
      base=sp[-1].u.integer;
      args--;
      pop_stack();
   }

   if (sp[-args].type!=T_STRING)
      Pike_error("Image.TTF.FaceInstance->ponder(): illegal argument 1\n");

   switch( sp[-args].u.string->size_shift )
   {
    case 0:
      ttf_please_translate_8bit(face_s->face,
                                sp[-args].u.string,&sstr,&len,base,
                                "Image.TTF.FaceInstance->ponder()");
      break;
    case 1:
      ttf_please_translate_16bit(face_s->face,
                                 sp[-args].u.string,&sstr,&len,base,
                                 "Image.TTF.FaceInstance->ponder()");
      break;
    default:
     Pike_error("Too wide string for truetype\n");
   }
   pop_n_elems(args);

   for (i=0; i<len; i++)
   {
      TT_Glyph glyph;
      TT_Glyph_Metrics metrics;
      int ind;

      ind=sstr[i];
/*       fprintf(stderr,"glyph: %d\n",ind); */

      if ((res=TT_New_Glyph(face_s->face,&glyph)))
	 my_tt_error("Image.TTF.FaceInstance->ponder()","TT_New_Glyph: ",res);

      if ((res=TT_Load_Glyph(face_i->instance, glyph,
			     (TT_UShort)ind, (TT_UShort)face_i->load_flags)))
	 my_tt_error("Image.TTF.FaceInstance->ponder()","TT_Load_Glyph: ",res);

      if ((res=TT_Get_Glyph_Metrics(glyph,&metrics)))
	 my_tt_error("Image.TTF.FaceInstance->ponder()",
		     "TT_Get_Glyph_Metrics: ",res);

      if (pos+metrics.bbox.xMin<xmin) xmin=pos+metrics.bbox.xMin;
      if (pos+metrics.bbox.xMax>xmax) xmax=pos+metrics.bbox.xMax;
      pos+=metrics.advance; /* insert kerning stuff here */

/*       fprintf(stderr,"bbox: (%f,%f)-(%f,%f)\n", */
/* 	      metrics.bbox.xMin/64.0, */
/* 	      metrics.bbox.yMin/64.0, */
/* 	      metrics.bbox.xMax/64.0, */
/* 	      metrics.bbox.yMax/64.0); */

/*       fprintf(stderr,"BearingX: %f\n",metrics.bearingX/64.0); */
/*       fprintf(stderr,"BearingY: %f\n",metrics.bearingY/64.0); */
/*       fprintf(stderr,"advance: %f\n",metrics.advance/64.0); */

/*       fprintf(stderr,"\n"); */
   }

   free(sstr);

/*    fprintf(stderr,"xmin: %f\n",xmin/64.0); */
/*    fprintf(stderr,"xmax: %f\n",xmax/64.0); */

   ref_push_object(THISOBJ);
}
Example #14
0
static void image_ttf_faceinstance_face(INT32 args)
{
   pop_n_elems(args);
   ref_push_object(THISi->faceobj);
}