summaryrefslogtreecommitdiff
path: root/hieroglyph/hggstate.c
blob: bb8608f3752431cf08a93e6135ca17da2bd7b434 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
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
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* 
 * hggsate.c
 * Copyright (C) 2006-2011 Akira TAGOH
 * 
 * Authors:
 *   Akira TAGOH  <akira@tagoh.org>
 * 
 * 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
 * Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <string.h>
#include "hgarray.h"
#include "hgint.h"
#include "hgmem.h"
#include "hgpath.h"
#include "hgreal.h"
#include "hggstate.h"

#include "hggstate.proto.h"

HG_DEFINE_VTABLE_WITH (gstate, NULL, NULL, NULL);

/*< private >*/
static hg_usize_t
_hg_object_gstate_get_capsulated_size(void)
{
	return HG_ALIGNED_TO_POINTER (sizeof (hg_gstate_t));
}

static hg_uint_t
_hg_object_gstate_get_allocation_flags(void)
{
	return HG_MEM_FLAGS_DEFAULT;
}

static hg_bool_t
_hg_object_gstate_initialize(hg_object_t *object,
			     va_list      args)
{
	hg_gstate_t *gstate = (hg_gstate_t *)object;

	gstate->qpath = Qnil;
	gstate->qclippath = Qnil;
	gstate->qdashpattern = Qnil;

	return TRUE;
}

static hg_quark_t
_hg_object_gstate_copy(hg_object_t             *object,
		       hg_quark_iterate_func_t  func,
		       hg_pointer_t             user_data,
		       hg_pointer_t            *ret)
{
	hg_gstate_t *gstate = (hg_gstate_t *)object, *g = NULL;
	hg_quark_t retval;

	hg_return_val_if_fail (object->type == HG_TYPE_GSTATE, Qnil, HG_e_typecheck);

	if (object->on_copying != Qnil)
		return object->on_copying;

	object->on_copying = retval = hg_gstate_new(gstate->o.mem, (hg_pointer_t *)&g);
	if (retval != Qnil) {
		memcpy(&g->ctm, &gstate->ctm, sizeof (hg_gstate_t) - sizeof (hg_object_t) - (sizeof (hg_quark_t) * 3));
		if (gstate->qpath == Qnil) {
			g->qpath = Qnil;
		} else {
			g->qpath = func(gstate->qpath, user_data, NULL);
			if (g->qpath == Qnil) {
				hg_debug(HG_MSGCAT_GSTATE, "Unable to copy the path object");
				goto bail;
			}
			hg_mem_unref(gstate->o.mem,
				     g->qpath);
		}
		if (gstate->qclippath == Qnil) {
			g->qclippath = Qnil;
		} else {
			g->qclippath = func(gstate->qclippath, user_data, NULL);
			if (g->qclippath == Qnil) {
				hg_debug(HG_MSGCAT_GSTATE, "Unable to copy the clippath object");
				goto bail;
			}
			hg_mem_unref(gstate->o.mem,
				     g->qclippath);
		}
		if (gstate->qdashpattern == Qnil) {
			g->qdashpattern = Qnil;
		} else {
			g->qdashpattern = func(gstate->qdashpattern, user_data, NULL);
			if (g->qdashpattern == Qnil) {
				hg_debug(HG_MSGCAT_GSTATE, "Unable to copy the dashpattern object");
				goto bail;
			}
			hg_mem_unref(gstate->o.mem,
				     g->qdashpattern);
		}

		if (ret)
			*ret = g;
		else
			hg_mem_unlock_object(g->o.mem, retval);
	}
	goto finalize;
  bail:
	if (g) {
		hg_object_free(g->o.mem, retval);

		retval = Qnil;
	}
  finalize:
	object->on_copying = Qnil;

	return retval;
}

static hg_char_t *
_hg_object_gstate_to_cstr(hg_object_t             *object,
			  hg_quark_iterate_func_t  func,
			  hg_pointer_t             user_data)
{
	return g_strdup("-gstate-");
}

