summaryrefslogtreecommitdiff
path: root/cd/src/cd_active.c
blob: f8229bdec014310eb891a0d15ab5bc17fa53ecc4 (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
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
/** \file
 * \brief OLD API that needs the cdActivate call
 *
 * See Copyright Notice in cd.h
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <stdarg.h>

#ifdef CD_NO_OLD_INTERFACE
#undef CD_NO_OLD_INTERFACE
#endif

#include "cd.h"
#include "wd.h"

static cdCanvas *active_canvas = NULL;

int cdActivate(cdCanvas *canvas)
{
  /* if is the active canvas, just update canvas state */
  if (active_canvas && canvas == active_canvas)
  {
    if (cdCanvasActivate(canvas) == CD_ERROR)
    {
      active_canvas = NULL;
      return CD_ERROR;
    }

    return CD_OK;
  }

  /* if exists an active canvas, deactivate it */
  if (active_canvas) 
    cdCanvasDeactivate(active_canvas);
  
  /* allow to active a NULL canvas, the user may restore a previous canvas that was NULL */
  if (canvas == NULL)
  {
    active_canvas = NULL;
    return CD_ERROR;
  }

  /* do the activation */
  active_canvas = canvas;
  
  if (cdCanvasActivate(canvas) == CD_ERROR)
  {
    active_canvas = NULL;
    return CD_ERROR;
  }
  
  return CD_OK;
}

cdCanvas* cdActiveCanvas(void)
{
  return active_canvas;
}

int cdSimulate(int mode)
{
  assert(active_canvas);
  if (!active_canvas) return CD_ERROR;
  return cdCanvasSimulate(active_canvas, mode);
}

cdState* cdSaveState(void)
{
  assert(active_canvas);
  if (!active_canvas) return NULL;
  return cdCanvasSaveState(active_canvas);
}

void cdRestoreState(cdState* state)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasRestoreState(active_canvas, state);
}

void cdFlush(void)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasFlush(active_canvas);
}

void cdClear(void)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasClear(active_canvas);
}

void cdSetAttribute(const char* name, char *data)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasSetAttribute(active_canvas, name, data);
}

void cdSetfAttribute(const char* name, const char* format, ...)
{
  char data[1024];
  va_list arglist;

  assert(active_canvas);
  if (!active_canvas) return;

  va_start(arglist, format);
  vsprintf(data, format, arglist);

  cdCanvasSetAttribute(active_canvas, name, data);
}

char* cdGetAttribute(const char* name)
{
  assert(active_canvas);
  if (!active_canvas) return NULL;
  return cdCanvasGetAttribute(active_canvas, name);
}

int cdPlay(cdContext* context, int xmin, int xmax, int ymin, int ymax, void *data)
{
  assert(active_canvas);
  if (!active_canvas) return CD_ERROR;
  return cdCanvasPlay(active_canvas, context, xmin, xmax, ymin, ymax, data);
}

int cdClip(int mode)
{
  assert(active_canvas);
  if (!active_canvas) return CD_ERROR;
  return cdCanvasClip(active_canvas, mode);
}

void cdClipArea(int xmin, int xmax, int ymin, int ymax)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasClipArea(active_canvas, xmin, xmax, ymin, ymax);
}

int cdGetClipArea(int *xmin, int *xmax, int *ymin, int *ymax)
{
  assert(active_canvas);
  if (!active_canvas) return CD_ERROR;
  return cdCanvasGetClipArea(active_canvas, xmin, xmax, ymin, ymax);
}

int cdPointInRegion(int x, int y)
{
  assert(active_canvas);
  if (!active_canvas) return CD_ERROR;
  return cdCanvasIsPointInRegion(active_canvas, x, y);
}

void cdOffsetRegion(int x, int y)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasOffsetRegion(active_canvas, x, y);
}

void cdRegionBox(int *xmin, int *xmax, int *ymin, int *ymax)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasGetRegionBox(active_canvas, xmin, xmax, ymin, ymax);
}

