gfig.c 257 KB
Newer Older
Manish Singh's avatar
Manish Singh committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
 * 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
22
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Manish Singh's avatar
Manish Singh committed
23
24
25
26
27
28
29
30
31
 * 
 * Some of this code was taken from the Whirl plug-in
 * which was copyrighted by Federico Mena Quintero (as below).
 * 
 * Whirl plug-in --- distort an image into a whirlpool
 * Copyright (C) 1997 Federico Mena Quintero           
 *
 */

32
/* Change log:
Manish Singh's avatar
Manish Singh committed
33
34
35
36
37
38
39
40
41
42
43
 * 0.9 First public release. 
 * 0.95 Second release.
 * 
 * 0.96 Added patch from  Rob Saunders that introduces a isometric type grid
 *      Removed use of gtk_idle* stuff on position update. Not required.
 *
 * 1.0  Fixed to work with the new gtk+-0.99.4 (tooltips stuff has changed).  
 * 
 * 1.1  Fixed crashes when objects not fully defined
 * 
 * 1.2  More bug fixes and prevent gtk warning when creating new figs
44
45
46
 * 
 * 1.3  Portability fixes and fixed bug reports 257 and 258 from and 81 & 101 & 133
 *      http://www.wilberworks.com/bugs.cgi
Manish Singh's avatar
Manish Singh committed
47
48
 */

Tor Lillqvist's avatar
Tor Lillqvist committed
49
50
#include "config.h"

Manish Singh's avatar
Manish Singh committed
51
52
#include <stdio.h>
#include <stdlib.h>
53

Tor Lillqvist's avatar
Tor Lillqvist committed
54
#ifdef HAVE_UNISTD_H
Manish Singh's avatar
Manish Singh committed
55
#include <unistd.h>
Tor Lillqvist's avatar
Tor Lillqvist committed
56
#endif
57

Manish Singh's avatar
Manish Singh committed
58
#include <string.h>
59
60
61
62
63
64

#ifdef __GNUC__
#warning GTK_DISABLE_DEPRECATED
#endif
#undef GTK_DISABLE_DEPRECATED

Manish Singh's avatar
Manish Singh committed
65
#include <gtk/gtk.h>
Tor Lillqvist's avatar
Tor Lillqvist committed
66

67
#ifdef G_OS_WIN32
Tor Lillqvist's avatar
Tor Lillqvist committed
68
69
70
71
#  include <io.h>
#  ifndef W_OK
#    define W_OK 2
#  endif
72
73
#endif

74
75
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>
Manish Singh's avatar
Manish Singh committed
76

77
78
#include "libgimp/stdplugins-intl.h"

79
80
#include "gfig-stock.h"

81
#include "pix_data.h"
Manish Singh's avatar
Manish Singh committed
82

83

Manish Singh's avatar
Manish Singh committed
84
85
/***** Magic numbers *****/

86
87
#define PREVIEW_SIZE     400
#define SCALE_WIDTH      120
Manish Singh's avatar
Manish Singh committed
88

89
90
91
92
93
#define MIN_GRID         10
#define MAX_GRID         50
#define MAX_UNDO         10
#define MIN_UNDO         1
#define MAX_LOAD_LINE    256
Manish Singh's avatar
Manish Singh committed
94
95
#define SMALL_PREVIEW_SZ 48
#define BRUSH_PREVIEW_SZ 32
96
#define GFIG_HEADER      "GFIG Version 0.1\n"
Manish Singh's avatar
Manish Singh committed
97

98
#define PREVIEW_MASK  (GDK_EXPOSURE_MASK       | \
Manish Singh's avatar
Manish Singh committed
99
		       GDK_POINTER_MOTION_MASK | \
100
                       GDK_BUTTON_PRESS_MASK   | \
Manish Singh's avatar
Manish Singh committed
101
		       GDK_BUTTON_RELEASE_MASK | \
102
103
104
		       GDK_BUTTON_MOTION_MASK  | \
		       GDK_KEY_PRESS_MASK      | \
		       GDK_KEY_RELEASE_MASK)
Manish Singh's avatar
Manish Singh committed
105

106
static GimpDrawable *gfig_select_drawable;
107
108
109
110
111
112
113
static GtkWidget    *gfig_preview;
static GtkWidget    *pic_preview;
static GtkWidget    *gfig_gtk_list;
static gint32        gfig_image;
static gint32        gfig_drawable;
static GtkWidget    *brush_page_pw;
static GtkWidget    *brush_sel_button;
Manish Singh's avatar
Manish Singh committed
114
115

static gint   tile_width, tile_height;
116
static gint   img_width, img_height, img_bpp, real_img_bpp;
Manish Singh's avatar
Manish Singh committed
117
118

static void      query  (void);
119
120
static void      run    (gchar       *name,
			 gint         nparams,
121
			 GimpParam   *param,
122
			 gint        *nreturn_vals,
123
			 GimpParam  **return_vals);
124
125
126
127
128
129
130
131
132
133

static gint      gfig_dialog               (void);
static void      gfig_ok_callback          (GtkWidget *widget,
					    gpointer   data);
static void      gfig_paint_callback       (GtkWidget *widget,
					    gpointer   data);
static void      gfig_clear_callback       (GtkWidget *widget,
					    gpointer   data);
static void      gfig_undo_callback        (GtkWidget *widget,
					    gpointer   data);
Sven Neumann's avatar
Sven Neumann committed
134
static gboolean  pic_preview_expose        (GtkWidget *widget,
135
					    GdkEvent  *event);
Sven Neumann's avatar
Sven Neumann committed
136
137
static void      gfig_preview_realize      (GtkWidget *widget);
static gboolean  gfig_preview_expose       (GtkWidget *widget,
138
					    GdkEvent  *event);
Sven Neumann's avatar
Sven Neumann committed
139
static gboolean  gfig_preview_events       (GtkWidget *widget,
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
					    GdkEvent  *event);
static gint      gfig_brush_preview_events (GtkWidget *widget,
					    GdkEvent  *event);

static void      gfig_scale_update_scale   (GtkAdjustment *adjustment,
					    gdouble       *value);