static hg_bool_t
_hg_object_gstate_gc_mark(hg_object_t *object)
{
	hg_gstate_t *gstate = (hg_gstate_t *)object;

	if (!hg_mem_gc_mark(gstate->o.mem, gstate->qpath))
		return FALSE;
	if (!hg_mem_gc_mark(gstate->o.mem, gstate->qclippath))
		return FALSE;
	if (!hg_mem_gc_mark(gstate->o.mem, gstate->qdashpattern))
		return FALSE;

	return TRUE;
}

static hg_bool_t
_hg_object_gstate_compare(hg_object_t             *o1,
			  hg_object_t             *o2,
			  hg_quark_compare_func_t  func,
			  hg_pointer_t             user_data)
{
	return FALSE;
}

/*< public >*/
/**
 * hg_gstate_new:
 * @mem:
 * @ret:
 *
 * FIXME
 *
 * Returns:
 */
hg_quark_t
hg_gstate_new(hg_mem_t     *mem,
	      hg_pointer_t *ret)
{
	hg_quark_t retval;
	hg_gstate_t *gstate = NULL;

	hg_return_val_if_fail (mem != NULL, Qnil, HG_e_VMerror);

	retval = hg_object_new(mem, (hg_pointer_t *)&gstate, HG_TYPE_GSTATE, 0);

	if (ret)
		*ret = gstate;
	else
		hg_mem_unlock_object(mem, retval);

	return retval;
}

/**
 * hg_gstate_set_ctm:
 * @gstate:
 * @matrix:
 *
 * FIXME
 */
void
hg_gstate_set_ctm(hg_gstate_t *gstate,
		  hg_matrix_t *matrix)
{
	hg_return_if_fail (gstate != NULL, HG_e_typecheck);
	hg_return_if_fail (matrix != NULL, HG_e_typecheck);

	memcpy(&gstate->ctm, matrix, sizeof (hg_matrix_t));
}

/**
 * hg_gstate_get_ctm:
 * @gstate:
 * @matrix:
 *
 * FIXME
 */
void
hg_gstate_get_ctm(hg_gstate_t *gstate,
		  hg_matrix_t *matrix)
{
	hg_return_if_fail (gstate != NULL, HG_e_typecheck);
	hg_return_if_fail (matrix != NULL, HG_e_typecheck);

	memcpy(matrix, &gstate->ctm, sizeof (hg_matrix_t));
}

/**
 * hg_gstate_get_path:
 * @gstate:
 *
 * FIXME
 *
 * Returns:
 */
hg_quark_t
hg_gstate_get_path(hg_gstate_t *gstate)
{
	hg_return_val_if_fail (gstate != NULL, Qnil, HG_e_typecheck);

	return gstate->qpath;
}

/**
 * hg_gstate_set_clippath:
 * @gstate:
 * @qpath:
 *
 * FIXME
 */
void
hg_gstate_set_clippath(hg_gstate_t *gstate,
		       hg_quark_t   qpath)
{
	hg_uint_t mem_id;

	hg_return_if_fail (gstate != NULL, HG_e_typecheck);
	hg_return_if_fail (HG_IS_QPATH (qpath), HG_e_typecheck);

	mem_id = hg_quark_get_mem_id(gstate->o.self);

	hg_return_if_fail (hg_quark_has_mem_id(qpath, mem_id), HG_e_VMerror);

	gstate->qclippath = qpath;
	hg_mem_unref(gstate->o.mem, qpath);
}

/**
 * hg_gstate_get_clippath:
 * @gstate:
 *
 * FIXME
 *
 * Returns:
 */
hg_quark_t
hg_gstate_get_clippath(hg_gstate_t *gstate)
{
	hg_return_val_if_fail (gstate != NULL, Qnil, HG_e_typecheck);

	return gstate->qclippath;
}

/**
 * hg_gstate_set_rgbcolor:
 * @gstate:
 * @red:
 * @green:
 * @blue:
 *
 * FIXME
 */