void cdGetCanvasSize(int *width, int *height, double *width_mm, double *height_mm)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasGetSize(active_canvas, width, height, width_mm, height_mm);
}

void cdMM2Pixel(double mm_dx, double mm_dy, int *dx, int *dy)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasMM2Pixel(active_canvas, mm_dx, mm_dy, dx, dy);
}

void cdPixel2MM(int dx, int dy, double *mm_dx, double *mm_dy)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasPixel2MM(active_canvas, dx, dy, mm_dx, mm_dy);
}

void cdOrigin(int x, int y)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasOrigin(active_canvas, x, y);
}

int cdUpdateYAxis(int *y)
{
  assert(active_canvas);
  if (!active_canvas) return CD_ERROR;
  return cdCanvasUpdateYAxis(active_canvas, y);
}

void cdPixel(int x, int y, long color)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasPixel(active_canvas, x, y, color);
}

void cdMark(int x, int y)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasMark(active_canvas, x, y);
}

void cdLine(int x1, int y1, int x2, int y2)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasLine(active_canvas, x1, y1, x2, y2);
}

void cdBegin(int mode)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasBegin(active_canvas, mode);
}

void cdVertex(int x, int y)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasVertex(active_canvas, x, y);
}

void cdEnd(void)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasEnd(active_canvas);
}

void cdRect(int xmin, int xmax, int ymin, int ymax)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasRect(active_canvas, xmin, xmax, ymin, ymax);
}

void cdBox(int xmin, int xmax, int ymin, int ymax)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasBox(active_canvas, xmin, xmax, ymin, ymax);
}

void cdArc(int xc, int yc, int w, int h, double angle1, double angle2)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasArc(active_canvas, xc, yc, w, h, angle1, angle2);
}

void cdSector(int xc, int yc, int w, int h, double angle1, double angle2)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasSector(active_canvas, xc, yc, w, h, angle1, angle2);
}

void cdChord(int xc, int yc, int w, int h, double angle1, double angle2)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasChord(active_canvas, xc, yc, w, h, angle1, angle2);
}

void cdText(int x, int y, const char *s)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasText(active_canvas, x, y, s);
}

int cdBackOpacity(int opacity)
{
  assert(active_canvas);
  if (!active_canvas) return CD_ERROR;
  return cdCanvasBackOpacity(active_canvas, opacity);
}

int cdWriteMode(int mode)
{
  assert(active_canvas);
  if (!active_canvas) return CD_ERROR;
  return cdCanvasWriteMode(active_canvas, mode);
}

int cdLineStyle(int style)
{
  assert(active_canvas);
  if (!active_canvas) return CD_ERROR;
  return cdCanvasLineStyle(active_canvas, style);
}

int cdLineJoin(int join)
{
  assert(active_canvas);
  if (!active_canvas) return CD_ERROR;
  return cdCanvasLineJoin(active_canvas, join);
}

int cdLineCap(int cap)
{
  assert(active_canvas);
  if (!active_canvas) return CD_ERROR;
  return cdCanvasLineCap(active_canvas, cap);
}

int cdRegionCombineMode(int mode)
{
  assert(active_canvas);
  if (!active_canvas) return CD_ERROR;
  return cdCanvasRegionCombineMode(active_canvas, mode);
}

void cdLineStyleDashes(const int* dashes, int count)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasLineStyleDashes(active_canvas, dashes, count);
}

int cdLineWidth(int width)
{
  assert(active_canvas);
  if (!active_canvas) return CD_ERROR;
  return cdCanvasLineWidth(active_canvas, width);
}

int cdFillMode(int mode)
{
  assert(active_canvas);
  if (!active_canvas) return CD_ERROR;
  return cdCanvasFillMode(active_canvas, mode);
}

int cdInteriorStyle (int style)
{
  assert(active_canvas);
  if (!active_canvas) return CD_ERROR;
  return cdCanvasInteriorStyle(active_canvas, style);
}

