Example #1
0
File: pixbuf.c Project: GNOME/dia
static gboolean
import_data (const gchar *filename, DiagramData *data, DiaContext *ctx, void* user_data)
{
  DiaObjectType *otype = object_get_type("Standard - Image");
  gint width, height;

  if (!otype) /* this would be really broken */
    return FALSE;

  if (!user_data) {
    dia_context_add_message(ctx, _("Calling error, missing user_data."));
    return FALSE;
  }

  if (gdk_pixbuf_get_file_info (filename, &width, &height))
    {
      DiaObject *obj;
      Handle *h1, *h2;
      Point point;
      point.x = point.y = 0.0;

      obj = otype->ops->create(&point, otype->default_user_data, &h1, &h2);
      if (obj)
        {
          GPtrArray *plist = g_ptr_array_new ();

          prop_list_add_filename (plist, "image_file", filename);
          prop_list_add_real (plist, "elem_width", width / 20.0);
          prop_list_add_real (plist, "elem_height", height / 20.0);

          obj->ops->set_props(obj, plist);
          prop_list_free (plist);

          layer_add_object(data->active_layer, obj);
          return TRUE;
        }
    }
  else
    {
      dia_context_add_message(ctx, _("Pixbuf[%s] can't load:\n%s"), 
			      (gchar*)user_data, dia_context_get_filename(ctx));
    }

  return FALSE;
}
Example #2
0
/* reads an ellipse entity from the dxf file and creates an ellipse object in dia*/
static DiaObject *
read_entity_ellipse_dxf(FILE *filedxf, DxfData *data, DiagramData *dia)
{
    /* ellipse data */
    Point center = {0, 0};
    real width = 1.0;
    real ratio_width_height = 1.0;
    
    DiaObjectType *otype = object_get_type("Standard - Ellipse");
    Handle *h1, *h2;
    
    DiaObject *ellipse_obj; 
    RGB_t color = { 0, };
    Color line_colour;
    GPtrArray *props;

    real line_width = DEFAULT_LINE_WIDTH;
    Layer *layer = dia->active_layer;
    
    do {
        if(read_dxf_codes(filedxf, data) == FALSE){
            return( NULL );
        }
        switch(data->code){
        case  8: 
            layer = layer_find_by_name(data->value, dia);
	    color = pal_get_rgb (_dxf_color_get_by_layer (layer));
            break;
        case 10: 
            center.x = g_ascii_strtod(data->value, NULL) * coord_scale * measure_scale;
            break;
        case 11: 
            ratio_width_height = g_ascii_strtod(data->value, NULL) * coord_scale * measure_scale;
            break;
        case 20: 
            center.y = (-1)*g_ascii_strtod(data->value, NULL) * coord_scale * measure_scale;
            break;
        case 39: 
            line_width = g_ascii_strtod(data->value, NULL) * WIDTH_SCALE;
            break;
        case 40: 
            width = g_ascii_strtod(data->value, NULL) * WIDTH_SCALE; /* XXX what scale */
            break;
	case 62 :
            color = pal_get_rgb (atoi(data->value));
            break;
        }
    } while(data->code != 0);
 
    center.x -= width;
    center.y -= (width*ratio_width_height);
    ellipse_obj = otype->ops->create(&center, otype->default_user_data,
                                     &h1, &h2);

    _color_init_from_rgb (&line_colour, color);

    props = g_ptr_array_new ();

    prop_list_add_point (props, "elem_corner", &center);
    prop_list_add_real (props, "elem_width", width);
    prop_list_add_real (props, "elem_height", width * ratio_width_height);
    prop_list_add_line_colour (props, &line_colour);
    prop_list_add_line_width (props, line_width);
    prop_list_add_show_background (props, FALSE);
    
    ellipse_obj->ops->set_props(ellipse_obj, props);
    prop_list_free(props);

    if (layer)
        layer_add_object(layer, ellipse_obj);
    else
        return ellipse_obj;

    return NULL; /* don't add it twice */
}
Example #3
0
/* reads a circle entity from the dxf file and creates a circle object in dia*/
static DiaObject *
read_entity_arc_dxf(FILE *filedxf, DxfData *data, DiagramData *dia)
{
    /* arc data */
    Point start, end;
    Point center = {0, 0};
    real radius = 1.0, start_angle = 0.0, end_angle=360.0;
    real curve_distance;

    DiaObjectType *otype = object_get_type("Standard - Arc");  
    Handle *h1, *h2;
  
    DiaObject *arc_obj;
    RGB_t color  = { 0, };
    Color line_colour;
    GPtrArray *props;

    real line_width = DEFAULT_LINE_WIDTH;
    Layer *layer = dia->active_layer;
		
    do {
        if(read_dxf_codes(filedxf, data) == FALSE){
            return( NULL );
        }
        switch(data->code){
        case  8: 
            layer = layer_find_by_name(data->value, dia);
	    color = pal_get_rgb (_dxf_color_get_by_layer (layer));
            break;
        case 10: 
            center.x = g_ascii_strtod(data->value, NULL) * coord_scale * measure_scale;
            break;
        case 20: 
            center.y = (-1)*g_ascii_strtod(data->value, NULL) * coord_scale * measure_scale;
            break;
        case 39: 
            line_width = g_ascii_strtod(data->value, NULL) * WIDTH_SCALE;
            break;
        case 40: 
            radius = g_ascii_strtod(data->value, NULL) * coord_scale * measure_scale;
            break;
        case 50:
            start_angle = g_ascii_strtod(data->value, NULL)*M_PI/180.0;
            break;
        case 51:
            end_angle = g_ascii_strtod(data->value, NULL)*M_PI/180.0;
            break;
	case 62 :
            color = pal_get_rgb (atoi(data->value));
            break;
        }
    } while(data->code != 0);

    /* printf("c.x=%f c.y=%f s",center.x,center.y); */
    start.x = center.x + cos(start_angle) * radius; 
    start.y = center.y - sin(start_angle) * radius;
    end.x = center.x + cos(end_angle) * radius;
    end.y = center.y - sin(end_angle) * radius;
    /*printf("s.x=%f s.y=%f e.x=%f e.y=%f\n",start.x,start.y,end.x,end.y);*/


    if (end_angle < start_angle) end_angle += 2.0*M_PI;
    curve_distance = radius * (1 - cos ((end_angle - start_angle)/2));

    /*printf("start_angle: %f end_angle: %f radius:%f  curve_distance:%f\n",
      start_angle,end_angle,radius,curve_distance);*/
   
    arc_obj = otype->ops->create(&center, otype->default_user_data,
                                     &h1, &h2);
    
    _color_init_from_rgb (&line_colour, color);

    props = g_ptr_array_new ();
    prop_list_add_point (props, "start_point", &start);
    prop_list_add_point (props, "end_point", &end);
    prop_list_add_real (props, "curve_distance", curve_distance);
    prop_list_add_line_colour (props, &line_colour);
    prop_list_add_line_width (props, line_width);
    
    arc_obj->ops->set_props(arc_obj, props);
    prop_list_free(props);
   
    if (layer)
        layer_add_object(layer, arc_obj);
    else
        return arc_obj ;

    return NULL; /* don't add it twice */
}