void
hg_gstate_set_rgbcolor(hg_gstate_t *gstate,
		       hg_real_t    red,
		       hg_real_t    green,
		       hg_real_t    blue)
{
	hg_return_if_fail (gstate != NULL, HG_e_typecheck);

	gstate->color.type = HG_COLOR_RGB;
	gstate->color.is.rgb.red = red;
	gstate->color.is.rgb.green = green;
	gstate->color.is.rgb.blue = blue;
}

/**
 * hg_gstate_set_hsbcolor:
 * @gstate:
 * @hue:
 * @saturation:
 * @brightness:
 *
 * FIXME
 */
void
hg_gstate_set_hsbcolor(hg_gstate_t *gstate,
		       hg_real_t    hue,
		       hg_real_t    saturation,
		       hg_real_t    brightness)
{
	hg_return_if_fail (gstate != NULL, HG_e_typecheck);

	gstate->color.type = HG_COLOR_HSB;
	gstate->color.is.hsb.hue = hue;
	gstate->color.is.hsb.saturation = saturation;
	gstate->color.is.hsb.brightness = brightness;
}

/**
 * hg_gstate_set_gray:
 * @gstate:
 * @gray:
 *
 * FIXME
 */
void
hg_gstate_set_graycolor(hg_gstate_t *gstate,
			hg_real_t    gray)
{
	hg_return_if_fail (gstate != NULL, HG_e_typecheck);

	gstate->color.type = HG_COLOR_GRAY;
	gstate->color.is.rgb.red = gray;
	gstate->color.is.rgb.green = gray;
	gstate->color.is.rgb.blue = gray;
}

/**
 * hg_gstate_set_linewidth:
 * @gstate:
 * @width:
 *
 * FIXME
 */
void
hg_gstate_set_linewidth(hg_gstate_t *gstate,
			hg_real_t    width)
{
	hg_return_if_fail (gstate != NULL, HG_e_typecheck);

	gstate->linewidth = width;
}

/**
 * hg_gstate_set_linecap:
 * @gstate:
 * @linecap:
 *
 * FIXME
 */
void
hg_gstate_set_linecap(hg_gstate_t  *gstate,
		      hg_linecap_t  linecap)
{
	hg_return_if_fail (gstate != NULL, HG_e_typecheck);
	hg_return_if_fail (linecap >= 0 && linecap < HG_LINECAP_END, HG_e_rangecheck);

	gstate->linecap = linecap;
}

/**
 * hg_gstate_set_linejoin:
 * @gstate:
 * @linejoin:
 *
 * FIXME
 */
void
hg_gstate_set_linejoin(hg_gstate_t   *gstate,
		       hg_linejoin_t  linejoin)
{
	hg_return_if_fail (gstate != NULL, HG_e_typecheck);
	hg_return_if_fail (linejoin >= 0 && linejoin < HG_LINEJOIN_END, HG_e_rangecheck);

	gstate->linejoin = linejoin;
}

/**
 * hg_gstate_set_miterlimit:
 * @gstate:
 * @miterlen:
 *
 * FIXME
 *
 * Returns:
 */
hg_bool_t
hg_gstate_set_miterlimit(hg_gstate_t *gstate,
			 hg_real_t    miterlen)
{
	hg_return_val_if_fail (gstate != NULL, FALSE, HG_e_typecheck);

	if (miterlen < 1.0)
		return FALSE;

	gstate->miterlen = miterlen;

	return TRUE;
}

/**
 * hg_gstate_set_dash:
 * @gstate:
 * @qpattern:
 * @offset:
 *
 * FIXME
 *
 * Returns:
 */