static void      gfig_scale2img_update     (GtkWidget *widget,
					    gpointer   data);

static gint      gfig_scale_x              (gint       x);
static gint      gfig_scale_y              (gint       y);
static gint      gfig_invscale_x           (gint       x);
static gint      gfig_invscale_y           (gint       y);
static GdkGC *   gfig_get_grid_gc          (GtkWidget *widget,
					    gint       gctype);
static void      gfig_pos_enable           (GtkWidget *widget,
					    gpointer   data);

static gint      list_button_press         (GtkWidget      *widget,
					    GdkEventButton *event,
					    gpointer        data);

static void      rescan_button_callback    (GtkWidget *widget,
					    gpointer   data);
static void      load_button_callback      (GtkWidget *widget,
					    gpointer   data);
static void      save_button_callback      (GtkWidget *widget,
					    gpointer   data);
static void      new_button_callback       (GtkWidget *widget,
					    gpointer   data);
static void   gfig_do_delete_gfig_callback (GtkWidget *widget,
					    gboolean   delete,
					    gpointer   data);
static void      gfig_delete_gfig_callback (GtkWidget *widget,
					    gpointer   data);
static void      edit_button_callback      (GtkWidget *widget,
					    gpointer   data);
static void      merge_button_callback     (GtkWidget *widget,
					    gpointer   data);
static void      about_button_callback     (GtkWidget *widget,
					    gpointer   data);
static void      reload_button_callback    (GtkWidget *widget,
					    gpointer   data);

static void      do_gfig                   (void);
static void      dialog_update_preview     (void);

188
189
190
static void      draw_grid                 (void);
static void      draw_grid_clear           (void);
static void      toggle_show_image         (void);
191
192
193
194
195
196
197
198
199
200
201
202
203
204
static void      toggle_obj_type           (GtkWidget *widget,
					    gpointer   data);

static void      gfig_new_gc               (void);
static void      find_grid_pos             (GdkPoint  *p,
					    GdkPoint  *gp,
					    guint      state);

static void      brush_list_button_callback (GtkWidget *widget,
					     gpointer   data);
static gint      calculate_point_to_line_distance (GdkPoint *p,
						   GdkPoint *A,
						   GdkPoint *B,
						   GdkPoint *I);
Manish Singh's avatar
Manish Singh committed
205

206
GimpPlugInInfo PLUG_IN_INFO =
Manish Singh's avatar
Manish Singh committed
207
{
208
209
210
211
  NULL,  /* init_proc  */
  NULL,  /* quit_proc  */
  query, /* query_proc */
  run,   /* run_proc   */
Manish Singh's avatar
Manish Singh committed
212
213
214
215
216
};

/* The types of an object */
/* Also includes actions that can be performed on objects */

217
218
typedef enum
{
Manish Singh's avatar
Manish Singh committed
219
220
221
222
223
224
225
226
227
228
229
230
231
  LINE,
  CIRCLE,
  ELLIPSE,
  ARC,
  POLY,
  STAR,
  SPIRAL,
  BEZIER,
  MOVE_OBJ,
  MOVE_POINT,
  COPY_OBJ,
  MOVE_COPY_OBJ,
  DEL_OBJ,
Adrian Likins's avatar
Adrian Likins committed
232
  NULL_OPER
233
} DobjType;
Manish Singh's avatar
Manish Singh committed
234

235
236
typedef enum
{
Manish Singh's avatar
Manish Singh committed
237
238
  RECT_GRID = 0,
  POLAR_GRID,
Adrian Likins's avatar
Adrian Likins committed
239
  ISO_GRID
240
} GridType;
Manish Singh's avatar
Manish Singh committed
241

242
243
typedef enum
{
BST 2000 Andy Thomas's avatar
BST 2000 Andy Thomas committed
244
245
  ORIGINAL_LAYER = 0,
  SINGLE_LAYER,
Adrian Likins's avatar
Adrian Likins committed
246
  MULTI_LAYER
247
} DrawonLayers;
Manish Singh's avatar
Manish Singh committed
248

249
250
typedef enum
{
Manish Singh's avatar
Manish Singh committed
251
252
  LAYER_TRANS_BG = 0,
  LAYER_BG_BG,
BST 2000 Andy Thomas's avatar
BST 2000 Andy Thomas committed
253
  LAYER_FG_BG,
Manish Singh's avatar
Manish Singh committed
254
  LAYER_WHITE_BG,
Adrian Likins's avatar
Adrian Likins committed
255
  LAYER_COPY_BG
256
} LayersBGType;
Manish Singh's avatar
Manish Singh committed
257

258
259
typedef enum
{
Manish Singh's avatar
Manish Singh committed
260
261
  PAINT_BRUSH_TYPE = 0,
  PAINT_SELECTION_TYPE,
Adrian Likins's avatar
Adrian Likins committed
262
  PAINT_SELECTION_FILL_TYPE
263
} PaintType;
Manish Singh's avatar
Manish Singh committed
264

265
266
typedef enum
{
267
  BRUSH_BRUSH_TYPE = 0,
Manish Singh's avatar
Manish Singh committed
268
269
  BRUSH_PENCIL_TYPE,
  BRUSH_AIRBRUSH_TYPE,
Adrian Likins's avatar
Adrian Likins committed
270
  BRUSH_PATTERN_TYPE
271
} BrushType;
Manish Singh's avatar
Manish Singh committed
272
273


274
#define GRID_TYPE_MENU   1
Manish Singh's avatar
Manish Singh committed
275
#define GRID_RENDER_MENU 2
276
277
278
#define GRID_IGNORE      0 
#define GRID_HIGHTLIGHT  1
#define GRID_RESTORE     2
Manish Singh's avatar
Manish Singh committed
279
280
281

#define GFIG_BLACK_GC -2
#define GFIG_WHITE_GC -3
282
#define GFIG_GREY_GC  -4
Manish Singh's avatar
Manish Singh committed
283
284

#define PAINT_LAYERS_MENU 1
285
286
#define PAINT_BGS_MENU    2
#define PAINT_TYPE_MENU   3
Manish Singh's avatar
Manish Singh committed
287