int cdHatch(int style)
{
  assert(active_canvas);
  if (!active_canvas) return CD_ERROR;
  return cdCanvasHatch(active_canvas, style);
}

void cdStipple(int w, int h, const unsigned char *stipple)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasStipple(active_canvas, w, h, stipple);
}

unsigned char* cdGetStipple(int *w, int *h)
{
  assert(active_canvas);
  if (!active_canvas) return NULL;
  return cdCanvasGetStipple(active_canvas, w, h);
}

void cdPattern(int w, int h, const long *pattern)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasPattern(active_canvas, w, h, pattern);
}

long* cdGetPattern(int* w, int* h)
{
  assert(active_canvas);
  if (!active_canvas) return NULL;
  return cdCanvasGetPattern(active_canvas, w, h);
}

void cdFont(int type_face, int style, int size)
{
  static const char * family[] = 
  {
    "System",       /* CD_SYSTEM */
    "Courier",      /* CD_COURIER */
    "Times",        /* CD_TIMES_ROMAN */
    "Helvetica"     /* CD_HELVETICA */
  };

  assert(active_canvas);
  assert(type_face>=CD_SYSTEM && type_face<=CD_NATIVE);
  if (!active_canvas) return;
  if (type_face<CD_SYSTEM || type_face>CD_NATIVE) return;

  if (type_face == CD_NATIVE)
  {
    char* native_font = cdCanvasNativeFont(active_canvas, NULL);
    cdCanvasNativeFont(active_canvas, native_font);
  }                                        
  else
    cdCanvasFont(active_canvas, family[type_face], style, size);
}

void cdGetFont(int *type_face, int *style, int *size)
{
  char family[1024];
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasGetFont(active_canvas, family, style, size);

  if (type_face)
  {
    if (strcmp(family, "System")==0) 
      *type_face = CD_SYSTEM;
    else if (strcmp(family, "Courier")==0) 
      *type_face = CD_COURIER;
    else if (strcmp(family, "Times")==0) 
      *type_face = CD_TIMES_ROMAN;
    else if (strcmp(family, "Helvetica")==0) 
      *type_face = CD_HELVETICA;
    else
      *type_face = CD_NATIVE;
  }
}

char* cdNativeFont(const char* font)
{
  assert(active_canvas);
  if (!active_canvas) return NULL;
  return cdCanvasNativeFont(active_canvas, font);
}

int cdTextAlignment(int alignment)
{
  assert(active_canvas);
  if (!active_canvas) return CD_ERROR;
  return cdCanvasTextAlignment(active_canvas, alignment);
}

double cdTextOrientation(double angle)
{
  assert(active_canvas);
  if (!active_canvas) return CD_ERROR;
  return cdCanvasTextOrientation(active_canvas, angle);
}

int cdMarkType(int type)
{
  assert(active_canvas);
  if (!active_canvas) return CD_ERROR;
  return cdCanvasMarkType(active_canvas, type);
}

int cdMarkSize(int size)
{
  assert(active_canvas);
  if (!active_canvas) return CD_ERROR;
  return cdCanvasMarkSize(active_canvas, size);
}

long cdBackground(long color)
{
  assert(active_canvas);
  if (!active_canvas) return CD_ERROR;
  return cdCanvasBackground(active_canvas, color);
}

long cdForeground(long color)
{
  assert(active_canvas);
  if (!active_canvas) return CD_ERROR;
  return cdCanvasForeground(active_canvas, color);
}

void cdFontDim(int *max_width, int *height, int *ascent, int *descent)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasGetFontDim(active_canvas, max_width, height, ascent, descent);
}

void cdTextSize(const char *s, int *width, int *height)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasGetTextSize(active_canvas, s, width, height);
}

void cdTextBounds(int x, int y, const char *s, int *rect)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasGetTextBounds(active_canvas, x, y, s, rect);
}