hg_bool_t
hg_gstate_set_dash(hg_gstate_t *gstate,
		   hg_quark_t   qpattern,
		   hg_real_t    offset)
{
	hg_array_t *a;
	hg_mem_t *mem;
	hg_uint_t id;
	hg_usize_t i;
	hg_bool_t is_zero = TRUE;

	hg_return_val_if_fail (gstate != NULL, FALSE, HG_e_typecheck);
	hg_return_val_if_fail (HG_IS_QARRAY (qpattern), FALSE, HG_e_typecheck);

	/* initialize hg_errno to estimate properly */
	hg_errno = 0;

	id = hg_quark_get_mem_id(qpattern);

	hg_return_val_if_fail ((mem = hg_mem_spool_get(id)) != NULL, FALSE, HG_e_VMerror);
	hg_return_val_if_lock_fail (a, mem, qpattern, FALSE);

	if (hg_array_length(a) > 11) {
		hg_debug(HG_MSGCAT_GSTATE, "Array size for dash pattern is too big");
		hg_errno = HG_ERROR_ (HG_STATUS_FAILED, HG_e_limitcheck);
		goto finalize;
	}
	if (hg_array_length(a) > 0) {
		for (i = 0; i < hg_array_length(a); i++) {
			hg_quark_t q = hg_array_get(a, i);

			if (!HG_ERROR_IS_SUCCESS0 ())
				return FALSE;
			if (HG_IS_QINT (q)) {
				if (HG_INT (q) != 0)
					is_zero = FALSE;
			} else if (HG_IS_QREAL (q)) {
				if (!HG_REAL_IS_ZERO (q))
					is_zero = FALSE;
			} else {
				hg_debug(HG_MSGCAT_GSTATE, "Dash pattern contains non-numeric.");
				hg_errno = HG_ERROR_ (HG_STATUS_FAILED, HG_e_typecheck);
				goto finalize;
			}
		}
		if (is_zero) {
			hg_debug(HG_MSGCAT_GSTATE, "No patterns in Array");
			hg_errno = HG_ERROR_ (HG_STATUS_FAILED, HG_e_rangecheck);
			goto finalize;
		}
	}

	gstate->qdashpattern = qpattern;
	gstate->dash_offset = offset;
  finalize:
	hg_mem_unlock_object(mem, qpattern);

	return HG_ERROR_IS_SUCCESS0 ();
}

/* hg_path_t wrappers */

/**
 * hg_gstate_newpath:
 * @gstate:
 *
 * FIXME
 *
 * Returns:
 */
hg_bool_t
hg_gstate_newpath(hg_gstate_t *gstate)
{
	hg_return_val_if_fail (gstate != NULL, FALSE, HG_e_typecheck);
	hg_return_val_if_fail (gstate->o.type == HG_TYPE_GSTATE, FALSE, HG_e_typecheck);

	gstate->qpath = hg_path_new(gstate->o.mem, NULL);

	return gstate->qpath != Qnil;
}

/**
 * hg_gstate_closepath:
 * @gstate:
 *
 * FIXME
 *
 * Returns:
 */
hg_bool_t
hg_gstate_closepath(hg_gstate_t *gstate)
{
	hg_path_t *p;
	hg_bool_t retval = FALSE;

	hg_return_val_if_fail (gstate != NULL, FALSE, HG_e_typecheck);
	hg_return_val_if_fail (gstate->o.type == HG_TYPE_GSTATE, FALSE, HG_e_typecheck);

	p = HG_MEM_LOCK (gstate->o.mem, gstate->qpath);
	if (p) {
		retval = hg_path_close(p);
		hg_mem_unlock_object(gstate->o.mem, gstate->qpath);
	}

	return retval;
}

/**
 * hg_gstate_moveto:
 * @gstate:
 * @x:
 * @y:
 *
 * FIXME
 *
 * Returns:
 */
hg_bool_t
hg_gstate_moveto(hg_gstate_t *gstate,
		 hg_real_t    x,
		 hg_real_t    y)
{
	hg_path_t *p;
	hg_bool_t retval = FALSE;

	hg_return_val_if_fail (gstate != NULL, FALSE, HG_e_typecheck);
	hg_return_val_if_fail (gstate->o.type == HG_TYPE_GSTATE, FALSE, HG_e_typecheck);

	if (gstate->qpath == Qnil) {
		gstate->qpath = hg_path_new(gstate->o.mem, NULL);
		if (gstate->qpath == Qnil)
			hg_error_return (HG_STATUS_FAILED, HG_e_limitcheck);
	}
	p = HG_MEM_LOCK (gstate->o.mem, gstate->qpath);
	if (p) {
		retval = hg_path_moveto(p, x, y);
		hg_mem_unlock_object(gstate->o.mem, gstate->qpath);
	}

	return retval;
}