288
289
#define SELECT_TYPE_MENU      1
#define SELECT_ARCTYPE_MENU   2
Manish Singh's avatar
Manish Singh committed
290
291
292
293
294
295
296
297
#define SELECT_TYPE_MENU_FILL 3
#define SELECT_TYPE_MENU_WHEN 4

#define OBJ_SELECT_GT 1
#define OBJ_SELECT_LT 2
#define OBJ_SELECT_EQ 4


298
typedef struct
Manish Singh's avatar
Manish Singh committed
299
{
300
301
  gint     gridspacing;
  GridType gridtype;
302
303
304
305
  gboolean drawgrid;
  gboolean snap2grid;
  gboolean lockongrid;
  gboolean showcontrol;
306
} GfigOpts;
Manish Singh's avatar
Manish Singh committed
307
308

/* Must keep in step with the above */
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
typedef struct
{
  void      *gridspacing;
  GtkWidget *gridtypemenu;
  GtkWidget *drawgrid;
  GtkWidget *snap2grid;
  GtkWidget *lockongrid;
  GtkWidget *showcontrol;
} GfigOptWidgets;

static GfigOptWidgets gfig_opt_widget;

typedef struct
{
  GfigOpts      opts;
324
  gboolean      showimage;
325
  gint          maxundo;
326
  gboolean      showpos;
327
  gdouble       brushfade;
BST 2000 Andy Thomas's avatar
BST 2000 Andy Thomas committed
328
  gdouble       brushgradient;
329
330
331
332
  gdouble       airbrushpressure;
  DrawonLayers  onlayers;
  LayersBGType  onlayerbg;
  PaintType     painttype;
333
334
  gboolean      reverselines;
  gboolean      scaletoimage;
335
  gdouble       scaletoimagefp;
336
  gboolean      approxcircles;
337
  BrushType     brshtype;
338
  DobjType      otype;
Manish Singh's avatar
Manish Singh committed
339
340
341
342
343
344
} SelectItVals;

/* Values when first invoked */
static SelectItVals selvals =
{
  {
Sven Neumann's avatar
Sven Neumann committed
345
346
347
348
349
350
    MIN_GRID + (MAX_GRID - MIN_GRID)/2, /* Gridspacing     */
    RECT_GRID,            /* Default to rectangle type     */
    FALSE,                /* drawgrid                      */
    FALSE,                /* snap2grid                     */
    FALSE,                /* lockongrid                    */
    TRUE                  /* show control points           */
Manish Singh's avatar
Manish Singh committed
351
  },
Sven Neumann's avatar
Sven Neumann committed
352
  FALSE,                  /* show image                    */
Manish Singh's avatar
Manish Singh committed
353
  MIN_UNDO + (MAX_UNDO - MIN_UNDO)/2,  /* Max level of undos */
Sven Neumann's avatar
Sven Neumann committed
354
355
356
357
358
359
360
361
362
363
364
365
366
  TRUE,                   /* Show pos updates              */
  0.0,                    /* Brush fade                    */
  0.0,                    /* Brush gradient                */
  20.0,                   /* Air bursh pressure            */
  ORIGINAL_LAYER,         /* Draw all objects on one layer */
  LAYER_TRANS_BG,         /* New layers background         */
  PAINT_BRUSH_TYPE,       /* Default to use brushes        */
  FALSE,                  /* reverse lines                 */
  TRUE,                   /* Scale to image when painting  */
  1.0,                    /* Scale to image fp             */
  FALSE,                  /* Approx circles by drawing lines */
  BRUSH_BRUSH_TYPE,       /* Default to use a brush        */
  LINE                    /* Initial object type           */
Manish Singh's avatar
Manish Singh committed
367
368
};

369
370
typedef enum
{
371
372
373
374
  ADD = 0,
  SUBTRACT,
  REPLACE,
  INTERSECT
375
} SelectionType;
Manish Singh's avatar
Manish Singh committed
376
377
    

378
379
typedef enum
{
380
  ARC_SEGMENT = 0,
Adrian Likins's avatar
Adrian Likins committed
381
  ARC_SECTOR
382
} ArcType;
Manish Singh's avatar
Manish Singh committed
383

384
385
typedef enum
{
Manish Singh's avatar
Manish Singh committed
386
  FILL_FOREGROUND = 0,
387
388
  FILL_BACKGROUND,
  FILL_PATTERN
389
} FillType;
Manish Singh's avatar
Manish Singh committed
390

391
392
typedef enum
{
Manish Singh's avatar
Manish Singh committed
393
  FILL_EACH = 0,
Adrian Likins's avatar
Adrian Likins committed
394
  FILL_AFTER
395
} FillWhen;
Manish Singh's avatar
Manish Singh committed
396

397
398
struct selection_option
{
399
400
401
402
403
404
405
406
  SelectionType type;           /* ADD etc .. */
  gint          antia;          /* Boolean for Antia */
  gint          feather;        /* Feather it ? */
  gdouble       feather_radius; /* Radius to feather */
  ArcType       as_pie;         /* Arc type selection segment/sector */
  FillType      fill_type;      /* Fill type for selection */
  FillWhen      fill_when;      /* Fill on each selection or after all? */
  gdouble       fill_opacity;   /* You can guess this one */
407
408
} selopt =
{
409
410
411
412
  ADD,          /* type */
  FALSE,        /* Antia */
  FALSE,        /* Feather */
  10.0,         /* feather radius */
Manish Singh's avatar
Manish Singh committed
413
414
  ARC_SEGMENT,  /* Arc as a segment */
  FILL_PATTERN, /* Fill as pattern */
415
416
  FILL_EACH,    /* Fill after each selection */
  100.0,        /* Max opacity */
Manish Singh's avatar
Manish Singh committed
417
418
419
};


420
421
422
static GList *gfig_path_list = NULL;
static GList *gfig_list      = NULL;
static gint   line_no;
Manish Singh's avatar
Manish Singh committed
423