void cdTextBox(int x, int y, const char *s, int *xmin, int *xmax, int *ymin, int *ymax)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasGetTextBox(active_canvas, x, y, s, xmin, xmax, ymin, ymax);
}

int cdGetColorPlanes(void)
{
  assert(active_canvas);
  if (!active_canvas) return CD_ERROR;
  return cdCanvasGetColorPlanes(active_canvas);
}

void cdPalette(int n, const long *palette, int mode)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasPalette(active_canvas, n, palette, mode);
}

void cdGetImageRGB(unsigned char *r, unsigned char *g, unsigned char *b, int x, int y, int w, int h)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasGetImageRGB(active_canvas, r, g, b, x, y, w, h);
}

void cdPutImageRectRGB(int iw, int ih, const unsigned char *r, const unsigned char *g, const unsigned char *b, int x, int y, int w, int h, int xmin, int xmax, int ymin, int ymax)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasPutImageRectRGB(active_canvas, iw, ih, r, g, b, x, y, w, h, xmin, xmax, ymin, ymax);
}

void cdPutImageRectRGBA(int iw, int ih, const unsigned char *r, const unsigned char *g, const unsigned char *b, const unsigned char *a, int x, int y, int w, int h, int xmin, int xmax, int ymin, int ymax)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasPutImageRectRGBA(active_canvas, iw, ih, r, g, b, a, x, y, w, h, xmin, xmax, ymin, ymax);
}

void cdPutImageRectMap(int iw, int ih, const unsigned char *index, const long *colors, int x, int y, int w, int h, int xmin, int xmax, int ymin, int ymax)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasPutImageRectMap(active_canvas, iw, ih, index, colors, x, y, w, h, xmin, xmax, ymin, ymax);
}

cdImage* cdCreateImage(int w, int h)
{
  assert(active_canvas);
  if (!active_canvas) return NULL;
  return cdCanvasCreateImage(active_canvas, w, h);
}

void cdGetImage(cdImage* image, int x, int y)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasGetImage(active_canvas, image, x, y);
}

void cdPutImageRect(cdImage* image, int x, int y, int xmin, int xmax, int ymin, int ymax)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasPutImageRect(active_canvas, image, x, y, xmin, xmax, ymin, ymax);
}

void cdScrollArea(int xmin, int xmax, int ymin, int ymax, int dx, int dy)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasScrollArea(active_canvas, xmin, xmax, ymin, ymax, dx, dy);
}

void cdPutBitmap(cdBitmap* bitmap, int x, int y, int w, int h)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasPutBitmap(active_canvas, bitmap, x, y, w, h);
}

void cdGetBitmap(cdBitmap* bitmap, int x, int y)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasGetBitmap(active_canvas, bitmap, x, y);
}

void wdWindow(double xmin, double xmax, double  ymin, double ymax)
{
  assert(active_canvas);
  if (!active_canvas) return;
  wdCanvasWindow(active_canvas, xmin, xmax, ymin, ymax);
}

void wdGetWindow (double *xmin, double  *xmax,  double  *ymin, double *ymax)
{
  assert(active_canvas);
  if (!active_canvas) return;
  wdCanvasGetWindow(active_canvas, xmin, xmax, ymin, ymax);
}

void wdViewport(int xmin, int xmax, int ymin, int ymax)
{
  assert(active_canvas);
  if (!active_canvas) return;
  wdCanvasViewport(active_canvas, xmin, xmax, ymin, ymax);
}

void wdGetViewport (int *xmin, int *xmax, int *ymin, int *ymax)
{
  assert(active_canvas);
  if (!active_canvas) return;
  wdCanvasGetViewport(active_canvas, xmin, xmax, ymin, ymax);
}

void wdWorld2Canvas(double xw, double yw, int *xv, int *yv)
{
  assert(active_canvas);
  if (!active_canvas) return;
  wdCanvasWorld2Canvas(active_canvas, xw, yw, xv, yv);
}