/**
 * hg_gstate_rmoveto:
 * @gstate:
 * @x:
 * @y:
 *
 * FIXME
 *
 * Returns:
 */
hg_bool_t
hg_gstate_rmoveto(hg_gstate_t *gstate,
		  hg_real_t    rx,
		  hg_real_t    ry)
{
	hg_path_t *p;
	hg_bool_t retval = FALSE;

	hg_return_val_if_fail (gstate != NULL, FALSE, HG_e_typecheck);
	hg_return_val_if_fail (gstate->o.type == HG_TYPE_GSTATE, FALSE, HG_e_typecheck);

	p = HG_MEM_LOCK (gstate->o.mem, gstate->qpath);
	if (p) {
		retval = hg_path_rmoveto(p, rx, ry);
		hg_mem_unlock_object(gstate->o.mem, gstate->qpath);
	}

	return retval;
}

/**
 * hg_gstate_lineto:
 * @gstate:
 * @x:
 * @y:
 *
 * FIXME
 *
 * Returns:
 */
hg_bool_t
hg_gstate_lineto(hg_gstate_t *gstate,
		 hg_real_t    x,
		 hg_real_t    y)
{
	hg_path_t *p;
	hg_bool_t retval = FALSE;

	hg_return_val_if_fail (gstate != NULL, FALSE, HG_e_typecheck);
	hg_return_val_if_fail (gstate->o.type == HG_TYPE_GSTATE, FALSE, HG_e_typecheck);

	p = HG_MEM_LOCK (gstate->o.mem, gstate->qpath);
	if (p) {
		retval = hg_path_lineto(p, x, y);
		hg_mem_unlock_object(gstate->o.mem, gstate->qpath);
	}

	return retval;
}

/**
 * hg_gstate_rlineto:
 * @gstate:
 * @x:
 * @y:
 *
 * FIXME
 *
 * Returns:
 */
hg_bool_t
hg_gstate_rlineto(hg_gstate_t *gstate,
		  hg_real_t    rx,
		  hg_real_t    ry)
{
	hg_path_t *p;
	hg_bool_t retval = FALSE;

	hg_return_val_if_fail (gstate != NULL, FALSE, HG_e_typecheck);
	hg_return_val_if_fail (gstate->o.type == HG_TYPE_GSTATE, FALSE, HG_e_typecheck);

	p = HG_MEM_LOCK (gstate->o.mem, gstate->qpath);
	if (p) {
		retval = hg_path_rlineto(p, rx, ry);
		hg_mem_unlock_object(gstate->o.mem, gstate->qpath);
	}

	return retval;
}

/**
 * hg_gstate_curveto:
 * @gstate:
 * @x1:
 * @y1:
 * @x2:
 * @y2:
 * @x3:
 * @y3:
 *
 * FIXME
 *
 * Returns:
 */
hg_bool_t
hg_gstate_curveto(hg_gstate_t *gstate,
		  hg_real_t    x1,
		  hg_real_t    y1,
		  hg_real_t    x2,
		  hg_real_t    y2,
		  hg_real_t    x3,
		  hg_real_t    y3)
{
	hg_path_t *p;
	hg_bool_t retval = FALSE;

	hg_return_val_if_fail (gstate != NULL, FALSE, HG_e_typecheck);
	hg_return_val_if_fail (gstate->o.type == HG_TYPE_GSTATE, FALSE, HG_e_typecheck);

	p = HG_MEM_LOCK (gstate->o.mem, gstate->qpath);
	if (p) {
		retval = hg_path_curveto(p, x1, y1, x2, y2, x3, y3);
		hg_mem_unlock_object(gstate->o.mem, gstate->qpath);
	}

	return retval;
}

/**
 * hg_gstate_rcurveto:
 * @gstate:
 * @x1:
 * @y1:
 * @x2:
 * @y2:
 * @x3:
 * @y3:
 *
 * FIXME
 *
 * Returns:
 */