424
425
426
427
428
static gint poly_num_sides    = 3; /* Default to three sided object */
static gint star_num_sides    = 3; /* Default to three sided object */
static gint spiral_num_turns  = 4; /* Default to 4 turns */
static gint spiral_toggle     = 0; /* 0 = clockwise -1 = anti-clockwise */
static gint bezier_closed     = 0; /* Closed curve 0 = false 1 = true */
Manish Singh's avatar
Manish Singh committed
429
430
static gint bezier_line_frame = 0; /* Show frame = false 1 = true */

431
static gint obj_show_single   = -1; /* -1 all >= 0 object number */
Manish Singh's avatar
Manish Singh committed
432
433
434
435

/* Structures etc for the objects */
/* Points used to draw the object  */

436
437
typedef struct DobjPoints
{
438
439
440
  struct DobjPoints *next;
  GdkPoint           pnt;
  gint               found_me;
441
} DobjPoints;
Manish Singh's avatar
Manish Singh committed
442

443

444
struct Dobject; /* fwd declaration for DobjFunc */
445

446
447
typedef void            (*DobjFunc)     (struct Dobject *);
typedef struct Dobject *(*DobjGenFunc)  (struct Dobject *);
448
449
typedef struct Dobject *(*DobjLoadFunc) (FILE *);
typedef void            (*DobjSaveFunc) (struct Dobject *, FILE *);
Manish Singh's avatar
Manish Singh committed
450
451

/* The object itself */
452
453
typedef struct Dobject
{
454
  DobjType      type;      /* What is the type? */
455
  gint          type_data; /* Extra data needed by the object */
456
457
  DobjPoints   *points;    /* List of points */
  DobjFunc      drawfunc;  /* How do I draw myself */
458
459
460
461
462
463
464
465
  DobjFunc      paintfunc; /* Draw me on canvas */
  DobjGenFunc   copyfunc;  /* copy */
  DobjLoadFunc  loadfunc;  /* Load this type of object */
  DobjSaveFunc  savefunc;  /* Save me out */
} Dobject;


static Dobject *obj_creating; /* Object we are creating */
466
467
static Dobject *tmp_line;     /* Needed when drawing lines */
static Dobject *tmp_bezier;   /* Neeed when drawing bezier curves */
468
469
470
471
472
473

typedef struct DAllObjs
{
  struct DAllObjs *next; 
  Dobject         *obj; /* Object on list */
} DAllObjs;
Manish Singh's avatar
Manish Singh committed
474
475
476
477
478
479

/* States of the object */
#define GFIG_OK       0x0
#define GFIG_MODIFIED 0x1
#define GFIG_READONLY 0x2

480
481
typedef struct DFigObj
{
482
483
484
  gchar     *name;        /* Trailing name of file  */
  gchar     *filename;    /* Filename itself */
  gchar     *draw_name;   /* Name of the drawing */
485
  gfloat     version;     /* Version number of data file */
486
487
488
  GfigOpts   opts;        /* Options enforced when fig saved */
  DAllObjs  *obj_list;    /* Objects that make up this list */
  gint       obj_status;  /* See above for possible values */
Manish Singh's avatar
Manish Singh committed
489
490
491
  GtkWidget *list_item;
  GtkWidget *label_widget;
  GtkWidget *pixmap_widget;
492
} GFigObj;  
Manish Singh's avatar
Manish Singh committed
493
494


495
496
typedef struct BrushDesc
{
497
498
  gchar  *bname;   /* name of the brush */
  gint32  width;   /* Width of brush */
499
  gint32  height;  /* Height of brush */
500
  guchar *pv_buf;  /* Buffer where brush placed */
501
502
  gint16  x_off;
  gint16  y_off;
503
  gint    bpp;     /* Depth - should ALWAYS be the same for all BrushDesc */
504
} BrushDesc;
Manish Singh's avatar
Manish Singh committed
505

506
507
static GFigObj  *current_obj;
static Dobject  *operation_obj;
Manish Singh's avatar
Manish Singh committed
508
static GdkPoint *move_all_pnt; /* Point moving all from */
509
510
511
512
513
514
515
516
517
static GFigObj  *pic_obj;
static DAllObjs *undo_table[MAX_UNDO];
static gint      need_to_scale;
static gint32    brush_image_ID = -1;

static GtkWidget *undo_widget;
static GtkWidget *gfig_op_menu; /* Popup menu in the list box */
static GtkWidget *delete_frame_to_freeze; /* Top preview frame window */
static GtkWidget *fade_out_hbox;   /* Fade out widget in brush page */
BST 2000 Andy Thomas's avatar
BST 2000 Andy Thomas committed
518
static GtkWidget *gradient_hbox;   /* Gradient widget in brush page */
519
520
static GtkWidget *pressure_hbox;   /* Pressure widget in brush page */
static GtkWidget *pencil_hbox;     /* Dummy widget in brush page */
521
static GtkWidget *pos_label;       /* XY pos marker */
522
523
524
static GtkWidget *brush_page_widget; /* Widget for the brush part of notebook */
static GtkWidget *select_page_widget; /* Widget for the selection part
				       * of notebook */
Manish Singh's avatar
Manish Singh committed
525

526
527
static gint       undo_water_mark = -1; /* Last slot filled in -1 = no undo */
static gint       drawing_pic = FALSE;  /* If true drawing to the small preview */
528
529
530
531
532
533
static GtkWidget *status_label_dname;
static GtkWidget *status_label_fname;
static GFigObj   *gfig_obj_for_menu; /* More static data -
				      * need to know which object was selected*/
static GtkWidget *save_menu_item;  
static GtkWidget *save_button;
Manish Singh's avatar
Manish Singh committed
534
535
536
537


/* Don't up just like BIGGG source files? */

538
539
540
541
542
543
544
545
546
547
548
549
550
551
static void       object_start            (GdkPoint *pnt, gint);
static void       object_operation        (GdkPoint *pnt, gint);
static void       object_operation_start  (GdkPoint *pnt, gint shift_down);
static void       object_operation_end    (GdkPoint *pnt, gint);
static void       object_end              (GdkPoint *pnt, gint shift_down);
static void       object_update           (GdkPoint * pnt);
static void       add_to_all_obj          (GFigObj * fobj, Dobject *obj);
static void       d_delete_dobjpoints     (DobjPoints *);
static Dobject  * d_new_line              (gint x, gint y);
static Dobject  * d_new_circle            (gint x, gint y);
static DAllObjs * copy_all_objs           (DAllObjs *objs);
static void       setup_undo              (void);
static void       d_pnt_add_line          (Dobject *obj,
					   gint x, gint y, gint pos);
