67 for ( y = 0; y < x; y++ )
75 static int cdAppByte(
unsigned char *es,
short int addme )
81 *es = (
unsigned char) addme & 0377;
85 static int cdAppShort(
unsigned char *es,
short int addme )
94 *es = (
unsigned char) temp & 0377;
96 *es = (
unsigned char) addme & 0377;
122 static int cdcomhead(
unsigned char *es,
int elemclass,
int id,
int len )
135 *es = (
unsigned char) elemclass << 4;
142 *es = (
unsigned char)
id;
143 *es = *es | (
unsigned char) ( 037 & len );
148 static int cdcomheadlong(
unsigned char *es,
int elemclass,
int id,
int len )
161 if ( !
cdcomhead( es, elemclass,
id, 31 ) )
180 unsigned char *newlist;
183 while ( ( octet_count + 1 ) >= im->
bytestoend )
204 for ( x = 0; x < octet_count; x++ )
220 unsigned char *headerp;
222 const unsigned char *
buf, *buf2;
232 if ( im->
state != 0 )
234 headerp = (
unsigned char *) calloc( 1024,
SIZEOF(
unsigned char ) );
240 buf = (
const unsigned char *)
"cd: CgmDraw Library";
241 blen = strlen( (
const char *)
buf );
250 octet_count += ( blen + 3 );
251 curly = 4 - ( octet_count % 4 );
254 octet_count += curly;
265 blen = strlen( (
char *) im->
desc );
274 octet_count += ( blen + 5 );
275 curly = 4 - ( octet_count % 4 );
278 octet_count += curly;
298 octet_count += 4;
head++;
319 fontlistlen = strlen( (
const char *)
buf ) + 1;
327 while ( ( *
buf ) && ( *
buf !=
',' ) )
342 octet_count += ( 4 + fontlistlen );
343 curly = 4 - ( octet_count % 4 );
346 octet_count += curly;
351 if (
cdAddElem( im, headerp, octet_count ) )
372 unsigned char *headerp;
374 unsigned char *
buf, *buf2;
380 if ( ( im->
state != 0 ) && ( im->
state != 2 ) )
382 if ( ( sticky > 2 ) || ( sticky < 0 ) )
386 tb = (
char *) calloc( 4 * 4,
SIZEOF(
char ) );
389 headerp = (
unsigned char *) calloc( 1024,
SIZEOF(
unsigned char ) );
398 sprintf( tb,
"picture %d", im->
picnum );
399 buf = (
unsigned char *) tb;
401 blen = strlen( (
char *)
buf );
411 octet_count += ( blen + 3 );
417 if ( octet_count % 4 )
470 if (
cdAddElem( im, headerp, octet_count ) )
582 unsigned char *es, *esp;
592 if ( lntype == im->
ltype )
596 if ( ( lntype < 1 ) || ( lntype > 5 ) )
600 es = (
unsigned char *) calloc( 4 * 4,
SIZEOF(
unsigned char ) );
607 free( esp );
return 0;
620 im->
ltype = (
short int) lntype;
639 unsigned char *es, *esp;
649 if ( lnwidth == im->
lwidth )
653 es = (
unsigned char *) calloc( 4 * 4,
SIZEOF(
unsigned char ) );
666 free( esp );
return 0;
680 free( esp );
return 0;
709 unsigned char *es, *esp;
718 if ( lncolor == im->
lcolor )
723 if ( ( lncolor >= im->
colorsTotal ) || ( lncolor < 0 ) )
727 es = (
unsigned char *) calloc( 4 * 4,
SIZEOF(
unsigned char ) );
735 free( esp );
return 0;
739 *es = 0377 & lncolor;
750 im->
lcolor = (
short int) lncolor;
772 unsigned char *es, *esp;
787 if ( ( instyle < 0 ) || ( instyle > 4 ) || ( instyle == 2 ) )
791 es = (
unsigned char *) calloc( 4 * 4,
SIZEOF(
unsigned char ) );
799 free( esp );
return 0;
830 unsigned char *es, *esp;
844 if ( ( incolor >= im->
colorsTotal ) || ( incolor < 0 ) )
848 es = (
unsigned char *) calloc( 4 * 4,
SIZEOF(
unsigned char ) );
855 free( esp );
return 0;
859 *es = 0377 & incolor;
893 unsigned char *es, *esp;
894 int octet_count, temp;
908 if ( ( inhatch < 1 ) || ( inhatch > 6 ) )
912 es = (
unsigned char *) calloc( 4 * 4,
SIZEOF(
unsigned char ) );
920 free( esp );
return 0;
926 *es = *es | ( temp & 0377 );
928 *es = *es | ( inhatch & 0377 );
962 unsigned char *es, *esp;
976 if ( ( edtype < 1 ) || ( edtype > 5 ) )
980 es = (
unsigned char *) calloc( 4 * 4,
SIZEOF(
unsigned char ) );
987 free( esp );
return 0;
1018 unsigned char *es, *esp;
1023 if ( edwidth == -1 )
1032 es = (
unsigned char *) calloc( 4 * 4,
SIZEOF(
unsigned char ) );
1044 free( esp );
return 0;
1058 free( esp );
return 0;
1067 if (
cdAddElem( im, esp, octet_count ) )
1088 unsigned char *es, *esp;
1092 if ( edcolor == -1 )
1102 if ( ( edcolor >= im->
colorsTotal ) || ( edcolor < 0 ) )
1106 es = (
unsigned char *) calloc( 4 * 4,
SIZEOF(
unsigned char ) );
1112 free( esp );
return 0;
1116 *es = 0377 & edcolor;
1124 if (
cdAddElem( im, esp, octet_count ) )
1146 unsigned char *es, *esp;
1147 int octet_count, temp;
1160 es = (
unsigned char *) calloc( 4 * 4,
SIZEOF(
unsigned char ) );
1167 free( esp );
return 0;
1169 es += 2; octet_count = 2;
1171 *es = *es | ( temp & 0377 );
1173 *es = *es | ( edvis & 0377 );
1179 if (
cdAddElem( im, esp, octet_count ) )
1181 im->
edgevis = (
short int) edvis;
1210 unsigned char *es, *esp;
1224 if ( ( font < 1 ) || ( font > im->
numfonts ) )
1228 es = (
unsigned char *) calloc( 4 * 4,
SIZEOF(
unsigned char ) );
1235 free( esp );
return 0;
1244 if (
cdAddElem( im, esp, octet_count ) )
1262 unsigned char *es, *esp;
1280 es = (
unsigned char *) calloc( 4 * 4,
SIZEOF(
unsigned char ) );
1287 free( esp );
return 0;
1298 if (
cdAddElem( im, esp, octet_count ) )
1316 unsigned char *es, *esp;
1329 es = (
unsigned char *) calloc( 4 * 4,
SIZEOF(
unsigned char ) );
1336 free( esp );
return 0;
1338 octet_count = 2; es += 2;
1344 if (
cdAddElem( im, esp, octet_count ) )
1366 unsigned char *es, *esp;
1380 es = (
unsigned char *) calloc( 4 * 4,
SIZEOF(
unsigned char ) );
1388 free( esp );
return 0;
1390 es += 2; octet_count = 2;
1396 if (
cdAddElem( im, esp, octet_count ) )
1423 unsigned char *es, *esp;
1428 es = (
unsigned char *) calloc( 4 * 4,
SIZEOF(
unsigned char ) );
1436 free( esp );
return 0;
1438 es += 2; octet_count += 2;
1453 if (
cdAddElem( im, esp, octet_count ) )
1473 unsigned char *es, *esp;
1483 if ( mtype == im->
mtype )
1487 if ( ( mtype < 1 ) || ( mtype > 5 ) )
1491 es = (
unsigned char *) calloc( 4 * 4,
SIZEOF(
unsigned char ) );
1498 free( esp );
return 0;
1509 if (
cdAddElem( im, esp, octet_count ) )
1511 im->
mtype = (
short int) mtype;
1530 unsigned char *es, *esp;
1540 if ( msize == im->
msize )
1544 es = (
unsigned char *) calloc( 4 * 4,
SIZEOF(
unsigned char ) );
1557 free( esp );
return 0;
1571 free( esp );
return 0;
1581 if (
cdAddElem( im, esp, octet_count ) )
1600 unsigned char *es, *esp;
1609 if ( mcolor == im->
mcolor )
1614 if ( ( mcolor >= im->
colorsTotal ) || ( mcolor < 0 ) )
1618 es = (
unsigned char *) calloc( 4 * 4,
SIZEOF(
unsigned char ) );
1626 free( esp );
return 0;
1630 *es = 0377 & mcolor;
1639 if (
cdAddElem( im, esp, octet_count ) )
1641 im->
mcolor = (
short int) mcolor;
1802 rd = ( im->
red[i] - r );
1803 gd = ( im->
green[i] - g );
1804 bd = ( im->
blue[i] - b );
1805 dist = rd * rd + gd * gd + bd * bd;
1806 if ( ( i == 0 ) || ( dist < mindist ) )
1838 if ( ( im->
red[i] == r ) &&
1839 ( im->
green[i] == g ) &&
1840 ( im->
blue[i] == b ) )
1855 short int ct = ( -1 );
1873 im->
red[ct] = (
short int) r;
1874 im->
green[ct] = (
short int) g;
1875 im->
blue[ct] = (
short int) b;
1876 im->
open[ct] = (
short int) 0;
1887 unsigned char *cts, *ctsp;
1899 numco = ei - si + 1;
1901 if ( ( numco > 0 ) && ( numco < 10 ) )
1905 cts = (
unsigned char *) calloc( 4 * 10,
SIZEOF(
unsigned char ) );
1909 if ( !
cdcomhead( ctsp, 5, 34, ( numco * 3 ) + 1 ) )
1911 free( cts );
return -1;
1913 ctsp += 2; octet_count += 2;
1915 else if ( ( numco > 9 ) && ( numco < 256 ) )
1919 cts = (
unsigned char *) calloc( 256 * 4,
SIZEOF(
unsigned char ) );
1925 free( cts );
return -1;
1927 ctsp += 4; octet_count += 4;
1938 for ( numco = si; numco <= ei; numco++ )
1947 curly = 4 - ( octet_count % 4 );
1950 octet_count += curly;
1954 if (
cdAddElem( im, cts, octet_count ) )
2125 unsigned char *es, *esp;
2137 es = (
unsigned char *) calloc( 4 * 4,
SIZEOF(
unsigned char ) );
2144 free( esp );
return 0;
2150 sweet = (
short int) x1;
2152 *es = *es | ( sour & 0377 );
2153 es++; octet_count++;
2154 *es = (
unsigned char) sweet;
2155 es++; octet_count++;
2156 sweet = (
short int) y1;
2158 *es = *es | ( sour & 0377 );
2159 es++; octet_count++;
2160 *es = (
unsigned char) sweet;
2161 es++; octet_count++;
2162 sweet = (
short int) x2;
2164 *es = *es | ( sour & 0377 );
2165 es++; octet_count++;
2166 *es = (
unsigned char) sweet;
2167 es++; octet_count++;
2168 sweet = (
short int) y2;
2170 *es = *es | ( sour & 0377 );
2171 es++; octet_count++;
2172 *es = (
unsigned char) sweet;
2176 if (
cdAddElem( im, esp, octet_count ) )
2194 unsigned char *es, *esp;
2204 es = (
unsigned char *) calloc( 4 * 4,
SIZEOF(
unsigned char ) );
2211 free( esp );
return 0;
2216 octet_count +=
cdAppShort( es, (
short int) x );
2218 octet_count +=
cdAppShort( es, (
short int) y );
2222 if (
cdAddElem( im, esp, octet_count ) )
2246 unsigned char *es, *esp;
2258 es = (
unsigned char *) calloc( 4 * 4,
SIZEOF(
unsigned char ) );
2266 free( esp );
return 0;
2268 es += 2; octet_count = 2;
2271 sweet = (
short int) x1;
2273 *es = *es | ( sour & 0377 );
2274 es++; octet_count++;
2275 *es = (
unsigned char) sweet;
2276 es++; octet_count++;
2277 sweet = (
short int) y1;
2279 *es = *es | ( sour & 0377 );
2280 es++; octet_count++;
2281 *es = (
unsigned char) sweet;
2282 es++; octet_count++;
2283 sweet = (
short int) x2;
2285 *es = *es | ( sour & 0377 );
2286 es++; octet_count++;
2287 *es = (
unsigned char) sweet;
2288 es++; octet_count++;
2289 sweet = (
short int) y2;
2291 *es = *es | ( sour & 0377 );
2292 es++; octet_count++;
2293 *es = (
unsigned char) sweet;
2297 if (
cdAddElem( im, esp, octet_count ) )
2318 unsigned char *es, *esp;
2330 es = (
unsigned char *) calloc( 4 * 4,
SIZEOF(
unsigned char ) );
2338 free( esp );
return 0;
2340 es += 2; octet_count = 2;
2343 sweet = (
short int) cx;
2345 *es = *es | ( sour & 0377 );
2346 es++; octet_count++;
2347 *es = (
unsigned char) sweet;
2348 es++; octet_count++;
2349 sweet = (
short int) cy;
2351 *es = *es | ( sour & 0377 );
2352 es++; octet_count++;
2353 *es = (
unsigned char) sweet;
2354 es++; octet_count++;
2355 sweet = (
short int) r;
2357 *es = *es | ( sour & 0377 );
2358 es++; octet_count++;
2359 *es = (
unsigned char) sweet;
2364 if (
cdAddElem( im, esp, octet_count ) )
2383 unsigned char *es, *esp;
2395 es = (
unsigned char *) calloc( 4 * 4,
SIZEOF(
unsigned char ) );
2403 free( esp );
return 0;
2405 es += 2; octet_count = 2;
2408 sweet = (
short int) sx;
2410 *es = *es | ( sour & 0377 );
2411 es++; octet_count++;
2412 *es = (
unsigned char) sweet;
2413 es++; octet_count++;
2414 sweet = (
short int) sy;
2416 *es = *es | ( sour & 0377 );
2417 es++; octet_count++;
2418 *es = (
unsigned char) sweet;
2419 es++; octet_count++;
2420 sweet = (
short int) ix;
2422 *es = *es | ( sour & 0377 );
2423 es++; octet_count++;
2424 *es = (
unsigned char) sweet;
2425 es++; octet_count++;
2426 sweet = (
short int) iy;
2428 *es = *es | ( sour & 0377 );
2429 es++; octet_count++;
2430 *es = (
unsigned char) sweet;
2431 es++; octet_count++;
2432 sweet = (
short int) ex;
2434 *es = *es | ( sour & 0377 );
2435 es++; octet_count++;
2436 *es = (
unsigned char) sweet;
2437 es++; octet_count++;
2438 sweet = (
short int) ey;
2440 *es = *es | ( sour & 0377 );
2441 es++; octet_count++;
2442 *es = (
unsigned char) sweet;
2446 if (
cdAddElem( im, esp, octet_count ) )
2469 unsigned char *es, *esp;
2479 if ( ( cl != 0 ) && ( cl != 1 ) )
2483 es = (
unsigned char *) calloc( 4 * 6,
SIZEOF(
unsigned char ) );
2491 free( esp );
return 0;
2493 es += 2; octet_count = 2;
2496 octet_count +=
cdAppShort( es, (
short int) sx );
2498 octet_count +=
cdAppShort( es, (
short int) sy );
2500 octet_count +=
cdAppShort( es, (
short int) ix );
2502 octet_count +=
cdAppShort( es, (
short int) iy );
2504 octet_count +=
cdAppShort( es, (
short int) ex );
2506 octet_count +=
cdAppShort( es, (
short int) ey );
2508 octet_count +=
cdAppShort( es, (
short int) cl );
2512 if (
cdAddElem( im, esp, octet_count ) )
2532 unsigned char *es, *esp;
2542 es = (
unsigned char *) calloc( 4 * 4,
SIZEOF(
unsigned char ) );
2550 free( esp );
return 0;
2552 es += 2; octet_count = 2;
2555 octet_count +=
cdAppShort( es, (
short int) cx );
2557 octet_count +=
cdAppShort( es, (
short int) cy );
2559 octet_count +=
cdAppShort( es, (
short int) d1x );
2561 octet_count +=
cdAppShort( es, (
short int) d1y );
2563 octet_count +=
cdAppShort( es, (
short int) d2x );
2565 octet_count +=
cdAppShort( es, (
short int) d2y );
2569 if (
cdAddElem( im, esp, octet_count ) )
2595 unsigned char *es, *esp;
2607 es = (
unsigned char *) calloc( 4 * 10,
SIZEOF(
unsigned char ) );
2614 if ( !
cdcomhead( es, 4, 7, ( n * 4 ) ) )
2616 free( esp );
return 0;
2618 es += 2; octet_count = 2;
2620 else if ( n < 8191 )
2634 es = (
unsigned char *) calloc( 4 * ( n + 1 ),
SIZEOF(
unsigned char ) );
2641 free( esp );
return 0;
2643 es += 4; octet_count = 4;
2653 for ( x = 0; x < n; x++ )
2663 if (
cdAddElem( im, esp, octet_count ) )
2691 unsigned char *es, *esp;
2703 es = (
unsigned char *) calloc( 6 * 10,
SIZEOF(
unsigned char ) );
2710 if ( !
cdcomhead( es, 4, 8, ( n * 6 ) ) )
2712 free( esp );
return 0;
2714 es += 2; octet_count = 2;
2716 else if ( n < 5462 )
2730 es = (
unsigned char *) calloc( 6 * ( n + 1 ),
SIZEOF(
unsigned char ) );
2737 free( esp );
return 0;
2739 es += 4; octet_count = 4;
2749 for ( x = 0; x < n; x++ )
2760 if (
cdAddElem( im, esp, octet_count ) )
2784 unsigned char *es, *esp;
2796 es = (
unsigned char *) calloc( 4 * 10,
SIZEOF(
unsigned char ) );
2803 if ( !
cdcomhead( es, 4, 1, ( n * 4 ) ) )
2805 free( esp );
return 0;
2807 es += 2; octet_count = 2;
2809 else if ( n < 8191 )
2819 es = (
unsigned char *) calloc( 4 * ( n + 1 ),
SIZEOF(
unsigned char ) );
2826 free( esp );
return 0;
2828 es += 4; octet_count = 4;
2837 for ( x = 0; x < n; x++ )
2847 if (
cdAddElem( im, esp, octet_count ) )
2871 unsigned char *es, *esp;
2882 es = (
unsigned char *) calloc( 4 * 10,
SIZEOF(
unsigned char ) );
2889 if ( !
cdcomhead( es, 4, 3, ( n * 4 ) ) )
2891 free( esp );
return 0;
2893 es += 2; octet_count = 2;
2895 else if ( n < 8191 )
2905 es = (
unsigned char *) calloc( 4 * ( n + 1 ),
SIZEOF(
unsigned char ) );
2912 free( esp );
return 0;
2914 es += 4; octet_count = 4;
2923 for ( x = 0; x < n; x++ )
2933 if (
cdAddElem( im, esp, octet_count ) )
2962 unsigned char *es, *esp;
2972 tslen = strlen( ts );
2977 if ( ( tslen > 32700 ) || ( tslen < 0 ) )
2980 es = (
unsigned char *) calloc( ( ( 4 * 4 ) + tslen ),
SIZEOF(
unsigned char ) );
2987 free( esp );
return 0;
2989 es += 4; octet_count = 4;
3010 *es++ = (
unsigned char) *ts++;
3012 octet_count += tslen;
3014 curly = 4 - ( octet_count % 4 );
3017 octet_count += curly;
3022 if (
cdAddElem( im, esp, octet_count ) )
3043 ltstate = im->
ltype;
3047 if ( !
cdLine( im, x1, y1, x2, y2 ) )
3066 if ( !
cdLine( im, x1, y1, x2, y2 ) )
3077 return ( !( ( ( y < 0 ) || ( y >= im->
sy ) ) ||
3078 ( ( x < 0 ) || ( x >= im->
sx ) ) ) );
3117 if ( ( specmode < 0 ) || ( specmode > 2 ) )
3128 if ( ( specmode < 0 ) || ( specmode > 2 ) )
3139 if ( ( specmode < 0 ) || ( specmode > 2 ) )
3169 unsigned char *oldfonts;
3174 listsize = strlen( (
char *) oldfonts ) + 1 + strlen( fontname ) + 1;
3178 listsize = strlen( fontname ) + 1;
3180 im->
fontlist = (
unsigned char *) calloc( listsize,
SIZEOF(
unsigned char ) );
3185 sprintf( (
char *) im->
fontlist,
"%s%s%s", (
char *) oldfonts,
",", fontname );
3189 sprintf( (
char *) im->
fontlist,
"%s", fontname );
3214 if ( ( im->
state != 0 ) && ( im->
state != 2 ) )
3260 free( im );
return 0;
3274 tmps =
"'ProfileId: Model-Profile''ProfileEd:1''ColourClass:colour''Source:NIST CGMDraw 1.3''Date: 1996-12-16'";
3275 tmpsl = strlen( tmps );
3278 im->
desc = (
unsigned char *) calloc( tmpsl + 1,
SIZEOF(
unsigned char ) );
3279 strncpy( (
char *) im->
desc, tmps, tmpsl );
3282 tmps =
"TIMES_ROMAN,TIMES_BOLD,TIMES_ITALIC,TIMES_BOLD_ITALIC,HELVETICA,HELVETICA_BOLD,HELVETICA_ITALIC,HELVETICA_BOLD_ITALIC,COURIER,COURIER_BOLD,COURIER_ITALIC,COURIER_BOLD_ITALIC";
3284 tmpsl = strlen( tmps );
3285 im->
fontlist = (
unsigned char *) calloc( tmpsl + 1,
SIZEOF(
unsigned char ) );
3286 strcpy( (
char *) im->
fontlist, tmps );
3303 unsigned char *es, *esp;
3304 int octet_count = 0;
3307 if ( im->
state != 1 )
3312 esp = (
unsigned char *) calloc( 1024,
SIZEOF(
unsigned char ) );
3320 free( esp );
return 0;
3324 if (
cdAddElem( im, esp, octet_count ) )
3343 unsigned char *efile, *efilep;
3346 if ( im->
state == 2 )
3348 efile = (
unsigned char *) calloc( 4 * 4,
SIZEOF(
unsigned char ) );
3373 for ( x = 0; x < used; x++ )