hg_bool_t
hg_gstate_rcurveto(hg_gstate_t *gstate,
		   hg_real_t    rx1,
		   hg_real_t    ry1,
		   hg_real_t    rx2,
		   hg_real_t    ry2,
		   hg_real_t    rx3,
		   hg_real_t    ry3)
{
	hg_path_t *p;
	hg_bool_t retval = FALSE;

	hg_return_val_if_fail (gstate != NULL, FALSE, HG_e_typecheck);
	hg_return_val_if_fail (gstate->o.type == HG_TYPE_GSTATE, FALSE, HG_e_typecheck);

	p = HG_MEM_LOCK (gstate->o.mem, gstate->qpath);
	if (p) {
		retval = hg_path_rcurveto(p, rx1, ry1, rx2, ry2, rx3, ry3);
		hg_mem_unlock_object(gstate->o.mem, gstate->qpath);
	}

	return retval;
}

/**
 * hg_gstate_arc:
 * @gstate:
 * @x:
 * @y:
 * @r:
 * @angle1:
 * @angle2:
 *
 * FIXME
 *
 * Returns:
 */
hg_bool_t
hg_gstate_arc(hg_gstate_t *gstate,
	      hg_real_t    x,
	      hg_real_t    y,
	      hg_real_t    r,
	      hg_real_t    angle1,
	      hg_real_t    angle2)
{
	hg_path_t *p;
	hg_bool_t retval = FALSE;

	hg_return_val_if_fail (gstate != NULL, FALSE, HG_e_typecheck);
	hg_return_val_if_fail (gstate->o.type == HG_TYPE_GSTATE, FALSE, HG_e_typecheck);

	if (gstate->qpath == Qnil) {
		gstate->qpath = hg_path_new(gstate->o.mem, NULL);
		if (gstate->qpath == Qnil)
			hg_error_return (HG_STATUS_FAILED, HG_e_limitcheck);
	}
	p = HG_MEM_LOCK (gstate->o.mem, gstate->qpath);
	if (p) {
		retval = hg_path_arc(p, x, y, r, angle1, angle2);
		hg_mem_unlock_object(gstate->o.mem, gstate->qpath);
	}

	return retval;
}

/**
 * hg_gstate_arcn:
 * @gstate:
 * @x:
 * @y:
 * @r:
 * @angle1:
 * @angle2:
 *
 * FIXME
 *
 * Returns:
 */
hg_bool_t
hg_gstate_arcn(hg_gstate_t *gstate,
	       hg_real_t    x,
	       hg_real_t    y,
	       hg_real_t    r,
	       hg_real_t    angle1,
	       hg_real_t    angle2)
{
	hg_path_t *p;
	hg_bool_t retval = FALSE;

	hg_return_val_if_fail (gstate != NULL, FALSE, HG_e_typecheck);
	hg_return_val_if_fail (gstate->o.type == HG_TYPE_GSTATE, FALSE, HG_e_typecheck);

	if (gstate->qpath == Qnil) {
		gstate->qpath = hg_path_new(gstate->o.mem, NULL);
		if (gstate->qpath == Qnil)
			hg_error_return (HG_STATUS_FAILED, HG_e_limitcheck);
	}
	p = HG_MEM_LOCK (gstate->o.mem, gstate->qpath);
	if (p) {
		retval = hg_path_arcn(p, x, y, r, angle1, angle2);
		hg_mem_unlock_object(gstate->o.mem, gstate->qpath);
	}

	return retval;
}

/**
 * hg_gstate_arcto:
 * @gstate:
 * @x1:
 * @y1:
 * @x2:
 * @y2:
 * @r:
 * @ret:
 *
 * FIXME
 *
 * Returns:
 */