552
553
static GFigObj  * gfig_load               (const gchar *filename,
                                           const gchar *name);
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
static void       free_all_objs           (DAllObjs * objs);
static void       draw_objects            (DAllObjs *objs, gint show_single);
static Dobject  * d_load_line             (FILE *from);
static Dobject  * d_load_circle           (FILE *from);
static gchar    * get_line                (gchar *buf, gint s,
					   FILE * from, gint init);
static GFigObj  * gfig_new                (void);
static void       clear_undo              (void);
static void       list_button_update      (GFigObj *obj);
static void       prepend_to_all_obj      (GFigObj *fobj, DAllObjs *nobj);
static void       gfig_update_stat_labels (void);
static void       gfig_obj_modified       (GFigObj *obj, gint stat_type);
static void       gfig_op_menu_create     (GtkWidget *window);
static void       gridtype_menu_callback  (GtkWidget *widget, gpointer data);
static void       draw_one_obj            (Dobject * obj);
static void       d_save_poly             (Dobject * obj, FILE *to);
static Dobject  * d_load_poly             (FILE *from);
static void       d_draw_poly             (Dobject *obj);
static void       d_paint_poly            (Dobject *obj);
static Dobject  * d_copy_poly             (Dobject * obj);
static Dobject  * d_new_poly              (gint x, gint y);
static void       d_update_poly           (GdkPoint *pnt);
static void       d_poly_start            (GdkPoint *pnt, gint shift_down);
static void       d_poly_end              (GdkPoint *pnt, gint shift_down);
static void       d_save_star             (Dobject * obj, FILE *to);
static Dobject  * d_load_star             (FILE *from);
static void       d_draw_star             (Dobject *obj);
static void       d_paint_star            (Dobject *obj);
static Dobject  * d_copy_star             (Dobject * obj);
static Dobject  * d_new_star              (gint x, gint y);
static void       d_update_star           (GdkPoint *pnt);
static void       d_star_start            (GdkPoint *pnt, gint shift_down);
static void       d_star_end              (GdkPoint *pnt, gint shift_down);
static Dobject  * d_load_spiral           (FILE *from);
static void       d_draw_spiral           (Dobject *obj);
static void       d_paint_spiral          (Dobject *obj);
static Dobject  * d_copy_spiral           (Dobject * obj);
static Dobject  * d_new_spiral            (gint x, gint y);
static void       d_update_spiral         (GdkPoint *pnt);
static void       d_spiral_start          (GdkPoint *pnt, gint shift_down);
static void       d_spiral_end            (GdkPoint *pnt, gint shift_down);

static Dobject  * d_load_bezier           (FILE *from);
static void       d_draw_bezier           (Dobject *obj);
static void       d_paint_bezier          (Dobject *obj);
static Dobject  * d_copy_bezier           (Dobject * obj);
static Dobject  * d_new_bezier            (gint x, gint y);
static void       d_update_bezier         (GdkPoint *pnt);
static void       d_bezier_start          (GdkPoint *pnt, gint shift_down);
static void       d_bezier_end            (GdkPoint *pnt, gint shift_down);

static void       new_obj_2edit           (GFigObj *obj);
static Dobject  * d_new_ellipse           (gint x, gint y);
static Dobject  * d_load_ellipse          (FILE *from);
static Dobject  * d_new_arc               (gint x, gint y);
static Dobject  * d_load_arc              (FILE *from);
static gint       load_options            (GFigObj *gfig, FILE *fp);
static gint       gfig_obj_counts         (DAllObjs * objs);

static void    gfig_brush_fill_preview_xy (GtkWidget *pw, gint x , gint y);
Manish Singh's avatar
Manish Singh committed
614
615
616
617


/* globals */

618
619
620
621
622
623
static gint    gfig_run;
static GdkGC  *gfig_gc;
static GdkGC  *grid_hightlight_drawgc;
static gint    grid_gc_type = GTK_STATE_NORMAL;
static guchar *pv_cache = NULL;
static guchar  preview_row[PREVIEW_SIZE*4];
Manish Singh's avatar
Manish Singh committed
624
625

/* Stuff for the preview bit */
626
627
628
629
630
631
static gint    sel_x1, sel_y1, sel_x2, sel_y2;
static gint    sel_width, sel_height;
static gint    preview_width, preview_height;
static gint    has_alpha;
static gdouble scale_x_factor, scale_y_factor;
static gdouble org_scale_x_factor, org_scale_y_factor;
Manish Singh's avatar
Manish Singh committed
632

Adrian Likins's avatar
Adrian Likins committed
633
MAIN ()
Manish Singh's avatar
Manish Singh committed
634
635