void wdWorld2CanvasSize(double hw, double vw, int *hv, int *vv)
{
  assert(active_canvas);
  if (!active_canvas) return;
  wdCanvasWorld2CanvasSize(active_canvas, hw, vw, hv, vv);
}

void wdCanvas2World(int xv, int yv, double *xw, double *yw)
{
  assert(active_canvas);
  if (!active_canvas) return;
  wdCanvasCanvas2World(active_canvas, xv, yv, xw, yw);
}

void wdClipArea(double xmin, double xmax, double ymin, double ymax)
{
  assert(active_canvas);
  if (!active_canvas) return;
  wdCanvasClipArea(active_canvas, xmin, xmax, ymin, ymax);
}

int wdPointInRegion(double x, double y)
{
  assert(active_canvas);
  if (!active_canvas) return CD_ERROR;
  return wdCanvasIsPointInRegion(active_canvas, x, y);
}

void wdOffsetRegion(double x, double y)
{
  assert(active_canvas);
  if (!active_canvas) return;
  wdCanvasOffsetRegion(active_canvas, x, y);
}

void wdRegionBox(double *xmin, double *xmax, double *ymin, double *ymax)
{
  assert(active_canvas);
  if (!active_canvas) return;
  wdCanvasGetRegionBox(active_canvas, xmin, xmax, ymin, ymax);
}

int wdGetClipArea(double *xmin, double *xmax, double *ymin, double *ymax)
{
  assert(active_canvas);
  if (!active_canvas) return CD_ERROR;
  return wdCanvasGetClipArea(active_canvas, xmin, xmax, ymin, ymax);
}

void wdLine (double x1, double y1, double x2, double y2)
{
  assert(active_canvas);
  if (!active_canvas) return;
  wdCanvasLine(active_canvas, x1, y1, x2, y2);
}

void wdBox (double xmin, double xmax, double ymin, double ymax)
{
  assert(active_canvas);
  if (!active_canvas) return;
  wdCanvasBox(active_canvas, xmin, xmax, ymin, ymax);
}

void wdRect(double xmin, double xmax, double ymin, double ymax)
{
  assert(active_canvas);
  if (!active_canvas) return;
  wdCanvasRect(active_canvas, xmin, xmax, ymin, ymax);
}

void wdArc(double xc, double yc, double w, double h, double angle1, double angle2)
{
  assert(active_canvas);
  if (!active_canvas) return;
  wdCanvasArc(active_canvas, xc, yc, w, h, angle1, angle2);
}

void wdSector(double xc, double yc, double w, double h, double angle1, double angle2)
{
  assert(active_canvas);
  if (!active_canvas) return;
  wdCanvasSector(active_canvas, xc, yc, w, h, angle1, angle2);
}

void wdChord(double xc, double yc, double w, double h, double angle1, double angle2)
{
  assert(active_canvas);
  if (!active_canvas) return;
  wdCanvasChord(active_canvas, xc, yc, w, h, angle1, angle2);
}

void wdText(double x, double y, const char *s)
{
  assert(active_canvas);
  if (!active_canvas) return;
  wdCanvasText(active_canvas, x, y, s);
}

void wdVertex(double x, double y)
{
  assert(active_canvas);
  if (!active_canvas) return;
  wdCanvasVertex(active_canvas, x, y);
}

void wdMark(double x, double y)
{
  assert(active_canvas);
  if (!active_canvas) return;
  wdCanvasMark(active_canvas, x, y);
}

void wdPixel(double x, double y, long color)
{
  assert(active_canvas);
  if (!active_canvas) return;
  wdCanvasPixel(active_canvas, x, y, color);
}

void wdPutImageRect(cdImage* image, double x, double y, int xmin, int xmax, int ymin, int ymax)
{
  assert(active_canvas);
  if (!active_canvas) return;
  wdCanvasPutImageRect(active_canvas, image, x, y, xmin, xmax, ymin, ymax);
}