hg_bool_t
hg_gstate_arcto(hg_gstate_t *gstate,
		hg_real_t    x1,
		hg_real_t    y1,
		hg_real_t    x2,
		hg_real_t    y2,
		hg_real_t    r,
		hg_real_t    ret[4])
{
	hg_path_t *p;
	hg_bool_t retval = FALSE;

	hg_return_val_if_fail (gstate != NULL, FALSE, HG_e_typecheck);
	hg_return_val_if_fail (gstate->o.type == HG_TYPE_GSTATE, FALSE, HG_e_typecheck);

	p = HG_MEM_LOCK (gstate->o.mem, gstate->qpath);
	if (p) {
		retval = hg_path_arcto(p, x1, y1, x2, y2, r, ret);
		hg_mem_unlock_object(gstate->o.mem, gstate->qpath);
	}

	return retval;
}

/**
 * hg_gstate_pathbbox:
 * @gstate:
 * @ignore_last_moveto:
 * @bbox:
 *
 * FIXME
 *
 * Returns:
 */
hg_bool_t
hg_gstate_pathbbox(hg_gstate_t    *gstate,
		   hg_bool_t       ignore_last_moveto,
		   hg_path_bbox_t *bbox)
{
	hg_path_t *p;
	hg_bool_t retval = FALSE;

	hg_return_val_if_fail (gstate != NULL, FALSE, HG_e_typecheck);
	hg_return_val_if_fail (gstate->o.type == HG_TYPE_GSTATE, FALSE, HG_e_typecheck);

	p = HG_MEM_LOCK (gstate->o.mem, gstate->qpath);
	if (p) {
		retval = hg_path_get_bbox(p,
					  ignore_last_moveto,
					  bbox);
		hg_mem_unlock_object(gstate->o.mem, gstate->qpath);
	}

	return retval;
}

/**
 * hg_gstate_initclip:
 * @gstate:
 *
 * FIXME
 *
 * Returns:
 */
hg_bool_t
hg_gstate_initclip(hg_gstate_t *gstate)
{
	hg_return_val_if_fail (gstate != NULL, FALSE, HG_e_typecheck);
	hg_return_val_if_fail (gstate->o.type == HG_TYPE_GSTATE, FALSE, HG_e_typecheck);

	/* expecting the current path is properly set */
	if (gstate->qpath == Qnil)
		hg_error_return (HG_STATUS_FAILED, HG_e_VMerror);

	gstate->qclippath = gstate->qpath;
	gstate->qpath = hg_path_new(gstate->o.mem, NULL);
	if (gstate->qpath == Qnil)
		hg_error_return (HG_STATUS_FAILED, HG_e_limitcheck);

	hg_error_return (HG_STATUS_SUCCESS, 0);
}

/**
 * hg_gstate_clippath:
 * @gstate:
 *
 * FIXME
 *
 * Returns:
 */
hg_bool_t
hg_gstate_clippath(hg_gstate_t *gstate)
{
	hg_quark_t q;

	hg_return_val_if_fail (gstate != NULL, FALSE, HG_e_typecheck);
	hg_return_val_if_fail (gstate->o.type == HG_TYPE_GSTATE, FALSE, HG_e_typecheck);

	q = hg_object_quark_copy(gstate->o.mem, gstate->qclippath, NULL);
	if (q == Qnil)
		hg_error_return (HG_STATUS_FAILED, HG_e_VMerror);

	gstate->qpath = q;

	hg_error_return (HG_STATUS_SUCCESS, 0);
}

/**
 * hg_gstate_get_current_point:
 * @gstate:
 * @x:
 * @y:
 *
 * FIXME
 *
 * Returns:
 */
hg_bool_t
hg_gstate_get_current_point(hg_gstate_t *gstate,
			    hg_real_t   *x,
			    hg_real_t   *y)
{
	hg_path_t *p;
	hg_bool_t retval = FALSE;

	hg_return_val_if_fail (gstate != NULL, FALSE, HG_e_typecheck);
	hg_return_val_if_fail (gstate->o.type == HG_TYPE_GSTATE, FALSE, HG_e_typecheck);

	p = HG_MEM_LOCK (gstate->o.mem, gstate->qpath);
	if (p) {
		retval = hg_path_get_current_point(p, x, y);
		hg_mem_unlock_object(gstate->o.mem, gstate->qpath);
	}

	return retval;
}