static void
636
query (void)
Manish Singh's avatar
Manish Singh committed
637
{
638
  static GimpParamDef args[] =
Manish Singh's avatar
Manish Singh committed
639
  {
640
641
642
643
    { GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive" },
    { GIMP_PDB_IMAGE, "image", "Input image (unused)" },
    { GIMP_PDB_DRAWABLE, "drawable", "Input drawable" },
    { GIMP_PDB_INT32, "dummy", "dummy" } 
Manish Singh's avatar
Manish Singh committed
644
  };
David Monniaux's avatar
David Monniaux committed
645

Manish Singh's avatar
Manish Singh committed
646
  gimp_install_procedure ("plug_in_gfig",
Marc Lehmann's avatar
Marc Lehmann committed
647
648
			  "Create Geometrical shapes with the Gimp",
			  "More here later",
Manish Singh's avatar
Manish Singh committed
649
650
651
			  "Andy Thomas",
			  "Andy Thomas",
			  "1997",
Stanislav Brabec's avatar
Stanislav Brabec committed
652
			  N_("<Image>/Filters/Render/Gfig..."),
Manish Singh's avatar
Manish Singh committed
653
			  "RGB*, GRAY*",
654
			  GIMP_PLUGIN,
655
			  G_N_ELEMENTS (args), 0,
656
			  args, NULL);
Manish Singh's avatar
Manish Singh committed
657
658
659
}

static void
660
661
run (gchar       *name,
     gint         nparams,
662
     GimpParam   *param,
663
     gint        *nreturn_vals,
664
     GimpParam  **return_vals)
Manish Singh's avatar
Manish Singh committed
665
{
666
667
668
669
  GimpParam         *values = g_new (GimpParam, 1);
  GimpDrawable      *drawable;
  GimpRunMode        run_mode;
  GimpPDBStatusType  status = GIMP_PDB_SUCCESS;
Manish Singh's avatar
Manish Singh committed
670

671
  gint pwidth, pheight;
Manish Singh's avatar
Manish Singh committed
672

673
  /*kill (getpid (), 19);*/
Manish Singh's avatar
Manish Singh committed
674

675
676
  INIT_I18N ();

Manish Singh's avatar
Manish Singh committed
677
678
679
680
681
682
683
  run_mode = param[0].data.d_int32;
  gfig_image = param[1].data.d_image;
  gfig_drawable = param[2].data.d_drawable;

  *nreturn_vals = 1;
  *return_vals = values;

684
  values[0].type = GIMP_PDB_STATUS;
Manish Singh's avatar
Manish Singh committed
685
686
  values[0].data.d_status = status;

687
  gfig_select_drawable = drawable =
Manish Singh's avatar
Manish Singh committed
688
689
    gimp_drawable_get (param[2].data.d_drawable);

690
691
  tile_width  = gimp_tile_width ();
  tile_height = gimp_tile_height ();
Manish Singh's avatar
Manish Singh committed
692
693

  /* TMP Hack - clear any selections */
694
695
  if (! gimp_selection_is_empty (gfig_image))
    gimp_selection_clear (gfig_image);
Manish Singh's avatar
Manish Singh committed
696

697
698
  gimp_drawable_mask_bounds (drawable->drawable_id,
			     &sel_x1, &sel_y1, &sel_x2, &sel_y2);
Manish Singh's avatar
Manish Singh committed
699
700
701
702
703
704

  sel_width  = sel_x2 - sel_x1;
  sel_height = sel_y2 - sel_y1;

  /* Calculate preview size */
  
705
706
707
708
709
710
711
712
713
  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;
714
    }
Manish Singh's avatar
Manish Singh committed
715
  
716
717
  preview_width  = MAX (pwidth, 2);  /* Min size is 2 */
  preview_height = MAX (pheight, 2); 
Manish Singh's avatar
Manish Singh committed
718

719
720
721
722
  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;
723

Manish Singh's avatar
Manish Singh committed
724
725
  switch (run_mode)
    {
726
    case GIMP_RUN_INTERACTIVE:
Manish Singh's avatar
Manish Singh committed
727
      /*gimp_get_data ("plug_in_gfig", &selvals);*/
728
      if (! gfig_dialog ())
Manish Singh's avatar
Manish Singh committed
729
730
731
732
733
734
	{
	  gimp_drawable_detach (drawable);
	  return;
	}
      break;

735
736
    case GIMP_RUN_NONINTERACTIVE:
      status = GIMP_PDB_CALLING_ERROR;
Manish Singh's avatar
Manish Singh committed
737
738
      break;

739
    case GIMP_RUN_WITH_LAST_VALS:
Manish Singh's avatar
Manish Singh committed
740
741
742
743
744
745
746
      /*gimp_get_data ("plug_in_gfig", &selvals);*/
      break;

    default:
      break;
    }

747
748
  if (gimp_drawable_is_rgb (drawable->drawable_id) ||
      gimp_drawable_is_gray (drawable->drawable_id))
Manish Singh's avatar
Manish Singh committed
749
750
    {
      /* Set the tile cache size */
751
752
      gimp_tile_cache_ntiles ((drawable->width + gimp_tile_width () - 1) /
			      gimp_tile_width ());
Manish Singh's avatar
Manish Singh committed
753

754
      do_gfig ();
Manish Singh's avatar
Manish Singh committed
755

756
      if (run_mode != GIMP_RUN_NONINTERACTIVE)
Manish Singh's avatar
Manish Singh committed
757
758
759
	gimp_displays_flush ();

#if 0
760
      if (run_mode == GIMP_RUN_INTERACTIVE)
Manish Singh's avatar
Manish Singh committed
761
762
763
764
765
	gimp_set_data ("plug_in_gfig", &selvals, sizeof (SelectItVals));
#endif /* 0 */
    }
  else
    {
766
      status = GIMP_PDB_EXECUTION_ERROR;
Manish Singh's avatar
Manish Singh committed
767
768
769
770
771
772
773
774
775
    }

  values[0].data.d_status = status;

  gimp_drawable_detach (drawable);
}

/*
  Translate SPACE to "\\040", etc.
Manish Singh's avatar
Manish Singh committed
776
  Taken from gflare plugin
Manish Singh's avatar
Manish Singh committed
777
 */
778
779
780
static void
gfig_name_encode (gchar *dest,
		  gchar *src)
Manish Singh's avatar
Manish Singh committed
781
{
782
  gint cnt = MAX_LOAD_LINE - 1;
Manish Singh's avatar
Manish Singh committed
783
784
785

  while (*src && cnt--)
    {
786
      if (g_ascii_iscntrl (*src) || g_ascii_isspace (*src) || *src == '\\')
Manish Singh's avatar
Manish Singh committed
787
788
789
790
791
792
793
794
795
796
797
798
799
	{
	  sprintf (dest, "\\%03o", *src++);
	  dest += 4;
	}
      else
	*dest++ = *src++;
    }
  *dest = '\0';
}

/*
  Translate "\\040" to SPACE, etc.
 */
800
801
802
static void
gfig_name_decode (gchar *dest,
		  gchar *src)
