Example #1
0
static void
_dae_update_data(DiagramAsElement *dae)
{
  struct stat statbuf;
  Element *elem = &dae->element;
  DiaObject *obj = &elem->object;
  static int working = 0;
  
  if (working > 2)
    return; /* protect against infinite recursion */
  ++working;

  if (   strlen(dae->filename)
      && g_stat(dae->filename, &statbuf) == 0
      && dae->mtime != statbuf.st_mtime) {
    DiaImportFilter *inf;

    if (dae->data)
      g_object_unref(dae->data);
    dae->data = g_object_new (DIA_TYPE_DIAGRAM_DATA, NULL);

    inf = filter_guess_import_filter(dae->filename);
    if (inf) {
      DiaContext *ctx = dia_context_new (diagram_as_element_type.name);

      dia_context_set_filename (ctx, dae->filename);
      if (inf->import_func(dae->filename, dae->data, ctx, inf->user_data)) {
        data_update_extents (dae->data); /* should already be called by importer? */
        dae->scale = dae->element.width / (dae->data->extents.right - dae->data->extents.left);
        dae->element.height = (dae->data->extents.bottom - dae->data->extents.top) * dae->scale;
        dae->mtime = statbuf.st_mtime;
      }
      /* FIXME: where to put the message in case of an error? */
      dia_context_release (ctx);
    }
    /* invalidate possibly cached image */
    if (dae->image) {
      g_object_unref (dae->image);
      dae->image = NULL;
    }
  }
  /* fixme - fit the scale to draw the diagram in elements size ?*/
  if (dae->scale)
    dae->scale = dae->element.width / (dae->data->extents.right - dae->data->extents.left);

  elem->extra_spacing.border_trans = dae->border_line_width/2.0;
  element_update_boundingbox(elem);
  element_update_handles(elem);
  element_update_connections_rectangle(elem, dae->connections);

  /* adjust objects position, otherwise it'll jump on move */
  obj->position = elem->corner;

  --working;
}
Example #2
0
/** Convert infname to outfname, using input filter inf and export filter
 * ef.  If either is null, try to guess them.
 * size might be NULL.
 */
static gboolean
do_convert(const char *infname, 
	   const char *outfname, DiaExportFilter *ef,
	   const char *size,
	   char *show_layers)
{
  DiaImportFilter *inf;
  DiagramData *diagdata = NULL;
  DiaContext *ctx;

  inf = filter_guess_import_filter(infname);
  if (!inf) 
    inf = &dia_import_filter;

  if (ef == NULL) {
    ef = filter_guess_export_filter(outfname);
    if (!ef) {
      g_critical(_("%s error: don't know how to export into %s\n"),
	      argv0,outfname);
      exit(1);
    }
  }

  dia_is_interactive = FALSE;

  if (0==strcmp(infname,outfname)) {
    g_critical(_("%s error: input and output filenames are identical: %s"),
            argv0, infname);
    exit(1);
  }
  
  diagdata = g_object_new (DIA_TYPE_DIAGRAM_DATA, NULL);
  ctx = dia_context_new(_("Import"));

  if (!inf->import_func(infname, diagdata, ctx, inf->user_data)) {
    g_critical(_("%s error: need valid input file %s\n"),
            argv0, infname);
    exit(1);
  }

  /* Apply --show-layers */
  if (show_layers)
    handle_show_layers(diagdata, show_layers);

  /* recalculate before export */
  data_update_extents(diagdata);

  /* Do our best in providing the size to the filter, but don't abuse user_data 
   * too much for it. It _must not_ be changed after initialization and there 
   * are quite some filter selecting their output format by it. --hb
   */
  if (size) {
    if (ef == filter_export_get_by_name ("png-libart")) /* the warning we get is appropriate, don't cast */
      ef->export_func(diagdata, ctx, outfname, infname, size);
    else {
      g_warning ("--size parameter unsupported for %s filter", 
                 ef->unique_name ? ef->unique_name : "selected");
      ef->export_func(diagdata, ctx, outfname, infname, ef->user_data);
    }
  }
  else
    ef->export_func(diagdata, ctx, outfname, infname, ef->user_data);
  /* if (!quiet) */ fprintf(stdout,
                      _("%s --> %s\n"),
                        infname,outfname);
  g_object_unref(diagdata);
  dia_context_release(ctx);
  return TRUE;
}