forked from verhas/ScriptBasic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface.c
More file actions
832 lines (652 loc) · 18.8 KB
/
interface.c
File metadata and controls
832 lines (652 loc) · 18.8 KB
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
/* FILE: gdinterf.c
This file is a ScriptBasic interface file to the library gd.
NTLIBS: libpng.lib gd.lib zlibs.lib
UXLIBS: -lc -lpng -lz -lgd
*/
#include <stdio.h>
#include "../../basext.h"
#include "gd.h"
#include "gdfontt.h"
#include "gdfonts.h"
#include "gdfontmb.h"
#include "gdfontl.h"
#include "gdfontg.h"
#define MAXBFONT 5
#define DEFAULTBFONT 3
#define DEFAULTPTSIZE 12.0
#define ANGLE_UP 270
#define GD_ERROR_ARGUMENT 0x00080001
#define GD_ERROR_FILE 0x00080002
#define GD_ERROR_ERROR 0x00080003
#define GD_ERROR_POLYAS 0x00080004
#define GD_ERROR_POLYAS1 0x00080005
/* the created images are stored in a list and any existing image
is automatically destroyed when the module exists. */
typedef struct _ImageList {
struct _ImageList *prev,*next;
gdImagePtr im;
char *TTFfont;
int BinFont;
int color;
int angle;
double ptsize;
} ImageList, *pImageList;
typedef struct _GdClass {
pImageList pImages;
} GdClass, *pGdClass;
/* Inserts the image into the list of images. */
#define InsertImage(x) __InsertImage(pSt,ppModuleInternal,(x))
static pImageList __InsertImage(pSupportTable pSt,
void **ppModuleInternal,
gdImagePtr pImage){
pGdClass p;
pImageList q;
p = (pGdClass)besMODULEPOINTER;
q = besALLOC(sizeof(ImageList));
if( q == NULL )return NULL;
q->next = p->pImages;
q->prev = NULL;
q->im = pImage;
if( q->next )
q->next->prev = q;
p->pImages = q;
q->TTFfont = NULL;
q->BinFont = DEFAULTBFONT; /* the default font is medium bold */
q->color = 0; /* the default is the background color */
q->angle = 0;
q->ptsize = DEFAULTPTSIZE;
return q;
}
/* Removes the list element. The image itself is NOT destroyed! */
#define RemoveImage(x) __RemoveImage(pSt,ppModuleInternal,(x))
static void __RemoveImage(pSupportTable pSt,
void **ppModuleInternal,
pImageList q){
pGdClass p;
p = (pGdClass)besMODULEPOINTER;
if( q->prev )
q->prev->next = q->next;
else
p->pImages = q->next;
if( q->next )
q->next->prev = q->prev;
besFREE(q);
}
besVERSION_NEGOTIATE
return (int)INTERFACE_VERSION;
besEND
besSUB_START
pGdClass p;
besMODULEPOINTER = besALLOC(sizeof(GdClass));
if( besMODULEPOINTER == NULL )return 0;
p = (pGdClass)besMODULEPOINTER;
p->pImages = NULL;
besEND
besSUB_FINISH
pGdClass p;
pImageList q,k;
p = (pGdClass)besMODULEPOINTER;
q = p->pImages;
while( q ){
gdImageDestroy(q->im);
q = (k=q)->next;
besFREE(k);
}
besFREE(p);
besEND
/* get mandatory long argument */
#define GET_M_L_ARGUMENT(x,y) Argument = besARGUMENT(y);\
besDEREFERENCE(Argument);\
if( Argument == NULL )return COMMAND_ERROR_ARGUMENT_RANGE;\
Argument = besCONVERT2LONG(Argument);\
x = (int)LONGVALUE(Argument);
#define GET_COLOR_ARGUMENT(y) \
if( besARGNR < y ){ color = p->color; }else{\
Argument = besARGUMENT(y);\
besDEREFERENCE(Argument);\
if( Argument == NULL ) color = p->color; else{\
Argument = besCONVERT2LONG(Argument);\
color = (int)LONGVALUE(Argument);}}
/* get mandatory pointer argument */
#define GET_M_P_ARGUMENT(x,y) Argument = besARGUMENT(y);\
besDEREFERENCE(Argument);\
if( Argument == NULL )return COMMAND_ERROR_ARGUMENT_RANGE;\
if( TYPE(Argument) != VTYPE_STRING ||\
STRLEN(Argument) != sizeof(x) )return COMMAND_ERROR_ARGUMENT_TYPE;\
memcpy(&(x),STRINGVALUE(Argument),sizeof(x));
/*gdImageCreateFromPng(FILE *in) */
besFUNCTION(gdicfpng)
VARIABLE Argument;
gdImagePtr pIm;
pImageList p;
char *pszFileName;
int FileAccess;
FILE *fp;
besRETURNVALUE = NULL;
if( besARGNR < 1 )return COMMAND_ERROR_FEW_ARGS;
Argument = besARGUMENT(1);
besDEREFERENCE(Argument);
if( Argument == NULL )return GD_ERROR_ARGUMENT;
Argument = besCONVERT2STRING(Argument);
besCONVERT2ZCHAR(Argument,pszFileName);
FileAccess = besHOOK_FILE_ACCESS(pszFileName);
if( !(FileAccess&1) ){
besFREE(pszFileName);
return GD_ERROR_FILE;
}
fp = fopen(pszFileName,"rb");
besFREE(pszFileName);
if( fp == NULL )return GD_ERROR_FILE;
pIm = gdImageCreateFromPng(fp);
fclose(fp);
if( pIm == NULL )return COMMAND_ERROR_MEMORY_LOW;
p = InsertImage(pIm);
if( p == NULL ){
gdImageDestroy(pIm);
return COMMAND_ERROR_MEMORY_LOW;
}
besALLOC_RETURN_STRING(sizeof(p));
memcpy(STRINGVALUE(besRETURNVALUE),&p,sizeof(p));
besEND
besFUNCTION(getxdime)
VARIABLE Argument;
pImageList p;
if( besARGNR < 1 )return COMMAND_ERROR_FEW_ARGS;
GET_M_P_ARGUMENT(p,1)
besALLOC_RETURN_LONG;
LONGVALUE(besRETURNVALUE) = gdImageSX(p->im);
besEND
besFUNCTION(getydime)
VARIABLE Argument;
pImageList p;
if( besARGNR < 1 )return COMMAND_ERROR_FEW_ARGS;
GET_M_P_ARGUMENT(p,1)
besALLOC_RETURN_LONG;
LONGVALUE(besRETURNVALUE) = gdImageSY(p->im);
besEND
/* gdImageCreate */
besFUNCTION(gdic)
VARIABLE Argument;
int sx,sy;
gdImagePtr pIm;
pImageList p;
besRETURNVALUE = NULL;
if( besARGNR < 2 )return COMMAND_ERROR_FEW_ARGS;
GET_M_L_ARGUMENT(sx,1)
GET_M_L_ARGUMENT(sy,2)
pIm = gdImageCreate(sx,sy);
if( pIm == NULL )return COMMAND_ERROR_MEMORY_LOW;
p = InsertImage(pIm);
if( p == NULL ){
gdImageDestroy(pIm);
return COMMAND_ERROR_MEMORY_LOW;
}
besALLOC_RETURN_STRING(sizeof(p));
memcpy(STRINGVALUE(besRETURNVALUE),&p,sizeof(p));
besEND
/* gdImageDestroy(im) */
besFUNCTION(imdestr)
VARIABLE Argument;
pImageList p;
if( besARGNR < 1 )return COMMAND_ERROR_FEW_ARGS;
GET_M_P_ARGUMENT(p,1)
gdImageDestroy(p->im);
RemoveImage(p);
besEND
/* gdAllocateColor(im,r,g,b) */
besFUNCTION(gdac)
VARIABLE Argument;
int r,g,b,color;
pImageList p;
besRETURNVALUE = NULL;
if( besARGNR < 4 )return COMMAND_ERROR_FEW_ARGS;
GET_M_P_ARGUMENT(p,1)
GET_M_L_ARGUMENT(r,2)
GET_M_L_ARGUMENT(g,3)
GET_M_L_ARGUMENT(b,4)
color = gdImageColorAllocate(p->im,r,g,b);
besALLOC_RETURN_LONG;
LONGVALUE(besRETURNVALUE) = (long)color;
besEND
/* gdImageLine(im, 0, 0, 63, 63, white) */
besFUNCTION(gdline)
VARIABLE Argument;
int xs,ys,xe,ye,color;
pImageList p;
besRETURNVALUE = NULL;
/* color is optional */
if( besARGNR < 5 )return COMMAND_ERROR_FEW_ARGS;
GET_M_P_ARGUMENT(p,1)
GET_M_L_ARGUMENT(xs,2)
GET_M_L_ARGUMENT(ys,3)
GET_M_L_ARGUMENT(xe,4)
GET_M_L_ARGUMENT(ye,5)
if( besARGNR == 5 ){/* color is missing */
color = p->color;
}else{
Argument = besARGUMENT(6);
besDEREFERENCE(Argument);
if( Argument == NULL )/* color is an explicit undef */
color = gdStyled;
else{
Argument = besCONVERT2LONG(Argument);
color = (int)LONGVALUE(Argument);
}
}
gdImageLine(p->im,xs,ys,xe,ye,color);
besEND
/* gdImageRectangle(im, 0, 0, 63, 63, white)
gdImageFilledRectangle(im, 0, 0, 63, 63, white)
*/
besFUNCTION(gdrect)
VARIABLE Argument;
int xs,ys,xe,ye,color;
pImageList p;
long fill;
besRETURNVALUE = NULL;
if( besARGNR < 7 )return COMMAND_ERROR_FEW_ARGS;
GET_M_P_ARGUMENT(p,1)
GET_M_L_ARGUMENT(xs,2)
GET_M_L_ARGUMENT(ys,3)
GET_M_L_ARGUMENT(xe,4)
GET_M_L_ARGUMENT(ye,5)
GET_COLOR_ARGUMENT(6)
GET_M_L_ARGUMENT(fill,7)
if( fill )
gdImageFilledRectangle(p->im,xs,ys,xe,ye,color);
else
gdImageRectangle(p->im,xs,ys,xe,ye,color);
besEND
besFUNCTION(impng)
VARIABLE Argument;
pImageList p;
FILE *fp;
char *pszFileName;
int FileAccess;
if( besARGNR < 2 )return COMMAND_ERROR_FEW_ARGS;
GET_M_P_ARGUMENT(p,1)
Argument = besARGUMENT(2);
besDEREFERENCE(Argument);
if( Argument == NULL )return GD_ERROR_ARGUMENT;
Argument = besCONVERT2STRING(Argument);
besCONVERT2ZCHAR(Argument,pszFileName);
FileAccess = besHOOK_FILE_ACCESS(pszFileName);
if( !(FileAccess&2) ){
besFREE(pszFileName);
return GD_ERROR_FILE;
}
/* We can not use the hook functions here. Why?
I do not really know why, but it seems that the main part of the
process and the DLL uses different allocation heap on Windows NT
and it also affects the file handling. I tried to open a file
using the hook function and with fopen. They returned different
file handles, and a fgetc, fread, fwrite or similar function could not
cope with a file handle pointer opened via the hook function. Somehow
they even destroyed the file pointer and caused core dump when file
closing took place (via hook_fclose). */
fp = fopen(pszFileName,"wb");
besFREE(pszFileName);
if( fp == NULL )return GD_ERROR_FILE;
gdImagePng(p->im,fp);
fclose(fp);
besEND
/*void* gdImagePngPtr(gdImagePtr im, int *size)*/
besFUNCTION(impngstr)
VARIABLE Argument;
int size;
void *q;
pImageList p;
besRETURNVALUE = NULL;
if( besARGNR < 1 )return COMMAND_ERROR_FEW_ARGS;
GET_M_P_ARGUMENT(p,1)
q = gdImagePngPtr(p->im,&size);
if( size <= 0 )return GD_ERROR_ERROR;
besALLOC_RETURN_STRING((long)size);
memcpy(STRINGVALUE(besRETURNVALUE),q,size);
free(q);
besEND
/* gdImageSetPixel(im, 0, 0, white) */
besFUNCTION(gdpix)
VARIABLE Argument;
int x,y,color;
pImageList p;
besRETURNVALUE = NULL;
if( besARGNR < 3 )return COMMAND_ERROR_FEW_ARGS;
GET_M_P_ARGUMENT(p,1)
GET_M_L_ARGUMENT(x,2)
GET_M_L_ARGUMENT(y,3)
GET_COLOR_ARGUMENT(4)
gdImageSetPixel(p->im,x,y,color);
besEND
/*
gd::Polygon(Image,Xarray,Yarray,Color)
*/
besFUNCTION(gdpoly)
VARIABLE Argument;
VARIABLE vX,vY;
VARIABLE V;
int ArraySize,color;
long i,j;
pImageList p;
gdPoint *point;
long fill;
besRETURNVALUE = NULL;
if( besARGNR < 5 )return COMMAND_ERROR_FEW_ARGS;
GET_M_P_ARGUMENT(p,1)
vX = besARGUMENT(2);
besDEREFERENCE(vX);
if( TYPE(vX) != VTYPE_ARRAY )return COMMAND_ERROR_ARGUMENT_TYPE;
ArraySize = ARRAYHIGH(vX) - ARRAYLOW(vX) +1;
vY = besARGUMENT(3);
besDEREFERENCE(vY);
if( TYPE(vY) != VTYPE_ARRAY )return COMMAND_ERROR_ARGUMENT_TYPE;
if( ArraySize != ARRAYHIGH(vY) - ARRAYLOW(vY) +1 )
return GD_ERROR_POLYAS;
if( ARRAYLOW(vX) != ARRAYLOW(vY) )return GD_ERROR_POLYAS1;
point = besALLOC(ArraySize*sizeof(gdPoint));
if( point == NULL )return COMMAND_ERROR_MEMORY_LOW;
for( i=0 , j = ARRAYLOW(vX) ; i < ArraySize ; i++ , j++ ){
V = ARRAYVALUE(vX,j);
if( V == NULL ){
besFREE(point);
return COMMAND_ERROR_ARGUMENT_TYPE;
}
point[i].x = LONGVALUE(besCONVERT2LONG(V));
V = ARRAYVALUE(vY,j);
if( V == NULL ){
besFREE(point);
return COMMAND_ERROR_ARGUMENT_TYPE;
}
point[i].y = LONGVALUE(besCONVERT2LONG(V));
}
GET_COLOR_ARGUMENT(4)
GET_M_L_ARGUMENT(fill,5)
if( fill )
gdImageFilledPolygon(p->im,point,ArraySize,color);
else
gdImagePolygon(p->im,point,ArraySize,color);
besFREE(point);
besEND
/*
void gdImageArc(gdImagePtr im, int cx, int cy, int w, int h, int s, int e, int color)
*/
besFUNCTION(gdarc)
VARIABLE Argument;
long cx,cy,w,h,s,e,color;
pImageList p;
besRETURNVALUE = NULL;
if( besARGNR < 7 )return COMMAND_ERROR_FEW_ARGS;
GET_M_P_ARGUMENT(p,1)
GET_M_L_ARGUMENT(cx,2)
GET_M_L_ARGUMENT(cy,3)
GET_M_L_ARGUMENT(w,4)
GET_M_L_ARGUMENT(h,5)
GET_M_L_ARGUMENT(s,6)
GET_M_L_ARGUMENT(e,7)
GET_COLOR_ARGUMENT(8)
gdImageArc(p->im, (int) cx, (int) cy, (int) w, (int) h, (int) s, (int) e, (int) color);
besEND
/*
void gdImageFillToBorder(gdImagePtr im, int x, int y, int border, int color)
*/
besFUNCTION(gdfilltb)
VARIABLE Argument;
long x,y,border,color;
pImageList p;
besRETURNVALUE = NULL;
if( besARGNR < 4 )return COMMAND_ERROR_FEW_ARGS;
GET_M_P_ARGUMENT(p,1)
GET_M_L_ARGUMENT(x,2)
GET_M_L_ARGUMENT(y,3)
GET_M_L_ARGUMENT(border,4)
GET_COLOR_ARGUMENT(5)
gdImageFillToBorder(p->im, (int) x, (int) y, (int) border, (int) color);
besEND
/*
void gdImageFill(gdImagePtr im, int x, int y, int color)
*/
besFUNCTION(gdfill)
VARIABLE Argument;
long x,y,color;
pImageList p;
besRETURNVALUE = NULL;
if( besARGNR < 3 )return COMMAND_ERROR_FEW_ARGS;
GET_M_P_ARGUMENT(p,1)
GET_M_L_ARGUMENT(x,2)
GET_M_L_ARGUMENT(y,3)
GET_COLOR_ARGUMENT(4)
gdImageFill(p->im, (int) x, (int) y, (int) color);
besEND
/*
void gdImageSetBrush(gdImagePtr im, gdImagePtr brush)
*/
besFUNCTION(gdstbrus)
VARIABLE Argument;
pImageList p,q;
besRETURNVALUE = NULL;
if( besARGNR < 2 )return COMMAND_ERROR_FEW_ARGS;
GET_M_P_ARGUMENT(p,1)
GET_M_P_ARGUMENT(q,2)
if( p == q )return COMMAND_ERROR_ARGUMENT_RANGE;
gdImageSetBrush(p->im, q->im );
besEND
/*
void gdImageSetTile(gdImagePtr im, gdImagePtr tile)
*/
besFUNCTION(gdstile)
VARIABLE Argument;
pImageList p,q;
besRETURNVALUE = NULL;
if( besARGNR < 2 )return COMMAND_ERROR_FEW_ARGS;
GET_M_P_ARGUMENT(p,1)
GET_M_P_ARGUMENT(q,2)
gdImageSetTile(p->im, q->im );
besEND
/*
void gdImageSetStyle(gdImagePtr im, int *style, int styleLength)
*/
besFUNCTION(gdsstyle)
VARIABLE Argument;
VARIABLE vSTYLE,V;
int ArraySize;
long i,j;
pImageList p;
int *style;
besRETURNVALUE = NULL;
if( besARGNR < 2 )return COMMAND_ERROR_FEW_ARGS;
GET_M_P_ARGUMENT(p,1)
vSTYLE = besARGUMENT(2);
besDEREFERENCE(vSTYLE);
if( TYPE(vSTYLE) != VTYPE_ARRAY )return COMMAND_ERROR_ARGUMENT_TYPE;
ArraySize = ARRAYHIGH(vSTYLE) - ARRAYLOW(vSTYLE) +1;
style = besALLOC(ArraySize*sizeof(int));
if( style == NULL )return COMMAND_ERROR_MEMORY_LOW;
for( i=0 , j = ARRAYLOW(vSTYLE) ; i < ArraySize ; i++ , j++ ){
V = ARRAYVALUE(vSTYLE,j);
if( V == NULL )
style[i] = gdTransparent;
else
style[i] = (int)LONGVALUE(besCONVERT2LONG(V));
}
gdImageSetStyle(p->im,style,ArraySize);
besFREE(style);
besEND
/*
int gdImage/Blue/Green/Red(gdImagePtr im, int color)
gd::GetColorComponent(image,color,gd::Red/gd::Green/gd::Blue)
*/
besFUNCTION(gdgetc)
VARIABLE Argument;
long color,component;
pImageList p;
besRETURNVALUE = NULL;
if( besARGNR < 3 )return COMMAND_ERROR_FEW_ARGS;
GET_M_P_ARGUMENT(p,1)
GET_M_L_ARGUMENT(color,2)
GET_M_L_ARGUMENT(component,3);
switch( component ){
default: return COMMAND_ERROR_ARGUMENT_RANGE;
case 1: color = gdImageRed(p->im,color);
break;
case 2: color = gdImageGreen(p->im,color);
break;
case 4: color = gdImageBlue(p->im,color);
break;
}
besALLOC_RETURN_LONG;
LONGVALUE(besRETURNVALUE) = color;
besEND
/*
int gdImageBoundsSafe(gdImagePtr im, int x, int y)
*/
besFUNCTION(gdbons)
VARIABLE Argument;
long x,y;
pImageList p;
besRETURNVALUE = NULL;
if( besARGNR < 3 )return COMMAND_ERROR_FEW_ARGS;
GET_M_P_ARGUMENT(p,1)
GET_M_L_ARGUMENT(x,2)
GET_M_L_ARGUMENT(y,3);
besALLOC_RETURN_LONG;
LONGVALUE(besRETURNVALUE) = gdImageBoundsSafe(p->im,(int)x,(int)y);
besEND
/* set the color for subsequent calls when color is not defined */
besFUNCTION(gdcolor)
VARIABLE Argument;
long color;
pImageList p;
besRETURNVALUE = NULL;
if( besARGNR < 2 )return COMMAND_ERROR_FEW_ARGS;
GET_M_P_ARGUMENT(p,1)
GET_M_L_ARGUMENT(color,2)
p->color = color;
besEND
/* set the font to be used in subsequent gd::print commands */
besFUNCTION(gdfont)
VARIABLE Argument;
pImageList p;
char *s;
long slen;
int IsTTF;
besRETURNVALUE = NULL;
if( besARGNR < 2 )return COMMAND_ERROR_FEW_ARGS;
GET_M_P_ARGUMENT(p,1)
if( p->TTFfont )besFREE(p->TTFfont);
p->TTFfont = NULL;
p->BinFont = DEFAULTBFONT;
p->angle = 0;
p->ptsize = DEFAULTPTSIZE;
Argument = besARGUMENT(2);
besDEREFERENCE(Argument);
if( Argument ){/* explicit undef sets to default font */
if( IsTTF=(TYPE(Argument) == VTYPE_STRING) ){
/* this is TrueType font */
slen = STRLEN(Argument); /* this is a file name, we better check that there is no null char in it */
s = STRINGVALUE(Argument);
while( slen --)if( *s++ == (char)0 )return COMMAND_ERROR_ARGUMENT_RANGE;
besCONVERT2ZCHAR(Argument,p->TTFfont);
}else{
Argument = besCONVERT2LONG(Argument);
p->BinFont = LONGVALUE(Argument);
if( p->BinFont < 1 || p->BinFont > MAXBFONT )p->BinFont = DEFAULTBFONT;
}
}
if( besARGNR < 3 )return COMMAND_ERROR_SUCCESS;
Argument = besARGUMENT(3);
besDEREFERENCE(Argument);
if( Argument != NULL ){/* explicit undef makes it to default 0 */
Argument = besCONVERT2LONG(Argument);
p->angle = LONGVALUE(Argument);
if( ! IsTTF ){
if( p->angle != 0 && p->angle != ANGLE_UP ){
p->angle = 0;
return COMMAND_ERROR_ARGUMENT_RANGE;
}
}
}
if( ! IsTTF || besARGNR < 4 )return COMMAND_ERROR_SUCCESS; /* size is ignored in case of built in functions */
Argument = besARGUMENT(4); /* size of a TTF font */
besDEREFERENCE(Argument);
if( Argument == NULL )return COMMAND_ERROR_SUCCESS;
Argument = besCONVERT2DOUBLE(Argument);
p->ptsize = DOUBLEVALUE(Argument);
besEND
/*
void gdImageString[Up](gdImagePtr im, gdFontPtr font, int x, int y, unsigned char *s, int color)
char *gdImageStringTTF(gdImagePtr im, int *brect, int fg, char *fontname, double ptsize, double angle, int x, int y, char *string)
gd::print image,x,y,"text to print"
*/
besFUNCTION(gdprint)
VARIABLE Argument;
VARIABLE *pV;
long x,y;
pImageList p;
int argI;
char *s,*r;
gdFontPtr font;
int brect[8];
unsigned long slen;
besRETURNVALUE = NULL;
if( besARGNR < 3 )return COMMAND_ERROR_FEW_ARGS;
GET_M_P_ARGUMENT(p,1)
GET_M_L_ARGUMENT(x,2)
GET_M_L_ARGUMENT(y,3);
pV = besALLOC((besARGNR-3)*sizeof(VARIABLE));
if( pV == NULL )return COMMAND_ERROR_MEMORY_LOW;
pV -= 4;
for( slen = 0, argI = 4 ; argI <= besARGNR ; argI++ ){
Argument = besARGUMENT(argI);
besDEREFERENCE(Argument);
pV[argI] = besCONVERT2STRING(Argument); /* note that undef is converted to null string */
slen += STRLEN(pV[argI]);
}
s = besALLOC(slen+1);
if( s == NULL ){
pV += 4;
besFREE(pV);
return COMMAND_ERROR_MEMORY_LOW;
}
for( r = s , argI = 4 ; argI <= besARGNR ; argI++ ){
for( slen = 0 ; STRINGVALUE(pV[argI])[slen] && slen < STRLEN(pV[argI]) ; slen++ )
*r++ = STRINGVALUE(pV[argI])[slen];
}
*r = (char)0;
pV += 4;
besFREE(pV);
if( p->TTFfont ){
r = gdImageStringTTF(p->im, brect, p->color, p->TTFfont, p->ptsize,
(double)p->angle, (int) x, (int) y, s) ;
if( r ){
besFREE(s);
return GD_ERROR_ERROR;
}
}else{
font = gdFontMediumBold;
switch( p->BinFont ){
case 1: font = gdFontTiny; break;
case 2: font = gdFontSmall; break;
case 3: font = gdFontMediumBold; break;
case 4: font = gdFontLarge; break;
case 5: font = gdFontGiant; break;
}
if( p->angle == ANGLE_UP )
gdImageStringUp(p->im,font, (int) x, (int) y, s, p->color);
else
gdImageString(p->im,font, (int) x, (int) y, s, p->color);
}
besFREE(s);
besEND
/*
void gdImageColorTransparent(gdImagePtr im, int color)
*/
besFUNCTION(gdtrnspa)
VARIABLE Argument;
long c;
pImageList p;
besRETURNVALUE = NULL;
if( besARGNR < 2 )return COMMAND_ERROR_FEW_ARGS;
GET_M_P_ARGUMENT(p,1)
GET_M_L_ARGUMENT(c,2)
gdImageColorTransparent(p->im,(int)c);
besEND