Manish Singh's avatar
Manish Singh committed
803
{
804
805
  gint cnt = MAX_LOAD_LINE - 1;
  gint tmp;
Manish Singh's avatar
Manish Singh committed
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827

  while (*src && cnt--)
    {
      if (*src == '\\' && *(src+1) && *(src+2) && *(src+3))
	{
	  sscanf (src+1, "%3o", &tmp);
	  *dest++ = tmp;
	  src += 4;
	}
      else
	*dest++ = *src++;
    }
  *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.
 */

828
829
static gint
gfig_list_pos (GFigObj *gfig)
Manish Singh's avatar
Manish Singh committed
830
{
831
832
  GFigObj *g;
  gint n;
Manish Singh's avatar
Manish Singh committed
833
834
835
  GList *tmp;

  n = 0;
836
837

  for (tmp = gfig_list; tmp; tmp = g_list_next (tmp)) 
Manish Singh's avatar
Manish Singh committed
838
839
840
841
842
    {
      g = tmp->data;
      
      if (strcmp (gfig->draw_name, g->draw_name) <= 0)
	break;
843

Manish Singh's avatar
Manish Singh committed
844
845
      n++;
    }
846
  return n;
Manish Singh's avatar
Manish Singh committed
847
848
}

849
850
851
852
/*
 *	Insert gfigs in alphabetical order
 */

853
854
static gint
gfig_list_insert (GFigObj *gfig)
Manish Singh's avatar
Manish Singh committed
855
{
856
  gint n;
Manish Singh's avatar
Manish Singh committed
857

858
  n = gfig_list_pos (gfig);
Manish Singh's avatar
Manish Singh committed
859
860
861
862
863
864

  gfig_list = g_list_insert (gfig_list, gfig, n);

  return n;
}

865
866
static void
gfig_free (GFigObj *gfig)
Manish Singh's avatar
Manish Singh committed
867
868
869
{
  g_assert (gfig != NULL);

870
  free_all_objs (gfig->obj_list);
871
872
873
874
875

  g_free (gfig->name);
  g_free (gfig->filename);
  g_free (gfig->draw_name);

Manish Singh's avatar
Manish Singh committed
876
877
878
  g_free (gfig);
}

879
880
static void
gfig_free_everything (GFigObj *gfig)
Manish Singh's avatar
Manish Singh committed
881
882
883
{
  g_assert (gfig != NULL);

884
  if (gfig->filename)
Manish Singh's avatar
Manish Singh committed
885
    {
886
      remove (gfig->filename);
Manish Singh's avatar
Manish Singh committed
887
    }
888
  gfig_free (gfig);
Manish Singh's avatar
Manish Singh committed
889
890
}

891
892
static void
gfig_list_free_all (void)
Manish Singh's avatar
Manish Singh committed
893
{
894
  g_list_foreach (gfig_list, (GFunc) gfig_free, NULL);
Manish Singh's avatar
Manish Singh committed
895
896
897
898
899
  g_list_free (gfig_list);
  gfig_list = NULL;
}


900
901
static void
gfig_list_load_all (GList *plist)
Manish Singh's avatar
Manish Singh committed
902
{
903
904
905
906
907
908
  GFigObj     *gfig;
  GList       *list;
  gchar	      *path;
  gchar	      *filename;
  GDir	      *dir;
  const gchar *dir_ent;
Manish Singh's avatar
Manish Singh committed
909
910
911
912
913
914
915
916
917
918
919
920

  /*  Make sure to clear any existing gfigs  */
  current_obj = pic_obj = NULL;
  gfig_list_free_all ();

  list = plist;
  while (list)
    {
      path = list->data;
      list = list->next;

      /* Open directory */
921
      dir = g_dir_open (path, 0, NULL);
Manish Singh's avatar
Manish Singh committed
922
923

      if (!dir)
924
	g_warning ("Error reading Gfig folder \"%s\"", path);
Manish Singh's avatar
Manish Singh committed
925
926
      else
	{
927
	  while ((dir_ent = g_dir_read_name (dir)))
Manish Singh's avatar
Manish Singh committed
928
	    {
929
	      filename = g_build_filename (path, dir_ent, NULL);
Manish Singh's avatar
Manish Singh committed
930
931

	      /* Check the file and see that it is not a sub-directory */
932
              if (g_file_test (filename, G_FILE_TEST_IS_REGULAR))
Manish Singh's avatar
Manish Singh committed
933
		{
934
		  gfig = gfig_load (filename, dir_ent);
Manish Singh's avatar
Manish Singh committed
935
936
937
938
		  
		  if (gfig)
		    {
		      /* Read only ?*/
939
		      if (access (filename, W_OK))
Manish Singh's avatar
Manish Singh committed
940
941
942
943
944
945
946
			gfig->obj_status |= GFIG_READONLY;

		      gfig_list_insert (gfig);
		    }
		}

	      g_free (filename);
947
	    }
948
	  g_dir_close (dir);
949
	}
Manish Singh's avatar
Manish Singh committed
950
951
    }

952
  if (!gfig_list)
Manish Singh's avatar
Manish Singh committed
953
954
    {
      /* lets have at least one! */
955
956
957
      gfig = gfig_new ();
      gfig->draw_name = g_strdup (_("First Gfig"));
      gfig_list_insert (gfig);
Manish Singh's avatar
Manish Singh committed
958
959
    }

960
  pic_obj = current_obj = gfig_list->data;  /* set to first entry */
Manish Singh's avatar
Manish Singh committed
961
962
}

963
964
static GFigObj *
gfig_new (void)
Manish Singh's avatar
Manish Singh committed
965
{
966
  return g_new0 (GFigObj, 1);
Manish Singh's avatar
Manish Singh committed
967
968
}

969
970
971
972
static void
gfig_load_objs (GFigObj *gfig,
		gint     load_count,
		FILE    *fp)
Manish Singh's avatar
Manish Singh committed
973
{
974
  Dobject *obj;
Manish Singh's avatar
Manish Singh committed
975
976
977
  gchar load_buf[MAX_LOAD_LINE];

  /* Loading object */
978
  /*kill (getpid (), 19);*/
Manish Singh's avatar
Manish Singh committed
979
  /* Read first line */
980
  while (load_count-- > 0)
Manish Singh's avatar
Manish Singh committed
981
982
    {
      obj = NULL;
983
984
985
      get_line (load_buf, MAX_LOAD_LINE, fp, 0);

      if (!strcmp (load_buf, "<LINE>"))
Manish Singh's avatar
Manish Singh committed
986
	{
987
	  obj = d_load_line (fp);
Manish Singh's avatar
Manish Singh committed
988
	}
989
      else if (!strcmp (load_buf, "<CIRCLE>"))
Manish Singh's avatar
Manish Singh committed
990
	{
991
	  obj = d_load_circle (fp);
Manish Singh's avatar
Manish Singh committed
992
	}
993
      else if (!strcmp (load_buf, "<ELLIPSE>"))
Manish Singh's avatar
Manish Singh committed
994
	{
995
	  obj = d_load_ellipse (fp);
Manish Singh's avatar
Manish Singh committed
996
	}
997
      else if (!strcmp (load_buf, "<POLY>"))
Manish Singh's avatar
Manish Singh committed
998
	{
999
	  obj = d_load_poly (fp);
Manish Singh's avatar
Manish Singh committed
1000
	}
1001
      else if (!strcmp (load_buf, "<STAR>"))
Manish Singh's avatar
Manish Singh committed
1002
	{
1003
	  obj = d_load_star (fp);
Manish Singh's avatar
Manish Singh committed
1004
	}
1005
      else if (!strcmp (load_buf, "<SPIRAL>"))
Manish Singh's avatar
Manish Singh committed
1006
	{
1007
	  obj = d_load_spiral (fp);
Manish Singh's avatar
Manish Singh committed
1008
	}
1009
      else if (!strcmp (load_buf, "<BEZIER>"))
Manish Singh's avatar
Manish Singh committed
1010
	{
1011
	  obj = d_load_bezier (fp);
Manish Singh's avatar
Manish Singh committed
1012
	}
1013
      else if (!strcmp (load_buf, "<ARC>"))
Manish Singh's avatar
Manish Singh committed
1014
	{
1015
	  obj = d_load_arc (fp);
Manish Singh's avatar
Manish Singh committed
1016
1017
1018
	}
      else
	{
1019
	  g_warning ("Unknown obj type file %s line %d\n", gfig->filename, line_no);
Manish Singh's avatar
Manish Singh committed
1020
1021
	}
      
1022
      if (obj)
Manish Singh's avatar
Manish Singh committed
1023
	{
1024
	  add_to_all_obj (gfig, obj);
Manish Singh's avatar
Manish Singh committed
1025
1026
1027
1028
	}
    }
}

1029
static GFigObj *
1030
1031
gfig_load (const gchar *filename,
           const gchar *name)
Manish Singh's avatar
Manish Singh committed
1032
{
1033
1034
1035
1036
1037
1038
1039
  GFigObj *gfig;
  FILE    *fp;
  gchar    load_buf[MAX_LOAD_LINE];
  gchar    str_buf[MAX_LOAD_LINE];
  gint     chk_count;
  gint     load_count = 0;

Manish Singh's avatar
Manish Singh committed
1040
1041
1042
  g_assert (filename != NULL);

#ifdef DEBUG
1043
  printf ("Loading %s (%s)\n", filename, name);
Manish Singh's avatar
Manish Singh committed
1044
1045
1046
1047
1048
1049
1050
1051
1052
#endif /* DEBUG */

  fp = fopen (filename, "r");
  if (!fp)
    {
      g_warning ("Error opening: %s", filename);
      return NULL;
    }

1053
  gfig = gfig_new ();
Manish Singh's avatar
Manish Singh committed
1054

1055
1056
  gfig->name = g_strdup (name);
  gfig->filename = g_strdup (filename);
Manish Singh's avatar
Manish Singh committed
1057
1058
1059
1060
1061
1062
1063
1064


  /* HEADER
   * draw_name
   * version
   * obj_list
   */

1065
  get_line (load_buf, MAX_LOAD_LINE, fp, 1);
Manish Singh's avatar
Manish Singh committed
1066

1067
  if (strncmp (GFIG_HEADER, load_buf, strlen (load_buf)))
Manish Singh's avatar
Manish Singh committed
1068
    {
1069
1070
      g_message ("File '%s' is not a gfig file", gfig->filename);
      return NULL;
Manish Singh's avatar
Manish Singh committed
1071
1072
    }
  
1073
1074
1075
1076
  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);
Manish Singh's avatar
Manish Singh committed
1077

1078
  get_line (load_buf, MAX_LOAD_LINE, fp, 0);
1079
1080
  if (strncmp (load_buf, "Version: ", 9) == 0)
    gfig->version = g_ascii_strtod (load_buf + 9, NULL);
Manish Singh's avatar
Manish Singh committed
1081

1082
1083
  get_line (load_buf, MAX_LOAD_LINE, fp, 0);
  sscanf (load_buf, "ObjCount: %d", &load_count);
Manish Singh's avatar
Manish Singh committed
1084

1085
  if (load_options (gfig, fp))
Manish Singh's avatar
Manish Singh committed
1086
    {
1087
1088
1089
      g_message ("File '%s' corrupt file - Line %d Option section incorrect",
		 filename, line_no);
      return NULL;
Manish Singh's avatar
Manish Singh committed
1090
1091
    }

1092
  /*return (NULL);*/
Manish Singh's avatar
Manish Singh committed
1093

1094
  gfig_load_objs (gfig, load_count, fp);
Manish Singh's avatar
Manish Singh committed
1095
1096
1097

  /* Check count ? */
  
1098
  chk_count = gfig_obj_counts (gfig->obj_list);
Manish Singh's avatar
Manish Singh committed
1099

1100
  if (chk_count != load_count)
Manish Singh's avatar
Manish Singh committed
1101
    {
1102
1103
1104
      g_message ("File '%s' corrupt file - Line %d Object count to small",
		 filename, line_no);
      return NULL;
Manish Singh's avatar
Manish Singh committed
1105
1106
    }