1998-03-20 10:40:04 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* This is a plug-in for the GIMP.
|
|
|
|
*
|
|
|
|
* Generates images containing vector type drawings.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1997 Andy Thomas alt@picnic.demon.co.uk
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
1998-04-13 13:44:11 +08:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1998-03-20 10:40:04 +08:00
|
|
|
*/
|
|
|
|
|
1999-05-29 09:28:24 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
1998-03-20 10:40:04 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2004-07-13 00:57:29 +08:00
|
|
|
#include <string.h>
|
2003-06-06 20:42:22 +08:00
|
|
|
#include <errno.h>
|
2002-02-18 22:34:50 +08:00
|
|
|
|
1999-05-29 09:28:24 +08:00
|
|
|
#ifdef HAVE_UNISTD_H
|
1998-03-20 10:40:04 +08:00
|
|
|
#include <unistd.h>
|
1999-05-29 09:28:24 +08:00
|
|
|
#endif
|
2002-02-18 22:34:50 +08:00
|
|
|
|
1998-09-21 07:04:33 +08:00
|
|
|
#include <gtk/gtk.h>
|
1999-05-29 09:28:24 +08:00
|
|
|
|
2000-02-21 19:54:33 +08:00
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
#include <libgimp/gimpui.h>
|
2004-07-13 00:57:29 +08:00
|
|
|
|
2000-02-21 19:54:33 +08:00
|
|
|
#include "libgimp/stdplugins-intl.h"
|
|
|
|
|
2003-10-19 17:44:46 +08:00
|
|
|
#include "gfig.h"
|
2004-07-05 04:50:25 +08:00
|
|
|
#include "gfig-style.h"
|
|
|
|
#include "gfig-dialog.h"
|
2003-10-24 21:28:46 +08:00
|
|
|
#include "gfig-arc.h"
|
|
|
|
#include "gfig-bezier.h"
|
|
|
|
#include "gfig-circle.h"
|
|
|
|
#include "gfig-dobject.h"
|
|
|
|
#include "gfig-ellipse.h"
|
2003-11-12 05:23:33 +08:00
|
|
|
#include "gfig-grid.h"
|
2003-10-24 21:28:46 +08:00
|
|
|
#include "gfig-line.h"
|
|
|
|
#include "gfig-poly.h"
|
2003-11-12 05:23:33 +08:00
|
|
|
#include "gfig-preview.h"
|
2003-10-24 21:28:46 +08:00
|
|
|
#include "gfig-spiral.h"
|
|
|
|
#include "gfig-star.h"
|
2003-01-07 07:47:04 +08:00
|
|
|
#include "gfig-stock.h"
|
|
|
|
|
2003-10-24 21:28:46 +08:00
|
|
|
#include "pix-data.h"
|
1998-03-20 10:40:04 +08:00
|
|
|
|
2003-01-07 02:02:27 +08:00
|
|
|
|
1998-03-20 10:40:04 +08:00
|
|
|
/***** Magic numbers *****/
|
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
#define GFIG_HEADER "GFIG Version 0.2\n"
|
|
|
|
|
1998-03-20 10:40:04 +08:00
|
|
|
|
|
|
|
static void query (void);
|
2003-07-02 08:15:09 +08:00
|
|
|
static void run (const gchar *name,
|
2003-12-14 07:58:33 +08:00
|
|
|
gint nparams,
|
|
|
|
const GimpParam *param,
|
|
|
|
gint *nreturn_vals,
|
|
|
|
GimpParam **return_vals);
|
2000-02-21 19:54:33 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
|
1998-03-20 10:40:04 +08:00
|
|
|
|
2000-08-22 11:27:14 +08:00
|
|
|
GimpPlugInInfo PLUG_IN_INFO =
|
1998-03-20 10:40:04 +08:00
|
|
|
{
|
2000-02-21 19:54:33 +08:00
|
|
|
NULL, /* init_proc */
|
|
|
|
NULL, /* quit_proc */
|
|
|
|
query, /* query_proc */
|
|
|
|
run, /* run_proc */
|
1998-03-20 10:40:04 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-10-19 17:44:46 +08:00
|
|
|
gint line_no;
|
1998-03-20 10:40:04 +08:00
|
|
|
|
2003-10-20 05:03:21 +08:00
|
|
|
gint obj_show_single = -1; /* -1 all >= 0 object number */
|
1998-03-20 10:40:04 +08:00
|
|
|
|
|
|
|
/* Structures etc for the objects */
|
|
|
|
/* Points used to draw the object */
|
|
|
|
|
|
|
|
|
2003-10-19 17:44:46 +08:00
|
|
|
Dobject *obj_creating; /* Object we are creating */
|
|
|
|
Dobject *tmp_line; /* Needed when drawing lines */
|
1998-03-20 10:40:04 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
|
2003-10-19 17:44:46 +08:00
|
|
|
gint need_to_scale;
|
2000-02-21 19:54:33 +08:00
|
|
|
|
1998-03-20 10:40:04 +08:00
|
|
|
|
2004-07-13 00:57:29 +08:00
|
|
|
static gint load_options (GFigObj *gfig,
|
2004-07-07 03:32:55 +08:00
|
|
|
FILE *fp);
|
1998-03-20 10:40:04 +08:00
|
|
|
/* globals */
|
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
GdkGC *gfig_gc;
|
1998-03-20 10:40:04 +08:00
|
|
|
|
|
|
|
/* Stuff for the preview bit */
|
2004-07-05 04:50:25 +08:00
|
|
|
static gint sel_x1, sel_y1, sel_x2, sel_y2;
|
|
|
|
static gint sel_width, sel_height;
|
|
|
|
gint preview_width, preview_height;
|
|
|
|
gdouble scale_x_factor, scale_y_factor;
|
|
|
|
GdkPixbuf *back_pixbuf = NULL;
|
1998-03-20 10:40:04 +08:00
|
|
|
|
gimp-joke-980321
* app/iscissors.c, app/tips_dialog.c, app/gradient.c,
libgimp/gimp.c, plug-ins/AlienMap/AlienMap.c,
plug-ins/bmp/bmp.c, plug-ins/fits/fitsrw.h,
plug-ins/fits/fitsrw.c, plug-ins/flarefx/flarefx.c,
plug-ins/gfig/gfig.c, plug-ins/gfli/gfli.c,
plug-ins/gicon/gicon.c, plug-ins/gqbist/gqbist.c,
plug-ins/gtm/gtm.c, plug-ins/hot/hot.c,
plug-ins/ifscompose/ifscompose.c,
plug-ins/ifscompose/ifscompose_utils.c
plug-ins/max_rgb/max_rgb.c, plug-ins/nlfilt/nlfilt.c,
plug-ins/pat/pat.c, plug-ins/pcx/pcx.c, plug-ins/rotate/rotate.c,
plug-ins/script-fu/script-fu-server.c, plug-ins/snoise/snoise.c,
plug-ins/threshold_alpha/threshold_alpha.c,
plug-ins/zealouscrop/zealouscrop.c :gimp-joke-980321
plug-ins/CML_explorer, plug-ins/autocrop,
plug-ins/align_layers, plug-ins/blinds,
plug-ins/bmp, plug-ins/megawidget: gimp-joke-980322
Applied gimp-joke-980322-0.patch and gimp-joke-980321-0.patch
from Yasuhiro SHIRASAKI <joke@awa.tohoku.ac.jp>. Mostly
portability for DEC osf1's cc. Lots of MAIN();'s, trailing
commas in enums, and guchar/gchar madness.
Gimp now sends mail, cleans vinyl records,
removes stubborn stains, julien fries, and more!
-adrian
1998-03-23 04:44:39 +08:00
|
|
|
MAIN ()
|
1998-03-20 10:40:04 +08:00
|
|
|
|
|
|
|
static void
|
2000-02-21 19:54:33 +08:00
|
|
|
query (void)
|
1998-03-20 10:40:04 +08:00
|
|
|
{
|
2000-08-22 11:27:14 +08:00
|
|
|
static GimpParamDef args[] =
|
1998-03-20 10:40:04 +08:00
|
|
|
{
|
2004-05-07 22:59:33 +08:00
|
|
|
{ GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive" },
|
|
|
|
{ GIMP_PDB_IMAGE, "image", "Input image (unused)" },
|
2000-08-22 11:27:14 +08:00
|
|
|
{ GIMP_PDB_DRAWABLE, "drawable", "Input drawable" },
|
2004-05-07 22:59:33 +08:00
|
|
|
{ GIMP_PDB_INT32, "dummy", "dummy" }
|
1998-03-20 10:40:04 +08:00
|
|
|
};
|
2000-01-19 07:02:32 +08:00
|
|
|
|
1998-03-20 10:40:04 +08:00
|
|
|
gimp_install_procedure ("plug_in_gfig",
|
2003-12-14 07:58:33 +08:00
|
|
|
"Create Geometrical shapes with the Gimp",
|
|
|
|
"More here later",
|
|
|
|
"Andy Thomas",
|
|
|
|
"Andy Thomas",
|
|
|
|
"1997",
|
2004-05-07 22:59:33 +08:00
|
|
|
N_("_Gfig..."),
|
2003-12-14 07:58:33 +08:00
|
|
|
"RGB*, GRAY*",
|
|
|
|
GIMP_PLUGIN,
|
|
|
|
G_N_ELEMENTS (args), 0,
|
|
|
|
args, NULL);
|
2004-05-07 22:59:33 +08:00
|
|
|
|
|
|
|
gimp_plugin_menu_register ("plug_in_gfig",
|
|
|
|
N_("<Image>/Filters/Render"));
|
1998-03-20 10:40:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-07-02 08:15:09 +08:00
|
|
|
run (const gchar *name,
|
|
|
|
gint nparams,
|
|
|
|
const GimpParam *param,
|
|
|
|
gint *nreturn_vals,
|
|
|
|
GimpParam **return_vals)
|
1998-03-20 10:40:04 +08:00
|
|
|
{
|
2003-01-07 02:02:27 +08:00
|
|
|
GimpParam *values = g_new (GimpParam, 1);
|
|
|
|
GimpDrawable *drawable;
|
|
|
|
GimpRunMode run_mode;
|
|
|
|
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
2004-07-05 04:50:25 +08:00
|
|
|
gint pwidth, pheight;
|
2003-03-26 00:38:19 +08:00
|
|
|
INIT_I18N ();
|
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
gfig_context = (GFigContext*)g_malloc (sizeof (GFigContext));
|
|
|
|
gfig_context->show_background = TRUE;
|
|
|
|
gfig_context->selected_obj = NULL;
|
1998-03-20 10:40:04 +08:00
|
|
|
run_mode = param[0].data.d_int32;
|
2004-07-05 04:50:25 +08:00
|
|
|
gfig_context->image_id = param[1].data.d_image;
|
|
|
|
gfig_context->drawable_id = param[2].data.d_drawable;
|
1998-03-20 10:40:04 +08:00
|
|
|
|
|
|
|
*nreturn_vals = 1;
|
|
|
|
*return_vals = values;
|
|
|
|
|
2000-08-22 11:27:14 +08:00
|
|
|
values[0].type = GIMP_PDB_STATUS;
|
1998-03-20 10:40:04 +08:00
|
|
|
values[0].data.d_status = status;
|
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
gimp_image_undo_group_start (gfig_context->image_id);
|
|
|
|
|
2004-06-25 06:51:55 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
drawable = gimp_drawable_get (param[2].data.d_drawable);
|
1998-03-20 10:40:04 +08:00
|
|
|
|
|
|
|
/* TMP Hack - clear any selections */
|
2004-07-05 04:50:25 +08:00
|
|
|
if (! gimp_selection_is_empty (gfig_context->image_id))
|
|
|
|
gimp_selection_clear (gfig_context->image_id);
|
1998-03-20 10:40:04 +08:00
|
|
|
|
2001-06-15 04:07:38 +08:00
|
|
|
gimp_drawable_mask_bounds (drawable->drawable_id,
|
2003-12-14 07:58:33 +08:00
|
|
|
&sel_x1, &sel_y1, &sel_x2, &sel_y2);
|
1998-03-20 10:40:04 +08:00
|
|
|
|
|
|
|
sel_width = sel_x2 - sel_x1;
|
|
|
|
sel_height = sel_y2 - sel_y1;
|
|
|
|
|
2004-06-25 06:51:55 +08:00
|
|
|
|
1998-03-20 10:40:04 +08:00
|
|
|
/* Calculate preview size */
|
2003-10-30 04:57:21 +08:00
|
|
|
|
2000-02-21 19:54:33 +08:00
|
|
|
if (sel_width > sel_height)
|
|
|
|
{
|
|
|
|
pwidth = MIN (sel_width, PREVIEW_SIZE);
|
|
|
|
pheight = sel_height * pwidth / sel_width;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pheight = MIN (sel_height, PREVIEW_SIZE);
|
|
|
|
pwidth = sel_width * pheight / sel_height;
|
2003-01-07 02:02:27 +08:00
|
|
|
}
|
2004-07-13 00:57:29 +08:00
|
|
|
|
2003-10-30 04:57:21 +08:00
|
|
|
|
2000-02-21 19:54:33 +08:00
|
|
|
preview_width = MAX (pwidth, 2); /* Min size is 2 */
|
2003-10-30 04:57:21 +08:00
|
|
|
preview_height = MAX (pheight, 2);
|
1998-03-20 10:40:04 +08:00
|
|
|
|
2000-02-21 19:54:33 +08:00
|
|
|
org_scale_x_factor = scale_x_factor =
|
|
|
|
(gdouble) sel_width / (gdouble) preview_width;
|
|
|
|
org_scale_y_factor = scale_y_factor =
|
|
|
|
(gdouble) sel_height / (gdouble) preview_height;
|
2003-01-07 02:02:27 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
gimp_tile_cache_ntiles ((drawable->width + gimp_tile_width () - 1) /
|
|
|
|
gimp_tile_width ());
|
|
|
|
|
|
|
|
gimp_drawable_detach (drawable);
|
|
|
|
|
2004-07-07 03:32:55 +08:00
|
|
|
/* initialize */
|
|
|
|
gfig_init_object_classes ();
|
|
|
|
|
1998-03-20 10:40:04 +08:00
|
|
|
switch (run_mode)
|
|
|
|
{
|
2000-08-22 11:27:14 +08:00
|
|
|
case GIMP_RUN_INTERACTIVE:
|
1998-03-20 10:40:04 +08:00
|
|
|
/*gimp_get_data ("plug_in_gfig", &selvals);*/
|
2003-01-07 02:02:27 +08:00
|
|
|
if (! gfig_dialog ())
|
2003-12-14 07:58:33 +08:00
|
|
|
{
|
2004-07-05 04:50:25 +08:00
|
|
|
gimp_drawable_detach (gfig_drawable);
|
|
|
|
gimp_image_undo_group_end (gfig_context->image_id);
|
|
|
|
|
2003-12-14 07:58:33 +08:00
|
|
|
return;
|
|
|
|
}
|
1998-03-20 10:40:04 +08:00
|
|
|
break;
|
|
|
|
|
2000-08-22 11:27:14 +08:00
|
|
|
case GIMP_RUN_NONINTERACTIVE:
|
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
1998-03-20 10:40:04 +08:00
|
|
|
break;
|
|
|
|
|
2000-08-22 11:27:14 +08:00
|
|
|
case GIMP_RUN_WITH_LAST_VALS:
|
1998-03-20 10:40:04 +08:00
|
|
|
/*gimp_get_data ("plug_in_gfig", &selvals);*/
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
gimp_image_undo_group_end (gfig_context->image_id);
|
2004-07-13 00:57:29 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
if (run_mode != GIMP_RUN_NONINTERACTIVE)
|
|
|
|
gimp_displays_flush ();
|
2004-07-13 00:57:29 +08:00
|
|
|
else
|
1998-03-20 10:40:04 +08:00
|
|
|
#if 0
|
2004-07-05 04:50:25 +08:00
|
|
|
if (run_mode == GIMP_RUN_INTERACTIVE)
|
|
|
|
gimp_set_data ("plug_in_gfig", &selvals, sizeof (SelectItVals));
|
1998-03-20 10:40:04 +08:00
|
|
|
else
|
2004-07-05 04:50:25 +08:00
|
|
|
#endif /* 0 */
|
1998-03-20 10:40:04 +08:00
|
|
|
{
|
2000-08-22 11:27:14 +08:00
|
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
1998-03-20 10:40:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
values[0].data.d_status = status;
|
|
|
|
|
|
|
|
gimp_drawable_detach (drawable);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Translate SPACE to "\\040", etc.
|
1998-04-24 10:18:52 +08:00
|
|
|
Taken from gflare plugin
|
1998-03-20 10:40:04 +08:00
|
|
|
*/
|
2004-07-05 04:50:25 +08:00
|
|
|
void
|
2000-02-21 19:54:33 +08:00
|
|
|
gfig_name_encode (gchar *dest,
|
2003-12-14 07:58:33 +08:00
|
|
|
gchar *src)
|
1998-03-20 10:40:04 +08:00
|
|
|
{
|
2000-02-21 19:54:33 +08:00
|
|
|
gint cnt = MAX_LOAD_LINE - 1;
|
1998-03-20 10:40:04 +08:00
|
|
|
|
|
|
|
while (*src && cnt--)
|
|
|
|
{
|
2002-02-18 22:34:50 +08:00
|
|
|
if (g_ascii_iscntrl (*src) || g_ascii_isspace (*src) || *src == '\\')
|
2003-12-14 07:58:33 +08:00
|
|
|
{
|
|
|
|
sprintf (dest, "\\%03o", *src++);
|
|
|
|
dest += 4;
|
|
|
|
}
|
1998-03-20 10:40:04 +08:00
|
|
|
else
|
2003-12-14 07:58:33 +08:00
|
|
|
*dest++ = *src++;
|
1998-03-20 10:40:04 +08:00
|
|
|
}
|
|
|
|
*dest = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Translate "\\040" to SPACE, etc.
|
|
|
|
*/
|
2004-07-05 04:50:25 +08:00
|
|
|
void
|
2003-07-03 21:26:06 +08:00
|
|
|
gfig_name_decode (gchar *dest,
|
2003-12-14 07:58:33 +08:00
|
|
|
const gchar *src)
|
1998-03-20 10:40:04 +08:00
|
|
|
{
|
2003-07-03 21:26:06 +08:00
|
|
|
gint cnt = MAX_LOAD_LINE - 1;
|
|
|
|
guint tmp;
|
1998-03-20 10:40:04 +08:00
|
|
|
|
|
|
|
while (*src && cnt--)
|
|
|
|
{
|
|
|
|
if (*src == '\\' && *(src+1) && *(src+2) && *(src+3))
|
2003-12-14 07:58:33 +08:00
|
|
|
{
|
|
|
|
sscanf (src+1, "%3o", &tmp);
|
|
|
|
*dest++ = tmp;
|
|
|
|
src += 4;
|
|
|
|
}
|
1998-03-20 10:40:04 +08:00
|
|
|
else
|
2003-12-14 07:58:33 +08:00
|
|
|
*dest++ = *src++;
|
1998-03-20 10:40:04 +08:00
|
|
|
}
|
|
|
|
*dest = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Load all gfig, which are founded in gfig-path-list, into gfig_list.
|
|
|
|
* gfig-path-list must be initialized first. (plug_in_parse_gfig_path ())
|
|
|
|
* based on code from Gflare.
|
|
|
|
*/
|
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
gint
|
2000-02-21 19:54:33 +08:00
|
|
|
gfig_list_pos (GFigObj *gfig)
|
1998-03-20 10:40:04 +08:00
|
|
|
{
|
2000-02-21 19:54:33 +08:00
|
|
|
GFigObj *g;
|
|
|
|
gint n;
|
1998-03-20 10:40:04 +08:00
|
|
|
GList *tmp;
|
|
|
|
|
|
|
|
n = 0;
|
2000-02-21 19:54:33 +08:00
|
|
|
|
2003-10-30 04:57:21 +08:00
|
|
|
for (tmp = gfig_list; tmp; tmp = g_list_next (tmp))
|
1998-03-20 10:40:04 +08:00
|
|
|
{
|
|
|
|
g = tmp->data;
|
2003-10-30 04:57:21 +08:00
|
|
|
|
1998-03-20 10:40:04 +08:00
|
|
|
if (strcmp (gfig->draw_name, g->draw_name) <= 0)
|
2003-12-14 07:58:33 +08:00
|
|
|
break;
|
2000-02-21 19:54:33 +08:00
|
|
|
|
1998-03-20 10:40:04 +08:00
|
|
|
n++;
|
|
|
|
}
|
2000-02-21 19:54:33 +08:00
|
|
|
return n;
|
1998-03-20 10:40:04 +08:00
|
|
|
}
|
|
|
|
|
2003-01-28 06:07:49 +08:00
|
|
|
/*
|
2003-12-14 07:58:33 +08:00
|
|
|
* Insert gfigs in alphabetical order
|
2003-01-28 06:07:49 +08:00
|
|
|
*/
|
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
gint
|
2000-02-21 19:54:33 +08:00
|
|
|
gfig_list_insert (GFigObj *gfig)
|
1998-03-20 10:40:04 +08:00
|
|
|
{
|
2000-02-21 19:54:33 +08:00
|
|
|
gint n;
|
1998-03-20 10:40:04 +08:00
|
|
|
|
2000-02-21 19:54:33 +08:00
|
|
|
n = gfig_list_pos (gfig);
|
1998-03-20 10:40:04 +08:00
|
|
|
|
|
|
|
gfig_list = g_list_insert (gfig_list, gfig, n);
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
void
|
2000-02-21 19:54:33 +08:00
|
|
|
gfig_free (GFigObj *gfig)
|
1998-03-20 10:40:04 +08:00
|
|
|
{
|
|
|
|
g_assert (gfig != NULL);
|
|
|
|
|
2003-01-28 06:07:49 +08:00
|
|
|
free_all_objs (gfig->obj_list);
|
2000-02-21 19:54:33 +08:00
|
|
|
|
|
|
|
g_free (gfig->name);
|
|
|
|
g_free (gfig->filename);
|
|
|
|
g_free (gfig->draw_name);
|
|
|
|
|
1998-03-20 10:40:04 +08:00
|
|
|
g_free (gfig);
|
|
|
|
}
|
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
GFigObj *
|
2000-02-21 19:54:33 +08:00
|
|
|
gfig_new (void)
|
1998-03-20 10:40:04 +08:00
|
|
|
{
|
2003-01-28 06:07:49 +08:00
|
|
|
return g_new0 (GFigObj, 1);
|
1998-03-20 10:40:04 +08:00
|
|
|
}
|
|
|
|
|
2000-02-21 19:54:33 +08:00
|
|
|
static void
|
|
|
|
gfig_load_objs (GFigObj *gfig,
|
2003-12-14 07:58:33 +08:00
|
|
|
gint load_count,
|
|
|
|
FILE *fp)
|
1998-03-20 10:40:04 +08:00
|
|
|
{
|
2000-02-21 19:54:33 +08:00
|
|
|
Dobject *obj;
|
1998-03-20 10:40:04 +08:00
|
|
|
gchar load_buf[MAX_LOAD_LINE];
|
2004-07-05 04:50:25 +08:00
|
|
|
glong offset;
|
|
|
|
glong offset2;
|
|
|
|
Style style;
|
1998-03-20 10:40:04 +08:00
|
|
|
|
2000-02-21 19:54:33 +08:00
|
|
|
while (load_count-- > 0)
|
1998-03-20 10:40:04 +08:00
|
|
|
{
|
|
|
|
obj = NULL;
|
2000-02-21 19:54:33 +08:00
|
|
|
get_line (load_buf, MAX_LOAD_LINE, fp, 0);
|
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
/* kludge */
|
|
|
|
offset = ftell (fp);
|
|
|
|
gfig_skip_style (&style, fp);
|
|
|
|
|
2004-07-08 01:52:16 +08:00
|
|
|
obj = d_load_object (load_buf, fp);
|
2003-10-30 04:57:21 +08:00
|
|
|
|
2000-02-21 19:54:33 +08:00
|
|
|
if (obj)
|
2003-12-14 07:58:33 +08:00
|
|
|
{
|
|
|
|
add_to_all_obj (gfig, obj);
|
2004-07-05 04:50:25 +08:00
|
|
|
offset2 = ftell (fp);
|
|
|
|
fseek (fp, offset, SEEK_SET);
|
|
|
|
gfig_load_style (&obj->style, fp);
|
|
|
|
fseek (fp, offset2, SEEK_SET);
|
2003-12-14 07:58:33 +08:00
|
|
|
}
|
2004-07-08 01:52:16 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
g_message ("Failed to load object, load count = %d", load_count);
|
|
|
|
}
|
1998-03-20 10:40:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
GFigObj *
|
2001-10-20 00:41:09 +08:00
|
|
|
gfig_load (const gchar *filename,
|
|
|
|
const gchar *name)
|
1998-03-20 10:40:04 +08:00
|
|
|
{
|
2003-01-07 02:02:27 +08:00
|
|
|
GFigObj *gfig;
|
|
|
|
FILE *fp;
|
|
|
|
gchar load_buf[MAX_LOAD_LINE];
|
|
|
|
gchar str_buf[MAX_LOAD_LINE];
|
|
|
|
gint chk_count;
|
|
|
|
gint load_count = 0;
|
2004-07-05 04:50:25 +08:00
|
|
|
gdouble version;
|
|
|
|
guchar magic1[20];
|
|
|
|
guchar magic2[20];
|
1998-03-20 10:40:04 +08:00
|
|
|
g_assert (filename != NULL);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2000-02-21 19:54:33 +08:00
|
|
|
printf ("Loading %s (%s)\n", filename, name);
|
1998-03-20 10:40:04 +08:00
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
fp = fopen (filename, "r");
|
|
|
|
if (!fp)
|
|
|
|
{
|
2003-11-15 21:53:33 +08:00
|
|
|
g_message (_("Could not open '%s' for reading: %s"),
|
2004-01-19 11:06:04 +08:00
|
|
|
gimp_filename_to_utf8 (filename), g_strerror (errno));
|
1998-03-20 10:40:04 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-02-21 19:54:33 +08:00
|
|
|
gfig = gfig_new ();
|
1998-03-20 10:40:04 +08:00
|
|
|
|
2000-02-21 19:54:33 +08:00
|
|
|
gfig->name = g_strdup (name);
|
|
|
|
gfig->filename = g_strdup (filename);
|
1998-03-20 10:40:04 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* HEADER
|
|
|
|
* draw_name
|
|
|
|
* version
|
|
|
|
* obj_list
|
|
|
|
*/
|
|
|
|
|
2000-02-21 19:54:33 +08:00
|
|
|
get_line (load_buf, MAX_LOAD_LINE, fp, 1);
|
1998-03-20 10:40:04 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
sscanf (load_buf, "%10s %10s %lf", magic1, magic2, &version);
|
|
|
|
|
|
|
|
if (strcmp (magic1, "GFIG") || strcmp (magic2, "Version"))
|
1998-03-20 10:40:04 +08:00
|
|
|
{
|
2004-01-19 11:06:04 +08:00
|
|
|
g_message ("File '%s' is not a gfig file",
|
|
|
|
gimp_filename_to_utf8 (gfig->filename));
|
2000-02-21 19:54:33 +08:00
|
|
|
return NULL;
|
1998-03-20 10:40:04 +08:00
|
|
|
}
|
2003-10-30 04:57:21 +08:00
|
|
|
|
2000-02-21 19:54:33 +08:00
|
|
|
get_line (load_buf, MAX_LOAD_LINE, fp, 0);
|
|
|
|
sscanf (load_buf, "Name: %100s", str_buf);
|
|
|
|
gfig_name_decode (load_buf, str_buf);
|
|
|
|
gfig->draw_name = g_strdup (load_buf);
|
2004-07-13 00:57:29 +08:00
|
|
|
|
2000-02-21 19:54:33 +08:00
|
|
|
get_line (load_buf, MAX_LOAD_LINE, fp, 0);
|
2001-10-29 20:51:21 +08:00
|
|
|
if (strncmp (load_buf, "Version: ", 9) == 0)
|
|
|
|
gfig->version = g_ascii_strtod (load_buf + 9, NULL);
|
2004-07-13 00:57:29 +08:00
|
|
|
|
2000-02-21 19:54:33 +08:00
|
|
|
get_line (load_buf, MAX_LOAD_LINE, fp, 0);
|
|
|
|
sscanf (load_buf, "ObjCount: %d", &load_count);
|
2004-07-13 00:57:29 +08:00
|
|
|
|
2000-02-21 19:54:33 +08:00
|
|
|
if (load_options (gfig, fp))
|
1998-03-20 10:40:04 +08:00
|
|
|
{
|
2000-02-21 19:54:33 +08:00
|
|
|
g_message ("File '%s' corrupt file - Line %d Option section incorrect",
|
2004-07-05 04:50:25 +08:00
|
|
|
gimp_filename_to_utf8 (filename), line_no);
|
2000-02-21 19:54:33 +08:00
|
|
|
return NULL;
|
1998-03-20 10:40:04 +08:00
|
|
|
}
|
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
if (gfig_load_styles (gfig, fp))
|
|
|
|
{
|
|
|
|
g_message ("File '%s' corrupt file - Line %d Option section incorrect",
|
|
|
|
gimp_filename_to_utf8 (filename), line_no);
|
|
|
|
return NULL;
|
|
|
|
}
|
1998-03-20 10:40:04 +08:00
|
|
|
|
2004-07-13 00:57:29 +08:00
|
|
|
|
|
|
|
|
2000-02-21 19:54:33 +08:00
|
|
|
gfig_load_objs (gfig, load_count, fp);
|
2004-07-13 00:57:29 +08:00
|
|
|
|
1998-03-20 10:40:04 +08:00
|
|
|
/* Check count ? */
|
2004-07-13 00:57:29 +08:00
|
|
|
|
2000-02-21 19:54:33 +08:00
|
|
|
chk_count = gfig_obj_counts (gfig->obj_list);
|
2004-07-13 00:57:29 +08:00
|
|
|
|
2000-02-21 19:54:33 +08:00
|
|
|
if (chk_count != load_count)
|
1998-03-20 10:40:04 +08:00
|
|
|
{
|
2000-02-21 19:54:33 +08:00
|
|
|
g_message ("File '%s' corrupt file - Line %d Object count to small",
|
2004-07-05 04:50:25 +08:00
|
|
|
gimp_filename_to_utf8 (filename), line_no);
|
2000-02-21 19:54:33 +08:00
|
|
|
return NULL;
|
1998-03-20 10:40:04 +08:00
|
|
|
}
|
2004-07-13 00:57:29 +08:00
|
|
|
|
2000-02-21 19:54:33 +08:00
|
|
|
fclose (fp);
|
1998-03-20 10:40:04 +08:00
|
|
|
|
2004-07-10 06:09:40 +08:00
|
|
|
if (!gfig_context->current_obj)
|
|
|
|
gfig_context->current_obj = gfig;
|
1998-03-20 10:40:04 +08:00
|
|
|
|
|
|
|
gfig->obj_status = GFIG_OK;
|
|
|
|
|
2000-02-21 19:54:33 +08:00
|
|
|
return gfig;
|
1998-03-20 10:40:04 +08:00
|
|
|
}
|
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
void
|
|
|
|
save_options (GString *string)
|
1998-03-20 10:40:04 +08:00
|
|
|
{
|
|
|
|
/* Save options */
|
2004-07-05 04:50:25 +08:00
|
|
|
g_string_append_printf (string, "<OPTIONS>\n");
|
|
|
|
g_string_append_printf (string, "GridSpacing: %d\n", selvals.opts.gridspacing);
|
2000-02-21 19:54:33 +08:00
|
|
|
if (selvals.opts.gridtype == RECT_GRID)
|
2004-07-05 04:50:25 +08:00
|
|
|
{
|
|
|
|
g_string_append_printf (string, "GridType: RECT_GRID\n");
|
|
|
|
}
|
2000-02-21 19:54:33 +08:00
|
|
|
else if (selvals.opts.gridtype == POLAR_GRID)
|
2004-07-05 04:50:25 +08:00
|
|
|
{
|
|
|
|
g_string_append_printf (string, "GridType: POLAR_GRID\n");
|
|
|
|
}
|
2000-02-21 19:54:33 +08:00
|
|
|
else if (selvals.opts.gridtype == ISO_GRID)
|
2004-07-05 04:50:25 +08:00
|
|
|
{
|
|
|
|
g_string_append_printf (string, "GridType: ISO_GRID\n");
|
|
|
|
}
|
2004-07-13 00:57:29 +08:00
|
|
|
else
|
2004-07-05 04:50:25 +08:00
|
|
|
{
|
|
|
|
g_string_append_printf (string, "GridType: RECT_GRID\n"); /* default to RECT_GRID */
|
|
|
|
}
|
|
|
|
|
|
|
|
g_string_append_printf (string, "DrawGrid: %s\n", (selvals.opts.drawgrid)?"TRUE":"FALSE");
|
|
|
|
g_string_append_printf (string, "Snap2Grid: %s\n", (selvals.opts.snap2grid)?"TRUE":"FALSE");
|
|
|
|
g_string_append_printf (string, "LockOnGrid: %s\n", (selvals.opts.lockongrid)?"TRUE":"FALSE");
|
|
|
|
g_string_append_printf (string, "ShowControl: %s\n", (selvals.opts.showcontrol)?"TRUE":"FALSE");
|
|
|
|
g_string_append_printf (string, "</OPTIONS>\n");
|
|
|
|
}
|
|
|
|
|
2004-07-13 00:57:29 +08:00
|
|
|
static void
|
|
|
|
gfig_save_obj_start (Dobject *obj,
|
2004-07-05 04:50:25 +08:00
|
|
|
GString *string)
|
|
|
|
{
|
2004-07-10 06:09:40 +08:00
|
|
|
g_string_append_printf (string, "<%s ", obj->class->name);
|
|
|
|
gfig_style_save_as_attributes (&obj->style, string);
|
|
|
|
g_string_append_printf (string, ">\n");
|
2004-07-05 04:50:25 +08:00
|
|
|
}
|
|
|
|
|
2004-07-13 00:57:29 +08:00
|
|
|
static void
|
|
|
|
gfig_save_obj_end (Dobject *obj,
|
2004-07-05 04:50:25 +08:00
|
|
|
GString *string)
|
|
|
|
{
|
2004-07-10 06:09:40 +08:00
|
|
|
g_string_append_printf (string, "</%s>\n",obj->class->name);
|
2000-02-21 19:54:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
load_bool (gchar *opt_buf,
|
2003-12-14 07:58:33 +08:00
|
|
|
gint *toset)
|
2000-02-21 19:54:33 +08:00
|
|
|
{
|
|
|
|
if (!strcmp (opt_buf, "TRUE"))
|
1998-03-20 10:40:04 +08:00
|
|
|
*toset = 1;
|
2000-02-21 19:54:33 +08:00
|
|
|
else if (!strcmp (opt_buf, "FALSE"))
|
1998-03-20 10:40:04 +08:00
|
|
|
*toset = 0;
|
|
|
|
else
|
2000-02-21 19:54:33 +08:00
|
|
|
return (-1);
|
1998-03-20 10:40:04 +08:00
|
|
|
|
2000-02-21 19:54:33 +08:00
|
|
|
return (0);
|
1998-03-20 10:40:04 +08:00
|
|
|
}
|
|
|
|
|
2000-02-21 19:54:33 +08:00
|
|
|
static gint
|
|
|
|
load_options (GFigObj *gfig,
|
2003-12-14 07:58:33 +08:00
|
|
|
FILE *fp)
|
1998-03-20 10:40:04 +08:00
|
|
|
{
|
|
|
|
gchar load_buf[MAX_LOAD_LINE];
|
|
|
|
gchar str_buf[MAX_LOAD_LINE];
|
|
|
|
gchar opt_buf[MAX_LOAD_LINE];
|
|
|
|
|
2000-02-21 19:54:33 +08:00
|
|
|
get_line (load_buf, MAX_LOAD_LINE, fp, 0);
|
1998-03-20 10:40:04 +08:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2000-02-21 19:54:33 +08:00
|
|
|
printf ("load '%s'\n", load_buf);
|
1998-03-20 10:40:04 +08:00
|
|
|
#endif /* DEBUG */
|
|
|
|
|
2000-02-21 19:54:33 +08:00
|
|
|
if (strcmp (load_buf, "<OPTIONS>"))
|
|
|
|
return (-1);
|
2003-10-30 04:57:21 +08:00
|
|
|
|
2000-02-21 19:54:33 +08:00
|
|
|
get_line (load_buf, MAX_LOAD_LINE, fp, 0);
|
1998-03-20 10:40:04 +08:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2000-02-21 19:54:33 +08:00
|
|
|
printf ("opt line '%s'\n", load_buf);
|
1998-03-20 10:40:04 +08:00
|
|
|
#endif /* DEBUG */
|
|
|
|
|
2000-02-21 19:54:33 +08:00
|
|
|
while (strcmp (load_buf, "</OPTIONS>"))
|
1998-03-20 10:40:04 +08:00
|
|
|
{
|
|
|
|
/* Get option name */
|
|
|
|
#ifdef DEBUG
|
2000-02-21 19:54:33 +08:00
|
|
|
printf ("num = %d\n", sscanf (load_buf, "%s %s", str_buf, opt_buf));
|
1998-03-20 10:40:04 +08:00
|
|
|
|
2000-02-21 19:54:33 +08:00
|
|
|
printf ("option %s val %s\n", str_buf, opt_buf);
|
1998-03-20 10:40:04 +08:00
|
|
|
#else
|
2000-02-21 19:54:33 +08:00
|
|
|
sscanf (load_buf, "%s %s", str_buf, opt_buf);
|
1998-03-20 10:40:04 +08:00
|
|
|
#endif /* DEBUG */
|
|
|
|
|
2000-02-21 19:54:33 +08:00
|
|
|
if (!strcmp (str_buf, "GridSpacing:"))
|
2003-12-14 07:58:33 +08:00
|
|
|
{
|
|
|
|
/* Value is decimal */
|
|
|
|
int sp = 0;
|
|
|
|
sp = atoi (opt_buf);
|
|
|
|
if (sp <= 0)
|
|
|
|
return (-1);
|
|
|
|
gfig->opts.gridspacing = sp;
|
|
|
|
}
|
2000-02-21 19:54:33 +08:00
|
|
|
else if (!strcmp (str_buf, "DrawGrid:"))
|
2003-12-14 07:58:33 +08:00
|
|
|
{
|
|
|
|
/* Value is bool */
|
|
|
|
if (load_bool (opt_buf, &gfig->opts.drawgrid))
|
|
|
|
return (-1);
|
|
|
|
}
|
2000-02-21 19:54:33 +08:00
|
|
|
else if (!strcmp (str_buf, "Snap2Grid:"))
|
2003-12-14 07:58:33 +08:00
|
|
|
{
|
|
|
|
/* Value is bool */
|
|
|
|
if (load_bool (opt_buf, &gfig->opts.snap2grid))
|
|
|
|
return (-1);
|
|
|
|
}
|
2000-02-21 19:54:33 +08:00
|
|
|
else if (!strcmp (str_buf, "LockOnGrid:"))
|
2003-12-14 07:58:33 +08:00
|
|
|
{
|
|
|
|
/* Value is bool */
|
|
|
|
if (load_bool (opt_buf, &gfig->opts.lockongrid))
|
|
|
|
return (-1);
|
|
|
|
}
|
2000-02-21 19:54:33 +08:00
|
|
|
else if (!strcmp (str_buf, "ShowControl:"))
|
2003-12-14 07:58:33 +08:00
|
|
|
{
|
|
|
|
/* Value is bool */
|
|
|
|
if (load_bool (opt_buf, &gfig->opts.showcontrol))
|
|
|
|
return (-1);
|
|
|
|
}
|
2000-02-21 19:54:33 +08:00
|
|
|
else if (!strcmp (str_buf, "GridType:"))
|
2003-12-14 07:58:33 +08:00
|
|
|
{
|
|
|
|
/* Value is string */
|
|
|
|
if (!strcmp (opt_buf, "RECT_GRID"))
|
|
|
|
gfig->opts.gridtype = RECT_GRID;
|
|
|
|
else if (!strcmp (opt_buf, "POLAR_GRID"))
|
|
|
|
gfig->opts.gridtype = POLAR_GRID;
|
|
|
|
else if (!strcmp (opt_buf, "ISO_GRID"))
|
|
|
|
gfig->opts.gridtype = ISO_GRID;
|
|
|
|
else
|
|
|
|
return (-1);
|
|
|
|
}
|
1998-03-20 10:40:04 +08:00
|
|
|
|
2000-02-21 19:54:33 +08:00
|
|
|
get_line (load_buf, MAX_LOAD_LINE, fp, 0);
|
2003-01-07 02:02:27 +08:00
|
|
|
|
1998-03-20 10:40:04 +08:00
|
|
|
#ifdef DEBUG
|
2000-02-21 19:54:33 +08:00
|
|
|
printf ("opt line '%s'\n", load_buf);
|
1998-03-20 10:40:04 +08:00
|
|
|
#endif /* DEBUG */
|
2003-10-30 04:57:21 +08:00
|
|
|
}
|
2000-02-21 19:54:33 +08:00
|
|
|
return (0);
|
1998-03-20 10:40:04 +08:00
|
|
|
}
|
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
GString *
|
|
|
|
gfig_save_as_string ()
|
1998-03-20 10:40:04 +08:00
|
|
|
{
|
2004-07-05 04:50:25 +08:00
|
|
|
DAllObjs *objs;
|
|
|
|
gint count = 0;
|
|
|
|
gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
|
|
|
|
gchar conv_buf[MAX_LOAD_LINE*3 +1];
|
|
|
|
GString *string;
|
1998-03-20 10:40:04 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
string = g_string_new (GFIG_HEADER);
|
2004-07-13 00:57:29 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
gfig_name_encode (conv_buf, gfig_context->current_obj->draw_name);
|
|
|
|
g_string_append_printf (string, "Name: %s\n", conv_buf);
|
|
|
|
g_string_append_printf (string, "Version: %s\n",
|
|
|
|
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
|
|
|
|
gfig_context->current_obj->version));
|
|
|
|
objs = gfig_context->current_obj->obj_list;
|
1998-03-20 10:40:04 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
count = gfig_obj_counts (objs);
|
1998-03-20 10:40:04 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
g_string_append_printf (string, "ObjCount: %d\n", count);
|
1998-03-20 10:40:04 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
save_options (string);
|
1998-03-20 10:40:04 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
gfig_save_styles (string);
|
2003-10-30 04:57:21 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
for (objs = gfig_context->current_obj->obj_list; objs; objs = objs->next)
|
1998-03-20 10:40:04 +08:00
|
|
|
{
|
2004-07-05 04:50:25 +08:00
|
|
|
gfig_save_obj_start (objs->obj, string);
|
2003-10-30 04:57:21 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
gfig_save_style (&objs->obj->style, string);
|
2000-02-21 19:54:33 +08:00
|
|
|
|
2003-10-20 05:03:21 +08:00
|
|
|
if (objs->obj->points)
|
2004-07-08 01:52:16 +08:00
|
|
|
d_save_object (objs->obj, string);
|
1998-03-20 10:40:04 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
gfig_save_obj_end (objs->obj, string);
|
1998-03-20 10:40:04 +08:00
|
|
|
}
|
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
return string;
|
1998-03-20 10:40:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
gboolean
|
|
|
|
gfig_save_as_parasite ()
|
1998-03-20 10:40:04 +08:00
|
|
|
{
|
2004-07-05 04:50:25 +08:00
|
|
|
GimpParasite *parasite;
|
|
|
|
GString *string;
|
1998-03-20 10:40:04 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
string = gfig_save_as_string ();
|
2000-02-22 01:15:30 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
/* temporarily make the parasite non-persistent until the
|
|
|
|
* format has stabilized.
|
|
|
|
*/
|
|
|
|
#if 0
|
2004-07-13 00:57:29 +08:00
|
|
|
parasite = gimp_parasite_new ("gfig", GIMP_PARASITE_PERSISTENT | GIMP_PARASITE_UNDOABLE,
|
2004-07-05 04:50:25 +08:00
|
|
|
datasize, data);
|
|
|
|
#endif
|
2000-02-22 01:15:30 +08:00
|
|
|
|
2004-07-13 00:57:29 +08:00
|
|
|
parasite = gimp_parasite_new ("gfig", GIMP_PARASITE_UNDOABLE,
|
2004-07-05 04:50:25 +08:00
|
|
|
string->len, string->str);
|
2000-02-22 01:15:30 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
g_string_free (string, TRUE);
|
2000-02-24 09:52:31 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
if (!gimp_drawable_parasite_attach (gfig_context->drawable_id, parasite))
|
2000-04-11 04:47:04 +08:00
|
|
|
{
|
2004-07-05 04:50:25 +08:00
|
|
|
g_message (_("Error trying to save figure as a parasite: can't attach parasite to drawable.\n"));
|
|
|
|
gimp_parasite_free (parasite);
|
|
|
|
return FALSE;
|
2000-04-11 04:47:04 +08:00
|
|
|
}
|
1998-03-20 10:40:04 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
gimp_parasite_free (parasite);
|
|
|
|
return TRUE;
|
1998-03-20 10:40:04 +08:00
|
|
|
}
|
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
GFigObj *
|
|
|
|
gfig_load_from_parasite ()
|
1998-03-20 10:40:04 +08:00
|
|
|
{
|
2004-07-05 04:50:25 +08:00
|
|
|
FILE *fp;
|
|
|
|
gchar *fname;
|
|
|
|
GimpParasite *parasite;
|
|
|
|
GFigObj *gfig;
|
1998-03-20 10:40:04 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
fname = gimp_temp_name ("gfigtmp");
|
|
|
|
fp = fopen (fname, "w");
|
|
|
|
if (!fp)
|
|
|
|
{
|
|
|
|
g_message (_("Error trying to open temp file '%s'for parasite loading.\n"), fname);
|
|
|
|
return NULL;
|
|
|
|
}
|
1998-03-20 10:40:04 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
parasite = gimp_drawable_parasite_find (gfig_context->drawable_id, "gfig");
|
1998-03-20 10:40:04 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
if (!parasite)
|
|
|
|
return NULL;
|
2000-02-21 19:54:33 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
fprintf (stderr, "GFig parasite found.\n");
|
1998-03-20 10:40:04 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
fwrite (gimp_parasite_data (parasite),
|
|
|
|
sizeof (guchar),
|
|
|
|
gimp_parasite_data_size (parasite),
|
|
|
|
fp);
|
|
|
|
|
|
|
|
gimp_parasite_free (parasite);
|
|
|
|
fclose (fp);
|
1998-03-20 10:40:04 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
gfig = gfig_load (fname, "(none)");
|
|
|
|
unlink (fname);
|
1998-03-20 10:40:04 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
return (gfig);
|
1998-03-20 10:40:04 +08:00
|
|
|
}
|
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
void
|
|
|
|
gfig_save_callbk (void)
|
1998-03-20 10:40:04 +08:00
|
|
|
{
|
2004-07-05 04:50:25 +08:00
|
|
|
FILE *fp;
|
|
|
|
gchar *savename;
|
|
|
|
GString *string;
|
1998-03-20 10:40:04 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
savename = gfig_context->current_obj->filename;
|
1998-03-20 10:40:04 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
fp = fopen (savename, "w+");
|
1998-03-20 10:40:04 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
if (!fp)
|
1998-03-20 10:40:04 +08:00
|
|
|
{
|
2004-07-05 04:50:25 +08:00
|
|
|
g_message (_("Could not open '%s' for writing: %s"),
|
|
|
|
gimp_filename_to_utf8 (savename), g_strerror (errno));
|
|
|
|
return;
|
1998-03-20 10:40:04 +08:00
|
|
|
}
|
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
string = gfig_save_as_string ();
|
2003-01-07 02:02:27 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
fwrite (string->str, string->len, 1, fp);
|
2003-01-07 02:02:27 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
if (ferror (fp))
|
|
|
|
g_message ("Failed to write file\n");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gfig_context->current_obj->obj_status &= ~(GFIG_MODIFIED | GFIG_READONLY);
|
1998-03-20 10:40:04 +08:00
|
|
|
}
|
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
fclose (fp);
|
1998-03-20 10:40:04 +08:00
|
|
|
|
2003-10-30 04:57:21 +08:00
|
|
|
}
|