Beispiel #1
0
Datei: arc.c Projekt: mpuels/dia
static DiaObject *
arc_load(ObjectNode obj_node, int version,DiaContext *ctx)
{
  Arc *arc;
  Connection *conn;
  DiaObject *obj;
  AttributeNode attr;

  arc = g_malloc0(sizeof(Arc));

  conn = &arc->connection;
  obj = &conn->object;

  obj->type = &arc_type;
  obj->ops = &arc_ops;

  connection_load(conn, obj_node, ctx);

  arc->arc_color = color_black;
  attr = object_find_attribute(obj_node, "arc_color");
  if (attr != NULL)
    data_color(attribute_first_data(attr), &arc->arc_color, ctx);

  arc->curve_distance = 0.1;
  attr = object_find_attribute(obj_node, "curve_distance");
  if (attr != NULL)
    arc->curve_distance = data_real(attribute_first_data(attr), ctx);

  arc->line_width = 0.1;
  attr = object_find_attribute(obj_node, PROP_STDNAME_LINE_WIDTH);
  if (attr != NULL)
    arc->line_width = data_real(attribute_first_data(attr), ctx);

  arc->line_style = LINESTYLE_SOLID;
  attr = object_find_attribute(obj_node, "line_style");
  if (attr != NULL)
    arc->line_style = data_enum(attribute_first_data(attr), ctx);

  arc->dashlength = DEFAULT_LINESTYLE_DASHLEN;
  attr = object_find_attribute(obj_node, "dashlength");
  if (attr != NULL)
    arc->dashlength = data_real(attribute_first_data(attr), ctx);

  arc->line_caps = LINECAPS_BUTT;
  attr = object_find_attribute(obj_node, "line_caps");
  if (attr != NULL)
    arc->line_caps = data_enum(attribute_first_data(attr), ctx);

  load_arrow(obj_node, &arc->start_arrow, "start_arrow",
	     "start_arrow_length", "start_arrow_width", ctx);

  load_arrow(obj_node, &arc->end_arrow, "end_arrow",
	     "end_arrow_length", "end_arrow_width", ctx);

  connection_init(conn, 4, 0);

  _arc_setup_handles (arc);

  /* older versions did not prohibit everything reduced to a single point
   * and afterwards failed on all the calculations producing nan.
   */
  if (distance_point_point (&arc->connection.endpoints[0], 
                            &arc->connection.endpoints[1]) < 0.02) {
    arc->curve_distance = 0.0;
    arc->connection.endpoints[0].x -= 0.01;
    arc->connection.endpoints[1].x += 0.01;
    arc_update_handles (arc);
  }

  arc_update_data(arc);

  return &arc->connection.object;
}
Beispiel #2
0
static DiaObject *
line_load(ObjectNode obj_node, int version, DiaContext *ctx)
{
  Line *line;
  Connection *conn;
  DiaObject *obj;
  AttributeNode attr;

  line = g_malloc0(sizeof(Line));

  conn = &line->connection;
  obj = &conn->object;

  obj->type = &line_type;
  obj->ops = &line_ops;

  connection_load(conn, obj_node, ctx);

  line->line_color = color_black;
  attr = object_find_attribute(obj_node, "line_color");
  if (attr != NULL)
    data_color(attribute_first_data(attr), &line->line_color, ctx);

  line->line_width = 0.1;
  attr = object_find_attribute(obj_node, PROP_STDNAME_LINE_WIDTH);
  if (attr != NULL)
    line->line_width = data_real(attribute_first_data(attr), ctx);

  line->line_style = LINESTYLE_SOLID;
  attr = object_find_attribute(obj_node, "line_style");
  if (attr != NULL)
    line->line_style = data_enum(attribute_first_data(attr), ctx);

  line->line_caps = LINECAPS_BUTT;
  attr = object_find_attribute(obj_node, "line_caps");
  if (attr != NULL)
    line->line_caps = data_enum(attribute_first_data(attr), ctx);

  load_arrow(obj_node, &line->start_arrow, 
	     "start_arrow", "start_arrow_length", "start_arrow_width", ctx);

  load_arrow(obj_node, &line->end_arrow, 
	     "end_arrow", "end_arrow_length", "end_arrow_width", ctx);

  line->absolute_start_gap = 0.0;
  attr = object_find_attribute(obj_node, "absolute_start_gap");
  if (attr != NULL)
    line->absolute_start_gap =  data_real(attribute_first_data(attr), ctx);
  line->absolute_end_gap = 0.0;
  attr = object_find_attribute(obj_node, "absolute_end_gap");
  if (attr != NULL)
    line->absolute_end_gap =  data_real(attribute_first_data(attr), ctx);

  line->dashlength = DEFAULT_LINESTYLE_DASHLEN;
  attr = object_find_attribute(obj_node, "dashlength");
  if (attr != NULL)
    line->dashlength = data_real(attribute_first_data(attr), ctx);

  connection_init(conn, 2, 0);

  line->cpl = connpointline_load(obj,obj_node,"numcp",1,NULL, ctx);
  line_update_data(line);

  return &line->connection.object;
}