void wdPutImageRectRGB(int iw, int ih, const unsigned char *r, const unsigned char *g, const unsigned char *b, double x, double y, double w, double h, int xmin, int xmax, int ymin, int ymax)
{
  assert(active_canvas);
  if (!active_canvas) return;
  wdCanvasPutImageRectRGB(active_canvas, iw, ih, r, g, b, x, y, w, h, xmin, xmax, ymin, ymax);
}

void wdPutImageRectRGBA(int iw, int ih, const unsigned char *r, const unsigned char *g, const unsigned char *b, const unsigned char *a, double x, double y, double w, double h, int xmin, int xmax, int ymin, int ymax)
{
  assert(active_canvas);
  if (!active_canvas) return;
  wdCanvasPutImageRectRGBA(active_canvas, iw, ih, r, g, b, a, x, y, w, h, xmin, xmax, ymin, ymax);
}

void wdPutImageRectMap(int iw, int ih, const unsigned char *index, const long *colors, double x, double y, double w, double h, int xmin, int xmax, int ymin, int ymax)
{
  assert(active_canvas);
  if (!active_canvas) return;
  wdCanvasPutImageRectMap(active_canvas, iw, ih, index, colors, x, y, w, h, xmin, xmax, ymin, ymax);
}

void wdPutBitmap(cdBitmap* bitmap, double x, double y, double w, double h)
{
  assert(active_canvas);
  if (!active_canvas) return;
  wdCanvasPutBitmap(active_canvas, bitmap, x, y, w, h);
}

double wdLineWidth(double width_mm)
{
  assert(active_canvas);
  if (!active_canvas) return CD_ERROR;
  return wdCanvasLineWidth(active_canvas, width_mm);
}

void wdFont(int type_face, int style, double size_mm)
{
  static const char * family[] = 
  {
    "System",       /* CD_SYSTEM */
    "Courier",      /* CD_COURIER */
    "Times Roman",  /* CD_TIMES_ROMAN */
    "Helvetica"     /* CD_HELVETICA */
  };

  assert(active_canvas);
  if (!active_canvas) return;
  if (type_face<CD_SYSTEM || type_face>CD_HELVETICA) return;

  wdCanvasFont(active_canvas, family[type_face], style, (int)(size_mm*CD_MM2PT + 0.5));
}

void wdGetFont(int *type_face, int *style, double *size)
{
  char family[1024];
  assert(active_canvas);
  if (!active_canvas) return;
  wdCanvasGetFont(active_canvas, family, style, size);

  if (type_face)
  {
    if (strcmp(family, "System")==0) 
      *type_face = CD_SYSTEM;
    else if (strcmp(family, "Courier")==0) 
      *type_face = CD_COURIER;
    else if (strcmp(family, "Times Roman")==0) 
      *type_face = CD_TIMES_ROMAN;
    else if (strcmp(family, "Helvetica")==0) 
      *type_face = CD_HELVETICA;
    else
      *type_face = CD_NATIVE;
  }
}

double wdMarkSize(double size_mm)
{
  assert(active_canvas);
  if (!active_canvas) return CD_ERROR;
  return wdCanvasMarkSize(active_canvas, size_mm);
}

void wdFontDim(double *max_width, double *height, double *ascent, double *descent)
{
  assert(active_canvas);
  if (!active_canvas) return;
  wdCanvasGetFontDim(active_canvas, max_width, height, ascent, descent);
}

void wdTextSize(const char *s, double *width, double *height)
{
  assert(active_canvas);
  if (!active_canvas) return;
  wdCanvasGetTextSize(active_canvas, s, width, height);
}

void wdTextBox(double x, double y, const char *s, double *xmin, double *xmax, double *ymin, double *ymax)
{
  assert(active_canvas);
  if (!active_canvas) return;
  wdCanvasGetTextBox(active_canvas, x, y, s, xmin, xmax, ymin, ymax);
}

