예제 #1
0
static void
_dae_draw(DiagramAsElement *dae, DiaRenderer *renderer)
{
  DiaRendererClass *renderer_ops = DIA_RENDERER_GET_CLASS (renderer);
  Element *elem = &dae->element;

  if (!dae->data) {
    /* just draw the box */
    Point lower_right = {
      elem->corner.x + elem->width,
      elem->corner.y + elem->height 
    };

    renderer_ops->draw_rect(renderer,&elem->corner, &lower_right, 
                            &dae->border_color);

  } else {
    if (FALSE) {
      /* if the renderer supports transformations ... */
      /* temporary messing with it (not enough) */
      dae->data->paper.scaling *= dae->scale;
      data_render (dae->data, DIA_RENDERER (renderer), NULL, NULL, NULL);
      dae->data->paper.scaling /= dae->scale;
    } else {
      /* we have to render to an image and draw that */
      if (!dae->image) { /* lazy creation */
	gchar *imgfname = NULL;
	gint fd = g_file_open_tmp ("diagram-as-elementXXXXXX.png", &imgfname, NULL);
	if (fd != -1) {
          DiaExportFilter *ef = filter_export_get_by_name ("cairo-alpha-png");
	  if (!ef) /* prefer cairo with alpha, but don't require it */
	    ef = filter_guess_export_filter (imgfname);
	  close(fd);
	  if (ef) {
	    DiaContext *ctx = dia_context_new ("Diagram as Object");

	    dia_context_set_filename (ctx, imgfname);
	    if (ef->export_func (dae->data, ctx, imgfname, dae->filename, ef->user_data)) {
	      DiaImage *tmp_image = dia_image_load (imgfname);

	      /* some extra gymnastics to create an image w/o filename */
	      if (tmp_image) {
	        dae->image = dia_image_new_from_pixbuf ((GdkPixbuf *)dia_image_pixbuf (tmp_image));
	        g_object_unref (tmp_image);
	      }
	      /* FIXME: where to put the message in case of an error? */
	      dia_context_release (ctx);
	    }
	  } /* found a filter */
	  g_unlink (imgfname);
	  g_free (imgfname);
	} /* temporary file created*/
      } /* only if we have no image yet */
      if (dae->image)
	renderer_ops->draw_image (renderer, &elem->corner, elem->width, elem->height, dae->image);
    }
  }
}
예제 #2
0
파일: shape-export.c 프로젝트: UIKit0/dia
static gboolean
export_shape(DiagramData *data, DiaContext *ctx,
	     const gchar *filename, const gchar *diafilename,
	     void* user_data)
{
    DiaSvgRenderer *renderer;
    int i;
    gchar *point;
    gchar *png_filename = NULL;
    DiaExportFilter *exportfilter;
    gfloat old_scaling;
    Rectangle *ext = &data->extents;
    gfloat scaling_x, scaling_y;

    /* create the png preview shown in the toolbox */
    point = strrchr(filename, '.');
    if (point == NULL || strcmp(point, ".shape") != 0) {
	dia_context_add_message(ctx, _("Shape files must end in .shape, or they cannot be loaded by Dia"));
	return FALSE;
    }
    i = (int)(point-filename);
    point = g_strndup(filename, i);
    png_filename = g_strdup_printf("%s.png",point);
    g_free(point);
    /* we are especially requesting the libart/png cause it is the only one with the size-hack */
    exportfilter = filter_export_get_by_name ("png-libart");
    /* ... but the code below does not use the size-hack anymore ... */
    if (!exportfilter)
      exportfilter = filter_guess_export_filter(png_filename);

    if (!exportfilter) {
      dia_context_add_message(ctx, _("Can't export PNG icon without export plugin!"));
    } else {
      /* get the scaling right */
      old_scaling = data->paper.scaling;
      scaling_x = 22/((ext->right - ext->left) * 20);
      scaling_y = 22/((ext->bottom - ext->top) * 20);
      data->paper.scaling = MIN(scaling_x, scaling_y);
      exportfilter->export_func(data, ctx, png_filename, diafilename, exportfilter->user_data);
      data->paper.scaling = old_scaling;
    }
    g_free(png_filename);

    /* create the shape */
    if((renderer = new_shape_renderer(data, filename))) {
      data_render(data, DIA_RENDERER(renderer), NULL, NULL, NULL);
      g_object_unref (renderer);
      return TRUE;
    }

    /* Create a sheet entry if applicable (../../sheets exists) */

    return FALSE;
}
예제 #3
0
파일: filedlg.c 프로젝트: AmiGanguli/dia
/**
 * A button hit in the Export Dialog
 */
static void
file_export_response_callback(GtkWidget *fs, 
                              gint       response, 
                              gpointer   user_data)
{
  char *filename;
  Diagram *dia;
  DiaExportFilter *ef;
  struct stat statbuf;

  dia = g_object_get_data (G_OBJECT (fs), "user_data");
  g_assert (dia);

  if (response == GTK_RESPONSE_ACCEPT) {
    gint index;

    diagram_update_extents(dia);

    filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fs));

    if (g_stat(filename, &statbuf) == 0) {
      GtkWidget *dialog = NULL;

      dialog = gtk_message_dialog_new (GTK_WINDOW(fs),
				       GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, 
				       GTK_MESSAGE_QUESTION,
				       GTK_BUTTONS_YES_NO,
				       _("File already exists"));
      gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
        _("The file '%s' already exists.\n"
        "Do you want to overwrite it?"), dia_message_filename(filename));
      gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);

      if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_YES) {
	/* if not overwrite allow to select another filename */
	gtk_widget_destroy(dialog);
	g_free (filename);
	return;
      }
      gtk_widget_destroy(dialog);
    }

    index = gtk_combo_box_get_active (GTK_COMBO_BOX(user_data));
    if (index >= 0)
      persistence_set_integer ("export-filter", index);
    ef = efilter_by_index (index - 1, NULL);
    if (!ef)
      ef = filter_guess_export_filter(filename);
    if (ef) {
      DiaContext *ctx = dia_context_new (_("Export"));

      g_object_ref(dia->data);
      dia_context_set_filename (ctx, filename);
      ef->export_func(dia->data, ctx,
		      filename, dia->filename, ef->user_data);
      g_object_unref(dia->data);
      dia_context_release (ctx);
    } else
      message_error(_("Could not determine which export filter\n"
		      "to use to save '%s'"), dia_message_filename(filename));
    g_free (filename);
  }
  g_object_unref (dia); /* drop our diagram reference */
  gtk_widget_destroy(exportdlg);
}