void wdTextBounds(double x, double y, const char *s, double *rect)
{
  assert(active_canvas);
  if (!active_canvas) return;
  wdCanvasGetTextBounds(active_canvas, x, y, s, rect);
}

void wdPattern(int w, int h, const long *color, double w_mm, double h_mm)
{
  assert(active_canvas);
  if (!active_canvas) return;
  wdCanvasPattern(active_canvas, w, h, color, w_mm, h_mm);
}

void wdStipple(int w, int h, const unsigned char *fgbg, double w_mm, double h_mm)
{
  assert(active_canvas);
  if (!active_canvas) return;
  wdCanvasStipple(active_canvas, w, h, fgbg, w_mm, h_mm);
}

void wdHardcopy(cdContext* ctx, void *data, cdCanvas *canvas, void(*draw_func)(void))
{
  wdCanvasHardcopy(canvas, ctx, data, (void(*)(cdCanvas*))draw_func);
}

void cdVectorText(int x, int y, const char* s)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasVectorText(active_canvas, x, y, s);
}

void cdMultiLineVectorText(int x, int y, const char* s)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasMultiLineVectorText(active_canvas, x, y, s);
}

char *cdVectorFont(const char *filename)
{
  assert(active_canvas);
  if (!active_canvas) return NULL;
  return cdCanvasVectorFont(active_canvas, filename);
}

void cdVectorTextDirection(int x1, int y1, int x2, int y2)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasVectorTextDirection(active_canvas, x1, y1, x2, y2);
}

double* cdVectorTextTransform(const double* matrix)
{
  assert(active_canvas);
  if (!active_canvas) return NULL;
  return cdCanvasVectorTextTransform(active_canvas, matrix);
}

void cdVectorTextSize(int size_x, int size_y, const char* s)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasVectorTextSize(active_canvas, size_x, size_y, s);
}

int cdVectorCharSize(int size)
{
  assert(active_canvas);
  if (!active_canvas) return CD_ERROR;
  return cdCanvasVectorCharSize(active_canvas, size);
}

void cdGetVectorTextSize(const char* s, int *x, int *y)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasGetVectorTextSize(active_canvas, s, x, y);
}

void cdGetVectorTextBounds(const char* s, int x, int y, int *rect)
{
  assert(active_canvas);
  if (!active_canvas) return;
  cdCanvasGetVectorTextBounds(active_canvas, s, x, y, rect);
}

void wdVectorTextDirection(double x1, double y1, double x2, double y2)
{
  assert(active_canvas);
  if (!active_canvas) return;
  wdCanvasVectorTextDirection(active_canvas, x1, y1, x2, y2);
}

void wdVectorTextSize(double size_x, double size_y, const char* s)
{
  assert(active_canvas);
  if (!active_canvas) return;
  wdCanvasVectorTextSize(active_canvas, size_x, size_y, s);
}

void wdGetVectorTextSize(const char* s, double *x, double *y)
{
  assert(active_canvas);
  if (!active_canvas) return;
  wdCanvasGetVectorTextSize(active_canvas, s, x, y);
}

double wdVectorCharSize(double size)
{
  assert(active_canvas);
  if (!active_canvas) return CD_ERROR;
  return wdCanvasVectorCharSize(active_canvas, size);
}

void wdVectorText(double x, double y, const char* s)
{
  assert(active_canvas);
  if (!active_canvas) return;
  wdCanvasVectorText(active_canvas, x, y, s);
}

void wdMultiLineVectorText(double x, double y, const char* s)
{
  assert(active_canvas);
  if (!active_canvas) return;
  wdCanvasMultiLineVectorText(active_canvas, x, y, s);
}

void wdGetVectorTextBounds(const char* s, double x, double y, double *rect)
{
  assert(active_canvas);
  if (!active_canvas) return;
  wdCanvasGetVectorTextBounds(active_canvas, s, x, y, rect);
}