summaryrefslogtreecommitdiff
path: root/cd/src/intcgm
diff options
context:
space:
mode:
Diffstat (limited to 'cd/src/intcgm')
-rwxr-xr-xcd/src/intcgm/bparse.c1660
-rwxr-xr-xcd/src/intcgm/bparse.h117
-rwxr-xr-xcd/src/intcgm/circle.c100
-rwxr-xr-xcd/src/intcgm/circle.h3
-rwxr-xr-xcd/src/intcgm/ellipse.c143
-rwxr-xr-xcd/src/intcgm/ellipse.h3
-rwxr-xr-xcd/src/intcgm/intcgm.h84
-rwxr-xr-xcd/src/intcgm/intcgm1.c291
-rwxr-xr-xcd/src/intcgm/intcgm2.c1651
-rwxr-xr-xcd/src/intcgm/intcgm2.h52
-rwxr-xr-xcd/src/intcgm/intcgm4.c1265
-rwxr-xr-xcd/src/intcgm/intcgm4.h28
-rwxr-xr-xcd/src/intcgm/intcgm6.c253
-rwxr-xr-xcd/src/intcgm/intcgm6.h15
-rwxr-xr-xcd/src/intcgm/list.c117
-rwxr-xr-xcd/src/intcgm/list.h30
-rwxr-xr-xcd/src/intcgm/sism.c392
-rwxr-xr-xcd/src/intcgm/sism.h3
-rwxr-xr-xcd/src/intcgm/tparse.c1370
-rwxr-xr-xcd/src/intcgm/tparse.h101
-rwxr-xr-xcd/src/intcgm/types.h225
21 files changed, 7903 insertions, 0 deletions
diff --git a/cd/src/intcgm/bparse.c b/cd/src/intcgm/bparse.c
new file mode 100755
index 0000000..c0ffada
--- /dev/null
+++ b/cd/src/intcgm/bparse.c
@@ -0,0 +1,1660 @@
+#include <stdio.h> /* FILE, ftell, fseek, fputc, fopen, fclose, fputs, fprintf */
+#include <string.h> /* strlen, strncpy */
+#include <stdlib.h> /* malloc, free */
+#include "cd.h"
+#include "cdcgm.h"
+#include "list.h"
+#include "types.h"
+#include "bparse.h"
+#include "intcgm.h"
+#include "intcgm2.h"
+#include "intcgm4.h"
+#include "intcgm6.h"
+
+/*********************
+* Delimiter elements *
+*********************/
+
+int cgmb_noop ( void )
+{
+ return 0;
+}
+
+int cgmb_begmtf ( void )
+{
+ char *header = NULL;
+
+ if ( intcgm_cgm.len )
+ {
+ if ( cgmb_s ( &header ) ) return 1;
+ }
+
+ if (cdcgmbegmtfcb)
+ {
+ int err;
+ err = cdcgmbegmtfcb ( intcgm_canvas, &intcgm_view_xmin, &intcgm_view_ymin, &intcgm_view_xmax, &intcgm_view_ymax );
+ if ( err==CD_ABORT ) return -1;
+ }
+
+ return 0;
+}
+
+int cgmb_endmtf ( void )
+{
+ return 0;
+}
+
+int cgmb_begpic ( void )
+{
+ char *s = NULL;
+
+ if ( intcgm_cgm.first )
+ intcgm_cgm.first = 0;
+ else
+ cdCanvasFlush(intcgm_canvas);
+
+ if ( intcgm_color_table==NULL )
+ {
+ if ( intcgm_cgm.max_cix < 1 ) intcgm_cgm.max_cix = 1;
+
+ intcgm_color_table = (trgb *) malloc ( sizeof(trgb)*(intcgm_cgm.max_cix+1) );
+
+ intcgm_color_table[0].red = 255;
+ intcgm_color_table[0].green = 255;
+ intcgm_color_table[0].blue = 255;
+ intcgm_color_table[1].red = 0;
+ intcgm_color_table[1].green = 0;
+ intcgm_color_table[1].blue = 0;
+ }
+
+ cdCanvasClip(intcgm_canvas, CD_CLIPAREA);
+
+ if ( cgmb_s ( &s ) ) return 1;
+
+ if (cdcgmbegpictcb)
+ {
+ int err;
+ err = cdcgmbegpictcb ( intcgm_canvas, s );
+ if ( err==CD_ABORT ) return -1;
+ }
+
+ return 0;
+}
+
+int cgmb_begpib ( void )
+{
+ if (cdcgmbegpictbcb)
+ {
+ int err;
+ err = cdcgmbegpictbcb ( intcgm_canvas, 1., 1., intcgm_scale_factor_x, intcgm_scale_factor_y,
+ intcgm_scale_factor_mm_x*intcgm_cgm.scaling_mode.scale_factor,
+ intcgm_scale_factor_mm_y*intcgm_cgm.scaling_mode.scale_factor,
+ intcgm_cgm.drawing_mode,
+ intcgm_vdc_ext.xmin, intcgm_vdc_ext.ymin, intcgm_vdc_ext.xmax, intcgm_vdc_ext.ymax );
+
+ if ( err==CD_ABORT ) return -1;
+ }
+
+ if (cdcgmsizecb)
+ {
+ int err, w, h;
+ double w_mm=0., h_mm=0.;
+
+ w = intcgm_view_xmax-intcgm_view_xmin+1;
+ h = intcgm_view_ymax-intcgm_view_ymin+1;
+
+ if ( intcgm_cgm.vdc_type==INTEGER )
+ {
+ w = (int) (intcgm_cgm.vdc_ext.second.x - intcgm_cgm.vdc_ext.first.x);
+ h = (int) (intcgm_cgm.vdc_ext.second.y - intcgm_cgm.vdc_ext.first.y);
+ if ( intcgm_cgm.scaling_mode.mode==METRIC )
+ {
+ w_mm = w * intcgm_cgm.scaling_mode.scale_factor;
+ h_mm = h * intcgm_cgm.scaling_mode.scale_factor;
+ }
+ }
+ else
+ {
+ if ( intcgm_cgm.scaling_mode.mode==METRIC )
+ {
+ w_mm = (intcgm_cgm.vdc_ext.second.x - intcgm_cgm.vdc_ext.first.x) * intcgm_cgm.scaling_mode.scale_factor;
+ h_mm = (intcgm_cgm.vdc_ext.second.y - intcgm_cgm.vdc_ext.first.y) * intcgm_cgm.scaling_mode.scale_factor;
+ }
+ }
+
+ err = cdcgmsizecb ( intcgm_canvas, w, h, w_mm, h_mm );
+ if ( err==CD_ABORT ) return -1;
+ }
+
+ return 0;
+}
+
+int cgmb_endpic ( void )
+{
+ return 0;
+}
+
+/*******************************
+* Metafile Descriptor Elements *
+*******************************/
+
+int cgmb_mtfver ( void )
+{
+ long version;
+
+ if ( cgmb_i ( &version ) ) return 1;
+
+ return 0;
+}
+
+int cgmb_mtfdsc ( void )
+{
+ char *s = NULL;
+
+ if ( cgmb_s ( &s ) ) return 1;
+
+ return 0;
+}
+
+int cgmb_vdctyp ( void )
+{
+ if ( cgmb_e ( &(intcgm_cgm.vdc_type) ) ) return 1;
+
+ return 0;
+}
+
+int cgmb_intpre ( void )
+{
+ long prec;
+
+ if ( cgmb_i ( &prec ) ) return 1;
+
+ if ( prec==8 ) intcgm_cgm.int_prec.b_prec = 0;
+ else if ( prec==16 ) intcgm_cgm.int_prec.b_prec = 1;
+ else if ( prec==24 ) intcgm_cgm.int_prec.b_prec = 2;
+ else if ( prec==32 ) intcgm_cgm.int_prec.b_prec = 3;
+
+ return 0;
+}
+
+int cgmb_realpr ( void )
+{
+ short mode = 0, i1;
+ long i2, i3;
+
+ if ( cgmb_e ( &i1 ) ) return 1;
+ if ( cgmb_i ( &i2 ) ) return 1;
+ if ( cgmb_i ( &i3 ) ) return 1;
+
+ if ( i1 == 0 && i2 == 9 && i3 == 23 ) mode = 0;
+ else if ( i1 == 0 && i2 == 12 && i3 == 52 ) mode = 1;
+ else if ( i1 == 1 && i2 == 16 && i3 == 16 ) mode = 2;
+ else if ( i1 == 1 && i2 == 32 && i3 == 32 ) mode = 3;
+
+ intcgm_cgm.real_prec.b_prec = mode;
+
+ return 0;
+}
+
+int cgmb_indpre ( void )
+{
+ long prec;
+
+ if ( cgmb_i ( &prec ) ) return 1;
+
+ if ( prec==8 ) intcgm_cgm.ix_prec.b_prec = 0;
+ else if ( prec==16 ) intcgm_cgm.ix_prec.b_prec = 1;
+ else if ( prec==24 ) intcgm_cgm.ix_prec.b_prec = 2;
+ else if ( prec==32 ) intcgm_cgm.ix_prec.b_prec = 3;
+
+ return 0;
+}
+
+int cgmb_colpre ( void )
+{
+ long prec;
+
+ if ( cgmb_i ( &prec ) ) return 1;
+
+ if ( prec==8 ) intcgm_cgm.cd_prec = 0;
+ else if ( prec==16 ) intcgm_cgm.cd_prec = 1;
+ else if ( prec==24 ) intcgm_cgm.cd_prec = 2;
+ else if ( prec==32 ) intcgm_cgm.cd_prec = 3;
+
+ return 0;
+}
+
+int cgmb_colipr ( void )
+{
+ long prec;
+
+ if ( cgmb_i ( &prec ) ) return 1;
+
+ if ( prec==8 ) intcgm_cgm.cix_prec = 0;
+ else if ( prec==16 ) intcgm_cgm.cix_prec = 1;
+ else if ( prec==24 ) intcgm_cgm.cix_prec = 2;
+ else if ( prec==32 ) intcgm_cgm.cix_prec = 3;
+
+ return 0;
+}
+
+int cgmb_maxcoi ( void )
+{
+ if ( cgmb_ci ( (unsigned long *)&(intcgm_cgm.max_cix) ) ) return 1;
+
+ intcgm_color_table = (trgb *) realloc ( intcgm_color_table, sizeof(trgb)*(intcgm_cgm.max_cix+1) );
+
+ intcgm_color_table[0].red = 255;
+ intcgm_color_table[0].green = 255;
+ intcgm_color_table[0].blue = 255;
+ intcgm_color_table[1].red = 0;
+ intcgm_color_table[1].green = 0;
+ intcgm_color_table[1].blue = 0;
+
+ return 0;
+}
+
+int cgmb_covaex ( void )
+{
+ if ( cgmb_rgb ( &(intcgm_cgm.color_ext.black.red), &(intcgm_cgm.color_ext.black.green), &(intcgm_cgm.color_ext.black.blue) ) ) return 1;
+ if ( cgmb_rgb ( &(intcgm_cgm.color_ext.white.red), &(intcgm_cgm.color_ext.white.green), &(intcgm_cgm.color_ext.white.blue) ) ) return 1;
+
+ return 0;
+}
+
+int cgmb_mtfell ( void )
+{
+ long group, element;
+ long n, i;
+
+ if ( cgmb_i ( &n ) ) return 1;
+
+ for ( i=0; i<n; i++ )
+ {
+ if ( cgmb_ix ( &group ) ) return 1;
+ if ( cgmb_ix ( &element ) ) return 1;
+ }
+
+ return 0;
+}
+
+int cgmb_bmtfdf ( void )
+{
+ int c, id, len, cont, totbc;
+ unsigned short b;
+ int count=0;
+ int old_cgmlen;
+ char *buff;
+
+ buff = (char *) malloc ( sizeof(char)*intcgm_cgm.len );
+
+ memcpy ( buff, intcgm_cgm.buff.dados, intcgm_cgm.len );
+
+ old_cgmlen = intcgm_cgm.len;
+
+ totbc = 0;
+
+ while ( count<old_cgmlen )
+ {
+ intcgm_cgm.bc = 0;
+
+ b = ((unsigned char)buff[count] << 8) | (unsigned char)buff[count+1];
+ count += 2;
+
+ intcgm_cgm.bl += 2;
+
+ len = b & 0x001F;
+
+ id = ( b & 0x0FE0 ) >> 5;
+
+ c = ( b & 0xF000 ) >> 12;
+
+ cont = 0;
+
+ if ( len > 30 )
+ {
+ b = ((unsigned char)buff[count] << 8) | (unsigned char)buff[count+1];
+ count += 2;
+
+ intcgm_cgm.bl += 2;
+
+ len = b & 0x7FFF;
+ cont = ( b & 0x8000 );
+ }
+
+ intcgm_cgm.len = len;
+
+ if ( intcgm_cgm.len )
+ {
+ if ( intcgm_cgm.len>intcgm_cgm.buff.size )
+ intcgm_cgm.buff.dados = (char *) realloc ( (char *)intcgm_cgm.buff.dados, sizeof(char) * intcgm_cgm.len );
+
+ memcpy ( intcgm_cgm.buff.dados, &buff[count], intcgm_cgm.len );
+ count += intcgm_cgm.len;
+
+ intcgm_cgm.bl += intcgm_cgm.len;
+
+ if ( len & 1 )
+ {
+ count++;
+ intcgm_cgm.bl += 1;
+ }
+
+ while ( cont )
+ {
+ unsigned short b;
+ int old_len = intcgm_cgm.len;
+
+ intcgm_cgm.bl += 2;
+
+ b = ((unsigned char)buff[count] << 8) | (unsigned char)buff[count+1];
+ count += 2;
+
+ cont = ( b & 0x8000 );
+
+ len = b & 0x7fff;
+
+ intcgm_cgm.len += len;
+
+ if ( intcgm_cgm.len>intcgm_cgm.buff.size )
+ intcgm_cgm.buff.dados = (char *) realloc ( (char *)intcgm_cgm.buff.dados, sizeof(char) * intcgm_cgm.len );
+
+ memcpy ( &intcgm_cgm.buff.dados[old_len], &buff[count], len );
+ count += len;
+
+ if ( len & 1 )
+ {
+ count++;
+
+ intcgm_cgm.bl += 1;
+ }
+ }
+ }
+
+ if ( cgmb_exec_comand ( c, id ) ) return 1;
+ totbc += count;
+ /*count=0;*/
+ }
+
+ return 0;
+}
+
+int cgmb_fntlst ( void )
+{
+ char *fl = NULL;
+
+ if ( intcgm_text_att.font_list==NULL ) intcgm_text_att.font_list = cgm_NewList();
+
+ while ( intcgm_cgm.bc < intcgm_cgm.len )
+ {
+ if ( cgmb_s ( &fl ) ) return 1;
+
+ cgm_AppendList ( intcgm_text_att.font_list, fl );
+ }
+
+ return 0;
+}
+
+int cgmb_chslst ( void )
+{
+ short mode;
+ char *s = NULL;
+
+ while ( intcgm_cgm.bc < intcgm_cgm.len )
+ {
+ if ( cgmb_e ( &mode ) ) return 1;
+ if ( cgmb_s ( &s ) ) return 1;
+ }
+
+ return 0;
+}
+
+int cgmb_chcdac ( void )
+{
+ short mode;
+
+ if ( cgmb_e ( &mode ) ) return 1;
+
+ return 0;
+}
+
+
+/******************************
+* Picture Descriptor Elements *
+******************************/
+
+int cgmb_sclmde ( void )
+{
+ if ( cgmb_e ( &(intcgm_cgm.scaling_mode.mode) ) ) return 1;
+ if ( intcgm_cgm.real_prec.b_prec==1 )
+ {
+ if ( cgmb_getfl64 ( &(intcgm_cgm.scaling_mode.scale_factor) ) ) return 1;
+ }
+ else
+ {
+ float f;
+ if ( cgmb_getfl32 ( (float *) &f ) ) return 1;
+ if ( f<1e-20 ) f = 1;
+ intcgm_cgm.scaling_mode.scale_factor = f;
+ }
+
+ if ( intcgm_cgm.scaling_mode.mode==ABSTRACT ) intcgm_cgm.scaling_mode.scale_factor=1.;
+
+ intcgm_cgm.drawing_mode = ABSTRACT;
+
+ if (cdcgmsclmdecb)
+ {
+ int err;
+ err = cdcgmsclmdecb ( intcgm_canvas, intcgm_cgm.scaling_mode.mode, &intcgm_cgm.drawing_mode, &intcgm_cgm.scaling_mode.scale_factor );
+ if ( err==CD_ABORT ) return -1;
+ }
+
+ if ( intcgm_cgm.drawing_mode==ABSTRACT )
+ {
+ intcgm_clip_xmin = cgm_canvas2vdcx ( intcgm_view_xmin );
+ intcgm_clip_xmax = cgm_canvas2vdcx ( intcgm_view_xmax );
+ intcgm_clip_ymin = cgm_canvas2vdcy ( intcgm_view_ymin );
+ intcgm_clip_ymax = cgm_canvas2vdcy ( intcgm_view_ymax );
+ }
+ else
+ {
+ intcgm_clip_xmin = intcgm_vdc_ext.xmin*intcgm_cgm.scaling_mode.scale_factor;
+ intcgm_clip_xmax = intcgm_vdc_ext.xmax*intcgm_cgm.scaling_mode.scale_factor;
+ intcgm_clip_ymin = intcgm_vdc_ext.ymin*intcgm_cgm.scaling_mode.scale_factor;
+ intcgm_clip_ymax = intcgm_vdc_ext.ymax*intcgm_cgm.scaling_mode.scale_factor;
+ }
+
+ return 0;
+}
+
+int cgmb_clslmd ( void )
+{
+ if ( cgmb_e ( &(intcgm_cgm.clrsm) ) ) return 1;
+
+ return 0;
+}
+
+int cgmb_lnwdmd ( void )
+{
+ if ( cgmb_e ( &(intcgm_cgm.lnwsm) ) ) return 1;
+
+ return 0;
+}
+
+int cgmb_mkszmd ( void )
+{
+ if ( cgmb_e ( &(intcgm_cgm.mkssm) ) ) return 1;
+
+ return 0;
+}
+
+int cgmb_edwdmd ( void )
+{
+ if ( cgmb_e ( &(intcgm_cgm.edwsm) ) ) return 1;
+
+ return 0;
+}
+
+int cgmb_vdcext ( void )
+{
+ if ( cgmb_p ( &(intcgm_cgm.vdc_ext.first.x), &(intcgm_cgm.vdc_ext.first.y) ) ) return 1;
+ if ( cgmb_p ( &(intcgm_cgm.vdc_ext.second.x), &(intcgm_cgm.vdc_ext.second.y) ) ) return 1;
+
+ if (cdcgmvdcextcb)
+ {
+ int err;
+ err = cdcgmvdcextcb( intcgm_canvas, intcgm_cgm.vdc_type, &(intcgm_cgm.vdc_ext.first.x), &(intcgm_cgm.vdc_ext.first.y),
+ &(intcgm_cgm.vdc_ext.second.x), &(intcgm_cgm.vdc_ext.second.y) );
+ if (err==CD_ABORT) return -1;
+ }
+
+ cgm_do_vdcext ( intcgm_cgm.vdc_ext.first, intcgm_cgm.vdc_ext.second );
+
+ return 0;
+}
+
+int cgmb_bckcol ( void )
+{
+ if ( cgmb_rgb ( &(intcgm_cgm.back_color.red), &(intcgm_cgm.back_color.green), &(intcgm_cgm.back_color.blue) ) ) return 1;
+
+ cgm_do_bckcol ( intcgm_cgm.back_color );
+
+ return 0;
+}
+
+/*******************
+* Control Elements *
+*******************/
+
+int cgmb_vdcipr ( void )
+{
+ long prec;
+
+ if ( cgmb_i ( &prec ) ) return 1;
+
+ if ( prec==8 ) intcgm_cgm.vdc_int.b_prec = 0;
+ else if ( prec==16 ) intcgm_cgm.vdc_int.b_prec = 1;
+ else if ( prec==24 ) intcgm_cgm.vdc_int.b_prec = 2;
+ else if ( prec==32 ) intcgm_cgm.vdc_int.b_prec = 3;
+
+ return 0;
+}
+
+int cgmb_vdcrpr ( void )
+{
+ short i1;
+ long mode = 0, i2, i3;
+
+ if ( cgmb_e ( &i1 ) ) return 1;
+ if ( cgmb_i ( &i2 ) ) return 1;
+ if ( cgmb_i ( &i3 ) ) return 1 ;
+
+ if ( i1 == 0 && i2 == 9 && i3 == 23 ) mode = 0;
+ else if ( i1 == 0 && i2 == 12 && i3 == 52 ) mode = 1;
+ else if ( i1 == 1 && i2 == 16 && i3 == 16 ) mode = 2;
+ else if ( i1 == 1 && i2 == 32 && i3 == 32 ) mode = 3;
+
+ intcgm_cgm.vdc_real.b_prec = mode;
+
+ return 0;
+}
+
+int cgmb_auxcol ( void )
+{
+ if ( cgmb_co ( &(intcgm_cgm.aux_color) ) ) return 1;
+
+ return 0;
+}
+
+int cgmb_transp ( void )
+{
+ if ( cgmb_e ( &(intcgm_cgm.transparency) ) ) return 1;
+
+ cgm_do_transp ( intcgm_cgm.transparency );
+
+ return 0;
+}
+
+int cgmb_clprec ( void )
+{
+ if ( cgmb_p ( &(intcgm_cgm.clip_rect.first.x), &(intcgm_cgm.clip_rect.first.y) ) ) return 1;
+ if ( cgmb_p ( &(intcgm_cgm.clip_rect.second.x), &(intcgm_cgm.clip_rect.second.y) ) ) return 1;
+
+ cgm_do_clprec ( intcgm_cgm.clip_rect.first, intcgm_cgm.clip_rect.second );
+
+ return 0;
+}
+
+int cgmb_clpind ( void )
+{
+ if ( cgmb_e ( &(intcgm_cgm.clip_ind) ) ) return 1;
+
+ cgm_do_clpind ( intcgm_cgm.clip_ind );
+
+ return 0;
+}
+
+/*******************************
+* Graphical Primitive Elements *
+*******************************/
+
+static tpoint *_intcgm_point_list ( int *np )
+{
+ *np=0;
+
+ while ( intcgm_cgm.bc < intcgm_cgm.len )
+ {
+ if ( cgmb_p ( &(intcgm_point_list[*np].x), &(intcgm_point_list[*np].y) ) ) return NULL;
+ ++(*np);
+ if ( *np==intcgm_npoints)
+ {
+ intcgm_npoints *= 2;
+ intcgm_point_list = (tpoint *) realloc ( intcgm_point_list, intcgm_npoints*sizeof(tpoint) );
+ }
+ }
+
+ return intcgm_point_list;
+}
+
+int cgmb_polyln ( void )
+{
+ tpoint *pts;
+ int np;
+
+ pts = _intcgm_point_list ( &np );
+ if ( pts==NULL ) return 1;
+
+ cgm_do_polyln ( np, pts );
+
+ return 0;
+}
+
+int cgmb_djtply ( void )
+{
+ tpoint *pts;
+ int np;
+
+ pts = _intcgm_point_list ( &np );
+ if ( pts==NULL ) return 1;
+
+ cgm_do_djtply ( np, pts );
+
+ return 0;
+}
+
+int cgmb_polymk ( void )
+{
+ tpoint *pts;
+ int np;
+
+ pts = _intcgm_point_list ( &np );
+ if ( pts==NULL ) return 1;
+
+ cgm_do_polymk ( np, pts );
+
+ return 0;
+}
+
+int cgmb_text ( void )
+{
+ tpoint pos;
+ char *s = NULL;
+ short t;
+
+ if ( cgmb_p ( &pos.x, &pos.y ) ) return 1;
+ if ( cgmb_e ( &t ) ) return 1;
+ if ( cgmb_s ( &s ) ) return 1;
+
+ cgm_do_text ( NORM_TEXT, s, pos );
+
+ free ( s );
+
+ return 0;
+}
+
+int cgmb_rsttxt ( void )
+{
+ double height, width;
+ tpoint pos;
+ char *s = NULL;
+ short t;
+
+ if ( cgmb_vdc ( &width ) ) return 1;
+ if ( cgmb_vdc ( &height ) ) return 1;
+ if ( cgmb_p ( &pos.x, &pos.y ) ) return 1;
+ if ( cgmb_e ( &t ) ) return 1;
+ if ( cgmb_s ( &s ) ) return 1;
+
+ intcgm_text_att.height = height;
+
+ cgm_do_text ( RESTRICTED_TEXT, s, pos );
+
+ if ( s!= NULL ) free ( s );
+
+ return 0;
+}
+
+int cgmb_apdtxt ( void )
+{
+ char *s = NULL;
+ short t;
+
+ if ( cgmb_e ( &t ) ) return 1;
+ if ( cgmb_s ( &s ) ) return 1;
+
+ if ( s==NULL ) free ( s );
+
+ return 0;
+}
+
+int cgmb_polygn ( void )
+{
+ tpoint *pts;
+ int np;
+ static int porra=0;
+
+ porra++;
+
+ pts = _intcgm_point_list ( &np );
+ if ( pts==NULL ) return 1;
+
+ cgm_do_polygn ( np, pts );
+
+ return 0;
+}
+
+static int _intcgm_vertex_list ( tpoint **pts, short **flags, int *np )
+{
+ int intcgm_block=500;
+
+ *np=0;
+ *pts = (tpoint *) malloc ( intcgm_block*sizeof(tpoint) );
+ *flags = (short *) malloc ( intcgm_block*sizeof(short) );
+
+ while ( intcgm_cgm.bc < intcgm_cgm.len )
+ {
+ if ( cgmb_p ( &((*pts)[*np].x), &((*pts)[*np].y) ) ) return 1;
+ if ( cgmb_e ( &((*flags)[*np]) ) ) return 1;
+
+ ++(*np);
+ if ( *np==intcgm_block)
+ {
+ intcgm_block *= 2;
+ *pts = (tpoint *) realloc ( *pts, intcgm_block*sizeof(tpoint) );
+ *flags = (short *) realloc ( *flags, intcgm_block*sizeof(short) );
+ }
+ }
+
+ return 0;
+}
+
+int cgmb_plgset ( void )
+{
+ tpoint *pts;
+ short *flags;
+ int np;
+
+ if ( _intcgm_vertex_list ( &pts, &flags, &np ) ) return 1;
+
+ cgm_do_plgset( NO, np, pts, flags );
+
+ free ( pts );
+ free ( flags );
+
+ return 0;
+}
+
+int cgmb_cellar ( void )
+{
+ register int i, j, k;
+ long prec;
+ long sx, sy;
+ short mode;
+ int b;
+ unsigned char dummy;
+ tpoint corner1, corner2, corner3;
+ tcolor *cell;
+
+ if ( cgmb_p ( &(corner1.x), &(corner1.y) ) ) return 1;
+ if ( cgmb_p ( &(corner2.x), &(corner2.y) ) ) return 1;
+ if ( cgmb_p ( &(corner3.x), &(corner3.y) ) ) return 1;
+
+ if ( cgmb_i ( &sx ) ) return 1;
+ if ( cgmb_i ( &sy ) ) return 1;
+
+ if ( cgmb_i ( &prec ) ) return 1;
+
+ if ( cgmb_e ( &mode ) ) return 1;
+
+ cell = (tcolor *) malloc ( sx*sy*sizeof(tcolor) );
+
+ if ( mode )
+ for ( k=0; k<sy; k++ )
+ {
+ b=intcgm_cgm.bc;
+ intcgm_cgm.pc=0;
+ for ( i=0; i<sx; i++ )
+ {
+ if ( cgmb_getpixel ( &(cell[k*sx+i]), prec ) ) return 1;
+ }
+ if ( k<(sy-1) && (intcgm_cgm.bc-b)%2 ) cgmb_getc ( &dummy );
+ cgm_getfilepos();
+ }
+ else
+ for ( k=0; k<sy; k++ )
+ {
+ b=intcgm_cgm.bc;
+ intcgm_cgm.pc=0;
+ for ( i=0; i<sx; )
+ {
+ long l;
+ tcolor cor;
+ if ( cgmb_i ( &l ) ) return 1;
+ if ( cgmb_getpixel ( &cor, prec ) ) return 1;
+ for ( j=0; j<l; j++ )
+ {
+ cell[k*sx+i] = cor;
+ i++;
+ }
+ }
+ if ( k<(sy-1) && (intcgm_cgm.bc-b)%2 ) cgmb_getc ( &dummy );
+ cgm_getfilepos();
+ }
+
+ if ( intcgm_cgm.clrsm == 0 ) /* indexed */
+ {
+ for ( i=0; i<sx*sy; i++ )
+ {
+ int ind = cell[i].ind;
+ cell[i].rgb.red = intcgm_color_table[ind].red;
+ cell[i].rgb.green = intcgm_color_table[ind].green;
+ cell[i].rgb.blue = intcgm_color_table[ind].blue;
+ }
+ }
+
+ cgm_do_cellar ( corner1, corner2, corner3, sx, sy, prec, cell );
+
+ free ( cell );
+
+ return 0;
+}
+
+static long sample_type, n_samples;
+
+static int BuildString ( char *sin, char **sout, int *slen, int *intcgm_block )
+{
+ *slen = strlen ( sin ) + strlen(*sout) + 1 + 1; /* + espaco em branco no final +\0 */
+ if (*slen > *intcgm_block)
+ {
+ *intcgm_block *= 2;
+ *sout = (char *) realloc(*sout,sizeof(char)*(*intcgm_block));
+ if ( *sout==NULL ) return 1;
+ }
+
+ strcat(*sout,sin);
+ strcat(*sout," ");
+
+ return 0;
+}
+
+int intcgm_generalized_drawing_primitive_4 ( void )
+{
+ long j, i;
+ tpoint pt[4];
+ unsigned char c;
+ double r;
+ char *s=NULL, tmp[80];
+ int intcgm_block = 500, slen = 0;
+ int id = -4;
+
+ s = (char *) malloc ( intcgm_block*sizeof(char) );
+
+ strcpy ( s, "" );
+
+ for ( j=0; j<4; j++ )
+ {
+ if ( cgmb_p ( &(pt[j].x), &(pt[j].y) ) ) return 1;
+ }
+
+ if ( cgmb_getc(&c) ) return 1;
+ if ( cgmb_getc(&c) ) return 1;
+
+ for ( j=0; j<6; j++ )
+ {
+ if ( cgmb_r(&r) ) return 1;
+ sprintf(tmp,"%g",r);
+ if ( BuildString ( tmp, &s, &slen, &intcgm_block ) ) return 1;
+ }
+
+ if ( cgmb_i(&i) ) return 1;
+ sprintf(tmp,"%ld",i);
+ if ( BuildString ( tmp, &s, &slen, &intcgm_block ) ) return 1;
+
+ if ( cgmb_i(&sample_type) ) return 1;
+ sprintf(tmp,"%ld",sample_type);
+ if ( BuildString ( tmp, &s, &slen, &intcgm_block ) ) return 1;
+
+ if ( cgmb_i(&n_samples) ) return 1;
+ sprintf(tmp,"%ld",n_samples);
+ if ( BuildString ( tmp, &s, &slen, &intcgm_block ) ) return 1;
+
+ for ( j=0; j<2; j++ )
+ {
+ if ( cgmb_r(&r) ) return 1;
+ sprintf(tmp,"%g",r);
+ if ( BuildString ( tmp, &s, &slen, &intcgm_block ) ) return 1;
+ }
+
+ for ( j=0; j<4; j++ )
+ {
+ if ( cgmb_i(&i) ) return 1;
+ sprintf(tmp,"%ld",i);
+ if ( BuildString ( tmp, &s, &slen, &intcgm_block ) ) return 1;
+ }
+
+ cgm_do_gdp ( id, pt, s );
+
+ free(s);
+
+ return 0;
+}
+
+typedef int (*_getdata) (void *);
+
+int intcgm_generalized_drawing_primitive_5 ( void )
+{
+ int (*getdata) (void *);
+ void *data;
+ char format[10];
+ int i;
+ char *s, tmp[80];
+ int intcgm_block = 500, slen = 0;
+ long id=-5;
+
+ s = (char *) malloc ( sizeof(char)*intcgm_block );
+
+ strcpy ( s, "" );
+
+ switch ( sample_type )
+ {
+ case 0:
+ getdata = (_getdata) cgmb_geti16;
+ data = (short *) malloc ( sizeof(short) );
+ if ( data==NULL ) return 1;
+ strcpy ( format, "%d\0" );
+ break;
+ case 1:
+ getdata = (_getdata) cgmb_geti32;
+ data = (long *) malloc ( sizeof(long) );
+ if ( data==NULL ) return 1;
+ strcpy ( format, "%d\0" );
+ break;
+ case 2:
+ getdata = (_getdata) cgmb_getfl32;
+ data = (float *) malloc ( sizeof(float) );
+ if ( data==NULL ) return 1;
+ strcpy ( format, "%g\0" );
+ break;
+ case 3:
+ getdata = (_getdata) cgmb_geti8;
+ data = (signed char *) malloc ( sizeof(signed char) );
+ if ( data==NULL ) return 1;
+ strcpy ( format, "%d\0" );
+ break;
+ case 4:
+ getdata = (_getdata) cgmb_geti16;
+ data = (short *) malloc ( sizeof(short) );
+ if ( data==NULL ) return 1;
+ strcpy ( format, "%d\0" );
+ break;
+ case 5:
+ getdata = (_getdata) cgmb_geti8;
+ data = (signed char *) malloc ( sizeof(signed char) );
+ if ( data==NULL ) return 1;
+ strcpy ( format, "%d\0" );
+ break;
+ }
+
+ for ( i=0; i<n_samples; i++ )
+ {
+
+ getdata(data);
+
+ if (sample_type==0)
+ sprintf(tmp,format,*(short *)data);
+ else if (sample_type==1)
+ sprintf(tmp,format,*(long *)data);
+ else if (sample_type==2)
+ sprintf(tmp,format,*(float *)data);
+ else if (sample_type==3)
+ sprintf(tmp,format,*(signed char *)data);
+ else if (sample_type==4)
+ sprintf(tmp,format,*(short *)data);
+ else if (sample_type==5)
+ sprintf(tmp,format,*(signed char *)data);
+
+ if ( BuildString ( tmp, &s, &slen, &intcgm_block ) ) return 1;
+
+ if (sample_type==4 || sample_type==5)
+ {
+ unsigned long ci;
+ char endstr='\0';
+
+ if ( cgmb_ci ( &ci ) ) return 1;
+ sprintf(tmp,"%ld%c",ci,endstr);
+ if ( BuildString ( tmp, &s, &slen, &intcgm_block ) ) return 1;
+ }
+ }
+
+ if ( intcgm_cgm.bc < intcgm_cgm.len )
+ {
+ int i;
+ unsigned char c;
+
+ for ( i=0; i<intcgm_cgm.len-intcgm_cgm.bc; i++ )
+ {
+ if ( cgmb_getc(&c) ) return 1;
+ if ( cgmb_getc(&c) ) return 1;
+ }
+ }
+
+ cgm_do_gdp ( id, NULL, s );
+
+ free(s);
+
+ return 0;
+}
+
+int cgmb_gdp ( void )
+{
+ long id, n, i;
+ double x, y;
+ char *s = NULL;
+
+ cgmb_i ( &id );
+
+ if ( id==-4 )
+ {
+ if ( intcgm_generalized_drawing_primitive_4 ( ) ) return 1;
+ }
+ else if ( id==-5 )
+ {
+ if ( intcgm_generalized_drawing_primitive_5 ( ) ) return 1;
+ }
+ else
+ {
+ if ( cgmb_i ( &n ) ) return 1;
+ for ( i=0; i<n; i++ )
+ {
+ if ( cgmb_p ( &x, &y ) ) return 1;
+ }
+ if ( cgmb_s ( &s ) ) return 1;
+ }
+
+ return 0;
+}
+
+int cgmb_rect ( void )
+{
+ tpoint point1;
+ tpoint point2;
+
+ if ( cgmb_p ( &(point1.x), &(point1.y) ) ) return 1;
+ if ( cgmb_p ( &(point2.x), &(point2.y) ) ) return 1;
+
+ cgm_do_rect ( point1, point2 );
+
+ return 0;
+}
+
+int cgmb_circle ( void )
+{
+ tpoint center;
+ double radius;
+
+ if ( cgmb_p ( &(center.x), &(center.y) ) ) return 1;
+
+ if ( cgmb_vdc ( &radius ) ) return 1;
+
+ cgm_do_circle ( center, radius );
+
+ return 0;
+}
+
+int cgmb_circ3p ( void )
+{
+ tpoint starting;
+ tpoint intermediate;
+ tpoint ending;
+
+ if ( cgmb_p ( &(starting.x), &(starting.y) ) ) return 1;
+ if ( cgmb_p ( &(intermediate.x), &(intermediate.y) ) ) return 1;
+ if ( cgmb_p ( &(ending.x), &(ending.y) ) ) return 1;
+
+ cgm_do_circ3p ( starting, intermediate, ending );
+
+ return 0;
+}
+
+int cgmb_cir3pc ( void )
+{
+ tpoint starting;
+ tpoint intermediate;
+ tpoint ending;
+ short close_type;
+
+ if ( cgmb_p ( &(starting.x), &(starting.y) ) ) return 1;
+ if ( cgmb_p ( &(intermediate.x), &(intermediate.y) ) ) return 1;
+ if ( cgmb_p ( &(ending.x), &(ending.y) ) ) return 1;
+
+ if ( cgmb_e ( &close_type ) ) return 1;
+
+ cgm_do_circ3pc ( starting, intermediate, ending, close_type );
+
+ return 0;
+}
+
+int cgmb_circnt ( void )
+{
+ tpoint center;
+ tpoint start;
+ tpoint end;
+ double radius;
+
+ if ( cgmb_p ( &(center.x), &(center.y) ) ) return 1;
+
+ if ( cgmb_vdc ( &(start.x) ) ) return 1;
+ if ( cgmb_vdc ( &(start.y) ) ) return 1;
+
+ if ( cgmb_vdc ( &(end.x) ) ) return 1;
+ if ( cgmb_vdc ( &(end.y) ) ) return 1;
+
+ if ( cgmb_vdc ( &radius ) ) return 1;
+
+ cgm_do_circcnt ( center, start, end, radius );
+
+ return 0;
+}
+
+int cgmb_ccntcl ( void )
+{
+ tpoint center;
+ tpoint start;
+ tpoint end;
+ double radius;
+ short close_type;
+
+ if ( cgmb_p ( &(center.x), &(center.y) ) ) return 1;
+
+ if ( cgmb_vdc ( &(start.x) ) ) return 1;
+ if ( cgmb_vdc ( &(start.y) ) ) return 1;
+
+ if ( cgmb_vdc ( &(end.x) ) ) return 1;
+ if ( cgmb_vdc ( &(end.y) ) ) return 1;
+
+ if ( cgmb_vdc ( &radius ) ) return 1;
+
+ if ( cgmb_e ( &close_type ) ) return 1;
+
+ cgm_do_ccntcl ( center, start, end, radius, close_type );
+
+ return 0;
+}
+
+int cgmb_ellips ( void )
+{
+ tpoint center;
+ tpoint first_CDP;
+ tpoint second_CDP;
+
+ if ( cgmb_p ( &(center.x), &(center.y) ) ) return 1;
+
+ if ( cgmb_p ( &(first_CDP.x), &(first_CDP.y) ) ) return 1;
+ if ( cgmb_p ( &(second_CDP.x), &(second_CDP.y) ) ) return 1;
+
+ cgm_do_ellips ( center, first_CDP, second_CDP );
+
+ return 0;
+}
+
+int cgmb_ellarc ( void )
+{
+ tpoint center;
+ tpoint first_CDP;
+ tpoint second_CDP;
+ tpoint start, end;
+
+ if ( cgmb_p ( &(center.x), &(center.y) ) ) return 1;
+
+ if ( cgmb_p ( &(first_CDP.x), &(first_CDP.y) ) ) return 1;
+ if ( cgmb_p ( &(second_CDP.x), &(second_CDP.y) ) ) return 1;
+
+ if ( cgmb_vdc ( &(start.x) ) ) return 1;
+ if ( cgmb_vdc ( &(start.y) ) ) return 1;
+
+ if ( cgmb_vdc ( &(end.x) ) ) return 1;
+ if ( cgmb_vdc ( &(end.y) ) ) return 1;
+
+ cgm_do_ellarc ( center, first_CDP, second_CDP, start, end );
+
+ return 0;
+}
+
+int cgmb_ellacl ( void )
+{
+
+ tpoint center;
+ tpoint first_CDP;
+ tpoint second_CDP;
+ tpoint start, end;
+ short close_type;
+
+ if ( cgmb_p ( &(center.x), &(center.y) ) ) return 1;
+
+ if ( cgmb_p ( &(first_CDP.x), &(first_CDP.y) ) ) return 1;
+ if ( cgmb_p ( &(second_CDP.x), &(second_CDP.y) ) ) return 1;
+
+ if ( cgmb_vdc ( &(start.x) ) ) return 1;
+ if ( cgmb_vdc ( &(start.y) ) ) return 1;
+
+ if ( cgmb_vdc ( &(end.x) ) ) return 1;
+ if ( cgmb_vdc ( &(end.y) ) ) return 1;
+
+ if ( cgmb_e ( &close_type ) ) return 1;
+
+ cgm_do_ellacl ( center, first_CDP, second_CDP, start, end, close_type );
+
+ return 0;
+}
+
+/*********************
+* Attribute Elements *
+*********************/
+
+int cgmb_lnbdin( void )
+{
+ if ( cgmb_ix ( &(intcgm_line_att.index) ) ) return 1;
+
+ return 0;
+}
+
+int cgmb_lntype ( void )
+{
+ if ( cgmb_ix ( &(intcgm_line_att.type) ) ) return 1;
+
+ return 0;
+}
+
+int cgmb_lnwidt ( void )
+{
+ if ( intcgm_cgm.lnwsm==0 )
+ {
+ if ( cgmb_vdc ( &(intcgm_line_att.width) ) ) return 1;
+ }
+ else
+ {
+ if ( cgmb_r ( &(intcgm_line_att.width) ) ) return 1;
+ }
+
+ return 0;
+}
+
+int cgmb_lncolr( void )
+{
+ if ( cgmb_co ( &(intcgm_line_att.color) ) ) return 1;
+
+ return 0;
+}
+
+int cgmb_mkbdin( void )
+{
+ if ( cgmb_ix ( &(intcgm_marker_att.index) ) ) return 1;
+
+ return 0;
+}
+
+int cgmb_mktype( void )
+{
+ if ( cgmb_ix ( &(intcgm_marker_att.type) ) ) return 1;
+
+ return 0;
+}
+
+int cgmb_mksize( void )
+{
+ if ( intcgm_cgm.mkssm == 0 )
+ {
+ if ( cgmb_vdc ( &(intcgm_marker_att.size) ) ) return 1;
+ }
+ else
+ {
+ if ( cgmb_r ( &(intcgm_marker_att.size) ) ) return 1;
+ }
+
+ return 0;
+}
+
+int cgmb_mkcolr( void )
+{
+ if ( cgmb_co ( &(intcgm_marker_att.color) ) ) return 1;
+
+ return 0;
+}
+
+int cgmb_txbdin( void )
+{
+ if ( cgmb_ix ( &(intcgm_text_att.index) ) ) return 1;
+
+ return 0;
+}
+
+int cgmb_txftin ( void )
+{
+ char *font;
+ char *font_array[] = {"SYSTEM", "COURIER", "TIMES", "HELVETICA", NULL};
+ char *style_array[] = {"BOLDITALIC", "ITALIC", "BOLD", "PLAIN", NULL};
+ int cdstyle[] = {CD_BOLD_ITALIC, CD_ITALIC, CD_BOLD, CD_PLAIN};
+ int i;
+
+ if ( cgmb_ix ( &(intcgm_text_att.font_index) ) ) return 1;
+
+ font = (char *) cgm_GetList ( intcgm_text_att.font_list, intcgm_text_att.font_index );
+
+ if ( font==NULL ) font = "SYSTEM";
+
+ intcgm_text_att.font = 0;
+ for ( i=0; font_array[i]!=NULL; i++ )
+ {
+ if ( strstr( font, font_array[i] ) )
+ {
+ intcgm_text_att.font = i;
+ break;
+ }
+ }
+
+ intcgm_text_att.style = 0;
+ for ( i=0; style_array[i]!=NULL; i++ )
+ {
+ if ( strstr( font, style_array[i] ) )
+ {
+ intcgm_text_att.style = cdstyle[i];
+ break;
+ }
+ }
+
+ cgm_setfont ( intcgm_text_att.font, intcgm_text_att.style, intcgm_text_att.height );
+
+ return 0;
+}
+
+int cgmb_txtprc( void )
+{
+ if ( cgmb_e ( &(intcgm_text_att.prec) ) ) return 1;
+
+ return 0;
+}
+
+int cgmb_chrexp ( void )
+{
+ if ( cgmb_r ( &(intcgm_text_att.exp_fact) ) ) return 1;
+
+ return 0;
+}
+
+int cgmb_chrspc ( void )
+{
+ if ( cgmb_r ( &(intcgm_text_att.char_spacing) ) ) return 1;
+
+ return 0;
+}
+
+int cgmb_txtclr( void )
+{
+ if ( cgmb_co ( &(intcgm_text_att.color) ) ) return 1;
+
+ return 0;
+}
+
+int cgmb_chrhgt ( void )
+{
+ if ( cgmb_vdc ( &(intcgm_text_att.height) ) ) return 1;
+
+ cgm_do_text_height ( intcgm_text_att.height );
+
+ return 0;
+}
+
+int cgmb_chrori ( void )
+{
+ if ( cgmb_vdc ( &(intcgm_text_att.char_up.x) ) ) return 1;
+ if ( cgmb_vdc ( &(intcgm_text_att.char_up.y) ) ) return 1;
+ if ( cgmb_vdc ( &(intcgm_text_att.char_base.x) ) ) return 1;
+ if ( cgmb_vdc ( &(intcgm_text_att.char_base.y) ) ) return 1;
+
+ return 0;
+}
+
+int cgmb_txtpat ( void )
+{
+ if ( cgmb_e ( &(intcgm_text_att.path) ) ) return 1;
+
+ return 0;
+}
+
+int cgmb_txtali ( void )
+{
+ if ( cgmb_e ( &(intcgm_text_att.alignment.hor) ) ) return 1;
+ if ( cgmb_e ( &(intcgm_text_att.alignment.ver) ) ) return 1;
+
+ if ( cgmb_r ( &(intcgm_text_att.alignment.cont_hor) ) ) return 1;
+ if ( cgmb_r ( &(intcgm_text_att.alignment.cont_ver) ) ) return 1;
+
+ cgm_do_txtalign ( intcgm_text_att.alignment.hor, intcgm_text_att.alignment.ver );
+
+ return 0;
+}
+
+int cgmb_chseti( void )
+{
+ long set;
+
+ if ( cgmb_ix ( &set ) ) return 1;
+
+ return 0;
+}
+
+int cgmb_achsti( void )
+{
+ long set;
+
+ if ( cgmb_i ( &set ) ) return 1;
+
+ return 0;
+}
+
+int cgmb_fillin( void )
+{
+ if ( cgmb_ix ( &(intcgm_fill_att.index) ) ) return 1;
+
+ return 0;
+}
+
+int cgmb_intsty( void )
+{
+ if ( cgmb_e ( &(intcgm_fill_att.int_style) ) ) return 1;
+
+ return 0;
+}
+
+int cgmb_fillco( void )
+{
+ if ( cgmb_co ( &(intcgm_fill_att.color) ) ) return 1;
+
+ return 0;
+}
+
+int cgmb_hatind( void )
+{
+ if ( cgmb_ix ( &(intcgm_fill_att.hatch_index) ) ) return 1;
+ if ( intcgm_fill_att.hatch_index==3 ) intcgm_fill_att.hatch_index = 4;
+ else if ( intcgm_fill_att.hatch_index==4 ) intcgm_fill_att.hatch_index = 3;
+
+ return 0;
+}
+
+int cgmb_patind( void )
+{
+ if ( cgmb_ix ( &(intcgm_fill_att.pat_index) ) ) return 1;
+
+ return 0;
+}
+
+int cgmb_edgind( void )
+{
+ if ( cgmb_ix ( &(intcgm_edge_att.index) ) ) return 1;
+
+ return 0;
+}
+
+int cgmb_edgtyp( void )
+{
+ if ( cgmb_ix ( &(intcgm_edge_att.type) ) ) return 1;
+
+ return 0;
+}
+
+int cgmb_edgwid ( void )
+{
+ if ( intcgm_cgm.edwsm==0 )
+ {
+ if ( cgmb_vdc ( &(intcgm_edge_att.width) ) ) return 1;
+ }
+ else
+ {
+ if ( cgmb_r ( &(intcgm_edge_att.width) ) ) return 1;
+ }
+
+ return 0;
+}
+
+int cgmb_edgcol ( void )
+{
+ if ( cgmb_co ( &(intcgm_edge_att.color) ) ) return 1;
+
+ return 0;
+}
+
+
+int cgmb_edgvis ( void )
+{
+ if ( cgmb_e ( &(intcgm_edge_att.visibility) ) ) return 1;
+
+ return 0;
+}
+
+int cgmb_fillrf ( void )
+{
+ if ( cgmb_p ( &(intcgm_fill_att.ref_pt.x), &(intcgm_fill_att.ref_pt.y) ) ) return 1;
+
+ return 0;
+}
+
+int cgmb_pattab ( void )
+{
+ long localp;
+ int i;
+ pat_table *pat;
+
+ pat = (pat_table *) malloc ( sizeof(pat_table) );
+
+ if ( intcgm_fill_att.pat_list==NULL ) intcgm_fill_att.pat_list = cgm_NewList();
+
+ if ( cgmb_i ( &(pat->index) ) ) return 1;
+
+ if ( cgmb_i ( &(pat->nx) ) ) return 1;
+ if ( cgmb_i ( &(pat->ny) ) ) return 1;
+
+ if ( cgmb_i ( &(localp) ) ) return 1;
+
+ pat->pattern = (tcolor *) malloc ( pat->nx*pat->ny*sizeof(tcolor) );
+
+ for ( i=0; i<(pat->nx*pat->ny); i++ )
+ {
+ if ( cgmb_getpixel ( &(pat->pattern[i]), localp ) ) return 1;
+ }
+
+ cgm_AppendList ( intcgm_fill_att.pat_list, pat );
+
+ return 0;
+}
+
+int cgmb_patsiz ( void )
+{
+ if ( cgmb_vdc ( &(intcgm_fill_att.pat_size.height.x) ) ) return 1;
+ if ( cgmb_vdc ( &(intcgm_fill_att.pat_size.height.y) ) ) return 1;
+ if ( cgmb_vdc ( &(intcgm_fill_att.pat_size.width.x) ) ) return 1;
+ if ( cgmb_vdc ( &(intcgm_fill_att.pat_size.width.y) ) ) return 1;
+
+ return 0;
+}
+
+int cgmb_coltab ( void )
+{
+ unsigned long starting_index, i;
+ int p[] = {8, 16, 24, 32};
+ int n = (intcgm_cgm.len-intcgm_cgm.cix_prec)/(3*(p[intcgm_cgm.cd_prec]/8));
+
+ if ( cgmb_ci ( &(starting_index) ) ) return 1;
+
+ for ( i=starting_index; i<starting_index+n; i++ )
+ {
+ if ( cgmb_rgb ( &(intcgm_color_table[i].red), &(intcgm_color_table[i].green), &(intcgm_color_table[i].blue) ) ) return 1;
+ }
+
+ if ( intcgm_cgm.bc==(intcgm_cgm.len-1) ) intcgm_cgm.bc++;
+
+ return 0;
+}
+
+int cgmb_asf ( void )
+{
+ tasf *pair;
+
+ if ( intcgm_asf_list==NULL ) intcgm_asf_list = cgm_NewList();
+
+ while( intcgm_cgm.bc < intcgm_cgm.len )
+ {
+ pair = (tasf *) malloc ( sizeof (tasf) );
+
+ if ( cgmb_e ( &(pair->type) ) ) return 1;
+ if ( cgmb_e ( &(pair->value) ) ) return 1;
+
+ cgm_AppendList ( intcgm_asf_list, pair );
+ }
+
+ return 0;
+}
+
+/*****************
+* Escape Element *
+*****************/
+
+/********************
+* External elements *
+********************/
+
+int cgmb_escape ( void ) /* escape */
+{
+#if 1
+
+ {
+ int i;
+ unsigned char c;
+ for ( i=0; i<intcgm_cgm.len; i++ ) cgmb_getc(&c);
+ }
+
+#else
+
+ {
+ long identifier;
+ char *data_rec;
+
+ if ( cgmb_i ( &(identifier) ) ) return 1;
+
+ if ( cgmb_s ( &data_rec ) ) return 1;
+
+ free(data_rec);
+ }
+
+#endif
+
+ return 0;
+}
+
+int cgmb_messag ( void )
+{
+ char *text;
+ short flag;
+
+ if ( cgmb_e ( &flag ) ) return 1;
+
+ if ( cgmb_s ( &text ) ) return 1;
+
+ free(text);
+
+ return 0;
+}
+
+int cgmb_appdta ( void )
+{
+ long identifier;
+ char *data_rec;
+
+ if ( cgmb_i ( &identifier ) ) return 1;
+
+ if ( cgmb_s ( &data_rec ) ) return 1;
+
+ free(data_rec);
+
+ return 0;
+}
diff --git a/cd/src/intcgm/bparse.h b/cd/src/intcgm/bparse.h
new file mode 100755
index 0000000..1b86fee
--- /dev/null
+++ b/cd/src/intcgm/bparse.h
@@ -0,0 +1,117 @@
+#ifndef _BPARSE_H_
+#define _BPARSE_H_
+
+typedef int(*_cdcgmsizecb)(cdCanvas* canvas, int w, int h, double w_mm, double h_mm);
+typedef int(*_cdcgmbegmtfcb)(cdCanvas* canvas, int *xmin, int *ymin, int *xmax, int *ymax);
+typedef int(*_cdcgmcountercb)(cdCanvas* canvas, double size);
+typedef int(*_cdcgmsclmdecb)(cdCanvas* canvas, short scl_mde, short *drw_mode, double *factor);
+typedef int(*_cdcgmvdcextcb)(cdCanvas* canvas, short type, double *xmn, double *ymn, double *xmx, double *ymx);
+typedef int(*_cdcgmbegpictcb)(cdCanvas* canvas , char *pict );
+typedef int(*_cdcgmbegpictbcb)(cdCanvas* canvas, double scale_x, double scale_y,
+ double vdc_x2pix, double vdc_y2pix,
+ double vdc_x2mm, double vdc_y2mm, int drw_mode,
+ double xmin, double ymin, double xmax, double ymax);
+
+extern _cdcgmsizecb cdcgmsizecb;
+extern _cdcgmbegmtfcb cdcgmbegmtfcb;
+extern _cdcgmcountercb cdcgmcountercb;
+extern _cdcgmsclmdecb cdcgmsclmdecb;
+extern _cdcgmvdcextcb cdcgmvdcextcb;
+extern _cdcgmbegpictcb cdcgmbegpictcb;
+extern _cdcgmbegpictbcb cdcgmbegpictbcb;
+
+int cgmb_noop ( void );
+int cgmb_begmtf ( void );
+int cgmb_endmtf ( void );
+int cgmb_begpic ( void );
+int cgmb_begpib ( void );
+int cgmb_endpic ( void );
+int cgmb_mtfver ( void );
+int cgmb_mtfdsc ( void );
+int cgmb_vdctyp ( void );
+int cgmb_intpre ( void );
+int cgmb_realpr ( void );
+int cgmb_indpre ( void );
+int cgmb_colpre ( void );
+int cgmb_colipr ( void );
+int cgmb_maxcoi ( void );
+int cgmb_covaex ( void );
+int cgmb_mtfell ( void );
+int cgmb_bmtfdf ( void );
+int cgmb_fntlst ( void );
+int cgmb_chslst ( void );
+int cgmb_chcdac ( void );
+int cgmb_sclmde ( void );
+int cgmb_clslmd ( void );
+int cgmb_lnwdmd ( void );
+int cgmb_mkszmd ( void );
+int cgmb_edwdmd ( void );
+int cgmb_vdcext ( void );
+int cgmb_bckcol ( void );
+int cgmb_vdcipr ( void );
+int cgmb_vdcrpr ( void );
+int cgmb_auxcol ( void );
+int cgmb_transp ( void );
+int cgmb_clprec ( void );
+int cgmb_clpind ( void );
+int cgmb_polyln ( void );
+int cgmb_djtply ( void );
+int cgmb_polymk ( void );
+int cgmb_text ( void );
+int cgmb_rsttxt ( void );
+int cgmb_apdtxt ( void );
+int cgmb_polygn ( void );
+int cgmb_plgset ( void );
+int cgmb_cellar ( void );
+int cgm_generalized_drawing_primitive_4 ( void );
+int cgm_generalized_drawing_primitive_5 ( void );
+int cgmb_gdp ( void );
+int cgmb_rect ( void );
+int cgmb_circle ( void );
+int cgmb_circ3p ( void );
+int cgmb_cir3pc ( void );
+int cgmb_circnt ( void );
+int cgmb_ccntcl ( void );
+int cgmb_ellips ( void );
+int cgmb_ellarc ( void );
+int cgmb_ellacl ( void );
+int cgmb_lnbdin ( void );
+int cgmb_lntype ( void );
+int cgmb_lnwidt ( void );
+int cgmb_lncolr ( void );
+int cgmb_mkbdin ( void );
+int cgmb_mktype ( void );
+int cgmb_mksize ( void );
+int cgmb_mkcolr ( void );
+int cgmb_txbdin ( void );
+int cgmb_txftin ( void );
+int cgmb_txtprc ( void );
+int cgmb_chrexp ( void );
+int cgmb_chrspc ( void );
+int cgmb_txtclr ( void );
+int cgmb_chrhgt ( void );
+int cgmb_chrori ( void );
+int cgmb_txtpat ( void );
+int cgmb_txtali ( void );
+int cgmb_chseti ( void );
+int cgmb_achsti ( void );
+int cgmb_fillin ( void );
+int cgmb_intsty ( void );
+int cgmb_fillco ( void );
+int cgmb_hatind ( void );
+int cgmb_patind ( void );
+int cgmb_edgind ( void );
+int cgmb_edgtyp ( void );
+int cgmb_edgwid ( void );
+int cgmb_edgcol ( void );
+int cgmb_edgvis ( void );
+int cgmb_fillrf ( void );
+int cgmb_pattab ( void );
+int cgmb_messag ( void );
+int cgmb_appdta ( void );
+int cgmb_patsiz ( void );
+int cgmb_coltab ( void );
+int cgmb_asf ( void );
+int cgmb_escape ( void );
+
+#endif
diff --git a/cd/src/intcgm/circle.c b/cd/src/intcgm/circle.c
new file mode 100755
index 0000000..4f54fed
--- /dev/null
+++ b/cd/src/intcgm/circle.c
@@ -0,0 +1,100 @@
+#include <stdio.h>
+#include <math.h>
+
+#include <cd.h>
+
+#include "list.h"
+#include "types.h"
+#include "intcgm.h"
+#include "intcgm6.h"
+
+#include "circle.h"
+
+#define DIM 360
+
+#ifndef PI
+#define PI 3.14159265358979323846
+#endif
+
+#define PI180 PI/180.
+#define TWOPI 2*PI
+#define VARCS TWOPI/32.
+
+int cgm_poly_circle ( double xc, double yc, double radius, double angi, double angf, int fechado )
+{
+ double coseno, seno;
+ double xs, ys;
+
+ coseno = cos (VARCS);
+ seno = sin (VARCS);
+
+ xs = radius * cos(angi);
+ ys = radius * sin(angi);
+
+ cdCanvasBegin(intcgm_canvas, cgm_setintstyle(intcgm_fill_att.int_style) );
+
+ if ( fechado==CLOSED_PIE ) cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(xc), cgm_vdcy2canvas(yc) );
+
+ cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(xc+xs), cgm_vdcy2canvas(yc+ys) );
+
+ while ( (angi+VARCS) < angf )
+ {
+ double xe = xs;
+ xs = xs * coseno - ys * seno;
+ ys = ys * coseno + xe * seno;
+ cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(xc+xs), cgm_vdcy2canvas(yc+ys) );
+ angi += VARCS;
+ }
+
+ cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(xc+radius*cos(angf)), cgm_vdcy2canvas(yc+radius*sin(angf)) );
+
+ cdCanvasEnd(intcgm_canvas);
+
+ return 0;
+}
+
+int cgm_line_circle ( double xc, double yc, double radius, double angi, double angf, int fechado )
+{
+ double coseno, seno;
+ double xant, yant, firstx, firsty;
+ double xs, ys;
+
+ /* GERA O DESENHO DO CIRCULO/ARCO */
+
+ coseno = cos (VARCS);
+ seno = sin (VARCS);
+
+ xs = radius * cos(angi);
+ ys = radius * sin(angi);
+
+ if ( fechado==CLOSED_PIE )
+ cdCanvasLine (intcgm_canvas, cgm_vdcx2canvas(xc), cgm_vdcy2canvas(yc), cgm_vdcx2canvas(xc+xs), cgm_vdcy2canvas(yc+ys) );
+
+ xant = firstx = xc+xs;
+ yant = firsty = yc+ys;
+
+ while ( (angi+VARCS) < angf )
+ {
+ double xe = xs;
+ xs = xs * coseno - ys * seno;
+ ys = ys * coseno + xe * seno;
+ cdCanvasLine (intcgm_canvas, cgm_vdcx2canvas(xant), cgm_vdcy2canvas(yant), cgm_vdcx2canvas(xc+xs), cgm_vdcy2canvas(yc+ys) );
+ xant = xc+xs;
+ yant = yc+ys;
+ angi += VARCS;
+ }
+
+ cdCanvasLine (intcgm_canvas, cgm_vdcx2canvas(xant), cgm_vdcy2canvas(yant),
+ cgm_vdcx2canvas(xc+radius*cos(angf)), cgm_vdcy2canvas(yc+radius*sin(angf)) );
+
+ xant = xc+radius*cos(angf);
+ yant = yc+radius*sin(angf);
+
+ if ( fechado==CLOSED_PIE )
+ cdCanvasLine (intcgm_canvas, cgm_vdcx2canvas(xant), cgm_vdcy2canvas(yant), cgm_vdcx2canvas(xc), cgm_vdcy2canvas(yc) );
+ else if ( fechado==CLOSED_CHORD )
+ cdCanvasLine (intcgm_canvas, cgm_vdcx2canvas(xant), cgm_vdcy2canvas(yant), cgm_vdcx2canvas(firstx), cgm_vdcy2canvas(firsty) );
+
+ return 0;
+}
+
diff --git a/cd/src/intcgm/circle.h b/cd/src/intcgm/circle.h
new file mode 100755
index 0000000..3209c0f
--- /dev/null
+++ b/cd/src/intcgm/circle.h
@@ -0,0 +1,3 @@
+int cgm_poly_circle ( double xc, double yc, double radius, double angi, double angf, int fechado );
+int cgm_line_circle ( double xc, double yc, double radius, double angi, double angf, int fechado );
+
diff --git a/cd/src/intcgm/ellipse.c b/cd/src/intcgm/ellipse.c
new file mode 100755
index 0000000..8d6889c
--- /dev/null
+++ b/cd/src/intcgm/ellipse.c
@@ -0,0 +1,143 @@
+#include <stdio.h>
+#include <math.h>
+
+#include <cd.h>
+
+#include "list.h"
+#include "types.h"
+#include "intcgm.h"
+#include "intcgm6.h"
+#include "ellipse.h"
+
+#ifndef PI
+#define PI 3.14159265358979323846
+#endif
+
+#define ANGMIN 0.00001
+
+/* Adjust the circle parametrization for the elipsis parametrization */
+double cgm_AdjArc ( double arc, double w, double h )
+{
+ double value;
+
+ if ((fabs(w*sin(arc))<1e-99) && (fabs(h*cos(arc))<1e-99))
+ value = 0.0;
+ else
+ value = atan2(w*sin(arc), h*cos(arc));
+
+ if ( arc > PI ) value += 2*PI;
+ if ( arc < -PI ) value -= 2*PI;
+
+ return value;
+}
+
+
+/* Desenha um arco de Elipse */
+
+void cgm_ElpArc ( double xc, double yc, double w, double h, double r, double a1,
+ double a2, int n, int tipo )
+
+{
+
+ /* Onde:
+
+ (xc,yc) Centro
+ (w,h) Largura e altura (diametro na direcao dos eixos principais)
+ r Inclinacao dos eixos principais com relacao x e y
+ a1,a2 Angulos incial e final do arco [-360,+360]
+ Note-se que o sentido e' dado pela diferenca a2-a1,
+ ou seja, 30 a 330 e' trigonometrico
+ 30 a -30 e' horario
+ n Numero de segmentos da poligonal equivalente
+ (64 parece ser um bom numero)
+ tipo 0=aberto 1=fechado(torta) 2=fechado(corda) */
+
+ double da, c, s, sx, sy, ang, xant, yant;
+ double px, py, tx, ty, txant, tyant, dx, dy;
+ int i, inicio;
+
+/* Reduz de diametro a raio */
+
+ w = w/2;
+ h = h/2;
+
+/* Transforma graus em radianos e ajusta a os angulos da parametrizacao */
+
+ a1 = cgm_AdjArc(a1,w,h);
+
+ a2 = cgm_AdjArc(a2,w,h);
+
+ if ( a2>a1 )
+ ang = a2 - a1;
+ else
+ ang = 2*PI - ( a1 - a2 );
+
+/* Gera os pontos do arco centrado na origem com os eixos em x e y */
+
+ da = ang/n;
+ c = cos(da);
+ s = sin(da);
+ sx = -w*s/h;
+ sy = h*s/w;
+
+ if ( tipo==1 || tipo==2 )
+ {
+ long int cor;
+ cor = cgm_getcolor ( intcgm_fill_att.color );
+ cdCanvasSetForeground (intcgm_canvas, cor );
+ cdCanvasBegin(intcgm_canvas, cgm_setintstyle(intcgm_fill_att.int_style) );
+ }
+ else
+ {
+ long int cor;
+ int size = (int)floor(intcgm_line_att.width+.5);
+ cdCanvasLineStyle (intcgm_canvas, intcgm_line_att.type );
+ cdCanvasLineWidth (intcgm_canvas, size>0? size: 1 );
+ cor = cgm_getcolor ( intcgm_line_att.color );
+ cdCanvasSetForeground (intcgm_canvas, cor );
+ }
+
+ dx = (fabs(r)>ANGMIN) ? sin(r) : 0;
+ dy = (fabs(r)>ANGMIN) ? cos(r) : 1;
+
+ xant = w*cos(a1);
+ yant = h*sin(a1);
+
+ txant = xc+dy*xant-dx*yant; /* Inclina (se for o caso) e translada */
+ tyant = yc+dx*xant+dy*yant; /* Inclina (se for o caso) e translada */
+
+ if ( tipo==1 )
+ {
+ cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(xc), cgm_vdcy2canvas(yc) );
+ cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(txant), cgm_vdcy2canvas(tyant) );
+ inicio = 2;
+ }
+ else if ( tipo==2 )
+ {
+ cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(txant), cgm_vdcy2canvas(tyant) );
+ inicio = 1;
+ }
+
+ for ( i=inicio; i<=(n+inicio-1); i++ )
+ {
+ px = c*xant+sx*yant;
+ py = sy*xant+c*yant;
+
+ tx = xc+dy*px-dx*py; /* Inclina (se for o caso) e translada */
+ ty = yc+dx*px+dy*py; /* Inclina (se for o caso) e translada */
+
+ if ( tipo==0 )
+ cdCanvasLine (intcgm_canvas, cgm_vdcx2canvas(txant), cgm_vdcy2canvas(tyant), cgm_vdcx2canvas(tx), cgm_vdcy2canvas(ty) );
+ else
+ cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(tx), cgm_vdcy2canvas(ty) );
+
+ xant = px;
+ yant = py;
+ txant = tx;
+ tyant = ty;
+ }
+
+/* Desenha */
+
+ if ( tipo==1 || tipo==2 ) cdCanvasEnd(intcgm_canvas);
+}
diff --git a/cd/src/intcgm/ellipse.h b/cd/src/intcgm/ellipse.h
new file mode 100755
index 0000000..80980ff
--- /dev/null
+++ b/cd/src/intcgm/ellipse.h
@@ -0,0 +1,3 @@
+void cgm_ElpArc ( double, double, double, double, double, double, double, int, int );
+double cgm_AdjArc ( double arc, double w, double h );
+
diff --git a/cd/src/intcgm/intcgm.h b/cd/src/intcgm/intcgm.h
new file mode 100755
index 0000000..c106ee0
--- /dev/null
+++ b/cd/src/intcgm/intcgm.h
@@ -0,0 +1,84 @@
+typedef int (*CGM_FUNC) (void);
+
+#ifdef _INTCGM1_C_
+
+t_cgm intcgm_cgm;
+cdCanvas* intcgm_canvas = NULL;
+
+tlimit intcgm_vdc_ext;
+double intcgm_scale_factor_x;
+double intcgm_scale_factor_y;
+double intcgm_scale_factor_mm_x;
+double intcgm_scale_factor_mm_y;
+double intcgm_scale_factor;
+int intcgm_view_xmin, intcgm_view_ymin, intcgm_view_xmax, intcgm_view_ymax;
+double intcgm_clip_xmin, intcgm_clip_ymin, intcgm_clip_xmax, intcgm_clip_ymax;
+
+_line_att intcgm_line_att = { 1, LINE_SOLID, 1., {1} };
+
+_marker_att intcgm_marker_att = { 3, MARK_ASTERISK, 1., {1} };
+
+_text_att intcgm_text_att = { 1, 1, NULL, 0, CD_PLAIN, 8, STRING, 1., 0., {1}, .1,
+ {0,1}, {1,0}, PATH_RIGHT, {NORMHORIZ,NORMVERT,0.,0.} };
+
+_fill_att intcgm_fill_att = { 1, HOLLOW, {1}, 1, 1, {0,0}, NULL, {{0.,0.},{0.,0.}} };
+
+_edge_att intcgm_edge_att = { 1, EDGE_SOLID, 1., {1}, OFF };
+
+trgb *intcgm_color_table;
+int intcgm_block;
+
+TList *intcgm_asf_list;
+
+tpoint *intcgm_point_list;
+int intcgm_npoints;
+
+CGM_FUNC intcgm_funcs[] = { NULL, &cgmb_rch, &cgmt_rch };
+
+#else
+
+extern t_cgm intcgm_cgm;
+extern cdCanvas* intcgm_canvas;
+
+extern tlimit intcgm_vdc_ext;
+extern double intcgm_scale_factor_x;
+extern double intcgm_scale_factor_y;
+extern double intcgm_scale_factor_mm_x;
+extern double intcgm_scale_factor_mm_y;
+extern double intcgm_scale_factor;
+extern int intcgm_view_xmin, intcgm_view_ymin, intcgm_view_xmax, intcgm_view_ymax;
+extern double intcgm_clip_xmin, intcgm_clip_ymin, intcgm_clip_xmax, intcgm_clip_ymax;
+
+extern _line_att intcgm_line_att;
+
+extern _marker_att intcgm_marker_att;
+
+extern _text_att intcgm_text_att;
+
+extern _fill_att intcgm_fill_att;
+
+extern _edge_att intcgm_edge_att;
+
+extern trgb *intcgm_color_table;
+extern int intcgm_block;
+
+extern TList *intcgm_asf_list;
+
+extern tpoint *intcgm_point_list;
+extern int intcgm_npoints;
+
+extern CGM_FUNC *intcgm_funcs;
+
+#endif
+
+typedef struct _tasf {
+ short type;
+ short value;
+ } tasf;
+
+typedef struct _pat_table {
+ long index;
+ long nx, ny;
+ tcolor *pattern;
+ } pat_table;
+
diff --git a/cd/src/intcgm/intcgm1.c b/cd/src/intcgm/intcgm1.c
new file mode 100755
index 0000000..d4b2399
--- /dev/null
+++ b/cd/src/intcgm/intcgm1.c
@@ -0,0 +1,291 @@
+#define _INTCGM1_C_
+
+#include <stdio.h> /* FILE, ftell, fseek, fputc, fopen, fclose, fputs, fprintf */
+#include <stdlib.h> /* malloc, free */
+#include <string.h> /* strlen */
+#include <math.h> /* floor */
+
+#ifdef SunOS
+#include <unistd.h> /* SEEK_SET, SEEK_END */
+#endif
+
+#include <float.h> /* FLT_MIN, FLT_MAX */
+#include <limits.h> /* INT_MIN, INT_MAX */
+
+#include "cd.h"
+#include "cdcgm.h"
+
+#include "list.h"
+#include "types.h"
+#include "intcgm2.h"
+#include "intcgm.h"
+#include "bparse.h"
+
+static int isitbin ( char *fname )
+{
+ unsigned char ch[2];
+ int erro, c, id;
+ unsigned short b;
+ FILE *f = fopen ( fname, "rb" );
+ if (!f)
+ return 0;
+
+ erro = fread ( ch, 1, 2, f );
+
+ b = (ch[0] << 8) + ch[1];
+
+ id = ( b & 0x0FE0 ) >> 5;
+
+ c = ( b & 0xF000 ) >> 12;
+
+ fclose(f);
+
+ if ( c==0 && id==1 )
+ return 1;
+ else
+ return 0;
+}
+
+static int cgmplay ( char* filename, int xmn, int xmx, int ymn, int ymx )
+{
+ intcgm_view_xmin = xmn;
+ intcgm_view_xmax = xmx;
+ intcgm_view_ymin = ymn;
+ intcgm_view_ymax = ymx;
+
+ intcgm_scale_factor_x = 1;
+ intcgm_scale_factor_y = 1;
+ intcgm_scale_factor = 1;
+
+ intcgm_block = 500;
+ intcgm_npoints = 500;
+ intcgm_cgm.buff.size = 1024;
+
+ intcgm_point_list = (tpoint *) malloc ( sizeof(tpoint)*intcgm_npoints);
+ intcgm_cgm.buff.dados = (char *) malloc ( sizeof(char) * intcgm_cgm.buff.size );
+
+ if ( isitbin(filename) )
+ {
+ intcgm_cgm.fp = fopen ( filename, "rb" );
+ if (!intcgm_cgm.fp)
+ {
+ free(intcgm_point_list);
+ free(intcgm_cgm.buff.dados);
+ return CD_ERROR;
+ }
+
+ fseek ( intcgm_cgm.fp, 0, SEEK_END );
+ intcgm_cgm.file_size = ftell ( intcgm_cgm.fp );
+ fseek ( intcgm_cgm.fp, 0, SEEK_SET );
+
+ intcgm_cgm.mode = 1;
+ intcgm_cgm.cgmf = intcgm_funcs[intcgm_cgm.mode];
+
+ intcgm_cgm.int_prec.b_prec = 1;
+ intcgm_cgm.real_prec.b_prec = 2;
+ intcgm_cgm.ix_prec.b_prec = 1;
+ intcgm_cgm.cd_prec = 0;
+ intcgm_cgm.cix_prec = 0;
+ intcgm_cgm.vdc_int.b_prec = 1;
+ intcgm_cgm.vdc_real.b_prec = 2;
+ }
+ else
+ {
+ intcgm_cgm.fp = fopen ( filename, "r" );
+ if (!intcgm_cgm.fp)
+ {
+ free(intcgm_point_list);
+ free(intcgm_cgm.buff.dados);
+ return CD_ERROR;
+ }
+
+ fseek ( intcgm_cgm.fp, 0, SEEK_END );
+ intcgm_cgm.file_size = ftell ( intcgm_cgm.fp );
+ fseek ( intcgm_cgm.fp, 0, SEEK_SET );
+
+ intcgm_cgm.mode = 2;
+ intcgm_cgm.cgmf = intcgm_funcs[intcgm_cgm.mode];
+
+ intcgm_cgm.int_prec.t_prec.minint = -32767;
+ intcgm_cgm.int_prec.t_prec.maxint = 32767;
+ intcgm_cgm.real_prec.t_prec.minreal = -32767;
+ intcgm_cgm.real_prec.t_prec.maxreal = 32767;
+ intcgm_cgm.real_prec.t_prec.digits = 4;
+ intcgm_cgm.ix_prec.t_prec.minint = 0;
+ intcgm_cgm.ix_prec.t_prec.maxint = 127;
+ intcgm_cgm.cd_prec = 127;
+ intcgm_cgm.vdc_int.t_prec.minint = -32767;
+ intcgm_cgm.vdc_int.t_prec.maxint = 32767;
+ intcgm_cgm.vdc_real.t_prec.minreal = 0;
+ intcgm_cgm.vdc_real.t_prec.maxreal = 1;
+ intcgm_cgm.vdc_real.t_prec.digits = 4;
+ }
+
+ intcgm_cgm.first = 1;
+ intcgm_cgm.len = 0;
+ intcgm_cgm.vdc_type = INTEGER;
+ intcgm_cgm.max_cix = 63;
+ intcgm_cgm.scaling_mode.mode = ABSTRACT;
+ intcgm_cgm.scaling_mode.scale_factor = 1.;
+ intcgm_cgm.drawing_mode = ABSTRACT;
+ intcgm_cgm.clrsm = INDEXED;
+ intcgm_cgm.lnwsm = SCALED;
+ intcgm_cgm.mkssm = SCALED;
+ intcgm_cgm.edwsm = SCALED;
+ intcgm_cgm.vdc_ext.first.x = 0;
+ intcgm_cgm.vdc_ext.first.y = 0;
+ intcgm_cgm.vdc_ext.second.x = 32767;
+ intcgm_cgm.vdc_ext.second.y = 32767;
+ intcgm_cgm.back_color.red = 0;
+ intcgm_cgm.back_color.green = 0;
+ intcgm_cgm.back_color.blue = 0;
+ intcgm_cgm.aux_color.rgb.red = 0;
+ intcgm_cgm.aux_color.rgb.green = 0;
+ intcgm_cgm.aux_color.rgb.blue = 0;
+ intcgm_cgm.color_ext.black.red = 0;
+ intcgm_cgm.color_ext.black.green = 0;
+ intcgm_cgm.color_ext.black.blue = 0;
+ intcgm_cgm.color_ext.white.red = 255;
+ intcgm_cgm.color_ext.white.green = 255;
+ intcgm_cgm.color_ext.white.blue = 255;
+ intcgm_cgm.transparency = ON;
+ intcgm_cgm.clip_rect.first.x = 0;
+ intcgm_cgm.clip_rect.first.y = 0;
+ intcgm_cgm.clip_rect.second.x = 32767;
+ intcgm_cgm.clip_rect.second.y = 32767;
+ intcgm_cgm.clip_ind = ON;
+ intcgm_cgm.bc = 0;
+ intcgm_cgm.bl= 0;
+ intcgm_cgm.cl = 0;
+
+ intcgm_line_att.index = 1;
+ intcgm_line_att.type = LINE_SOLID;
+ intcgm_line_att.width = 1;
+ intcgm_line_att.color.ind = 1;
+
+ intcgm_marker_att.index = 1;
+ intcgm_marker_att.type = 1;
+ intcgm_marker_att.size = 1;
+ intcgm_marker_att.color.ind = 1;
+
+ intcgm_text_att.index = 1;
+ intcgm_text_att.font_index = 1;
+ intcgm_text_att.font_list = NULL;
+ intcgm_text_att.font = 0;
+ intcgm_text_att.style = CD_PLAIN;
+ intcgm_text_att.size = 8;
+ intcgm_text_att.prec = STRING;
+ intcgm_text_att.exp_fact = 1;
+ intcgm_text_att.char_spacing = 0;
+ intcgm_text_att.color.ind = 1;
+ intcgm_text_att.height = 1;
+ intcgm_text_att.char_up.x = 0;
+ intcgm_text_att.char_up.y = 1;
+ intcgm_text_att.char_base.x = 1;
+ intcgm_text_att.char_base.y = 0;
+ intcgm_text_att.path = PATH_RIGHT;
+ intcgm_text_att.alignment.hor = NORMHORIZ;
+ intcgm_text_att.alignment.ver = NORMVERT;
+ intcgm_text_att.alignment.cont_hor = 0;
+ intcgm_text_att.alignment.cont_ver = 0;
+
+ intcgm_fill_att.index = 1;
+ intcgm_fill_att.int_style = HOLLOW;
+ intcgm_fill_att.color.ind = 1;
+ intcgm_fill_att.hatch_index = 1;
+ intcgm_fill_att.pat_index = 1;
+ intcgm_fill_att.ref_pt.x = 0;
+ intcgm_fill_att.ref_pt.y = 0;
+ intcgm_fill_att.pat_list = NULL;
+ intcgm_fill_att.pat_size.height.x = 0;
+ intcgm_fill_att.pat_size.height.y = 0;
+ intcgm_fill_att.pat_size.height.x = 0;
+ intcgm_fill_att.pat_size.width.y = 0;
+
+ intcgm_edge_att.index = 1;
+ intcgm_edge_att.type = EDGE_SOLID;
+ intcgm_edge_att.width = 1;
+ intcgm_edge_att.color.ind = 1;
+ intcgm_edge_att.visibility = OFF;
+
+ cdCanvasLineWidth(intcgm_canvas, 1);
+
+ intcgm_color_table = (trgb *) malloc ( sizeof(trgb)*intcgm_cgm.max_cix);
+ intcgm_color_table[0].red = 255;
+ intcgm_color_table[0].green = 255;
+ intcgm_color_table[0].blue = 255;
+ intcgm_color_table[1].red = 0;
+ intcgm_color_table[1].green = 0;
+ intcgm_color_table[1].blue = 0;
+
+ while ( !(*intcgm_cgm.cgmf)() ){};
+
+ if ( intcgm_point_list!=NULL )
+ {
+ free(intcgm_point_list);
+ intcgm_point_list = NULL;
+ }
+
+ if ( intcgm_cgm.buff.dados!=NULL )
+ {
+ free(intcgm_cgm.buff.dados);
+ intcgm_cgm.buff.dados = NULL;
+ }
+
+ if ( intcgm_color_table!=NULL )
+ {
+ free(intcgm_color_table);
+ intcgm_color_table = NULL;
+ }
+
+ fclose(intcgm_cgm.fp);
+
+ return CD_OK;
+}
+
+_cdcgmsizecb cdcgmsizecb = NULL;
+_cdcgmbegmtfcb cdcgmbegmtfcb = NULL;
+_cdcgmcountercb cdcgmcountercb = NULL;
+_cdcgmsclmdecb cdcgmsclmdecb = NULL;
+_cdcgmvdcextcb cdcgmvdcextcb = NULL;
+_cdcgmbegpictcb cdcgmbegpictcb = NULL;
+_cdcgmbegpictbcb cdcgmbegpictbcb = NULL;
+
+int cdRegisterCallbackCGM(int cb, cdCallback func)
+{
+ switch (cb)
+ {
+ case CD_SIZECB:
+ cdcgmsizecb = (_cdcgmsizecb)func;
+ return CD_OK;
+ case CD_CGMBEGMTFCB:
+ cdcgmbegmtfcb = (_cdcgmbegmtfcb)func;
+ return CD_OK;
+ case CD_CGMCOUNTERCB:
+ cdcgmcountercb = (_cdcgmcountercb)func;
+ return CD_OK;
+ case CD_CGMSCLMDECB:
+ cdcgmsclmdecb = (_cdcgmsclmdecb)func;
+ return CD_OK;
+ case CD_CGMVDCEXTCB:
+ cdcgmvdcextcb = (_cdcgmvdcextcb)func;
+ return CD_OK;
+ case CD_CGMBEGPICTCB:
+ cdcgmbegpictcb = (_cdcgmbegpictcb)func;
+ return CD_OK;
+ case CD_CGMBEGPICTBCB:
+ cdcgmbegpictbcb = (_cdcgmbegpictbcb)func;
+ return CD_OK;
+ }
+
+ return CD_ERROR;
+}
+
+int cdplayCGM(cdCanvas* _canvas, int xmin, int xmax, int ymin, int ymax, void *data)
+{
+ int ret;
+ intcgm_canvas = _canvas;
+ ret = cgmplay((char*)data, xmin, xmax, ymin, ymax);
+ _canvas = NULL;
+ return ret;
+}
diff --git a/cd/src/intcgm/intcgm2.c b/cd/src/intcgm/intcgm2.c
new file mode 100755
index 0000000..b6be7ee
--- /dev/null
+++ b/cd/src/intcgm/intcgm2.c
@@ -0,0 +1,1651 @@
+#include <stdio.h> /* FILE, ftell, fseek, fputc, fopen, fclose, fputs, fprintf */
+#include <string.h> /* strlen */
+#include <stdlib.h>
+#include <ctype.h>
+#include <math.h>
+#include "cd.h"
+#include "cdcgm.h"
+#include "list.h"
+#include "types.h"
+#include "bparse.h"
+#include "tparse.h"
+#include "intcgm.h"
+#include "intcgm6.h"
+#include "tparse.h"
+
+typedef struct {
+ const char *nome;
+ int (*func) (void);
+ } comando;
+
+/**************************************************
+***************************************************
+** **
+** FUNCOES CGM **
+** **
+***************************************************
+**************************************************/
+
+/************************************************
+* *
+* Dados para nao-binario *
+* *
+************************************************/
+
+/* delimiter elements */
+
+comando _cgmt_NULL = { "", NULL };
+comando _cgmt_BEGMF = { "begmf", &cgmt_begmtf };
+comando _cgmt_ENDMF = { "endmf", &cgmt_endmtf };
+comando _cgmt_BEG_PIC = { "begpic", &cgmt_begpic };
+comando _cgmt_BEG_PIC_BODY = { "begpicbody", &cgmt_begpib };
+comando _cgmt_END_PIC = { "endpic", &cgmt_endpic };
+
+/* metafile descriptor elements */
+
+comando _cgmt_MF_VERSION = { "mfversion", cgmt_mtfver };
+comando _cgmt_MF_DESC = { "mfdesc", cgmt_mtfdsc };
+comando _cgmt_VDC_TYPE = { "vdctype", cgmt_vdctyp };
+comando _cgmt_INTEGER_PREC = { "integerprec", cgmt_intpre };
+comando _cgmt_REAL_PREC = { "realprec", cgmt_realpr };
+comando _cgmt_INDEX_PREC = { "indexprec", cgmt_indpre };
+comando _cgmt_COLR_PREC = { "colrprec", cgmt_colpre };
+comando _cgmt_COLR_INDEX_PREC = { "colrindexprec", cgmt_colipr };
+comando _cgmt_MAX_COLR_INDEX = { "maxcolrindex", cgmt_maxcoi };
+comando _cgmt_COLR_VALUE_EXT = { "colrvalueext", cgmt_covaex };
+comando _cgmt_MF_ELEM_LIST = { "mfelemlist", cgmt_mtfell };
+comando _cgmt_BEG_MF_DEFAULTS = { "begmfdefaults", cgmt_bmtfdf };
+comando _cgmt_END_MF_DEFAULTS = { "endmfdefaults", cgmt_emtfdf };
+comando _cgmt_FONT_LIST = { "fontlist", cgmt_fntlst };
+comando _cgmt_CHAR_SET_LIST = { "charsetlist", cgmt_chslst };
+comando _cgmt_CHAR_CODING = { "charcoding", cgmt_chcdac };
+
+/* picture descriptor elements */
+
+comando _cgmt_SCALE_MODE = { "scalemode", cgmt_sclmde };
+comando _cgmt_COLR_MODE = { "colrmode", cgmt_clslmd };
+comando _cgmt_LINE_WIDTH_MODE = { "linewidthmode", cgmt_lnwdmd };
+comando _cgmt_MARKER_SIZE_MODE = { "markersizemode", cgmt_mkszmd };
+comando _cgmt_EDGE_WIDTH_MODE = { "edgewidthmode", cgmt_edwdmd };
+comando _cgmt_VDC_EXTENT = { "vdcext", cgmt_vdcext };
+comando _cgmt_BACK_COLR = { "backcolr", cgmt_bckcol };
+
+/* control elements */
+
+comando _cgmt_VDC_INTEGER_PREC = { "vdcintegerprec", cgmt_vdcipr };
+comando _cgmt_VDC_REAL_PREC = { "vdcrealprec", cgmt_vdcrpr };
+comando _cgmt_AUX_COLR = { "auxcolr", cgmt_auxcol };
+comando _cgmt_TRANSPARENCY = { "transparency", cgmt_transp };
+comando _cgmt_CLIP_RECT = { "cliprect", cgmt_clprec };
+comando _cgmt_CLIP = { "clip", cgmt_clpind };
+
+/* primitive elements */
+
+comando _cgmt_LINE = { "line", cgmt_polyln };
+comando _cgmt_INCR_LINE = { "incrline", cgmt_incply };
+comando _cgmt_DISJT_LINE = { "disjtline", cgmt_djtply };
+comando _cgmt_INCR_DISJT_LINE = { "incrdisjt_line", cgmt_indjpl };
+comando _cgmt_MARKER = { "marker", cgmt_polymk };
+comando _cgmt_INCR_MARKER = { "incrmarker", cgmt_incplm };
+comando _cgmt_TEXT = { "text", cgmt_text };
+comando _cgmt_RESTR_TEXT = { "restrtext", cgmt_rsttxt };
+comando _cgmt_APND_TEXT = { "apndtext", cgmt_apdtxt };
+comando _cgmt_POLYGON = { "polygon", cgmt_polygn };
+comando _cgmt_INCR_POLYGON = { "incrpolygon", cgmt_incplg };
+comando _cgmt_POLYGON_SET = { "polygonset", cgmt_plgset };
+comando _cgmt_INCR_POLYGON_SET = { "incrpolygonset", cgmt_inpgst };
+comando _cgmt_CELL_ARRAY = { "cellarray", cgmt_cellar };
+comando _cgmt_GDP = { "gdp", cgmt_gdp };
+comando _cgmt_RECT = { "rect", cgmt_rect };
+comando _cgmt_CIRCLE = { "circle", cgmt_circle };
+comando _cgmt_ARC_3_PT = { "arc3pt", cgmt_circ3p };
+comando _cgmt_ARC_3_PT_CLOSE = { "arc3ptclose", cgmt_cir3pc };
+comando _cgmt_ARC_CTR = { "arcctr", cgmt_circnt };
+comando _cgmt_ARC_CTR_CLOSE = { "arcctr_close", cgmt_ccntcl };
+comando _cgmt_ELLIPSE = { "ellipse", cgmt_ellips };
+comando _cgmt_ELLIP_ARC = { "elliparc", cgmt_ellarc };
+comando _cgmt_ELLIP_ARC_CLOSE = { "elliparcclose", cgmt_ellacl };
+
+/* attribute elements */
+
+comando _cgmt_LINE_INDEX = { "lineindex", cgmt_lnbdin };
+comando _cgmt_LINE_TYPE = { "linetype", cgmt_lntype };
+comando _cgmt_LINE_WIDTH = { "linewidth", cgmt_lnwidt };
+comando _cgmt_LINE_COLR = { "linecolr", cgmt_lncolr };
+comando _cgmt_MARKER_INDEX = { "markerindex", cgmt_mkbdin };
+comando _cgmt_MARKER_TYPE = { "markertype", cgmt_mktype };
+comando _cgmt_MARKER_WIDTH = { "markersize", cgmt_mksize };
+comando _cgmt_MARKER_COLR = { "markercolr", cgmt_mkcolr };
+comando _cgmt_TEXT_INDEX = { "textindex", cgmt_txbdin };
+comando _cgmt_TEXT_FONT_INDEX = { "textfontindex", cgmt_txftin };
+comando _cgmt_TEXT_PREC = { "textprec", cgmt_txtprc };
+comando _cgmt_CHAR_EXPAN = { "charexpan", cgmt_chrexp };
+comando _cgmt_CHAR_SPACE = { "charspace", cgmt_chrspc };
+comando _cgmt_TEXT_COLR = { "textcolr", cgmt_txtclr };
+comando _cgmt_CHAR_HEIGHT = { "charheight", cgmt_chrhgt };
+comando _cgmt_CHAR_ORI = { "charori", cgmt_chrori };
+comando _cgmt_TEXT_PATH = { "textpath", cgmt_txtpat };
+comando _cgmt_TEXT_ALIGN = { "textalign", cgmt_txtali };
+comando _cgmt_CHAR_SET_INDEX = { "charsetindex", cgmt_chseti };
+comando _cgmt_ALT_CHAR_SET = { "altcharsetindex", cgmt_achsti };
+comando _cgmt_FILL_INDEX = { "fillindex", cgmt_fillin };
+comando _cgmt_INT_STYLE = { "intstyle", cgmt_intsty };
+comando _cgmt_FILL_COLR = { "fillcolr", cgmt_fillco };
+comando _cgmt_HATCH_INDEX = { "hatchindex", cgmt_hatind };
+comando _cgmt_PAT_INDEX = { "patindex", cgmt_patind };
+comando _cgmt_EDGE_INDEX = { "edgeindex", cgmt_edgind };
+comando _cgmt_EDGE_TYPE = { "edgetype", cgmt_edgtyp };
+comando _cgmt_EDGE_WIDTH = { "edgewidth", cgmt_edgwid };
+comando _cgmt_EDGE_COLR = { "edgecolr", cgmt_edgcol };
+comando _cgmt_EDGE_VIS = { "edgevis", cgmt_edgvis };
+comando _cgmt_FILL_REF_PT = { "fillrefpt", cgmt_fillrf };
+comando _cgmt_PAT_TABLE = { "pattable", cgmt_pattab };
+comando _cgmt_PAT_SIZE = { "patsize", cgmt_patsiz };
+comando _cgmt_COLR_TABLE = { "colrtable", cgmt_coltab };
+comando _cgmt_ASF = { "asf", cgmt_asf };
+
+/* escape elements */
+
+comando _cgmt_ESCAPE = { "escape", cgmt_escape };
+comando _cgmt_DOMAIN_RING = { "domainring", NULL };
+
+/* external elements */
+
+comando _cgmt_MESSAGE = { "message", cgmt_messag };
+comando _cgmt_APPL_DATA = { "appldata", cgmt_appdta };
+
+comando *_cgmt_delimiter[] = {
+ &_cgmt_NULL,
+ &_cgmt_BEGMF,
+ &_cgmt_ENDMF,
+ &_cgmt_BEG_PIC,
+ &_cgmt_BEG_PIC_BODY,
+ &_cgmt_END_PIC,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL };
+
+comando *_cgmt_metafile[] = {
+ &_cgmt_END_MF_DEFAULTS,
+ &_cgmt_MF_VERSION,
+ &_cgmt_MF_DESC,
+ &_cgmt_VDC_TYPE,
+ &_cgmt_INTEGER_PREC,
+ &_cgmt_REAL_PREC,
+ &_cgmt_INDEX_PREC,
+ &_cgmt_COLR_PREC,
+ &_cgmt_COLR_INDEX_PREC,
+ &_cgmt_MAX_COLR_INDEX,
+ &_cgmt_COLR_VALUE_EXT,
+ &_cgmt_MF_ELEM_LIST,
+ &_cgmt_BEG_MF_DEFAULTS,
+ &_cgmt_FONT_LIST,
+ &_cgmt_CHAR_SET_LIST,
+ &_cgmt_CHAR_CODING,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
+
+comando *_cgmt_picture[] = {
+ &_cgmt_NULL,
+ &_cgmt_SCALE_MODE,
+ &_cgmt_COLR_MODE,
+ &_cgmt_LINE_WIDTH_MODE,
+ &_cgmt_MARKER_SIZE_MODE,
+ &_cgmt_EDGE_WIDTH_MODE,
+ &_cgmt_VDC_EXTENT,
+ &_cgmt_BACK_COLR,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL };
+
+comando *_cgmt_control[] = {
+ &_cgmt_NULL,
+ &_cgmt_VDC_INTEGER_PREC,
+ &_cgmt_VDC_REAL_PREC,
+ &_cgmt_AUX_COLR,
+ &_cgmt_TRANSPARENCY,
+ &_cgmt_CLIP_RECT,
+ &_cgmt_CLIP,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL };
+
+comando *_cgmt_primitive[] = {
+ &_cgmt_NULL,
+ &_cgmt_LINE,
+ &_cgmt_INCR_LINE,
+ &_cgmt_DISJT_LINE,
+ &_cgmt_INCR_DISJT_LINE,
+ &_cgmt_MARKER,
+ &_cgmt_INCR_MARKER,
+ &_cgmt_TEXT,
+ &_cgmt_RESTR_TEXT,
+ &_cgmt_APND_TEXT,
+ &_cgmt_POLYGON,
+ &_cgmt_INCR_POLYGON,
+ &_cgmt_POLYGON_SET,
+ &_cgmt_INCR_POLYGON_SET,
+ &_cgmt_CELL_ARRAY,
+ &_cgmt_GDP,
+ &_cgmt_RECT,
+ &_cgmt_CIRCLE,
+ &_cgmt_ARC_3_PT,
+ &_cgmt_ARC_3_PT_CLOSE,
+ &_cgmt_ARC_CTR,
+ &_cgmt_ARC_CTR_CLOSE,
+ &_cgmt_ELLIPSE,
+ &_cgmt_ELLIP_ARC,
+ &_cgmt_ELLIP_ARC_CLOSE,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
+
+comando *_cgmt_attributes[] = {
+ &_cgmt_NULL,
+ &_cgmt_LINE_INDEX,
+ &_cgmt_LINE_TYPE,
+ &_cgmt_LINE_WIDTH,
+ &_cgmt_LINE_COLR,
+ &_cgmt_MARKER_INDEX,
+ &_cgmt_MARKER_TYPE,
+ &_cgmt_MARKER_WIDTH,
+ &_cgmt_MARKER_COLR,
+ &_cgmt_TEXT_INDEX,
+ &_cgmt_TEXT_FONT_INDEX,
+ &_cgmt_TEXT_PREC,
+ &_cgmt_CHAR_EXPAN,
+ &_cgmt_CHAR_SPACE,
+ &_cgmt_TEXT_COLR,
+ &_cgmt_CHAR_HEIGHT,
+ &_cgmt_CHAR_ORI,
+ &_cgmt_TEXT_PATH,
+ &_cgmt_TEXT_ALIGN,
+ &_cgmt_CHAR_SET_INDEX,
+ &_cgmt_ALT_CHAR_SET,
+ &_cgmt_FILL_INDEX,
+ &_cgmt_INT_STYLE,
+ &_cgmt_FILL_COLR,
+ &_cgmt_HATCH_INDEX,
+ &_cgmt_PAT_INDEX,
+ &_cgmt_EDGE_INDEX,
+ &_cgmt_EDGE_TYPE,
+ &_cgmt_EDGE_WIDTH,
+ &_cgmt_EDGE_COLR,
+ &_cgmt_EDGE_VIS,
+ &_cgmt_FILL_REF_PT,
+ &_cgmt_PAT_TABLE,
+ &_cgmt_PAT_SIZE,
+ &_cgmt_COLR_TABLE,
+ &_cgmt_ASF,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL };
+
+comando *_cgmt_escape[] = {
+ &_cgmt_NULL,
+ &_cgmt_ESCAPE,
+ &_cgmt_DOMAIN_RING,
+ NULL};
+
+comando *_cgmt_external[] = {
+ &_cgmt_NULL,
+ &_cgmt_MESSAGE,
+ &_cgmt_APPL_DATA,
+ NULL };
+
+comando *_cgmt_segment[] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
+
+comando *_cgmt_NULL_NULL[] = {
+ &_cgmt_NULL,
+ NULL };
+
+comando **_cgmt_comandos[] = {
+ _cgmt_NULL_NULL,
+ _cgmt_delimiter,
+ _cgmt_metafile,
+ _cgmt_picture,
+ _cgmt_control,
+ _cgmt_primitive,
+ _cgmt_attributes,
+ _cgmt_escape,
+ _cgmt_external,
+ _cgmt_segment,
+ NULL };
+
+/************************************************
+* *
+* Dados para binario *
+* *
+************************************************/
+
+/* delimiter elements */
+
+CGM_FUNC _cgmb_NULL = NULL;
+
+CGM_FUNC _cgmb_NOOP = &cgmb_noop;
+CGM_FUNC _cgmb_BEGMF = &cgmb_begmtf;
+CGM_FUNC _cgmb_ENDMF = &cgmb_endmtf;
+CGM_FUNC _cgmb_BEG_PIC = &cgmb_begpic;
+CGM_FUNC _cgmb_BEG_PIC_BODY = &cgmb_begpib;
+CGM_FUNC _cgmb_END_PIC = &cgmb_endpic;
+
+/* metafile descriptor elements */
+
+CGM_FUNC _cgmb_MF_VERSION = &cgmb_mtfver;
+CGM_FUNC _cgmb_MF_DESC = &cgmb_mtfdsc;
+CGM_FUNC _cgmb_VDC_TYPE = &cgmb_vdctyp;
+CGM_FUNC _cgmb_INTEGER_PREC = &cgmb_intpre;
+CGM_FUNC _cgmb_REAL_PREC = &cgmb_realpr;
+CGM_FUNC _cgmb_INDEX_PREC = &cgmb_indpre;
+CGM_FUNC _cgmb_COLR_PREC = &cgmb_colpre;
+CGM_FUNC _cgmb_COLR_INDEX_PREC = &cgmb_colipr;
+CGM_FUNC _cgmb_MAX_COLR_INDEX = &cgmb_maxcoi;
+CGM_FUNC _cgmb_COLR_VALUE_EXT = &cgmb_covaex;
+CGM_FUNC _cgmb_MF_ELEM_LIST = &cgmb_mtfell;
+CGM_FUNC _cgmb_MF_DEFAULTS_RPL = &cgmb_bmtfdf;
+CGM_FUNC _cgmb_FONT_LIST = &cgmb_fntlst;
+CGM_FUNC _cgmb_CHAR_SET_LIST = &cgmb_chslst;
+CGM_FUNC _cgmb_CHAR_CODING = &cgmb_chcdac;
+
+/* picture descriptor elements */
+
+CGM_FUNC _cgmb_SCALE_MODE = &cgmb_sclmde;
+CGM_FUNC _cgmb_COLR_MODE = &cgmb_clslmd;
+CGM_FUNC _cgmb_LINE_WIDTH_MODE = &cgmb_lnwdmd;
+CGM_FUNC _cgmb_MARKER_SIZE_MODE = &cgmb_mkszmd;
+CGM_FUNC _cgmb_EDGE_WIDTH_MODE = &cgmb_edwdmd;
+CGM_FUNC _cgmb_VDC_EXTENT = &cgmb_vdcext;
+CGM_FUNC _cgmb_BACK_COLR = &cgmb_bckcol;
+
+/* control elements */
+
+CGM_FUNC _cgmb_VDC_INTEGER_PREC = &cgmb_vdcipr;
+CGM_FUNC _cgmb_VDC_REAL_PREC = &cgmb_vdcrpr;
+CGM_FUNC _cgmb_AUX_COLR = &cgmb_auxcol;
+CGM_FUNC _cgmb_TRANSPARENCY = &cgmb_transp;
+CGM_FUNC _cgmb_CLIP_RECT = &cgmb_clprec;
+CGM_FUNC _cgmb_CLIP = &cgmb_clpind;
+
+/* primitive elements */
+
+CGM_FUNC _cgmb_LINE = &cgmb_polyln;
+CGM_FUNC _cgmb_DISJT_LINE = &cgmb_djtply;
+CGM_FUNC _cgmb_MARKER = &cgmb_polymk;
+CGM_FUNC _cgmb_TEXT = &cgmb_text;
+CGM_FUNC _cgmb_RESTR_TEXT = &cgmb_rsttxt;
+CGM_FUNC _cgmb_APND_TEXT = &cgmb_apdtxt;
+CGM_FUNC _cgmb_POLYGON = &cgmb_polygn;
+CGM_FUNC _cgmb_POLYGON_SET = &cgmb_plgset;
+CGM_FUNC _cgmb_CELL_ARRAY = &cgmb_cellar;
+CGM_FUNC _cgmb_GDP = &cgmb_gdp;
+CGM_FUNC _cgmb_RECT = &cgmb_rect;
+CGM_FUNC _cgmb_CIRCLE = &cgmb_circle;
+CGM_FUNC _cgmb_ARC_3_PT = &cgmb_circ3p;
+CGM_FUNC _cgmb_ARC_3_PT_CLOSE = &cgmb_cir3pc;
+CGM_FUNC _cgmb_ARC_CTR = &cgmb_circnt;
+CGM_FUNC _cgmb_ARC_CTR_CLOSE = &cgmb_ccntcl;
+CGM_FUNC _cgmb_ELLIPSE = &cgmb_ellips;
+CGM_FUNC _cgmb_ELLIP_ARC = &cgmb_ellarc;
+CGM_FUNC _cgmb_ELLIP_ARC_CLOSE = &cgmb_ellacl;
+
+/* attribute elements */
+
+CGM_FUNC _cgmb_LINE_INDEX = &cgmb_lnbdin;
+CGM_FUNC _cgmb_LINE_TYPE = &cgmb_lntype;
+CGM_FUNC _cgmb_LINE_WIDTH = &cgmb_lnwidt;
+CGM_FUNC _cgmb_LINE_COLR = &cgmb_lncolr;
+CGM_FUNC _cgmb_MARKER_INDEX = &cgmb_mkbdin;
+CGM_FUNC _cgmb_MARKER_TYPE = &cgmb_mktype;
+CGM_FUNC _cgmb_MARKER_WIDTH = &cgmb_mksize;
+CGM_FUNC _cgmb_MARKER_COLR = &cgmb_mkcolr;
+CGM_FUNC _cgmb_TEXT_INDEX = &cgmb_txbdin;
+CGM_FUNC _cgmb_TEXT_FONT_INDEX = &cgmb_txftin;
+CGM_FUNC _cgmb_TEXT_PREC = &cgmb_txtprc;
+CGM_FUNC _cgmb_CHAR_EXPAN = &cgmb_chrexp;
+CGM_FUNC _cgmb_CHAR_SPACE = &cgmb_chrspc;
+CGM_FUNC _cgmb_TEXT_COLR = &cgmb_txtclr;
+CGM_FUNC _cgmb_CHAR_HEIGHT = &cgmb_chrhgt;
+CGM_FUNC _cgmb_CHAR_ORI = &cgmb_chrori;
+CGM_FUNC _cgmb_TEXT_PATH = &cgmb_txtpat;
+CGM_FUNC _cgmb_TEXT_ALIGN = &cgmb_txtali;
+CGM_FUNC _cgmb_CHAR_SET_INDEX = &cgmb_chseti;
+CGM_FUNC _cgmb_ALT_CHAR_SET = &cgmb_achsti;
+CGM_FUNC _cgmb_FILL_INDEX = &cgmb_fillin;
+CGM_FUNC _cgmb_INT_STYLE = &cgmb_intsty;
+CGM_FUNC _cgmb_FILL_COLR = &cgmb_fillco;
+CGM_FUNC _cgmb_HATCH_INDEX = &cgmb_hatind;
+CGM_FUNC _cgmb_PAT_INDEX = &cgmb_patind;
+CGM_FUNC _cgmb_EDGE_INDEX = &cgmb_edgind;
+CGM_FUNC _cgmb_EDGE_TYPE = &cgmb_edgtyp;
+CGM_FUNC _cgmb_EDGE_WIDTH = &cgmb_edgwid;
+CGM_FUNC _cgmb_EDGE_COLR = &cgmb_edgcol;
+CGM_FUNC _cgmb_EDGE_VIS = &cgmb_edgvis;
+CGM_FUNC _cgmb_FILL_REF_PT = &cgmb_fillrf;
+CGM_FUNC _cgmb_PAT_TABLE = &cgmb_pattab;
+CGM_FUNC _cgmb_PAT_SIZE = &cgmb_patsiz;
+CGM_FUNC _cgmb_COLR_TABLE = &cgmb_coltab;
+CGM_FUNC _cgmb_ASF = &cgmb_asf;
+
+/* escape elements */
+
+CGM_FUNC _cgmb_ESCAPE = &cgmb_escape;
+
+/* external elements */
+
+CGM_FUNC _cgmb_MESSAGE = &cgmb_messag;
+CGM_FUNC _cgmb_APPL_DATA = &cgmb_appdta;
+
+CGM_FUNC *_cgmb_delimiter[] = {
+ &_cgmb_NOOP,
+ &_cgmb_BEGMF,
+ &_cgmb_ENDMF,
+ &_cgmb_BEG_PIC,
+ &_cgmb_BEG_PIC_BODY,
+ &_cgmb_END_PIC,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL };
+
+CGM_FUNC *_cgmb_metafile[] = {
+ &_cgmb_NULL,
+ &_cgmb_MF_VERSION,
+ &_cgmb_MF_DESC,
+ &_cgmb_VDC_TYPE,
+ &_cgmb_INTEGER_PREC,
+ &_cgmb_REAL_PREC,
+ &_cgmb_INDEX_PREC,
+ &_cgmb_COLR_PREC,
+ &_cgmb_COLR_INDEX_PREC,
+ &_cgmb_MAX_COLR_INDEX,
+ &_cgmb_COLR_VALUE_EXT,
+ &_cgmb_MF_ELEM_LIST,
+ &_cgmb_MF_DEFAULTS_RPL,
+ &_cgmb_FONT_LIST,
+ &_cgmb_CHAR_SET_LIST,
+ &_cgmb_CHAR_CODING,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
+
+CGM_FUNC *_cgmb_picture[] = {
+ &_cgmb_NULL,
+ &_cgmb_SCALE_MODE,
+ &_cgmb_COLR_MODE,
+ &_cgmb_LINE_WIDTH_MODE,
+ &_cgmb_MARKER_SIZE_MODE,
+ &_cgmb_EDGE_WIDTH_MODE,
+ &_cgmb_VDC_EXTENT,
+ &_cgmb_BACK_COLR,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL };
+
+CGM_FUNC *_cgmb_control[] = {
+ &_cgmb_NULL,
+ &_cgmb_VDC_INTEGER_PREC,
+ &_cgmb_VDC_REAL_PREC,
+ &_cgmb_AUX_COLR,
+ &_cgmb_TRANSPARENCY,
+ &_cgmb_CLIP_RECT,
+ &_cgmb_CLIP,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL };
+
+CGM_FUNC *_cgmb_primitive[] = {
+ &_cgmb_NULL,
+ &_cgmb_LINE,
+ &_cgmb_DISJT_LINE,
+ &_cgmb_MARKER,
+ &_cgmb_TEXT,
+ &_cgmb_RESTR_TEXT,
+ &_cgmb_APND_TEXT,
+ &_cgmb_POLYGON,
+ &_cgmb_POLYGON_SET,
+ &_cgmb_CELL_ARRAY,
+ &_cgmb_GDP,
+ &_cgmb_RECT,
+ &_cgmb_CIRCLE,
+ &_cgmb_ARC_3_PT,
+ &_cgmb_ARC_3_PT_CLOSE,
+ &_cgmb_ARC_CTR,
+ &_cgmb_ARC_CTR_CLOSE,
+ &_cgmb_ELLIPSE,
+ &_cgmb_ELLIP_ARC,
+ &_cgmb_ELLIP_ARC_CLOSE,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
+
+CGM_FUNC *_cgmb_attributes[] = {
+ &_cgmb_NULL,
+ &_cgmb_LINE_INDEX,
+ &_cgmb_LINE_TYPE,
+ &_cgmb_LINE_WIDTH,
+ &_cgmb_LINE_COLR,
+ &_cgmb_MARKER_INDEX,
+ &_cgmb_MARKER_TYPE,
+ &_cgmb_MARKER_WIDTH,
+ &_cgmb_MARKER_COLR,
+ &_cgmb_TEXT_INDEX,
+ &_cgmb_TEXT_FONT_INDEX,
+ &_cgmb_TEXT_PREC,
+ &_cgmb_CHAR_EXPAN,
+ &_cgmb_CHAR_SPACE,
+ &_cgmb_TEXT_COLR,
+ &_cgmb_CHAR_HEIGHT,
+ &_cgmb_CHAR_ORI,
+ &_cgmb_TEXT_PATH,
+ &_cgmb_TEXT_ALIGN,
+ &_cgmb_CHAR_SET_INDEX,
+ &_cgmb_ALT_CHAR_SET,
+ &_cgmb_FILL_INDEX,
+ &_cgmb_INT_STYLE,
+ &_cgmb_FILL_COLR,
+ &_cgmb_HATCH_INDEX,
+ &_cgmb_PAT_INDEX,
+ &_cgmb_EDGE_INDEX,
+ &_cgmb_EDGE_TYPE,
+ &_cgmb_EDGE_WIDTH,
+ &_cgmb_EDGE_COLR,
+ &_cgmb_EDGE_VIS,
+ &_cgmb_FILL_REF_PT,
+ &_cgmb_PAT_TABLE,
+ &_cgmb_PAT_SIZE,
+ &_cgmb_COLR_TABLE,
+ &_cgmb_ASF,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL };
+
+CGM_FUNC *_cgmb_escape[] = {
+ &_cgmb_NULL,
+ &_cgmb_ESCAPE,
+ NULL};
+
+CGM_FUNC *_cgmb_external[] = {
+ &_cgmb_NULL,
+ &_cgmb_MESSAGE,
+ &_cgmb_APPL_DATA,
+ NULL };
+
+CGM_FUNC *_cgmb_segment[] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
+
+CGM_FUNC **_cgmb_comandos[] = {
+ _cgmb_delimiter,
+ _cgmb_metafile,
+ _cgmb_picture,
+ _cgmb_control,
+ _cgmb_primitive,
+ _cgmb_attributes,
+ _cgmb_escape,
+ _cgmb_external,
+ _cgmb_segment,
+ NULL };
+
+/************************************************
+* *
+* Funcoes para binario *
+* *
+************************************************/
+
+int cgm_getfilepos ( void )
+{
+ if (cdcgmcountercb)
+ return cdcgmcountercb ( intcgm_canvas, (ftell ( intcgm_cgm.fp )*100.)/intcgm_cgm.file_size );
+
+ return 0;
+}
+
+#define cgmb_getw cgmb_getu16
+#define cgmb_getb(b) cgmb_getc((unsigned char *)(b))
+
+static void cgmb_donothing ( void )
+{
+ intcgm_cgm.bc=intcgm_cgm.len;
+}
+
+int cgmb_exec_comand ( int classe, int id )
+{
+ int err;
+
+ if ( _cgmb_comandos[classe][id]==NULL )
+ {
+ cgmb_donothing();
+ return 0;
+ }
+
+ err = (*_cgmb_comandos[classe][id])();
+
+ if ( err == -1 )
+ return 1;
+ else if ( err )
+ {
+ cgmb_donothing();
+ return 0;
+ }
+
+ return 0;
+}
+
+int cgmb_getbit ( unsigned char *b )
+{
+ static unsigned char b1;
+
+ if ( intcgm_cgm.pc==0 || intcgm_cgm.pc==8 )
+ {
+ b1 = intcgm_cgm.buff.dados[intcgm_cgm.bc];
+ intcgm_cgm.bc++;
+
+ if ( intcgm_cgm.bc > intcgm_cgm.len )
+ {
+ return 1;
+ }
+
+ intcgm_cgm.pc=0;
+ }
+
+ *b = b1;
+
+ switch ( intcgm_cgm.pc )
+ {
+ case 0:
+ *b = ( *b | 0x0080 ) >> 7;
+ break;
+ case 1:
+ *b = ( *b | 0x0040 ) >> 6;
+ break;
+ case 2:
+ *b = ( *b | 0x0020 ) >> 5;
+ break;
+ case 3:
+ *b = ( *b | 0x0010 ) >> 4;
+ break;
+ case 4:
+ *b = ( *b | 0x0008 ) >> 3;
+ break;
+ case 5:
+ *b = ( *b | 0x0004 ) >> 2;
+ break;
+ case 6:
+ *b = ( *b | 0x0002 ) >> 1;
+ break;
+ case 7:
+ *b = ( *b | 0x0001 );
+ break;
+ }
+
+ intcgm_cgm.pc++;
+
+ return 0;
+}
+
+int cgmb_get2bit ( unsigned char *b )
+{
+ static unsigned char b1;
+
+ if ( intcgm_cgm.pc==0 || intcgm_cgm.pc==8 )
+ {
+ b1 = intcgm_cgm.buff.dados[intcgm_cgm.bc];
+ intcgm_cgm.bc++;
+
+ if ( intcgm_cgm.bc > intcgm_cgm.len ) return 1;
+
+ intcgm_cgm.pc=0;
+ }
+
+ *b = b1;
+
+ switch ( intcgm_cgm.pc )
+ {
+ case 0:
+ *b = ( *b | 0x00C0 ) >> 6;
+ break;
+ case 2:
+ *b = ( *b | 0x0030 ) >> 4;
+ break;
+ case 4:
+ *b = ( *b | 0x000C ) >> 2;
+ break;
+ case 6:
+ *b = ( *b | 0x0003 );
+ break;
+ }
+
+ intcgm_cgm.pc += 2;
+
+ return 0;
+}
+
+
+int cgmb_get4bit ( unsigned char *b )
+{
+ static unsigned char b1;
+
+ if ( intcgm_cgm.pc==0 || intcgm_cgm.pc==8 )
+ {
+ b1 = intcgm_cgm.buff.dados[intcgm_cgm.bc];
+ intcgm_cgm.bc++;
+
+ if ( intcgm_cgm.bc > intcgm_cgm.len ) return 1;
+
+ intcgm_cgm.pc=0;
+ }
+
+ *b = b1;
+
+ switch ( intcgm_cgm.pc )
+ {
+ case 0:
+ *b = ( *b | 0x00F0 ) >> 4;
+ break;
+ case 4:
+ *b = ( *b | 0x000F );
+ break;
+ }
+
+ intcgm_cgm.pc += 4;
+
+ return 0;
+}
+
+int cgmb_getw ( unsigned short * );
+
+int cgmb_getc ( unsigned char *b )
+{
+ *b = intcgm_cgm.buff.dados[intcgm_cgm.bc];
+ intcgm_cgm.bc++;
+
+ if ( intcgm_cgm.bc > intcgm_cgm.len ) return 1;
+
+ return 0;
+}
+
+int cgmb_geti8 ( signed char *b )
+{
+ unsigned char b1;
+
+ if ( cgmb_getb ( &b1 ) ) return 1;
+
+ *b = (signed char) b1;
+
+ return 0;
+}
+
+int cgmb_geti16 ( short *b )
+{
+ unsigned char b1, b2;
+
+ if ( cgmb_getb ( &b1 ) ) return 1;
+ if ( cgmb_getb ( &b2 ) ) return 1;
+
+ *b = ( b1<<8 ) | b2;
+
+ return 0;
+}
+
+int cgmb_geti24 ( long *b )
+{
+ unsigned char b1, b2, b3;
+
+ if ( cgmb_getb ( &b1 ) ) return 1;
+ if ( cgmb_getb ( &b2 ) ) return 1;
+ if ( cgmb_getb ( &b3 ) ) return 1;
+
+ *b = ( b1<<16 ) | ( b2<<8 ) | b3;
+
+ return 0;
+}
+
+int cgmb_geti32 ( long *b )
+{
+ unsigned char b1, b2, b3, b4;
+
+ if ( cgmb_getb ( &b1 ) ) return 1;
+ if ( cgmb_getb ( &b2 ) ) return 1;
+ if ( cgmb_getb ( &b3 ) ) return 1;
+ if ( cgmb_getb ( &b4 ) ) return 1;
+
+ *b = ( b1<<24 ) | ( b2<<16 ) | ( b3<<8 ) | b4;
+
+ return 0;
+}
+
+int cgmb_getu8 ( unsigned char *b )
+{
+ if ( cgmb_getb ( b ) ) return 1;
+
+ return 0;
+}
+
+int cgmb_getu16 ( unsigned short *b )
+{
+ unsigned char b1, b2;
+
+ if ( cgmb_getb ( &b1 ) ) return 1;
+ if ( cgmb_getb ( &b2 ) ) return 1;
+
+ *b = ( b1<<8 ) | b2;
+
+ return 0;
+}
+
+int cgmb_getu24 ( unsigned long *b )
+{
+ unsigned char b1, b2, b3;
+
+ if ( cgmb_getb ( &b1 ) ) return 1;
+ if ( cgmb_getb ( &b2 ) ) return 1;
+ if ( cgmb_getb ( &b3 ) ) return 1;
+
+ *b = ( b1<<16 ) | ( b2<<8 ) | b3;
+
+ return 0;
+}
+
+int cgmb_getu32 ( unsigned long *b )
+{
+ unsigned char b1, b2, b3, b4;
+
+ if ( cgmb_getb ( &b1 ) ) return 1;
+ if ( cgmb_getb ( &b2 ) ) return 1;
+ if ( cgmb_getb ( &b3 ) ) return 1;
+ if ( cgmb_getb ( &b4 ) ) return 1;
+
+ *b = ( b1<<24 ) | ( b2<<16 ) | ( b3<<8 ) | b4;
+
+ return 0;
+}
+
+int cgmb_getfl32 ( float *b )
+{
+ unsigned char b1, b2, b3, b4;
+ union {
+ float f;
+ long l;
+ } r;
+
+ if ( cgmb_getb ( &b1 ) ) return 1;
+ if ( cgmb_getb ( &b2 ) ) return 1;
+ if ( cgmb_getb ( &b3 ) ) return 1;
+ if ( cgmb_getb ( &b4 ) ) return 1;
+
+ r.l = ( b1<<24 ) | ( b2<<16 ) | ( b3<<8 ) | b4;
+ *b = r.f;
+
+ return 0;
+}
+
+int cgmb_getfl64 ( double *b )
+{
+ unsigned char b1, b2, b3, b4, b5, b6, b7, b8;
+ union {
+ double d;
+ long l[2];
+ } r;
+
+ if ( cgmb_getb ( &b1 ) ) return 1;
+ if ( cgmb_getb ( &b2 ) ) return 1;
+ if ( cgmb_getb ( &b3 ) ) return 1;
+ if ( cgmb_getb ( &b4 ) ) return 1;
+ if ( cgmb_getb ( &b5 ) ) return 1;
+ if ( cgmb_getb ( &b6 ) ) return 1;
+ if ( cgmb_getb ( &b7 ) ) return 1;
+ if ( cgmb_getb ( &b8 ) ) return 1;
+
+ r.l[1] = ( b1<<24 ) | ( b2<<16 ) | ( b3<<8 ) | b4;
+ r.l[0] = ( b5<<24 ) | ( b6<<16 ) | ( b7<<8 ) | b8;
+ *b = r.d;
+
+ return 0;
+}
+
+int cgmb_getfx32 ( float *b )
+{
+ short si;
+ unsigned short ui;
+
+ if ( cgmb_geti16 ( &si ) ) return 1;
+ if ( cgmb_getu16 ( &ui ) ) return 1;
+
+ *b = (float) ( si + ( ui / 65536.0 ) );
+
+ return 0;
+}
+
+int cgmb_getfx64 ( double *b )
+{
+ long si, ui;
+
+ if ( cgmb_geti32 ( &si ) ) return 1;
+ if ( cgmb_geti32 ( &ui ) ) return 1;
+
+ *b = si + ( (unsigned short) ui / ( 65536.0 * 65536.0 ) );
+
+ return 0;
+}
+
+int cgmb_ter ( void )
+{
+ return 0;
+}
+
+int cgmb_rch ( void )
+{
+ int c, id, len, cont, i;
+ unsigned char ch[2], dummy;
+ unsigned short b;
+ int erro;
+
+ if ( intcgm_cgm.bc!=intcgm_cgm.len )
+ {
+ return 1;
+ }
+
+ intcgm_cgm.bc = 0;
+
+ erro = fread ( ch, 1, 2, intcgm_cgm.fp );
+ if ( erro<2 ) return 1;
+
+ intcgm_cgm.bl += 2;
+
+ b = (ch[0] << 8) + ch[1];
+
+ len = b & 0x001F;
+
+ id = ( b & 0x0FE0 ) >> 5;
+
+ c = ( b & 0xF000 ) >> 12;
+
+ cont = 0;
+
+ if ( len > 30 )
+ {
+ erro = fread ( ch, 1, 2, intcgm_cgm.fp );
+ if ( erro<2 ) return 1;
+
+ intcgm_cgm.bl += 2;
+
+ b = (ch[0] << 8) + ch[1];
+
+ len = b & 0x7FFF;
+ cont = ( b & 0x8000 );
+ }
+
+ intcgm_cgm.len = len;
+
+ if ( intcgm_cgm.len )
+ {
+ if ( intcgm_cgm.len>intcgm_cgm.buff.size )
+ intcgm_cgm.buff.dados = (char *) realloc ( intcgm_cgm.buff.dados, sizeof(char) * intcgm_cgm.len );
+
+ erro = fread ( intcgm_cgm.buff.dados, 1, intcgm_cgm.len, intcgm_cgm.fp );
+ if ( erro<intcgm_cgm.len ) return 1;
+
+ intcgm_cgm.bl += intcgm_cgm.len;
+
+ if ( len & 1 )
+ {
+ erro = fread ( &dummy, 1, 1, intcgm_cgm.fp );
+ if ( erro<1 ) return 1;
+
+ intcgm_cgm.bl += 1;
+ }
+
+ while ( cont )
+ {
+ unsigned char ch[2];
+ unsigned short b;
+ int old_len = intcgm_cgm.len;
+
+ erro = fread ( ch, 1, 2, intcgm_cgm.fp );
+ if ( erro<2 ) return 1;
+
+ intcgm_cgm.bl += 2;
+
+ b = (ch[0] << 8) + ch[1];
+
+ cont = ( b & 0x8000 );
+
+ len = b & 0x7fff;
+
+ intcgm_cgm.len += len;
+
+ if ( intcgm_cgm.len>intcgm_cgm.buff.size )
+ intcgm_cgm.buff.dados = (char *) realloc ( (char *)intcgm_cgm.buff.dados, sizeof(char) * intcgm_cgm.len );
+
+ erro = fread ( &intcgm_cgm.buff.dados[old_len], 1, len, intcgm_cgm.fp );
+ if ( erro<len ) return 1;
+
+ if ( len & 1 )
+ {
+ erro = fread ( &dummy, 1, 1, intcgm_cgm.fp );
+ if ( erro<1 ) return 1;
+ intcgm_cgm.bl += 1;
+ }
+ }
+ }
+
+ cgm_getfilepos ();
+
+ if ( cgmb_exec_comand ( c, id ) ) return 1;
+
+ for ( i=0; i<intcgm_cgm.len-intcgm_cgm.bc; i++ )
+ {
+ unsigned char dummy;
+ if ( cgmb_getb ( &dummy ) ) return 1;
+ }
+
+ return 0;
+}
+
+int cgmb_ci ( unsigned long *ci )
+{
+ unsigned char c;
+ unsigned short i;
+
+ switch ( intcgm_cgm.cix_prec )
+ {
+ case 0: if ( cgmb_getu8 ( &c ) ) return 1;
+ *ci = (unsigned long) c;
+ break;
+ case 1: if ( cgmb_getu16 ( &i ) ) return 1;
+ *ci = (unsigned long) i;
+ break;
+ case 2: if ( cgmb_getu24 ( ci ) ) return 1;
+ break;
+ case 3: if ( cgmb_getu32 ( ci ) ) return 1;
+ break;
+ }
+
+ return 0;
+}
+
+int cgmb_cd ( unsigned long *cd )
+{
+ unsigned char c;
+ unsigned short i;
+
+ switch ( intcgm_cgm.cd_prec )
+ {
+ case 0: if ( cgmb_getu8 ( &c ) ) return 1;
+ *cd = (unsigned long) c;
+ break;
+ case 1: if ( cgmb_getu16 ( &i ) ) return 1;
+ *cd = (unsigned long) i;
+ break;
+ case 2: if ( cgmb_getu24 ( cd ) ) return 1;
+ break;
+ case 3: if ( cgmb_getu32 ( cd ) ) return 1;
+ break;
+ }
+
+ return 0;
+}
+
+int cgmb_rgb ( unsigned long *r, unsigned long *g, unsigned long *b )
+{
+ if ( cgmb_cd ( r ) ) return 1;
+ if ( cgmb_cd ( g ) ) return 1;
+ if ( cgmb_cd ( b ) ) return 1;
+
+ return 0;
+}
+
+int cgmb_ix ( long *ix )
+{
+ signed char c;
+ short i;
+
+ switch ( intcgm_cgm.ix_prec.b_prec )
+ {
+ case 0: if ( cgmb_geti8 ( &c ) ) return 1;
+ *ix = (long) c;
+ break;
+ case 1: if ( cgmb_geti16 ( &i ) ) return 1;
+ *ix = (long) i;
+ break;
+ case 2: if ( cgmb_geti24 ( ix ) ) return 1;
+ break;
+ case 3: if ( cgmb_geti32 ( ix ) ) return 1;
+ break;
+ }
+
+ return 0;
+}
+
+int cgmb_e ( short *e )
+{
+ return cgmb_geti16 ( e );
+}
+
+int cgmb_i ( long *li )
+{
+ signed char c;
+ short i;
+
+ switch ( intcgm_cgm.int_prec.b_prec )
+ {
+ case 0: if ( cgmb_geti8 ( &c ) ) return 1;
+ *li = (long) c;
+ break;
+ case 1: if ( cgmb_geti16 ( &i ) ) return 1;
+ *li = (long) i;
+ break;
+ case 2: if ( cgmb_geti24 ( li ) ) return 1;
+ break;
+ case 3: if ( cgmb_geti32 ( li ) ) return 1;
+ break;
+ }
+
+ return 0;
+}
+
+int cgmb_u ( unsigned long *ui )
+{
+ unsigned char c;
+ unsigned short i;
+
+ switch ( intcgm_cgm.int_prec.b_prec )
+ {
+ case 0: if ( cgmb_getu8 ( &c ) ) return 1;
+ *ui = (unsigned long) c;
+ break;
+ case 1: if ( cgmb_getu16 ( &i ) ) return 1;
+ *ui = (unsigned long) i;
+ break;
+ case 2: if ( cgmb_getu24 ( ui ) ) return 1;
+ break;
+ case 3: if ( cgmb_getu32 ( ui ) ) return 1;
+ break;
+ }
+
+ return 0;
+}
+
+int cgmb_r ( double *d )
+{
+ float f;
+
+ switch ( intcgm_cgm.real_prec.b_prec )
+ {
+ case 0: if ( cgmb_getfl32 ( &f ) ) return 1;
+ *d = (double) f;
+ break;
+ case 1: if ( cgmb_getfl64 ( d ) ) return 1;
+ break;
+ case 2: if ( cgmb_getfx32 ( &f ) ) return 1;
+ *d = (double) f;
+ break;
+ case 3: if ( cgmb_getfx64 ( d ) ) return 1;
+ break;
+ }
+
+ return 0;
+}
+
+int cgmb_s ( char **str )
+{
+ register unsigned i = 0;
+ unsigned char l;
+ unsigned short l1;
+ unsigned short cont;
+ char *s = NULL;
+
+ cont = 1;
+
+ if ( cgmb_getu8 ( &l ) ) return 1;
+
+ l1 = l;
+
+ while ( cont )
+ {
+ if ( l > 254 )
+ {
+ if ( cgmb_getu16 ( &l1 ) ) return 1;
+ cont = ( l1 & 0x8000);
+ l1 &= 0x7fff;
+ }
+ else
+ cont = 0;
+
+ s = (char *)realloc ( (unsigned char *)s, (sizeof ( char ) * l1) + 1 );
+
+ for ( i=0; i<l1; i++ )
+ {
+ unsigned char k;
+ if ( cgmb_getb ( &k ) ) return 1;
+ s[i] = (char) k;
+ }
+
+ }
+ s[i] = '\0';
+
+ *str = s;
+
+ return 0;
+}
+
+int cgmb_vdc ( double *vdc )
+{
+ signed char c;
+ short i;
+ long l;
+ float f;
+
+ if ( intcgm_cgm.vdc_type == 0 )
+ switch ( intcgm_cgm.vdc_int.b_prec )
+ {
+ case 0: if ( cgmb_geti8 ( &c ) ) return 1;
+ *vdc = (double) c;
+ break;
+ case 1: if ( cgmb_geti16 ( &i ) ) return 1;
+ *vdc = (double) i;
+ break;
+ case 2: if ( cgmb_geti24 ( &l ) ) return 1;
+ *vdc = (double) l;
+ break;
+ case 3: if ( cgmb_geti32 ( &l ) ) return 1;
+ *vdc = (double) l;
+ break;
+ }
+ else
+ switch ( intcgm_cgm.vdc_real.b_prec )
+ {
+ case 0: if ( cgmb_getfl32 ( &f ) ) return 1;
+ *vdc = (double) f;
+ break;
+ case 1: if ( cgmb_getfl64 ( vdc ) ) return 1;
+ break;
+ case 2: if ( cgmb_getfx32 ( &f ) ) return 1;
+ *vdc = (double) f;
+ break;
+ case 3: if ( cgmb_getfx64 ( vdc ) ) return 1;
+ break;
+ }
+
+ return 0;
+}
+
+int cgmb_p ( double *x, double *y )
+{
+ if ( cgmb_vdc ( x ) ) return 1;
+ if ( cgmb_vdc ( y ) ) return 1;
+
+ return 0;
+}
+
+int cgmb_co ( void *co )
+{
+ if ( intcgm_cgm.clrsm == 0 ) /* indexed */
+ {
+ unsigned long *ci = (unsigned long *) co;
+ if ( cgmb_ci ( ci ) ) return 1;
+ }
+ else
+ {
+ unsigned long *rgb = (unsigned long *) co;
+ if ( cgmb_rgb ( &rgb[0], &rgb[1], &rgb[2] ) ) return 1;
+ }
+
+ return 0;
+}
+
+int cgmb_pixeli ( unsigned long *ci, int localp )
+{
+ unsigned char c;
+ unsigned short i;
+
+ if ( localp==0 )
+ {
+ if ( intcgm_cgm.cix_prec==0 ) localp = 8;
+ else if ( intcgm_cgm.cix_prec==1 ) localp = 16;
+ else if ( intcgm_cgm.cix_prec==2 ) localp = 24;
+ else if ( intcgm_cgm.cix_prec==3 ) localp = 32;
+ }
+
+ switch ( localp )
+ {
+ case 1: if ( cgmb_getbit ( &c ) ) return 1;
+ *ci = (unsigned long) c;
+ break;
+ case 2: if ( cgmb_get2bit ( &c ) )
+ *ci = (unsigned long) c;
+ return 1;
+ break;
+ case 4: if ( cgmb_get4bit ( &c ) )
+ *ci = (unsigned long) c;
+ return 1;
+ break;
+ case 8: if ( cgmb_getu8 ( &c ) ) return 1;
+ *ci = (unsigned long) c;
+ break;
+ case 16: if ( cgmb_getu16 ( &i ) ) return 1;
+ *ci = (unsigned long) i;
+ break;
+ case 24: if ( cgmb_getu24 ( ci ) ) return 1;
+ break;
+ case 32: if ( cgmb_getu32 ( ci ) ) return 1;
+ break;
+ }
+
+ return 0;
+}
+
+int cgmb_pixeld ( unsigned long *cd, int localp )
+{
+ unsigned char c;
+ unsigned short i;
+
+ if ( localp==0 )
+ {
+ if ( intcgm_cgm.cd_prec==0 ) localp = 8;
+ else if ( intcgm_cgm.cd_prec==1 ) localp = 16;
+ else if ( intcgm_cgm.cd_prec==2 ) localp = 24;
+ else if ( intcgm_cgm.cd_prec==3 ) localp = 32;
+ }
+
+ switch ( localp )
+ {
+ case 1: if ( cgmb_getbit ( &c ) ) return 1;
+ *cd = (unsigned long) c;
+ break;
+ case 2: if ( cgmb_get2bit ( &c ) ) return 1;
+ *cd = (unsigned long) c;
+ break;
+ case 4: if ( cgmb_get4bit ( &c ) )
+ *cd = (unsigned long) c;
+ return 1;
+ break;
+ case 8: if ( cgmb_getu8 ( &c ) ) return 1;
+ *cd = (unsigned long) c;
+ break;
+ case 16: if ( cgmb_getu16 ( &i ) ) return 1;
+ *cd = (unsigned long) i;
+ break;
+ case 24: if ( cgmb_getu24 ( cd ) ) return 1;
+ break;
+ case 32: if ( cgmb_getu32 ( cd ) ) return 1;
+ break;
+ }
+
+ return 0;
+}
+
+int cgmb_pixelrgb ( unsigned long *r, unsigned long *g, unsigned long *b, int localp )
+{
+ if ( cgmb_pixeld ( r, localp ) ) return 1;
+ if ( cgmb_pixeld ( g, localp ) ) return 1;
+ if ( cgmb_pixeld ( b, localp ) ) return 1;
+
+ return 0;
+}
+
+int cgmb_getpixel ( void *co, int localp )
+{
+ if ( intcgm_cgm.clrsm == 0 ) /* indexed */
+ {
+ unsigned long *ci = (unsigned long *) co;
+ if ( cgmb_pixeli ( ci, localp ) ) return 1;
+ }
+ else
+ {
+ unsigned long *rgb = (unsigned long *) co;
+ if ( cgmb_pixelrgb ( &rgb[0], &rgb[1], &rgb[2], localp ) ) return 1;
+ }
+
+ return 0;
+}
+
+/************************************************
+* *
+* Funcoes para clear text *
+* *
+************************************************/
+
+void strlower ( char *string )
+{
+ int i;
+ for ( i=0; string[i]!='\0'; i++ )
+ string[i] = tolower ( string[i] );
+}
+
+char *cgmt_getsep (void)
+{
+ static char ch[256];
+
+ fscanf ( intcgm_cgm.fp, "%[ \r\n\t\v\f,]", ch );
+
+ return ch;
+}
+
+void cgmt_getcom (void)
+{
+ char chr[256], c;
+
+ while ( (c = fgetc( intcgm_cgm.fp )) == '%' )
+ {
+ fscanf ( intcgm_cgm.fp, "%[^%]%%", chr );
+
+ cgmt_getsep();
+ }
+
+ ungetc( c, intcgm_cgm.fp );
+}
+
+char *cgmt_getparentheses (void)
+{
+ static char ch[256];
+
+ cgmt_getsep();
+
+ fscanf ( intcgm_cgm.fp, "%[()]", ch );
+
+ return ch;
+}
+
+int cgmt_ter ( void )
+{
+ char c;
+
+ cgmt_getcom();
+
+ cgmt_getsep();
+
+ fscanf ( intcgm_cgm.fp, "%c", &c );
+
+ if ( c=='/' || c==';' ) return 0;
+
+ ungetc ( c, intcgm_cgm.fp );
+
+ return 1;
+}
+
+int cgmt_rch ( void )
+{
+ char chr[256];
+ char *pt;
+ int i, j;
+
+ cgmt_getsep();
+
+ cgmt_getcom();
+
+/* addcounter();*/
+
+ fscanf ( intcgm_cgm.fp, "%[^ \r\n\t\v\f,/;%\"()]", chr );
+
+ pt = strtok(chr,"_$");
+
+ while ( (pt = strtok ( NULL, "_$" )) )
+ strcat ( chr, pt );
+
+ strlower(chr);
+
+ for ( i=0; _cgmt_comandos[i]!=NULL; i++ )
+ {
+ for ( j=0; _cgmt_comandos[i][j]!=NULL; j++ )
+ {
+ if ( strcmp( chr, _cgmt_comandos[i][j]->nome )==0 )
+ {
+ int r = (*_cgmt_comandos[i][j]->func)();
+ cgm_getfilepos ();
+ return r;
+ }
+ }
+ }
+
+
+ return 0;
+}
+
+int cgmt_i ( long *i )
+{
+ cgmt_getsep();
+
+ cgmt_getcom();
+
+ if ( fscanf( intcgm_cgm.fp, "%ld", i ) ) return 0;
+
+ return 1;
+}
+
+int cgmt_ci ( unsigned long *ci )
+{
+ return cgmt_i ( (long*)ci );
+}
+
+int cgmt_cd ( unsigned long *cd )
+{
+ return cgmt_i ( (long *) cd );
+}
+
+int cgmt_rgb ( unsigned long *r, unsigned long *g, unsigned long *b )
+{
+ if ( cgmt_cd ( r ) ) return 1;
+
+ if ( cgmt_cd ( g ) ) return 1;
+
+ if ( cgmt_cd ( b ) ) return 1;
+
+ return 0;
+}
+
+int cgmt_ix ( long *ix )
+{
+ return cgmt_i ( (long *) ix );
+}
+
+int cgmt_e ( short *e, const char **el )
+{
+ char chr[256];
+ int i;
+ char *pt;
+
+ cgmt_getsep();
+
+ cgmt_getcom();
+
+ fscanf ( intcgm_cgm.fp, "%[^ \r\n\t\v\f,/;%\"\']", chr );
+
+ strlower(chr);
+
+ pt = strtok(chr,"_$");
+
+ while ( (pt = strtok ( NULL, "_$" )) )
+ strcat ( chr, pt );
+
+ for ( i=0; el[i]!=NULL; i++ )
+ if ( strcmp( chr, el[i] ) == 0 )
+ {
+ *e = i;
+ return 0;
+ };
+
+ return 1;
+}
+
+int cgmt_r ( double *f )
+{
+ cgmt_getsep();
+
+ cgmt_getcom();
+
+ if ( fscanf( intcgm_cgm.fp, "%lg", f ) ) return 0;
+
+ return 1;
+}
+
+int cgmt_s ( char **str )
+{
+ char c, delim;
+ int intcgm_block = 80;
+ int i = 0;
+
+ *str = (char *) malloc ( intcgm_block*sizeof(char) );
+
+ strcpy ( *str, "" );
+
+ cgmt_getsep();
+
+ cgmt_getcom();
+
+ delim = fgetc ( intcgm_cgm.fp );
+
+ if ( delim != '"' && delim != '\'' ) return 1;
+
+ do
+ {
+ if ( (c=fgetc(intcgm_cgm.fp))==delim )
+ if ( (c=fgetc(intcgm_cgm.fp))==delim )
+ (*str)[i++] = c;
+ else
+ {
+ ungetc(c,intcgm_cgm.fp);
+ break;
+ }
+ else
+ (*str)[i++] = c;
+
+ if ( (i+1)==intcgm_block )
+ {
+ intcgm_block *= 2;
+
+ *str = (char *) realloc ( *str, intcgm_block*sizeof(char) );
+ }
+ } while ( 1 );
+
+ (*str)[i] = '\0';
+
+ /* addcounter();*/
+
+ return 0;
+}
+
+int cgmt_vdc ( double *vdc )
+{
+ long l;
+
+ if ( intcgm_cgm.vdc_type==0 )
+ {
+ if ( cgmt_i ( &l ) ) return 1;
+ *vdc = (double) l;
+ return 0;
+ }
+ else
+ return cgmt_r ( vdc );
+}
+
+int cgmt_p ( double *x, double *y )
+{
+ cgmt_getparentheses();
+
+ if ( cgmt_vdc ( x ) ) return 1;
+
+ if ( cgmt_vdc ( y ) ) return 1;
+
+ cgmt_getparentheses();
+
+ return 0;
+}
+
+int cgmt_co ( void *co )
+{
+ if ( intcgm_cgm.clrsm == 0 ) /* indexed */
+ {
+ unsigned long *ci = (unsigned long*)co;
+ if ( cgmt_ci ( ci ) ) return 1;
+ }
+ else
+ {
+ unsigned long *cb = (unsigned long *) co;
+ if ( cgmt_rgb ( &cb[0], &cb[1], &cb[2] ) ) return 1;
+ }
+
+ return 0;
+}
diff --git a/cd/src/intcgm/intcgm2.h b/cd/src/intcgm/intcgm2.h
new file mode 100755
index 0000000..d7f5204
--- /dev/null
+++ b/cd/src/intcgm/intcgm2.h
@@ -0,0 +1,52 @@
+
+int cgm_getfilepos ( void );
+
+int cgmb_exec_comand ( int, int );
+int cgmb_geti8 ( signed char * );
+int cgmb_geti16 ( short * );
+int cgmb_geti24 ( long * );
+int cgmb_geti32 ( long * );
+int cgmb_getu8 ( unsigned char * );
+int cgmb_getu16 ( unsigned short * );
+int cgmb_getu24 ( unsigned long * );
+int cgmb_getu32 ( unsigned long * );
+int cgmb_getfl32 ( float * );
+int cgmb_getfl64 ( double * );
+int cgmb_getfx32 ( float * );
+int cgmb_getfx64 ( double * );
+int cgmb_ter ( void );
+int cgmb_rch ( void );
+int cgmb_ci ( unsigned long * );
+int cgmb_cd ( unsigned long * );
+int cgmb_rgb ( unsigned long *, unsigned long *, unsigned long * );
+int cgmb_ix ( long * );
+int cgmb_e ( short * );
+int cgmb_i ( long * );
+int cgmb_u ( unsigned long * );
+int cgmb_r ( double * );
+int cgmb_s ( char ** );
+int cgmb_vdc ( double * );
+int cgmb_p ( double *, double * );
+int cgmb_co ( void * );
+int cgmb_getpixel ( void *, int );
+int cgmb_getc ( unsigned char * );
+
+char *cgmt_getsep ( void );
+void cgmt_getcom ( void );
+char *cgmt_getparentheses ( void );
+int cgmt_ter ( void );
+int cgmt_rch ( void );
+int cgmt_i ( long * );
+int cgmt_ci ( unsigned long * );
+int cgmt_cd ( unsigned long * );
+int cgmt_rgb ( unsigned long *, unsigned long *, unsigned long * );
+int cgmt_ix ( long * );
+int cgmt_e ( short *, const char ** );
+int cgmt_r ( double * );
+int cgmt_s ( char ** );
+int cgmt_vdc ( double * );
+int cgmt_p ( double *, double * );
+int cgmt_co ( void * );
+
+
+
diff --git a/cd/src/intcgm/intcgm4.c b/cd/src/intcgm/intcgm4.c
new file mode 100755
index 0000000..4c8afe0
--- /dev/null
+++ b/cd/src/intcgm/intcgm4.c
@@ -0,0 +1,1265 @@
+#define _INTCGM4_C_
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <math.h>
+
+#include <cd.h>
+#include <cdcgm.h>
+
+#include "list.h"
+#include "types.h"
+#include "intcgm.h"
+#include "intcgm2.h"
+#include "intcgm4.h"
+#include "intcgm6.h"
+#include "ellipse.h"
+#include "circle.h"
+#include "sism.h"
+
+#ifndef PI
+#define PI 3.1415931
+#endif
+#define TWOPI 2*PI
+
+static double myhypot ( double x, double y )
+{
+ return sqrt ( x*x + y*y );
+}
+
+int cgm_do_vdcext ( tpoint first, tpoint second )
+{
+ double width, height;
+ double tmp;
+ double razao_vp;
+ double razao_wn;
+ int w_pixel, h_pixel;
+ double w_mm, h_mm;
+
+ if ( first.x > second.x )
+ {
+ tmp = first.x;
+ first.x = second.x;
+ second.x = tmp;
+ }
+
+ if ( first.y > second.y )
+ {
+ tmp = first.y;
+ first.y = second.y;
+ second.y = tmp;
+ }
+
+ width = intcgm_view_xmax-intcgm_view_xmin+1;
+ height = intcgm_view_ymax-intcgm_view_ymin+1;
+
+ razao_vp = (double) width/ (double) height;
+ razao_wn = (second.x-first.x) / (second.y-first.y);
+
+ if ( razao_vp > razao_wn )
+ {
+ first.x -= ((second.y-first.y)*razao_vp - (second.x-first.x)) / 2.;
+ second.x = (second.y-first.y)*razao_vp+first.x;
+ }
+ else
+ {
+ first.y -= ((second.x-first.x)/razao_vp - (second.y-first.y)) / 2.;
+ second.y = (second.x-first.x)/razao_vp+first.y;
+ }
+
+ intcgm_vdc_ext.xmin = first.x;
+ intcgm_vdc_ext.xmax = second.x;
+ intcgm_vdc_ext.ymin = first.y;
+ intcgm_vdc_ext.ymax = second.y;
+
+ intcgm_scale_factor_x = width/(second.x-first.x);
+ intcgm_scale_factor_y = height/(second.y-first.y);
+ intcgm_scale_factor = sqrt(width * width + height * height)/sqrt((second.x-first.x)+(second.y-first.y));
+ cdCanvasGetSize (intcgm_canvas, &w_pixel, &h_pixel, &w_mm, &h_mm );
+ intcgm_scale_factor_mm_x = w_pixel/w_mm;
+ intcgm_scale_factor_mm_y = h_pixel/h_mm;
+
+ if ( intcgm_cgm.drawing_mode==ABSTRACT )
+ {
+ intcgm_clip_xmin = cgm_canvas2vdcx ( intcgm_view_xmin );
+ intcgm_clip_xmax = cgm_canvas2vdcx ( intcgm_view_xmax );
+ intcgm_clip_ymin = cgm_canvas2vdcy ( intcgm_view_ymin );
+ intcgm_clip_ymax = cgm_canvas2vdcy ( intcgm_view_ymax );
+ }
+ else
+ {
+ intcgm_clip_xmin = intcgm_vdc_ext.xmin*intcgm_cgm.scaling_mode.scale_factor;
+ intcgm_clip_xmax = intcgm_vdc_ext.xmax*intcgm_cgm.scaling_mode.scale_factor;
+ intcgm_clip_ymin = intcgm_vdc_ext.ymin*intcgm_cgm.scaling_mode.scale_factor;
+ intcgm_clip_ymax = intcgm_vdc_ext.ymax*intcgm_cgm.scaling_mode.scale_factor;
+ }
+
+ cdCanvasClipArea (intcgm_canvas, cgm_vdcx2canvas(first.x), cgm_vdcx2canvas(second.x),
+ cgm_vdcy2canvas(first.y), cgm_vdcy2canvas(second.y) );
+ cdCanvasClip(intcgm_canvas, CD_CLIPOFF );
+
+ return 0;
+}
+
+int cgm_do_bckcol ( trgb rgb )
+{
+ long int cor = cdEncodeColor ( (unsigned char) rgb.red,
+ (unsigned char) rgb.green,
+ (unsigned char) rgb.blue );
+
+ cdCanvasSetBackground (intcgm_canvas, cor );
+
+ return 0;
+}
+
+int cgm_do_transp ( int transparency )
+{
+ if ( transparency )
+ cdCanvasBackOpacity (intcgm_canvas, CD_TRANSPARENT );
+ else
+ cdCanvasBackOpacity (intcgm_canvas, CD_OPAQUE );
+
+ return 0;
+}
+
+int cgm_do_clprec ( tpoint first, tpoint second )
+{
+ double tmp;
+
+ if ( first.x > second.x )
+ {
+ tmp = first.x;
+ first.x = second.x;
+ second.x = tmp;
+ }
+
+ if ( first.y > second.y )
+ {
+ tmp = first.y;
+ first.y = second.y;
+ second.y = tmp;
+ }
+
+ cdCanvasClipArea (intcgm_canvas, cgm_vdcx2canvas(first.x), cgm_vdcx2canvas(second.x),
+ cgm_vdcy2canvas(first.y), cgm_vdcy2canvas(second.y) );
+
+ return 0;
+}
+
+int cgm_do_clpind ( int indicator )
+{
+ if ( indicator )
+ cdCanvasClip(intcgm_canvas, CD_CLIPAREA );
+ else
+ cdCanvasClip(intcgm_canvas, CD_CLIPOFF );
+
+ return 0;
+}
+
+int cgm_do_polyln ( int n_points, tpoint *pt )
+{
+ int i;
+ long int cor;
+ double bb_xmin, bb_ymin, bb_xmax, bb_ymax;
+
+ cgm_getpolybbox ( pt, n_points, &bb_xmin, &bb_ymin, &bb_xmax, &bb_ymax );
+
+#if 0
+ if ( cgm_vdcx2canvas(bb_xmin) > intcgm_view_xmax || cgm_vdcx2canvas(bb_xmax) < intcgm_view_xmin ||
+ cgm_vdcy2canvas(bb_ymin) > intcgm_view_ymax || cgm_vdcy2canvas(bb_ymax) < intcgm_view_ymin ) return 0;
+#else
+ if ( bb_xmin > intcgm_clip_xmax || bb_xmax < intcgm_clip_xmin ||
+ bb_ymin > intcgm_clip_ymax || bb_ymax < intcgm_clip_ymin ) return 0;
+#endif
+
+ cgm_setlinestyle ( intcgm_line_att.type );
+ cgm_setlinewidth ( intcgm_line_att.width );
+ cor = cgm_getcolor ( intcgm_line_att.color );
+ cdCanvasSetForeground (intcgm_canvas, cor );
+
+ cdCanvasBegin(intcgm_canvas, CD_OPEN_LINES );
+
+ for ( i=0; i<n_points; i++ )
+ cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(pt[i].x), cgm_vdcy2canvas(pt[i].y) );
+
+ cdCanvasEnd (intcgm_canvas);
+
+ return 0;
+}
+
+int cgm_do_incply ( int n_points, tpoint *pt )
+{
+ int i;
+ double x, y;
+ long int cor;
+ double bb_xmin, bb_ymin, bb_xmax, bb_ymax;
+
+ cgm_getincpolybbox ( pt, n_points, &bb_xmin, &bb_ymin, &bb_xmax, &bb_ymax );
+
+#if 0
+ if ( cgm_vdcx2canvas(bb_xmin) > intcgm_view_xmax || cgm_vdcx2canvas(bb_xmax) < intcgm_view_xmin ||
+ cgm_vdcy2canvas(bb_ymin) > intcgm_view_ymax || cgm_vdcy2canvas(bb_ymax) < intcgm_view_ymin ) return 0;
+#else
+ if ( bb_xmin > intcgm_clip_xmax || bb_xmax < intcgm_clip_xmin ||
+ bb_ymin > intcgm_clip_ymax || bb_ymax < intcgm_clip_ymin ) return 0;
+#endif
+
+ cgm_setlinestyle ( intcgm_line_att.type );
+ cgm_setlinewidth ( intcgm_line_att.width );
+ cor = cgm_getcolor ( intcgm_line_att.color );
+ cdCanvasSetForeground (intcgm_canvas, cor );
+
+ cdCanvasBegin(intcgm_canvas, CD_OPEN_LINES );
+
+ x = pt[0].x; y = pt[0].y;
+ cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(pt[0].x), cgm_vdcy2canvas(pt[0].y) );
+
+ for ( i=1; i<n_points; i++ )
+ {
+ x += pt[i].x; y += pt[i].x;
+ cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(x), cgm_vdcy2canvas(y) );
+ }
+
+ cdCanvasEnd (intcgm_canvas);
+
+ return 0;
+}
+
+int cgm_do_djtply ( int n_points, tpoint *pt )
+{
+ int i;
+ long int cor;
+ double bb_xmin, bb_ymin, bb_xmax, bb_ymax;
+
+ cgm_getpolybbox ( pt, n_points, &bb_xmin, &bb_ymin, &bb_xmax, &bb_ymax );
+
+#if 0
+ if ( cgm_vdcx2canvas(bb_xmin) > intcgm_view_xmax || cgm_vdcx2canvas(bb_xmax) < intcgm_view_xmin ||
+ cgm_vdcy2canvas(bb_ymin) > intcgm_view_ymax || cgm_vdcy2canvas(bb_ymax) < intcgm_view_ymin ) return 0;
+#else
+ if ( bb_xmin > intcgm_clip_xmax || bb_xmax < intcgm_clip_xmin ||
+ bb_ymin > intcgm_clip_ymax || bb_ymax < intcgm_clip_ymin ) return 0;
+#endif
+
+ if ( n_points < 2 ) return 1;
+
+ cgm_setlinestyle ( intcgm_line_att.type );
+ cgm_setlinewidth ( intcgm_line_att.width );
+ cor = cgm_getcolor ( intcgm_line_att.color );
+ cdCanvasSetForeground (intcgm_canvas, cor );
+
+ for ( i=0; i<n_points; i=i+2 )
+ cdCanvasLine (intcgm_canvas, cgm_vdcx2canvas(pt[i].x), cgm_vdcy2canvas(pt[i].y),
+ cgm_vdcx2canvas(pt[i+1].x), cgm_vdcy2canvas(pt[i+1].y) );
+
+ return 0;
+}
+
+int cgm_do_indpl ( int n_points, tpoint *pt )
+{
+ int i;
+ long int cor;
+ double bb_xmin, bb_ymin, bb_xmax, bb_ymax;
+
+ cgm_getincpolybbox ( pt, n_points, &bb_xmin, &bb_ymin, &bb_xmax, &bb_ymax );
+
+#if 0
+ if ( cgm_vdcx2canvas(bb_xmin) > intcgm_view_xmax || cgm_vdcx2canvas(bb_xmax) < intcgm_view_xmin ||
+ cgm_vdcy2canvas(bb_ymin) > intcgm_view_ymax || cgm_vdcy2canvas(bb_ymax) < intcgm_view_ymin ) return 0;
+#else
+ if ( bb_xmin > intcgm_clip_xmax || bb_xmax < intcgm_clip_xmin ||
+ bb_ymin > intcgm_clip_ymax || bb_ymax < intcgm_clip_ymin ) return 0;
+#endif
+
+ if ( n_points < 2 ) return 1;
+
+ cgm_setlinestyle ( intcgm_line_att.type );
+ cgm_setlinewidth ( intcgm_line_att.width );
+ cor = cgm_getcolor ( intcgm_line_att.color );
+ cdCanvasSetForeground (intcgm_canvas, cor );
+
+ pt[1].x = pt[0].x + pt[1].x; pt[1].y = pt[0].y + pt[1].y;
+ cdCanvasLine (intcgm_canvas, cgm_vdcx2canvas(pt[0].x), cgm_vdcy2canvas(pt[0].y),
+ cgm_vdcx2canvas(pt[1].x), cgm_vdcy2canvas(pt[1].y) );
+
+ for ( i=2; i<n_points; i=i+2 )
+ {
+ pt[i].x += pt[i-1].x; pt[i].y += pt[i-1].y;
+ pt[i+1].x += pt[i].x; pt[i+1].y += pt[i].y;
+ cdCanvasLine (intcgm_canvas, cgm_vdcx2canvas(pt[i].x), cgm_vdcy2canvas(pt[i].y),
+ cgm_vdcx2canvas(pt[i+1].x), cgm_vdcy2canvas(pt[i+1].y) );
+ }
+
+ return 0;
+}
+
+int cgm_do_polymk ( int n_points, tpoint *pt )
+{
+ int i;
+ long int cor;
+ double bb_xmin, bb_ymin, bb_xmax, bb_ymax;
+
+ cgm_getpolybbox ( pt, n_points, &bb_xmin, &bb_ymin, &bb_xmax, &bb_ymax );
+
+#if 0
+ if ( cgm_vdcx2canvas(bb_xmin) > intcgm_view_xmax || cgm_vdcx2canvas(bb_xmax) < intcgm_view_xmin ||
+ cgm_vdcy2canvas(bb_ymin) > intcgm_view_ymax || cgm_vdcy2canvas(bb_ymax) < intcgm_view_ymin ) return 0;
+#else
+ if ( bb_xmin > intcgm_clip_xmax || bb_xmax < intcgm_clip_xmin ||
+ bb_ymin > intcgm_clip_ymax || bb_ymax < intcgm_clip_ymin ) return 0;
+#endif
+
+ cgm_setmarktype ( intcgm_marker_att.type );
+ cgm_setmarksize ( intcgm_marker_att.size );
+ cor = cgm_getcolor ( intcgm_marker_att.color );
+ cdCanvasSetForeground (intcgm_canvas, cor );
+
+ for ( i=0; i<n_points; i++ )
+ cdCanvasMark (intcgm_canvas, cgm_vdcx2canvas(pt[i].x), cgm_vdcy2canvas(pt[i].y) );
+
+ return 0;
+}
+
+int cgm_do_incplm ( int n_points, tpoint *pt )
+{
+ int i;
+ long int cor;
+ double bb_xmin, bb_ymin, bb_xmax, bb_ymax;
+
+ cgm_getincpolybbox ( pt, n_points, &bb_xmin, &bb_ymin, &bb_xmax, &bb_ymax );
+
+#if 0
+ if ( cgm_vdcx2canvas(bb_xmin) > intcgm_view_xmax || cgm_vdcx2canvas(bb_xmax) < intcgm_view_xmin ||
+ cgm_vdcy2canvas(bb_ymin) > intcgm_view_ymax || cgm_vdcy2canvas(bb_ymax) < intcgm_view_ymin ) return 0;
+#else
+ if ( bb_xmin > intcgm_clip_xmax || bb_xmax < intcgm_clip_xmin ||
+ bb_ymin > intcgm_clip_ymax || bb_ymax < intcgm_clip_ymin ) return 0;
+#endif
+
+ cgm_setmarktype ( intcgm_marker_att.type );
+ cgm_setmarksize ( intcgm_marker_att.size );
+ cor = cgm_getcolor ( intcgm_marker_att.color );
+ cdCanvasSetForeground (intcgm_canvas, cor );
+
+ cdCanvasMark (intcgm_canvas, cgm_vdcx2canvas(pt[0].x), cgm_vdcy2canvas(pt[0].y) );
+
+ for ( i=1; i<n_points; i++ )
+ {
+ pt[i].x += pt[i-1].x; pt[i].y += pt[i-1].y;
+ cdCanvasMark (intcgm_canvas, cgm_vdcx2canvas(pt[i].x), cgm_vdcy2canvas(pt[i].y) );
+ }
+
+ return 0;
+}
+
+int cgm_do_text ( int mode, char *string, tpoint pos )
+{
+ long int cor;
+
+ cor = cgm_getcolor ( intcgm_text_att.color );
+ cdCanvasSetForeground (intcgm_canvas, cor );
+
+ cgm_setfont ( intcgm_text_att.font, intcgm_text_att.style, intcgm_text_att.height );
+
+ cdCanvasText (intcgm_canvas, cgm_vdcx2canvas(pos.x), cgm_vdcy2canvas(pos.y), string );
+
+ return 0;
+}
+
+int cgm_do_txtalign ( int hor, int ver )
+{
+ enum { NORMHORIZ, LEFT, CTR, RIGHT };
+ enum { NORMVERT, TOP, CAP, HALF, BASE, BOTTOM };
+
+ switch (hor)
+ {
+ case NORMHORIZ:
+ switch (ver)
+ {
+ case NORMVERT:
+ cdCanvasTextAlignment(intcgm_canvas, CD_CENTER);
+ break;
+ case TOP:
+ cdCanvasTextAlignment(intcgm_canvas, CD_NORTH);
+ break;
+ case CAP:
+ cdCanvasTextAlignment(intcgm_canvas, CD_NORTH);
+ break;
+ case HALF:
+ cdCanvasTextAlignment(intcgm_canvas, CD_CENTER);
+ break;
+ case BASE:
+ cdCanvasTextAlignment(intcgm_canvas, CD_SOUTH);
+ break;
+ case BOTTOM:
+ cdCanvasTextAlignment(intcgm_canvas, CD_SOUTH);
+ break;
+ }
+ break;
+ case LEFT:
+ switch (ver)
+ {
+ case NORMVERT:
+ cdCanvasTextAlignment(intcgm_canvas, CD_WEST);
+ break;
+ case TOP:
+ cdCanvasTextAlignment(intcgm_canvas, CD_NORTH_WEST);
+ break;
+ case CAP:
+ cdCanvasTextAlignment(intcgm_canvas, CD_NORTH_WEST);
+ break;
+ case HALF:
+ cdCanvasTextAlignment(intcgm_canvas, CD_WEST);
+ break;
+ case BASE:
+ cdCanvasTextAlignment(intcgm_canvas, CD_SOUTH_WEST);
+ break;
+ case BOTTOM:
+ cdCanvasTextAlignment(intcgm_canvas, CD_SOUTH_WEST);
+ break;
+ }
+ break;
+ case CTR:
+ switch (ver)
+ {
+ case NORMVERT:
+ cdCanvasTextAlignment(intcgm_canvas, CD_CENTER);
+ break;
+ case TOP:
+ cdCanvasTextAlignment(intcgm_canvas, CD_NORTH);
+ break;
+ case CAP:
+ cdCanvasTextAlignment(intcgm_canvas, CD_NORTH);
+ break;
+ case HALF:
+ cdCanvasTextAlignment(intcgm_canvas, CD_CENTER);
+ break;
+ case BASE:
+ cdCanvasTextAlignment(intcgm_canvas, CD_SOUTH);
+ break;
+ case BOTTOM:
+ cdCanvasTextAlignment(intcgm_canvas, CD_SOUTH);
+ break;
+ }
+ break;
+ case RIGHT:
+ switch (ver)
+ {
+ case NORMVERT:
+ cdCanvasTextAlignment(intcgm_canvas, CD_EAST);
+ break;
+ case TOP:
+ cdCanvasTextAlignment(intcgm_canvas, CD_NORTH_EAST);
+ break;
+ case CAP:
+ cdCanvasTextAlignment(intcgm_canvas, CD_NORTH_EAST);
+ break;
+ case HALF:
+ cdCanvasTextAlignment(intcgm_canvas, CD_EAST);
+ break;
+ case BASE:
+ cdCanvasTextAlignment(intcgm_canvas, CD_SOUTH_EAST);
+ break;
+ case BOTTOM:
+ cdCanvasTextAlignment(intcgm_canvas, CD_SOUTH_EAST);
+ break;
+ }
+ break;
+ }
+
+ return 0;
+}
+
+int cgm_do_polygn ( int n_points, tpoint *pt )
+{
+ int i;
+ long int cor;
+ double bb_xmin, bb_ymin, bb_xmax, bb_ymax;
+
+ cgm_getpolybbox ( pt, n_points, &bb_xmin, &bb_ymin, &bb_xmax, &bb_ymax );
+
+#if 0
+ if ( cgm_vdcx2canvas(bb_xmin) > intcgm_view_xmax || cgm_vdcx2canvas(bb_xmax) < intcgm_view_xmin ||
+ cgm_vdcy2canvas(bb_ymin) > intcgm_view_ymax || cgm_vdcy2canvas(bb_ymax) < intcgm_view_ymin ) return 0;
+#else
+ if ( bb_xmin > intcgm_clip_xmax || bb_xmax < intcgm_clip_xmin ||
+ bb_ymin > intcgm_clip_ymax || bb_ymax < intcgm_clip_ymin ) return 0;
+#endif
+
+ cor = cgm_getcolor ( intcgm_fill_att.color );
+ cdCanvasSetForeground (intcgm_canvas, cor );
+
+ cgm_setlinewidth ( intcgm_line_att.width );
+
+ if ( intcgm_fill_att.int_style!=HOLLOW && intcgm_fill_att.int_style!=EMPTY )
+ {
+ cdCanvasBegin(intcgm_canvas, cgm_setintstyle ( intcgm_fill_att.int_style ) );
+
+ for ( i=0; i<n_points; i++ )
+ cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(pt[i].x), cgm_vdcy2canvas(pt[i].y) );
+
+ cdCanvasEnd (intcgm_canvas);
+ }
+
+ if ( intcgm_edge_att.visibility==ON )
+ {
+ cor = cgm_getcolor ( intcgm_edge_att.color );
+ cdCanvasSetForeground (intcgm_canvas, cor );
+
+ cgm_setlinewidth ( intcgm_edge_att.width );
+
+ cdCanvasBegin(intcgm_canvas, CD_CLOSED_LINES );
+
+ for ( i=0; i<n_points; i++ )
+ cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(pt[i].x), cgm_vdcy2canvas(pt[i].y) );
+
+ cdCanvasEnd (intcgm_canvas);
+ }
+
+ return 0;
+}
+
+int cgm_do_incplg ( int n_points, tpoint *pt )
+{
+ int i;
+ tpoint p;
+ long int cor;
+ double bb_xmin, bb_ymin, bb_xmax, bb_ymax;
+
+ cgm_getincpolybbox ( pt, n_points, &bb_xmin, &bb_ymin, &bb_xmax, &bb_ymax );
+
+#if 0
+ if ( cgm_vdcx2canvas(bb_xmin) > intcgm_view_xmax || cgm_vdcx2canvas(bb_xmax) < intcgm_view_xmin ||
+ cgm_vdcy2canvas(bb_ymin) > intcgm_view_ymax || cgm_vdcy2canvas(bb_ymax) < intcgm_view_ymin ) return 0;
+#else
+ if ( bb_xmin > intcgm_clip_xmax || bb_xmax < intcgm_clip_xmin ||
+ bb_ymin > intcgm_clip_ymax || bb_ymax < intcgm_clip_ymin ) return 0;
+#endif
+
+ cor = cgm_getcolor ( intcgm_fill_att.color );
+ cdCanvasSetForeground (intcgm_canvas, cor );
+
+ cdCanvasBegin(intcgm_canvas, cgm_setintstyle ( intcgm_fill_att.int_style ) );
+
+ p.x = pt[0].x; p.y = pt[0].y;
+ cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(pt[0].x), cgm_vdcy2canvas(pt[0].y) );
+
+ for ( i=1; i<n_points; i++ )
+ {
+ p.x += pt[i].x; p.y += pt[i].y;
+ cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(p.x), cgm_vdcy2canvas(p.y) );
+ }
+
+ cdCanvasEnd (intcgm_canvas);
+
+ return 0;
+}
+
+int cgm_do_plgset( int incremental, int n_points, tpoint *pt, short *flag )
+{
+ int i, j;
+ tpoint closure;
+ long int cor;
+ int start;
+ int vis = intcgm_edge_att.visibility;
+ double bb_xmin, bb_ymin, bb_xmax, bb_ymax;
+
+ cgm_getpolybbox ( pt, n_points, &bb_xmin, &bb_ymin, &bb_xmax, &bb_ymax );
+
+#if 0
+ if ( cgm_vdcx2canvas(bb_xmin) > intcgm_view_xmax || cgm_vdcx2canvas(bb_xmax) < intcgm_view_xmin ||
+ cgm_vdcy2canvas(bb_ymin) > intcgm_view_ymax || cgm_vdcy2canvas(bb_ymax) < intcgm_view_ymin ) return 0;
+#else
+ if ( bb_xmin > intcgm_clip_xmax || bb_xmax < intcgm_clip_xmin ||
+ bb_ymin > intcgm_clip_ymax || bb_ymax < intcgm_clip_ymin ) return 0;
+#endif
+
+ intcgm_edge_att.visibility = OFF;
+
+ cor = cgm_getcolor ( intcgm_fill_att.color );
+ cdCanvasSetForeground (intcgm_canvas, cor );
+
+ if ( intcgm_fill_att.int_style!=HOLLOW && intcgm_fill_att.int_style!=EMPTY )
+ {
+ cdCanvasBegin(intcgm_canvas, cgm_setintstyle ( intcgm_fill_att.int_style ) );
+ start = 1;
+ for ( i=0; i<n_points; i++ )
+ {
+ if ( start )
+ {
+ closure.x = pt[i].x;
+ closure.y = pt[i].y;
+ start = 0;
+ }
+ else if ( incremental==YES )
+ {
+ pt[i].x = pt[i].x+pt[i-1].x;
+ pt[i].y = pt[i].y+pt[i-1].y;
+ }
+
+ if ( flag[i]==CLOSE_VISIBLE || flag[i]==CLOSE_INVISIBLE )
+ {
+ cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(pt[i].x), cgm_vdcy2canvas(pt[i].y) );
+ cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(closure.x), cgm_vdcy2canvas(closure.y) );
+ start=1;
+ }
+ else
+ cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(pt[i].x), cgm_vdcy2canvas(pt[i].y) );
+ }
+ cdCanvasEnd (intcgm_canvas);
+ }
+
+
+ intcgm_edge_att.visibility = vis;
+
+ if ( intcgm_edge_att.visibility==ON )
+ {
+ int np;
+
+ cor = cgm_getcolor ( intcgm_edge_att.color );
+ cdCanvasSetForeground (intcgm_canvas, cor );
+
+ cgm_setlinewidth ( intcgm_edge_att.width );
+
+ np = 0;
+ start = 0;
+ for ( i=0; i<n_points; i++ )
+ {
+ if ( incremental==YES )
+ {
+ pt[i].x = pt[i].x+pt[i-1].x;
+ pt[i].y = pt[i].y+pt[i-1].y;
+ }
+
+ if ( flag[i]==CLOSE_VISIBLE || (flag[i]==VISIBLE && i==n_points-1) )
+ {
+ cdCanvasBegin(intcgm_canvas, CD_CLOSED_LINES );
+ for ( j=0; j<np; j++ )
+ cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(pt[start+j].x), cgm_vdcy2canvas(pt[start+j].y) );
+ cdCanvasEnd(intcgm_canvas);
+ start += np;
+ np = 0;
+ }
+ else if ( flag[i]==INVISIBLE || flag[i]==CLOSE_INVISIBLE )
+ {
+ cdCanvasBegin(intcgm_canvas, CD_OPEN_LINES );
+ for ( j=0; j<np; j++ )
+ cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(pt[start+j].x), cgm_vdcy2canvas(pt[start+j].y) );
+ cdCanvasEnd(intcgm_canvas);
+ start += np;
+ np = 0;
+ }
+ else
+ np++;
+ }
+ }
+
+ return 0;
+}
+
+int cgm_do_cellar ( tpoint corner1, tpoint corner2, tpoint corner3, int nx,
+ int ny, long color_prec, tcolor *cell )
+{
+ int cx1, cy1, cx2, cy2, cx3, cy3, tmp, i, j;
+ unsigned char *r, *g, *b;
+ double bb_xmin, bb_ymin, bb_xmax, bb_ymax;
+
+ bb_xmin = ( corner1.x < corner2.x ) ? corner1.x : corner2.x;
+ bb_xmax = ( corner1.x > corner2.x ) ? corner1.x : corner2.x;
+ bb_ymin = ( corner1.y < corner2.y ) ? corner1.y : corner2.y;
+ bb_ymax = ( corner1.y > corner2.y ) ? corner1.y : corner2.y;
+
+#if 0
+ if ( cgm_vdcx2canvas(bb_xmin) > intcgm_view_xmax || cgm_vdcx2canvas(bb_xmax) < intcgm_view_xmin ||
+ cgm_vdcy2canvas(bb_ymin) > intcgm_view_ymax || cgm_vdcy2canvas(bb_ymax) < intcgm_view_ymin ) return 0;
+#else
+ if ( bb_xmin > intcgm_clip_xmax || bb_xmax < intcgm_clip_xmin ||
+ bb_ymin > intcgm_clip_ymax || bb_ymax < intcgm_clip_ymin ) return 0;
+#endif
+
+ r = (unsigned char *) malloc ( nx*ny*sizeof(unsigned char) );
+ g = (unsigned char *) malloc ( nx*ny*sizeof(unsigned char) );
+ b = (unsigned char *) malloc ( nx*ny*sizeof(unsigned char) );
+
+ cx1 = cgm_vdcx2canvas(corner1.x);
+ cy1 = cgm_vdcy2canvas(corner1.y);
+ cx2 = cgm_vdcx2canvas(corner2.x);
+ cy2 = cgm_vdcy2canvas(corner2.y);
+ cx3 = cgm_vdcx2canvas(corner3.x);
+ cy3 = cgm_vdcy2canvas(corner3.y);
+
+#if 1
+ if ( cx1<cx3 && cy1==cy3 && cx2==cx3 && cy2>cy3 )
+ {
+ for ( i=0; i<ny; i++ )
+ for ( j=0; j<nx; j++ )
+ {
+ r[nx*i+j] = (unsigned char) cell[nx*i+j].rgb.red;
+ g[nx*i+j] = (unsigned char) cell[nx*i+j].rgb.green;
+ b[nx*i+j] = (unsigned char) cell[nx*i+j].rgb.blue;
+ }
+ }
+ else if ( cx1==cx3 && cy1<cy3 && cx2>cx3 && cy2==cy3 )
+ {
+ tmp = nx; nx = ny; ny = tmp;
+ for ( i=0; i<ny; i++ )
+ for ( j=0; j<nx; j++ )
+ {
+ r[nx*i+j] = (unsigned char) cell[ny*j+i].rgb.red;
+ g[nx*i+j] = (unsigned char) cell[ny*j+i].rgb.green;
+ b[nx*i+j] = (unsigned char) cell[ny*j+i].rgb.blue;
+ }
+ }
+ else if ( cx1<cx3 && cy1==cy3 && cx2==cx3 && cy2<cy3 )
+ {
+ for ( i=0; i<ny; i++ )
+ for ( j=0; j<nx; j++ )
+ {
+ r[nx*i+j] = (unsigned char) cell[nx*(ny-i-1)+j].rgb.red;
+ g[nx*i+j] = (unsigned char) cell[nx*(ny-i-1)+j].rgb.green;
+ b[nx*i+j] = (unsigned char) cell[nx*(ny-i-1)+j].rgb.blue;
+ }
+ }
+ else if ( cx1==cx3 && cy1>cy3 && cx2>cx3 && cy2==cy3 )
+ {
+ tmp = nx; nx = ny; ny = tmp;
+ for ( i=0; i<ny; i++ )
+ for ( j=0; j<nx; j++ )
+ {
+ r[nx*i+j] = (unsigned char) cell[ny*j+(ny-i-1)].rgb.red;
+ g[nx*i+j] = (unsigned char) cell[ny*j+(ny-i-1)].rgb.green;
+ b[nx*i+j] = (unsigned char) cell[ny*j+(ny-i-1)].rgb.blue;
+ }
+ }
+ else if ( cx1>cx3 && cy1==cy3 && cx2==cx3 && cy2>cy3 )
+ {
+ for ( i=0; i<ny; i++ )
+ for ( j=0; j<nx; j++ )
+ {
+ r[nx*i+j] = (unsigned char) cell[nx*i+(nx-j-1)].rgb.red;
+ g[nx*i+j] = (unsigned char) cell[nx*i+(nx-j-1)].rgb.green;
+ b[nx*i+j] = (unsigned char) cell[nx*i+(nx-j-1)].rgb.blue;
+ }
+ }
+ else if ( cx1==cx3 && cy1>cy3 && cx2<cx3 && cy2==cy3 )
+ {
+ tmp = nx; nx = ny; ny = tmp;
+ for ( i=0; i<ny; i++ )
+ for ( j=0; j<nx; j++ )
+ {
+ r[nx*i+j] = (unsigned char) cell[ny*(nx-j-1)+(ny-i-1)].rgb.red;
+ g[nx*i+j] = (unsigned char) cell[ny*(nx-j-1)+(ny-i-1)].rgb.green;
+ b[nx*i+j] = (unsigned char) cell[ny*(nx-j-1)+(ny-i-1)].rgb.blue;
+ }
+ }
+ else if ( cx1>cx3 && cy1==cy3 && cx2==cx3 && cy2<cy3 )
+ {
+ for ( i=0; i<ny; i++ )
+ for ( j=0; j<nx; j++ )
+ {
+ r[nx*i+j] = (unsigned char) cell[nx*(ny-i-1)+(nx-j-1)].rgb.red;
+ g[nx*i+j] = (unsigned char) cell[nx*(ny-i-1)+(nx-j-1)].rgb.green;
+ b[nx*i+j] = (unsigned char) cell[nx*(ny-i-1)+(nx-j-1)].rgb.blue;
+ }
+ }
+ else if ( cx1==cx3 && cy1<cy3 && cx2<cx3 && cy2==cy3 )
+ {
+ tmp = nx; nx = ny; ny = tmp;
+ for ( i=0; i<ny; i++ )
+ for ( j=0; j<nx; j++ )
+ {
+ r[nx*i+j] = (unsigned char) cell[ny*(nx-j-1)+i].rgb.red;
+ g[nx*i+j] = (unsigned char) cell[ny*(nx-j-1)+i].rgb.green;
+ b[nx*i+j] = (unsigned char) cell[ny*(nx-j-1)+i].rgb.blue;
+ }
+ }
+#else
+ for ( i=0; i<nx; i++ )
+ for ( j=0; j<ny; j++ )
+ {
+ r[nx*j+i] = (unsigned char) cell[nx*j+i].rgb.red;
+ g[nx*j+i] = (unsigned char) cell[nx*j+i].rgb.green;
+ b[nx*j+i] = (unsigned char) cell[nx*j+i].rgb.blue;
+ }
+#endif
+
+#if 1
+ if ( cx1>cx2 )
+ {
+ tmp = cx1;
+ cx1 = cx2;
+ cx2 = tmp;
+ }
+
+ if ( cy1>cy2 )
+ {
+ tmp = cy1;
+ cy1 = cy2;
+ cy2 = tmp;
+ }
+#endif
+
+ cdCanvasPutImageRectRGB (intcgm_canvas, nx, ny, r, g, b, cx1, cy1, cx2-cx1+1, cy2-cy1+1,0,0,0,0 );
+
+ free(r);
+ free(g);
+ free(b);
+
+ return 0;
+}
+
+int cgm_do_gdp ( int identifier, tpoint *pt, char *data_rec )
+{
+ if ( identifier==-4 )
+ cgm_sism4 ( pt, data_rec );
+ else if ( identifier==-5 )
+ cgm_sism5 ( data_rec );
+
+ return 0;
+}
+
+int cgm_do_rect ( tpoint point1, tpoint point2 )
+{
+ long int cor;
+ double bb_xmin, bb_ymin, bb_xmax, bb_ymax;
+
+ bb_xmin = ( point1.x < point2.x ) ? point1.x : point2.x;
+ bb_xmax = ( point1.x > point2.x ) ? point1.x : point2.x;
+ bb_ymin = ( point1.y < point2.y ) ? point1.y : point2.y;
+ bb_ymax = ( point1.y > point2.y ) ? point1.y : point2.y;
+
+#if 0
+ if ( cgm_vdcx2canvas(bb_xmin) > intcgm_view_xmax || cgm_vdcx2canvas(bb_xmax) < intcgm_view_xmin ||
+ cgm_vdcy2canvas(bb_ymin) > intcgm_view_ymax || cgm_vdcy2canvas(bb_ymax) < intcgm_view_ymin ) return 0;
+#else
+ if ( bb_xmin > intcgm_clip_xmax || bb_xmax < intcgm_clip_xmin ||
+ bb_ymin > intcgm_clip_ymax || bb_ymax < intcgm_clip_ymin ) return 0;
+#endif
+
+ cor = cgm_getcolor ( intcgm_fill_att.color );
+ cdCanvasSetForeground (intcgm_canvas, cor );
+
+ cdCanvasBegin(intcgm_canvas, cgm_setintstyle ( intcgm_fill_att.int_style ) );
+
+ cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(point1.x), cgm_vdcy2canvas(point1.y) );
+ cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(point2.x), cgm_vdcy2canvas(point1.y) );
+ cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(point2.x), cgm_vdcy2canvas(point2.y) );
+ cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(point1.x), cgm_vdcy2canvas(point2.y) );
+
+ cdCanvasEnd (intcgm_canvas);
+
+ return 0;
+}
+
+int cgm_do_circle ( tpoint center, double radius )
+{
+ double bb_xmin, bb_ymin, bb_xmax, bb_ymax;
+
+ bb_xmin = center.x - radius;
+ bb_xmax = center.x + radius;
+ bb_ymin = center.y - radius;
+ bb_ymax = center.y + radius;
+
+#if 0
+ if ( cgm_vdcx2canvas(bb_xmin) > intcgm_view_xmax || cgm_vdcx2canvas(bb_xmax) < intcgm_view_xmin||
+ cgm_vdcy2canvas(bb_ymin) > intcgm_view_ymax || cgm_vdcy2canvas(bb_ymax) < intcgm_view_ymin ) return 0;
+#else
+ if ( bb_xmin > intcgm_clip_xmax || bb_xmax < intcgm_clip_xmin ||
+ bb_ymin > intcgm_clip_ymax || bb_ymax < intcgm_clip_ymin ) return 0;
+#endif
+
+ if ( intcgm_fill_att.int_style!=EMPTY )
+ {
+ long int cor;
+
+ cor = cgm_getcolor ( intcgm_fill_att.color );
+ cdCanvasSetForeground (intcgm_canvas, cor );
+
+ cgm_setlinestyle ( intcgm_line_att.type );
+ cgm_setlinewidth ( intcgm_line_att.width );
+
+ if ( intcgm_fill_att.int_style!=EMPTY )
+ cgm_poly_circle ( center.x, center.y, radius, 0, TWOPI, CLOSED_CHORD );
+ else
+ cgm_line_circle ( center.x, center.y, radius, 0, TWOPI, CLOSED_CHORD );
+ }
+
+ if ( intcgm_edge_att.visibility==ON )
+ {
+ long int cor;
+
+ cor = cgm_getcolor ( intcgm_edge_att.color );
+ cdCanvasSetForeground (intcgm_canvas, cor );
+
+ cgm_setlinestyle ( intcgm_edge_att.type );
+ cgm_setlinewidth ( intcgm_edge_att.width );
+
+ cgm_line_circle ( center.x, center.y, radius, 0., TWOPI, CLOSED_CHORD );
+ }
+
+ return 0;
+}
+
+static double angulo ( double cx, double cy, double px, double py )
+{
+ double ang;
+ if ((fabs(py-cy)<1e-9) && (fabs(px-cx)<1e-9))
+ ang = 0.0;
+ else
+ ang = atan2 ( py - cy , px - cx );
+
+ if ( ang<0.) ang = TWOPI - fabs(ang);
+
+ return ang;
+}
+
+static void solve2 ( double m[][2], double *b, double *x )
+{
+ double det;
+
+ det = m[0][0]*m[1][1] - m[0][1]*m[1][0];
+
+ if ( det==0.0 ) return;
+
+ x[0] = ( b[0]*m[1][1] - b[1]*m[1][0] ) / det;
+ x[1] = ( m[0][0]*b[1] - m[0][1]*b[0] ) / det;
+}
+
+static void getcenter ( double xs, double ys, double xi, double yi, double xe, double ye,
+ double *xc, double *yc )
+{
+ double c[2];
+
+ double x2, y2, x3, y3, m[2][2], b[2];
+
+ x2 = xi - xs;
+ y2 = yi - ys;
+ x3 = xe - xs;
+ y3 = ye - ys;
+
+ m[0][0] = 2*x2;
+ m[1][0] = 2*y2;
+ m[0][1] = 2*x3;
+ m[1][1] = 2*y3;
+ b[0] = x2*x2 + y2*y2;
+ b[1] = x3*x3 + y3*y3;
+
+ solve2 ( m, b, c );
+
+ *xc = c[0] + xs;
+ *yc = c[1] + ys;
+}
+
+int cgm_do_circ3p ( tpoint starting, tpoint intermediate, tpoint ending )
+{
+ long int cor;
+ double xc, yc;
+ double angi, angm, angf;
+ double radius;
+ double bb_xmin, bb_ymin, bb_xmax, bb_ymax;
+
+ cor = cgm_getcolor ( intcgm_line_att.color );
+ cdCanvasSetForeground (intcgm_canvas, cor );
+
+ cgm_setlinestyle ( intcgm_line_att.type );
+ cgm_setlinewidth ( intcgm_line_att.width );
+
+ getcenter ( starting.x, starting.y, intermediate.x, intermediate.y, ending.x, ending.y, &xc, &yc );
+
+ angi = angulo( xc, yc, starting.x, starting.y );
+ angm = angulo( xc, yc, intermediate.x, intermediate.y );
+ angf = angulo( xc, yc, ending.x, ending.y );
+
+ if ( angm<angi )
+ {
+ double tmp = angi;
+ angi = angf;
+ angf = tmp;
+ }
+
+ if ( angf<angi ) angf = angf + TWOPI;
+
+ radius = sqrt ( (starting.x-xc)*(starting.x-xc) + (starting.y-yc)*(starting.y-yc) );
+
+ bb_xmin = xc - radius;
+ bb_xmax = xc + radius;
+ bb_ymin = yc - radius;
+ bb_ymax = yc + radius;
+
+#if 0
+ if ( cgm_vdcx2canvas(bb_xmin) > intcgm_view_xmax || cgm_vdcx2canvas(bb_xmax) < intcgm_view_xmin ||
+ cgm_vdcy2canvas(bb_ymin) > intcgm_view_ymax || cgm_vdcy2canvas(bb_ymax) < intcgm_view_ymin ) return 0;
+#else
+ if ( bb_xmin > intcgm_clip_xmax || bb_xmax < intcgm_clip_xmin ||
+ bb_ymin > intcgm_clip_ymax || bb_ymax < intcgm_clip_ymin ) return 0;
+#endif
+
+ cgm_line_circle ( xc, yc, radius, angi, angf, OPEN );
+
+ return 0;
+}
+
+int cgm_do_circ3pc ( tpoint starting, tpoint intermediate, tpoint ending, int close_type )
+{
+ long int cor;
+ double xc, yc;
+ double angi, angm, angf;
+ double radius;
+ double bb_xmin, bb_ymin, bb_xmax, bb_ymax;
+
+ cor = cgm_getcolor ( intcgm_fill_att.color );
+ cdCanvasSetForeground (intcgm_canvas, cor );
+
+ cgm_setlinestyle ( intcgm_line_att.type );
+ cgm_setlinewidth ( intcgm_line_att.width );
+
+ getcenter ( starting.x, starting.y, intermediate.x, intermediate.y, ending.x, ending.y, &xc, &yc );
+
+ angi = angulo( xc, yc, starting.x, starting.y );
+ angm = angulo( xc, yc, intermediate.x, intermediate.y );
+ angf = angulo( xc, yc, ending.x, ending.y );
+
+ radius = sqrt ( (starting.x-xc)*(starting.x-xc) + (starting.y-yc)*(starting.y-yc) );
+
+ bb_xmin = xc - radius;
+ bb_xmax = xc + radius;
+ bb_ymin = yc - radius;
+ bb_ymax = yc + radius;
+
+#if 0
+ if ( cgm_vdcx2canvas(bb_xmin) > intcgm_view_xmax || cgm_vdcx2canvas(bb_xmax) < intcgm_view_xmin ||
+ cgm_vdcy2canvas(bb_ymin) > intcgm_view_ymax || cgm_vdcy2canvas(bb_ymax) < intcgm_view_ymin ) return 0;
+#else
+ if ( bb_xmin > intcgm_clip_xmax || bb_xmax < intcgm_clip_xmin ||
+ bb_ymin > intcgm_clip_ymax || bb_ymax < intcgm_clip_ymin ) return 0;
+#endif
+
+ if ( angm<angi )
+ {
+ double tmp = angi;
+ angi = angf;
+ angf = tmp;
+ }
+
+ if ( angf<angi ) angf = angf + TWOPI;
+
+ if ( intcgm_fill_att.int_style!=EMPTY )
+ {
+ long int cor;
+
+ cor = cgm_getcolor ( intcgm_fill_att.color );
+ cdCanvasSetForeground (intcgm_canvas, cor );
+
+ cgm_setlinewidth ( intcgm_line_att.width );
+
+ if ( intcgm_fill_att.int_style!=EMPTY )
+ cgm_poly_circle ( xc, yc, radius, angi, angf, (close_type) ? CLOSED_CHORD : CLOSED_PIE );
+ else
+ cgm_line_circle ( xc, yc, radius, angi, angf, (close_type) ? CLOSED_CHORD : CLOSED_PIE );
+ }
+
+ if ( intcgm_edge_att.visibility==ON )
+ {
+ long int cor;
+
+ cor = cgm_getcolor ( intcgm_edge_att.color );
+ cdCanvasSetForeground (intcgm_canvas, cor );
+
+ cgm_setlinestyle ( intcgm_edge_att.type );
+ cgm_setlinewidth ( intcgm_edge_att.width );
+
+ cgm_line_circle ( xc, yc, radius, angi, angf, (close_type) ? CLOSED_CHORD : CLOSED_PIE );
+ }
+
+ return 0;
+}
+
+int cgm_do_circcnt ( tpoint center, tpoint start, tpoint end, double radius )
+{
+ long int cor;
+ double angi, angf;
+ double bb_xmin, bb_ymin, bb_xmax, bb_ymax;
+
+ bb_xmin = center.x - radius;
+ bb_xmax = center.x + radius;
+ bb_ymin = center.y - radius;
+ bb_ymax = center.y + radius;
+
+#if 0
+ if ( cgm_vdcx2canvas(bb_xmin) > intcgm_view_xmax || cgm_vdcx2canvas(bb_xmax) < intcgm_view_xmin ||
+ cgm_vdcy2canvas(bb_ymin) > intcgm_view_ymax || cgm_vdcy2canvas(bb_ymax) < intcgm_view_ymin ) return 0;
+#else
+ if ( bb_xmin > intcgm_clip_xmax || bb_xmax < intcgm_clip_xmin ||
+ bb_ymin > intcgm_clip_ymax || bb_ymax < intcgm_clip_ymin ) return 0;
+#endif
+
+ cor = cgm_getcolor ( intcgm_fill_att.color );
+ cdCanvasSetForeground (intcgm_canvas, cor );
+
+ cgm_setlinewidth ( intcgm_line_att.width );
+
+ angi = angulo( center.x, center.y, start.x, start.y );
+ angf = angulo( center.x, center.y, end.x, end.y );
+
+ if ( angf<angi )
+ {
+ double tmp = angi;
+ angi = angf;
+ angf = tmp;
+ }
+
+ cgm_line_circle ( center.x, center.y, radius, angi, angf, OPEN );
+
+ return 0;
+}
+
+int cgm_do_ccntcl ( tpoint center, tpoint start, tpoint end, double radius, int close_type )
+{
+ long int cor;
+ double angi, angf;
+ double bb_xmin, bb_ymin, bb_xmax, bb_ymax;
+
+ bb_xmin = center.x - radius;
+ bb_xmax = center.x + radius;
+ bb_ymin = center.y - radius;
+ bb_ymax = center.y + radius;
+
+#if 0
+ if ( cgm_vdcx2canvas(bb_xmin) > intcgm_view_xmax || cgm_vdcx2canvas(bb_xmax) < intcgm_view_xmin ||
+ cgm_vdcy2canvas(bb_ymin) > intcgm_view_ymax || cgm_vdcy2canvas(bb_ymax) < intcgm_view_ymin ) return 0;
+#else
+ if ( bb_xmin > intcgm_clip_xmax || bb_xmax < intcgm_clip_xmin ||
+ bb_ymin > intcgm_clip_ymax || bb_ymax < intcgm_clip_ymin ) return 0;
+#endif
+
+ cor = cgm_getcolor ( intcgm_fill_att.color );
+ cdCanvasSetForeground (intcgm_canvas, cor );
+
+ cgm_setlinewidth ( intcgm_line_att.width );
+
+ angi = angulo( center.x, center.y, start.x, start.y );
+ angf = angulo( center.x, center.y, end.x, end.y );
+
+ if ( angf<angi )
+ {
+ double tmp = angi;
+ angi = angf;
+ angf = tmp;
+ }
+
+ if ( intcgm_fill_att.int_style!=HOLLOW && intcgm_fill_att.int_style!=EMPTY )
+ {
+ long int cor;
+
+ cor = cgm_getcolor ( intcgm_fill_att.color );
+ cdCanvasSetForeground (intcgm_canvas, cor );
+
+ cgm_setlinewidth ( intcgm_line_att.width );
+
+ cgm_poly_circle ( center.x, center.y, radius, angi, angf, (close_type) ? CLOSED_CHORD : CLOSED_PIE );
+ }
+
+ if ( intcgm_edge_att.visibility==ON )
+ {
+ long int cor;
+
+ cor = cgm_getcolor ( intcgm_edge_att.color );
+ cdCanvasSetForeground (intcgm_canvas, cor );
+
+ cgm_setlinewidth ( intcgm_edge_att.width );
+
+ cgm_line_circle ( center.x, center.y, radius, angi, angf, (close_type) ? CLOSED_CHORD : CLOSED_PIE );
+ }
+
+ return 0;
+}
+
+int cgm_do_ellips ( tpoint center, tpoint first_CDP, tpoint second_CDP )
+{
+ double w = myhypot ( first_CDP.x-center.x, first_CDP.y-center.y );
+ double h = myhypot ( second_CDP.x-center.x, second_CDP.y-center.y );
+ double inc = atan2 ( first_CDP.y-center.y, first_CDP.x-center.x );
+ double bb_xmin, bb_ymin, bb_xmax, bb_ymax;
+
+ bb_xmin = center.x - w;
+ bb_xmax = center.x + w;
+ bb_ymin = center.y - h;
+ bb_ymax = center.y + h;
+
+#if 0
+ if ( cgm_vdcx2canvas(bb_xmin) > intcgm_view_xmax || cgm_vdcx2canvas(bb_xmax) < intcgm_view_xmin ||
+ cgm_vdcy2canvas(bb_ymin) > intcgm_view_ymax || cgm_vdcy2canvas(bb_ymax) < intcgm_view_ymin) return 0;
+#else
+ if ( bb_xmin > intcgm_clip_xmax || bb_xmax < intcgm_clip_xmin ||
+ bb_ymin > intcgm_clip_ymax || bb_ymax < intcgm_clip_ymin ) return 0;
+#endif
+
+ cgm_ElpArc ( center.x, center.y, w*2., h*2., inc, 0-inc, TWOPI-inc, 64, 2 );
+
+ return 0;
+}
+
+int cgm_do_ellarc ( tpoint center, tpoint first_CDP, tpoint second_CDP,
+ tpoint start, tpoint end )
+{
+ double w = myhypot ( first_CDP.x-center.x, first_CDP.y-center.y );
+ double h = myhypot ( second_CDP.x-center.x, second_CDP.y-center.y );
+ double inc = atan2 ( first_CDP.y-center.y, first_CDP.x-center.x );
+ double a1 = atan2 ( start.y, start.x );
+ double a2 = atan2 ( end.y, end.x );
+ double bb_xmin, bb_ymin, bb_xmax, bb_ymax;
+
+ bb_xmin = center.x - w;
+ bb_xmax = center.x + w;
+ bb_ymin = center.y - h;
+ bb_ymax = center.y + h;
+
+#if 0
+ if ( cgm_vdcx2canvas(bb_xmin) > intcgm_view_xmax || cgm_vdcx2canvas(bb_xmax) < intcgm_view_xmin ||
+ cgm_vdcy2canvas(bb_ymin) > intcgm_view_ymax || cgm_vdcy2canvas(bb_ymax) < intcgm_view_ymin ) return 0;
+#else
+ if ( bb_xmin > intcgm_clip_xmax || bb_xmax < intcgm_clip_xmin ||
+ bb_ymin > intcgm_clip_ymax || bb_ymax < intcgm_clip_ymin ) return 0;
+#endif
+
+ cgm_ElpArc ( center.x, center.y, w*2., h*2., inc, a1-inc, a2-inc, 64, 0 );
+
+ return 0;
+}
+
+int cgm_do_ellacl ( tpoint center, tpoint first_CDP, tpoint second_CDP,
+ tpoint start, tpoint end, int close_type )
+{
+ double w = myhypot ( first_CDP.x-center.x, first_CDP.y-center.y );
+ double h = myhypot ( second_CDP.x-center.x, second_CDP.y-center.y );
+ double inc = atan2 ( first_CDP.y-center.y, first_CDP.x-center.x );
+ double a1 = atan2 ( start.y, start.x );
+ double a2 = atan2 ( end.y, end.x );
+
+ double bb_xmin, bb_ymin, bb_xmax, bb_ymax;
+
+ bb_xmin = center.x - w;
+ bb_xmax = center.x + w;
+ bb_ymin = center.y - h;
+ bb_ymax = center.y + h;
+
+#if 0
+ if ( cgm_vdcx2canvas(bb_xmin) > intcgm_view_xmax || cgm_vdcx2canvas(bb_xmax) < intcgm_view_xmin ||
+ cgm_vdcy2canvas(bb_ymin) > intcgm_view_ymax || cgm_vdcy2canvas(bb_ymax) < intcgm_view_ymin ) return 0;
+#else
+ if ( bb_xmin > intcgm_clip_xmax || bb_xmax < intcgm_clip_xmin ||
+ bb_ymin > intcgm_clip_ymax || bb_ymax < intcgm_clip_ymin ) return 0;
+#endif
+
+ cgm_ElpArc ( center.x, center.y, w*2., h*2., inc, a1-inc, a2-inc, 64, close_type+1 );
+
+ return 0;
+}
+
+int cgm_do_text_height ( double height )
+{
+ cgm_setfont ( intcgm_text_att.font, intcgm_text_att.style, height );
+
+ return 0;
+}
+
diff --git a/cd/src/intcgm/intcgm4.h b/cd/src/intcgm/intcgm4.h
new file mode 100755
index 0000000..4b12873
--- /dev/null
+++ b/cd/src/intcgm/intcgm4.h
@@ -0,0 +1,28 @@
+int cgm_do_vdcext ( tpoint, tpoint );
+int cgm_do_bckcol ( trgb );
+int cgm_do_transp ( int );
+int cgm_do_clprec ( tpoint, tpoint );
+int cgm_do_clpind ( int );
+int cgm_do_polyln ( int, tpoint * );
+int cgm_do_incply ( int, tpoint * );
+int cgm_do_djtply ( int, tpoint * );
+int cgm_do_indpl ( int, tpoint * );
+int cgm_do_polymk ( int, tpoint * );
+int cgm_do_incplm ( int, tpoint * );
+int cgm_do_text ( int, char *, tpoint );
+int cgm_do_txtalign ( int hor, int ver );
+int cgm_do_polygn ( int, tpoint * );
+int cgm_do_incplg ( int, tpoint * );
+int cgm_do_plgset( int, int, tpoint *, short * );
+int cgm_do_cellar ( tpoint, tpoint, tpoint, int, int, long, tcolor * );
+int cgm_do_gdp ( int, tpoint *, char * );
+int cgm_do_rect ( tpoint point1, tpoint point2 );
+int cgm_do_circle ( tpoint, double );
+int cgm_do_circ3p ( tpoint, tpoint, tpoint );
+int cgm_do_circ3pc ( tpoint, tpoint, tpoint, int );
+int cgm_do_circcnt ( tpoint, tpoint, tpoint, double );
+int cgm_do_ccntcl ( tpoint, tpoint, tpoint, double, int );
+int cgm_do_ellips ( tpoint, tpoint, tpoint );
+int cgm_do_ellarc ( tpoint, tpoint, tpoint, tpoint, tpoint );
+int cgm_do_ellacl ( tpoint, tpoint, tpoint, tpoint, tpoint, int );
+int cgm_do_text_height ( double );
diff --git a/cd/src/intcgm/intcgm6.c b/cd/src/intcgm/intcgm6.c
new file mode 100755
index 0000000..c23afee
--- /dev/null
+++ b/cd/src/intcgm/intcgm6.c
@@ -0,0 +1,253 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+
+#include <cd.h>
+
+#include "list.h"
+#include "types.h"
+#include "intcgm.h"
+#include "intcgm2.h"
+#include "intcgm6.h"
+
+void cgm_setlinestyle ( int type )
+{
+ switch ( type )
+ {
+ case LINE_SOLID:
+ cdCanvasLineStyle (intcgm_canvas, CD_CONTINUOUS );
+ break;
+ case LINE_DASH:
+ cdCanvasLineStyle (intcgm_canvas, CD_DASHED );
+ break;
+ case LINE_DOT:
+ cdCanvasLineStyle (intcgm_canvas, CD_DOTTED );
+ break;
+ case LINE_DASH_DOT:
+ cdCanvasLineStyle (intcgm_canvas, CD_DASH_DOT );
+ break;
+ case LINE_DASH_DOT_DOT:
+ cdCanvasLineStyle (intcgm_canvas, CD_DASH_DOT_DOT );
+ break;
+ }
+}
+
+void cgm_setlinewidth ( double width )
+{
+ int w;
+ if ( intcgm_cgm.lnwsm == ABSOLUTE )
+ w = cgm_delta_vdc2canvas(width);
+ else
+ w = (int)floor ( width+0.5 );
+
+ cdCanvasLineWidth (intcgm_canvas, w>0?w:1 );
+}
+
+void cgm_setmarktype ( int type )
+{
+ switch ( type )
+ {
+ case MARK_DOT:
+ cdCanvasMarkType (intcgm_canvas, CD_STAR );
+ break;
+ case MARK_PLUS:
+ cdCanvasMarkType (intcgm_canvas, CD_PLUS );
+ break;
+ case MARK_ASTERISK:
+ cdCanvasMarkType (intcgm_canvas, CD_X );
+ break;
+ case MARK_CIRCLE:
+ cdCanvasMarkType (intcgm_canvas, CD_CIRCLE );
+ break;
+ case MARK_CROSS:
+ cdCanvasMarkType (intcgm_canvas, CD_PLUS );
+ break;
+ }
+}
+
+void cgm_setmarksize ( double size )
+{
+ if ( intcgm_cgm.lnwsm == ABSOLUTE )
+ cdCanvasMarkSize (intcgm_canvas, cgm_delta_vdc2canvas(size) );
+ else
+ cdCanvasMarkSize (intcgm_canvas, (int)floor ( size*0.5 ) );
+}
+
+long int *cgm_setpattern ( pat_table pat )
+{
+ int i;
+ long int *cor = (long int *) malloc ( pat.nx*pat.ny*sizeof(long int) );
+
+ for ( i=0; i<pat.nx*pat.ny ; i++ )
+ cor[i] = cgm_getcolor ( pat.pattern[i] );
+
+ return cor;
+}
+
+int cgm_setintstyle ( int style )
+{
+ if ( style==HOLLOW )
+ return CD_CLOSED_LINES;
+ else if ( style==SOLID )
+ {
+ cdCanvasInteriorStyle (intcgm_canvas, CD_SOLID );
+ return CD_FILL;
+ }
+ else if ( style==PATTERN )
+ {
+ int i;
+ pat_table *pat;
+ long int *p;
+
+ for ( i=1; (pat=(pat_table *)cgm_GetList( intcgm_fill_att.pat_list,i ))!=NULL; i++ )
+ {
+ if ( pat->index==intcgm_fill_att.pat_index ) break;
+ }
+
+ p = (long int *) malloc ( pat->nx*pat->ny*sizeof(long int) );
+
+ for ( i=0; i<pat->nx*pat->ny; i++ )
+ {
+ if ( intcgm_cgm.clrsm==DIRECT )
+ p[i] = cdEncodeColor ((unsigned char)(pat->pattern[i].rgb.red*255./intcgm_cgm.color_ext.white.red),
+ (unsigned char)(pat->pattern[i].rgb.green*255./intcgm_cgm.color_ext.white.green),
+ (unsigned char)(pat->pattern[i].rgb.blue*255./intcgm_cgm.color_ext.white.blue) );
+ else
+ p[i] = cdEncodeColor ((unsigned char)(intcgm_color_table[pat->pattern[i].ind].red*255/intcgm_cgm.color_ext.white.red),
+ (unsigned char)(intcgm_color_table[pat->pattern[i].ind].green*255/intcgm_cgm.color_ext.white.green),
+ (unsigned char)(intcgm_color_table[pat->pattern[i].ind].blue*255/intcgm_cgm.color_ext.white.blue) );
+ }
+
+ cdCanvasPattern(intcgm_canvas, pat->nx, pat->ny, (long *) p );
+
+ return CD_FILL;
+ }
+ else if ( style==HATCH )
+ {
+ cdCanvasHatch (intcgm_canvas, intcgm_fill_att.hatch_index-1 );
+ return CD_FILL;
+ }
+ else
+ return CD_CLOSED_LINES;
+}
+
+long int cgm_getcolor ( tcolor cor )
+{
+
+ if ( intcgm_cgm.clrsm==INDEXED )
+ return cdEncodeColor ((unsigned char)(intcgm_color_table[cor.ind].red*255/intcgm_cgm.color_ext.white.red),
+ (unsigned char)(intcgm_color_table[cor.ind].green*255/intcgm_cgm.color_ext.white.green),
+ (unsigned char)(intcgm_color_table[cor.ind].blue*255/intcgm_cgm.color_ext.white.blue) );
+ else
+ return cdEncodeColor ((unsigned char)(cor.rgb.red*255/intcgm_cgm.color_ext.white.red),
+ (unsigned char)(cor.rgb.green*255/intcgm_cgm.color_ext.white.green),
+ (unsigned char)(cor.rgb.blue*255/intcgm_cgm.color_ext.white.blue) );
+}
+
+int cgm_vdcx2canvas ( double vdc )
+{
+ if ( intcgm_cgm.drawing_mode==ABSTRACT )
+ return (int) floor ( intcgm_scale_factor_x*(vdc-intcgm_vdc_ext.xmin)+.5 ) + intcgm_view_xmin;
+ else
+ return (int) floor ( intcgm_scale_factor_mm_x*(vdc-intcgm_vdc_ext.xmin)*intcgm_cgm.scaling_mode.scale_factor +
+ intcgm_vdc_ext.xmin*intcgm_cgm.scaling_mode.scale_factor + .5 );
+}
+
+int cgm_vdcy2canvas ( double vdc )
+{
+ if ( intcgm_cgm.drawing_mode==ABSTRACT )
+ return (int) floor ( intcgm_scale_factor_y*(vdc-intcgm_vdc_ext.ymin)+.5 ) + intcgm_view_ymin;
+ else
+ return (int) floor ( intcgm_scale_factor_mm_y*(vdc-intcgm_vdc_ext.ymin)*intcgm_cgm.scaling_mode.scale_factor +
+ intcgm_vdc_ext.ymin*intcgm_cgm.scaling_mode.scale_factor + .5 );
+}
+
+int cgm_delta_vdc2canvas ( double vdc )
+{
+ int delta = (int) cgm_vdcx2canvas(intcgm_vdc_ext.xmin+vdc) - (int) cgm_vdcx2canvas(intcgm_vdc_ext.xmin);
+ return delta;
+}
+
+double cgm_canvas2vdcx ( int x )
+{
+ if ( intcgm_cgm.drawing_mode==ABSTRACT )
+ return (double) (x-intcgm_view_xmin)/intcgm_scale_factor_x + intcgm_vdc_ext.xmin;
+ else
+ return (double) (x-intcgm_view_xmin)/(intcgm_scale_factor_mm_x*intcgm_cgm.scaling_mode.scale_factor) + intcgm_vdc_ext.xmin;
+}
+
+double cgm_canvas2vdcy ( int y )
+{
+ if ( intcgm_cgm.drawing_mode==ABSTRACT )
+ return (double) (y-intcgm_view_ymin)/intcgm_scale_factor_y + intcgm_vdc_ext.ymin;
+ else
+ return (double) (y-intcgm_view_ymin)/(intcgm_scale_factor_mm_y*intcgm_cgm.scaling_mode.scale_factor) + intcgm_vdc_ext.ymin;
+}
+
+void cgm_getpolybbox ( tpoint *pt, int n_points, double *bb_xmin, double *bb_ymin,
+ double *bb_xmax, double *bb_ymax )
+{
+ int i;
+
+ *bb_xmin = *bb_xmax = pt[0].x;
+ *bb_ymin = *bb_ymax = pt[0].y;
+
+ for ( i=1; i<n_points; i++)
+ {
+ if ( pt[i].x < *bb_xmin ) *bb_xmin = pt[i].x;
+ else if ( pt[i].x > *bb_xmax ) *bb_xmax = pt[i].x;
+ if ( pt[i].y < *bb_ymin ) *bb_ymin = pt[i].y;
+ else if ( pt[i].y > *bb_ymax ) *bb_ymax = pt[i].y;
+ }
+}
+
+void cgm_getincpolybbox ( tpoint *pt, int n_points, double *bb_xmin, double *bb_ymin,
+ double *bb_xmax, double *bb_ymax )
+{
+ int i;
+ double px, py;
+
+ px = *bb_xmin = *bb_xmax = pt[0].x;
+ py = *bb_ymin = *bb_ymax = pt[0].y;
+
+ for ( i=1; i<n_points; i++)
+ {
+ px += pt[i].x; py += pt[i].y;
+ if ( px < *bb_xmin ) *bb_xmin = px;
+ else if ( px > *bb_xmax ) *bb_xmax = px;
+ if ( py < *bb_ymin ) *bb_ymin = py;
+ else if ( py > *bb_ymax ) *bb_ymax = py;
+ }
+}
+
+int cgm_setfont ( int font, int style, double height )
+{
+ int size;
+ int cy;
+ char* type_face;
+
+ cy = cgm_delta_vdc2canvas ( height );
+ size = (int) floor (((cy/intcgm_scale_factor_mm_y)/0.353)+0.5);
+ switch (font)
+ {
+ case 0:
+ type_face = "System";
+ break;
+ case 1:
+ type_face = "Courier";
+ break;
+ case 2:
+ type_face = "Times";
+ break;
+ case 3:
+ type_face = "Helvetica";
+ break;
+ default:
+ return 0;
+ }
+
+ cdCanvasFont(intcgm_canvas, type_face, style, size );
+
+ return 0;
+}
diff --git a/cd/src/intcgm/intcgm6.h b/cd/src/intcgm/intcgm6.h
new file mode 100755
index 0000000..fde660e
--- /dev/null
+++ b/cd/src/intcgm/intcgm6.h
@@ -0,0 +1,15 @@
+void cgm_setlinestyle ( int );
+void cgm_setlinewidth ( double );
+void cgm_setmarktype ( int );
+void cgm_setmarksize ( double );
+long int cgm_getcolor ( tcolor );
+long int *cgm_setpattern ( pat_table );
+int cgm_setfont ( int, int, double );
+int cgm_setintstyle ( int );
+int cgm_vdcx2canvas ( double );
+int cgm_vdcy2canvas ( double );
+int cgm_delta_vdc2canvas ( double );
+double cgm_canvas2vdcx ( int );
+double cgm_canvas2vdcy ( int );
+void cgm_getpolybbox ( tpoint *, int, double *n, double *, double *, double * );
+void cgm_getincpolybbox ( tpoint *, int, double *, double *, double *, double * );
diff --git a/cd/src/intcgm/list.c b/cd/src/intcgm/list.c
new file mode 100755
index 0000000..6fefbbc
--- /dev/null
+++ b/cd/src/intcgm/list.c
@@ -0,0 +1,117 @@
+/*
+* list.c
+* Generic List Manager
+* TeCGraf
+*
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "list.h"
+
+TList *cgm_NewList ( void )
+{
+ TList *l = (TList *) malloc ( sizeof (TList) );
+
+ list_nba(l) = 8;
+ list_head(l) = (void **)malloc(list_nba(l)*sizeof(void*));
+ list_n(l) = 0;
+
+ return l;
+}
+
+TList *cgm_AppendList ( TList *l, void *i )
+{
+ if ( l == NULL )
+ return NULL;
+
+ if (list_n(l) == list_nba(l))
+ {
+ list_nba(l) += 32;
+ list_head(l) = (void **)realloc(list_head(l),list_nba(l)*sizeof(void*));
+ }
+
+ list_head(l)[list_n(l)]=i;
+ list_n(l)++;
+
+ return l;
+}
+
+TList *cgm_AddList ( TList *l, int n, void *info )
+{
+ int i;
+
+ if ( l == NULL)
+ return NULL;
+
+ if ( n < 1)
+ n=1;
+
+ if ( n > list_n(l) )
+ return cgm_AppendList( l, info );
+
+ --n; /* o usuario ve a lista iniciando em 1 e a */
+ /* lista e' implementada iniciando em 0 */
+
+ if (list_n(l) == list_nba(l))
+ {
+ list_nba(l) *= 2;
+ list_head(l) = (void **)realloc(list_head(l),list_nba(l)*sizeof(void*));
+ }
+
+ for (i=list_n(l)-1; i>=n; --i)
+ list_head(l)[i+1]=list_head(l)[i];
+
+ list_head(l)[n]=info;
+ list_n(l)++;
+ return l;
+}
+
+TList *cgm_DelList ( TList *l, int n )
+{
+ int i;
+
+ if ( l == NULL || list_n(l) == 0 || n < 0)
+ return NULL;
+
+ if ( n < 1)
+ n=1;
+
+ if ( n > list_n(l))
+ n=list_n(l);
+
+ --n; /* o usuario ve a lista iniciando em 1 e a */
+ /* lista e' implementada iniciando em 0 */
+ list_n(l)--;
+
+ for (i=n; i<list_n(l); ++i)
+ list_head(l)[i]=list_head(l)[i+1];
+
+ return l;
+}
+
+void *cgm_GetList ( TList *l, int n )
+{
+ if ( l == NULL || n <= 0)
+ return NULL;
+
+ return n > list_n(l) ? NULL : list_head(l)[n-1];
+}
+
+int cgm_DelEntry ( TList *l, void *entry )
+{
+ int i=1;
+
+ if ( l == NULL || list_n(l) == 0)
+ return 0;
+
+ for (i=0; i< list_n(l); ++i)
+ if (list_head(l)[i]==entry)
+ {
+ cgm_DelList(l,i+1); /* o usuario ve a lista iniciando em 1 e a */
+ /* lista e' implementada iniciando em 0 */
+ return i+1;
+ }
+ return 0;
+}
+
diff --git a/cd/src/intcgm/list.h b/cd/src/intcgm/list.h
new file mode 100755
index 0000000..c661a7c
--- /dev/null
+++ b/cd/src/intcgm/list.h
@@ -0,0 +1,30 @@
+
+/*
+* list.h
+* prototipos das funcoes de manipulacao de lista
+* TeCGraf
+* 27 Ago 93
+*/
+
+#ifndef __LIST_H__
+#define __LIST_H__
+
+typedef struct TList_
+ {
+ void **h; /* head */
+ int nba;
+ int n; /* Numero de elementos na lista */
+ } TList;
+
+#define list_head(l) ((l)->h)
+#define list_n(l) ((l)->n)
+#define list_nba(l) ((l)->nba)
+
+TList *cgm_NewList ( void );
+TList *cgm_AppendList ( TList *, void * );
+TList *cgm_AddList ( TList *, int, void * );
+TList *cgm_DelList ( TList *, int );
+void *cgm_GetList ( TList *, int );
+int cgm_DelEntry ( TList *, void * );
+
+#endif
diff --git a/cd/src/intcgm/sism.c b/cd/src/intcgm/sism.c
new file mode 100755
index 0000000..9946ac3
--- /dev/null
+++ b/cd/src/intcgm/sism.c
@@ -0,0 +1,392 @@
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <math.h>
+#include <limits.h>
+#include <float.h>
+
+#include <cd.h>
+
+#include "list.h"
+#include "types.h"
+#include "intcgm.h"
+#include "intcgm2.h"
+#include "intcgm6.h"
+
+static tpoint trace_start_pos, base_direction, amp_direction, trace_direction;
+static double bline_sc_f, amp_sc_f, trc_st_f, VA_bline_offset, pos_clp_lmt,
+ neg_clp_lmt, pos_bckfil_bnd, neg_bckfil_bnd;
+static int trace_dsp_md, samp_type, n_samp, wig_trc_mod, nul_clr_i, n_trace;
+static double *sample;
+static long *coind;
+static int trace=0;
+
+void cgm_sism4 ( tpoint *pt, char *data_rec )
+{
+ sscanf ( data_rec, "%lg %lg %lg %lg %lg %lg %d %d %d %lg %lg %*d %d %d %d",
+ &bline_sc_f, &amp_sc_f, &trc_st_f, &VA_bline_offset, &pos_clp_lmt,
+ &neg_clp_lmt, &trace_dsp_md, &samp_type, &n_samp, &pos_bckfil_bnd,
+ &neg_bckfil_bnd, &wig_trc_mod, &nul_clr_i, &n_trace );
+
+ trace_start_pos = pt[0];
+ base_direction = pt[1];
+ amp_direction = pt[2];
+ trace_direction = pt[3];
+ trace = 0;
+}
+
+/* adjust the samples to the amplitude direction vector */
+static void dirvet ( double dx )
+{
+ int i;
+
+ for ( i=0; i<n_samp; i++ )
+ sample[i] *= dx/fabs(dx);
+}
+
+/* adust the x offset from the baseline to maximum amplitude */
+static void ampscf ( double dx )
+{
+ double max=1;
+ int i;
+
+ if ( samp_type == 0 || samp_type == 4 ) max = (double) SHRT_MAX;
+ else if ( samp_type == 1 ) max = (double) INT_MAX;
+ else if ( samp_type == 2 ) max = (double) FLT_MAX;
+ else if ( samp_type == 3 || samp_type == 5 ) max = (double) SCHAR_MAX;
+
+ for ( i=0; i<n_samp; i++ )
+ sample[i] = (sample[i]/max) * amp_sc_f * dx;
+}
+
+static double interpl ( int i, double y1, double y2, double x )
+{
+ return ( y1*(x-sample[i+1]) + y2*(sample[i]-x) ) / ( sample[i]-sample[i+1] );
+}
+
+static void vasamp ( int mode, double max, double min, int cordep )
+{
+ double factx, facty;
+ double x[5], y[5];
+ double samp1, samp2, mn, mx;
+ long int cor;
+ int i,j,n;
+
+ facty = base_direction.y * bline_sc_f;
+ factx = trace_direction.x * trc_st_f;
+
+ max *= amp_sc_f;
+ min *= amp_sc_f;
+ mn = min;
+ mx = max;
+
+ if ( mode==64 )
+ {
+ double tmp = min;
+ min = max;
+ max = tmp;
+ mn = min * -1.;
+ mx = max * -1.;
+ }
+
+ for ( i=0; i<(n_samp-1); i++ )
+ {
+ double y1 = trace_start_pos.y + facty*(i);
+ double y2 = trace_start_pos.y + facty*(i+1);
+ double dx = trace_start_pos.x + factx*(trace-1);
+
+ samp1 = sample[i];
+ samp2 = sample[i+1];
+
+ if ( mode==64 )
+ {
+ samp1 *= -1.;
+ samp2 *= -1.;
+ }
+
+ n=0;
+
+ if (samp1<mn && samp2>mn && samp2<mx)
+ {
+ x[n] = min + dx;
+ y[n++] = interpl(i,y1,y2,min);
+ x[n] = sample[i+1] + dx;
+ y[n++] = y2;
+ x[n] = min + dx;
+ y[n++] = y2;
+ }
+
+ else if (samp1<mn && samp2>mx)
+ {
+ x[n] = min + dx;
+ y[n++] = interpl(i,y1,y2,min);
+ x[n] = max + dx;
+ y[n++] = interpl(i,y1,y2,max);
+ x[n] = max + dx;
+ y[n++] = y2;
+ x[n] = min + dx;
+ y[n++] = y2;
+ }
+
+ else if ( (samp1>mn && samp1<mx) &&
+ (samp2>mn && samp2<mx) )
+ {
+ x[n] = min + dx;
+ y[n++] = y1;
+ x[n] = sample[i] + dx;
+ y[n++] = y1;
+ x[n] = sample[i+1] + dx;
+ y[n++] = y2;
+ x[n] = min + dx;
+ y[n++] = y2;
+ }
+
+ else if ( samp1>mn && samp1<mx && samp2>mx )
+ {
+ x[n] = min + dx;
+ y[n++] = y1;
+ x[n] = sample[i] + dx;
+ y[n++] = y1;
+ x[n] = max + dx;
+ y[n++] = interpl(i,y1,y2,max);
+ x[n] = max + dx;
+ y[n++] = y2;
+ x[n] = min + dx;
+ y[n++] = y2;
+ }
+
+ else if ( samp1>mx && samp2>mx )
+ {
+ x[n] = min + dx;
+ y[n++] = y1;
+ x[n] = max + dx;
+ y[n++] = y1;
+ x[n] = max + dx;
+ y[n++] = y2;
+ x[n] = min + dx;
+ y[n++] = y2;
+ }
+
+ else if ( samp1>mx && samp2<mx && samp2>mn )
+ {
+ x[n] = min + dx;
+ y[n++] = y1;
+ x[n] = max + dx;
+ y[n++] = y1;
+ x[n] = max + dx;
+ y[n++] = interpl(i,y1,y2,max);
+ x[n] = sample[i+1] + dx;
+ y[n++] = y2;
+ x[n] = min + dx;
+ y[n++] = y2;
+ }
+
+ else if ( samp1>mn && samp1<mx && samp2<mn )
+ {
+ x[n] = min + dx;
+ y[n++] = y1;
+ x[n] = sample[i] + dx;
+ y[n++] = y1;
+ x[n] = min + dx;
+ y[n++] = interpl(i,y1,y2,min);
+ }
+
+ if ( n>0 )
+ {
+ if ( cordep )
+ {
+ cor = cdEncodeColor ( (unsigned char)((intcgm_color_table[coind[i]].red*255)/intcgm_cgm.color_ext.white.red),
+ (unsigned char)((intcgm_color_table[coind[i]].green*255)/intcgm_cgm.color_ext.white.green),
+ (unsigned char)((intcgm_color_table[coind[i]].blue*255)/intcgm_cgm.color_ext.white.blue) );
+ cdCanvasSetForeground (intcgm_canvas, cor );
+ }
+
+ cdCanvasBegin(intcgm_canvas, CD_FILL );
+
+ for ( j=0; j<n; j++ )
+ cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(x[j]), cgm_vdcy2canvas(y[j]) );
+
+ cdCanvasEnd(intcgm_canvas);
+ }
+ }
+}
+
+static void bgclfl ( int mode )
+{
+ double factx, facty;
+ double posdx, negdx;
+ long int cor;
+ int i;
+
+ facty = base_direction.y * bline_sc_f;
+ factx = trace_direction.x * trc_st_f;
+
+ posdx = pos_bckfil_bnd * amp_sc_f * amp_direction.x;
+ negdx = neg_bckfil_bnd * amp_sc_f * amp_direction.x;
+
+ cdCanvasInteriorStyle(intcgm_canvas, CD_SOLID );
+
+ for ( i=0; i<n_samp; i++ )
+ {
+ int index = ( coind[i] <= intcgm_cgm.max_cix ) ? coind[i] : 1;
+
+ cor = cdEncodeColor ( (unsigned char)((intcgm_color_table[index].red*255)/intcgm_cgm.color_ext.white.red),
+ (unsigned char)((intcgm_color_table[index].green*255)/intcgm_cgm.color_ext.white.green),
+ (unsigned char)((intcgm_color_table[index].blue*255)/intcgm_cgm.color_ext.white.blue) );
+ cdCanvasSetForeground (intcgm_canvas, cor );
+
+ cdCanvasBegin(intcgm_canvas, CD_FILL );
+
+ cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(posdx + trace_start_pos.x + factx*(trace-1)),
+ cgm_vdcy2canvas(trace_start_pos.y + facty*(i)) );
+ cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(posdx + trace_start_pos.x + factx*(trace-1)),
+ cgm_vdcy2canvas(trace_start_pos.y + facty*(i+1)) );
+ cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(negdx + trace_start_pos.x + factx*(trace-1)),
+ cgm_vdcy2canvas(trace_start_pos.y + facty*(i+1)) );
+ cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(negdx + trace_start_pos.x + factx*(trace-1)),
+ cgm_vdcy2canvas(trace_start_pos.y + facty*(i)) );
+
+ cdCanvasEnd(intcgm_canvas);
+ }
+}
+
+void wiggle ( double posclp, double negclp )
+{
+ int i;
+ double facty = base_direction.y * bline_sc_f;
+ double factx = trace_direction.x * trc_st_f;
+ double dx = trace_start_pos.x + factx*(trace-1);
+
+ posclp *= amp_sc_f;
+ negclp *= amp_sc_f;
+
+ cdCanvasBegin(intcgm_canvas, CD_OPEN_LINES );
+
+ for ( i=0; i<n_samp; i++ )
+ {
+ double y1 = trace_start_pos.y + facty*(i);
+ double y2 = trace_start_pos.y + facty*(i+1);
+
+ if ( sample[i]>negclp && sample[i]<posclp &&
+ sample[i+1]>negclp && sample[i+1]<posclp )
+ cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(sample[i] + dx), cgm_vdcy2canvas(y1) );
+ else if ( sample[i]<negclp && sample[i+1]>negclp && sample[i+1]<posclp )
+ cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(negclp + dx), cgm_vdcy2canvas(interpl(i,y1,y2,negclp)) );
+ else if ( sample[i]<negclp && sample[i+1]>posclp )
+ {
+ cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(negclp + dx), cgm_vdcy2canvas(interpl(i,y1,y2,negclp)) );
+ cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(posclp + dx), cgm_vdcy2canvas(interpl(i,y1,y2,posclp)) );
+ }
+ else if ( sample[i]>negclp && sample[i]<posclp && sample[i+1]>posclp )
+ {
+ cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(sample[i] + dx), cgm_vdcy2canvas(y1) );
+ cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(posclp + dx), cgm_vdcy2canvas(interpl(i,y1,y2,posclp)) );
+ }
+ else if ( sample[i]>posclp && sample[i+1]<posclp && sample[i+1]>negclp )
+ cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(posclp + dx), cgm_vdcy2canvas(interpl(i,y1,y2,posclp)) );
+ else if ( sample[i]>posclp && sample[i+1]<negclp )
+ {
+ cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(posclp + dx), cgm_vdcy2canvas(interpl(i,y1,y2,posclp)) );
+ cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(negclp + dx), cgm_vdcy2canvas(interpl(i,y1,y2,negclp)) );
+ }
+ else if ( sample[i]>negclp && sample[i]<posclp && sample[i+1]<negclp )
+ {
+ cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(sample[i] + dx), cgm_vdcy2canvas(y1) );
+ cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(negclp + dx), cgm_vdcy2canvas(interpl(i,y1,y2,negclp)) );
+ }
+ }
+
+ cdCanvasEnd(intcgm_canvas);
+}
+
+void cgm_sism5 ( char *data_rec )
+{
+ int i, mode, trace_mode;
+ double pos_clp, neg_clp;
+
+ sample = (double *) malloc ( n_samp*sizeof(double) );
+
+ if ( trace_dsp_md > 7 )
+ coind = (long *) malloc ( n_samp*sizeof(long) );
+
+ for ( i=0; i<n_samp; i++ )
+ if ( trace_dsp_md < 8 )
+ sample[i] = strtod ( data_rec, &data_rec );
+ else
+ {
+ sample[i] = (double) strtol ( data_rec, &data_rec, 10 );
+ coind[i] = strtol ( data_rec, &data_rec, 10 );
+ }
+
+ trace += 1;
+
+ dirvet ( amp_direction.x );
+
+ ampscf ( amp_direction.x );
+
+ trace_mode = trace_dsp_md;
+
+ do
+ {
+
+ if ( trace_mode >= 64 )
+ mode = 64;
+ else if ( trace_mode >= 32 )
+ mode = 32;
+ else if ( trace_mode >= 16 )
+ mode = 16;
+ else if ( trace_mode >= 8 )
+ mode = 8;
+ else if ( trace_mode >= 4 )
+ mode = 4;
+ else if ( trace_mode >= 2 )
+ mode = 2;
+ else if ( trace_mode == 1 )
+ mode = 1;
+
+ switch ( mode )
+ {
+ case 64:
+ neg_clp = neg_clp_lmt;
+ pos_clp = ( pos_clp_lmt < 0 ) ? pos_clp_lmt : 0;
+ vasamp ( mode, pos_clp, neg_clp, 1 );
+ trace_mode -= 64;
+ break;
+ case 32:
+ neg_clp = ( neg_clp_lmt > 0 ) ? neg_clp_lmt : 0;
+ pos_clp = pos_clp_lmt;
+ vasamp ( mode, pos_clp, neg_clp, 1 );
+ trace_mode -= 32;
+ break;
+ case 16:
+ bgclfl( mode );
+ trace_mode -= 16;
+ break;
+ case 8:
+ bgclfl( mode );
+ trace_mode -= 8;
+ break;
+ case 4:
+ neg_clp = ( neg_clp_lmt > 0 ) ? neg_clp_lmt : 0;
+ pos_clp = pos_clp_lmt;
+ vasamp ( mode, pos_clp, neg_clp, 0 );
+ trace_mode -= 4;
+ break;
+ case 2:
+ neg_clp = ( neg_clp_lmt > 0 ) ? neg_clp_lmt : 0;
+ pos_clp = pos_clp_lmt;
+ vasamp ( mode, pos_clp, neg_clp, 0 );
+ trace_mode -= 2;
+ break;
+ case 1:
+ wiggle ( pos_clp_lmt, neg_clp_lmt );
+ trace_mode -= 1;
+ break;
+ }
+ } while ( trace_mode != 0 );
+
+ free(sample);
+
+ if ( trace_dsp_md > 7 )
+ free(coind);
+}
diff --git a/cd/src/intcgm/sism.h b/cd/src/intcgm/sism.h
new file mode 100755
index 0000000..f2f08f0
--- /dev/null
+++ b/cd/src/intcgm/sism.h
@@ -0,0 +1,3 @@
+void cgm_sism4 ( tpoint *, char * );
+void cgm_sism5 ( char * );
+
diff --git a/cd/src/intcgm/tparse.c b/cd/src/intcgm/tparse.c
new file mode 100755
index 0000000..9bc47b3
--- /dev/null
+++ b/cd/src/intcgm/tparse.c
@@ -0,0 +1,1370 @@
+#define _INTCGM2_C_
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <cd.h>
+#include <cdcgm.h>
+
+#include "list.h"
+#include "types.h"
+#include "bparse.h"
+#include "intcgm.h"
+#include "intcgm2.h"
+#include "intcgm4.h"
+#include "intcgm6.h"
+
+int cgmt_begmtf ( void ) /* begin metafile */
+{
+ char *str=NULL;
+
+ if ( cgmt_s ( &str ) ) return 1;
+
+ if (cdcgmbegmtfcb)
+ {
+ int err;
+ err = cdcgmbegmtfcb ( intcgm_canvas, &intcgm_view_xmin, &intcgm_view_ymin, &intcgm_view_xmax, &intcgm_view_ymax );
+ if ( err==CD_ABORT ) return -1;
+ }
+
+ free(str);
+
+ return cgmt_ter();
+}
+
+int cgmt_endmtf ( void ) /* end metafile */
+{
+ cgmt_ter();
+ return 1;
+}
+
+int cgmt_begpic ( void ) /* begin picture */
+{
+ char *string=NULL;
+
+ if ( intcgm_cgm.first )
+ intcgm_cgm.first = 0;
+ else
+ cdCanvasFlush(intcgm_canvas);
+
+ cdCanvasClip(intcgm_canvas, CD_CLIPAREA);
+
+ if ( cgmt_s ( &string ) ) return 1;
+
+ if (cdcgmbegpictcb)
+ {
+ int err;
+ err = cdcgmbegpictcb ( intcgm_canvas, string );
+ if ( err==CD_ABORT ) return -1;
+ }
+
+ free(string);
+
+ return cgmt_ter();
+}
+
+int cgmt_begpib ( void ) /* begin picture body */
+{
+ if (cdcgmbegpictbcb)
+ {
+ int err;
+ err = cdcgmbegpictbcb ( intcgm_canvas, 1., 1., intcgm_scale_factor_x, intcgm_scale_factor_y,
+ intcgm_scale_factor_mm_x*intcgm_cgm.scaling_mode.scale_factor,
+ intcgm_scale_factor_mm_y*intcgm_cgm.scaling_mode.scale_factor,
+ intcgm_cgm.drawing_mode,
+ intcgm_vdc_ext.xmin, intcgm_vdc_ext.ymin, intcgm_vdc_ext.xmax, intcgm_vdc_ext.ymax );
+ if ( err==CD_ABORT ) return -1;
+ }
+
+
+ if (cdcgmsizecb)
+ {
+ int err, w, h;
+ double w_mm=0., h_mm=0.;
+
+ w = intcgm_view_xmax-intcgm_view_xmin+1;
+ h = intcgm_view_ymax-intcgm_view_ymin+1;
+
+ if ( intcgm_cgm.vdc_type==INTEGER )
+ {
+ w = (int) (intcgm_cgm.vdc_ext.second.x - intcgm_cgm.vdc_ext.first.x);
+ h = (int) (intcgm_cgm.vdc_ext.second.y - intcgm_cgm.vdc_ext.first.y);
+ if ( intcgm_cgm.scaling_mode.mode==METRIC )
+ {
+ w_mm = w * intcgm_cgm.scaling_mode.scale_factor;
+ h_mm = h * intcgm_cgm.scaling_mode.scale_factor;
+ }
+ }
+ else
+ {
+ if ( intcgm_cgm.scaling_mode.mode==METRIC )
+ {
+ w_mm = (intcgm_cgm.vdc_ext.second.x - intcgm_cgm.vdc_ext.first.x) * intcgm_cgm.scaling_mode.scale_factor;
+ h_mm = (intcgm_cgm.vdc_ext.second.y - intcgm_cgm.vdc_ext.first.y) * intcgm_cgm.scaling_mode.scale_factor;
+ }
+ }
+
+ err = cdcgmsizecb ( intcgm_canvas, w, h, w_mm, h_mm );
+ if ( err==CD_ABORT ) return -1;
+ }
+
+ return cgmt_ter();
+}
+
+int cgmt_endpic ( void ) /* end picture */
+{
+ return cgmt_ter();
+}
+
+int cgmt_mtfver ( void ) /* metafile version */
+{
+ long version;
+
+ if ( cgmt_i ( &version ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_mtfdsc ( void ) /* metafile description */
+{
+ char *string=NULL;
+
+ if ( cgmt_s ( &string ) ) return 1;
+
+ free(string);
+
+ return cgmt_ter();
+}
+
+int cgmt_vdctyp ( void ) /* vdc type */
+{
+ const char *options[] = { "integer", "real", NULL };
+
+ if ( cgmt_e ( &(intcgm_cgm.vdc_type), options ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_intpre ( void ) /* integer precision */
+{
+ if ( cgmt_i ( &(intcgm_cgm.int_prec.t_prec.minint) ) ) return 1;
+ if ( cgmt_i ( &(intcgm_cgm.int_prec.t_prec.maxint) ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_realpr ( void ) /* real precision */
+{
+ if ( cgmt_r ( &(intcgm_cgm.real_prec.t_prec.minreal) ) ) return 1;
+ if ( cgmt_r ( &(intcgm_cgm.real_prec.t_prec.maxreal) ) ) return 1;
+ if ( cgmt_i ( &(intcgm_cgm.real_prec.t_prec.digits) ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_indpre ( void ) /* index precision */
+{
+ if ( cgmt_i ( &(intcgm_cgm.ix_prec.t_prec.minint) ) ) return 1;
+ if ( cgmt_i ( &(intcgm_cgm.ix_prec.t_prec.maxint) ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_colpre ( void ) /* colour precision */
+{
+ if ( cgmt_i ( &(intcgm_cgm.cd_prec) ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_colipr ( void ) /* colour index precision */
+{
+ if ( cgmt_i ( &(intcgm_cgm.cix_prec) ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_maxcoi ( void ) /* maximum colour index */
+{
+ if ( cgmt_i ( &(intcgm_cgm.max_cix) ) ) return 1;
+
+ intcgm_color_table = (trgb *) realloc ( intcgm_color_table, sizeof(trgb)*(intcgm_cgm.max_cix+1) );
+
+ intcgm_color_table[0].red = 255;
+ intcgm_color_table[0].green = 255;
+ intcgm_color_table[0].blue = 255;
+ intcgm_color_table[1].red = 0;
+ intcgm_color_table[1].green = 0;
+ intcgm_color_table[1].blue = 0;
+
+ return cgmt_ter();
+}
+
+int cgmt_covaex ( void ) /* colour value extent */
+{
+ if ( cgmt_rgb ( &(intcgm_cgm.color_ext.black.red), &(intcgm_cgm.color_ext.black.green), &(intcgm_cgm.color_ext.black.blue) ) ) return 1;
+
+ if ( cgmt_rgb ( &(intcgm_cgm.color_ext.white.red), &(intcgm_cgm.color_ext.white.green), &(intcgm_cgm.color_ext.white.blue) ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_mtfell ( void ) /* metafile element list */
+{
+ char *elist=NULL;
+
+ if ( cgmt_s ( &elist ) ) return 1;
+
+ free(elist);
+
+ return cgmt_ter();
+}
+
+int cgmt_bmtfdf (void ) /* begin metafile defaults */
+{
+ return cgmt_ter();
+}
+
+int cgmt_emtfdf ( void ) /* end metafile defaults */
+{
+ return cgmt_ter();
+}
+
+int cgmt_fntlst ( void ) /* font list */
+{
+ char *font=NULL;
+
+ if ( intcgm_text_att.font_list==NULL ) intcgm_text_att.font_list = cgm_NewList();
+
+ while ( cgmt_ter() )
+ {
+ if ( cgmt_s ( &font ) ) return 1;
+ cgm_AppendList ( intcgm_text_att.font_list, font );
+ }
+
+ return 0;
+}
+
+int cgmt_chslst ( void ) /* character set list */
+{
+ const char *options[] = { "std94", "std96", "std94multibyte", "std96multibyte",
+ "completecode", NULL };
+ char *tail;
+ short code;
+
+ do
+ {
+ if ( cgmt_e ( &(code), options ) ) return 1;
+
+ if ( cgmt_s ( &tail ) ) return 1;
+
+ free ( tail );
+
+ } while ( cgmt_ter() );
+
+ return 0;
+}
+
+int cgmt_chcdac ( void ) /* character coding announcer */
+{
+ const char *options[] = { "basic7bit", "basic8bit", "extd7bit", "extd8bit", NULL };
+ short code;
+
+ if ( cgmt_e ( &(code), options ) ) return 1;
+
+ return cgmt_ter ();
+}
+
+int cgmt_sclmde ( void ) /* scaling mode */
+{
+ const char *options[] = { "abstract", "metric", NULL };
+
+ if ( cgmt_e ( &(intcgm_cgm.scaling_mode.mode), options ) ) return 1;
+
+ if ( cgmt_r ( &(intcgm_cgm.scaling_mode.scale_factor) ) ) return 1;
+
+ if ( intcgm_cgm.scaling_mode.mode==ABSTRACT ) intcgm_cgm.scaling_mode.scale_factor=1.;
+
+ intcgm_cgm.drawing_mode = ABSTRACT;
+
+ if (cdcgmsclmdecb)
+ {
+ int err;
+ err = cdcgmsclmdecb ( intcgm_canvas, intcgm_cgm.scaling_mode.mode, &intcgm_cgm.drawing_mode, &intcgm_cgm.scaling_mode.scale_factor );
+ if ( err==CD_ABORT ) return -1;
+ }
+
+ if ( intcgm_cgm.drawing_mode==ABSTRACT )
+ {
+ intcgm_clip_xmin = cgm_canvas2vdcx ( intcgm_view_xmin );
+ intcgm_clip_xmax = cgm_canvas2vdcx ( intcgm_view_xmax );
+ intcgm_clip_ymin = cgm_canvas2vdcy ( intcgm_view_ymin );
+ intcgm_clip_ymax = cgm_canvas2vdcy ( intcgm_view_ymax );
+ }
+ else
+ {
+ intcgm_clip_xmin = intcgm_vdc_ext.xmin*intcgm_cgm.scaling_mode.scale_factor;
+ intcgm_clip_xmax = intcgm_vdc_ext.xmax*intcgm_cgm.scaling_mode.scale_factor;
+ intcgm_clip_ymin = intcgm_vdc_ext.ymin*intcgm_cgm.scaling_mode.scale_factor;
+ intcgm_clip_ymax = intcgm_vdc_ext.ymax*intcgm_cgm.scaling_mode.scale_factor;
+ }
+
+ return cgmt_ter();
+}
+
+int cgmt_clslmd ( void ) /* colour selection mode */
+{
+ const char *options[] = { "indexed", "direct", NULL };
+
+ if ( cgmt_e ( &(intcgm_cgm.clrsm), options ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_lnwdmd ( void ) /* line width specification mode */
+{
+ const char *options[] = { "abstract", "scaled", NULL };
+
+ if ( cgmt_e ( &(intcgm_cgm.lnwsm), options ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_mkszmd ( void ) /* marker size specification mode */
+{
+ const char *options[] = { "abstract", "scaled", NULL };
+
+ if ( cgmt_e ( &(intcgm_cgm.mkssm), options ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_edwdmd ( void ) /* edge width specification mode */
+{
+ const char *options[] = { "abstract", "scaled", NULL };
+
+ if ( cgmt_e ( &(intcgm_cgm.edwsm), options ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_vdcext ( void ) /* vdc extent */
+{
+ if ( cgmt_p ( &(intcgm_cgm.vdc_ext.first.x), &(intcgm_cgm.vdc_ext.first.y) ) ) return 1;
+
+ if ( cgmt_p ( &(intcgm_cgm.vdc_ext.second.x), &(intcgm_cgm.vdc_ext.second.y) ) ) return 1;
+
+ if (cdcgmvdcextcb)
+ {
+ int err;
+ err = cdcgmvdcextcb( intcgm_canvas, intcgm_cgm.vdc_type, &(intcgm_cgm.vdc_ext.first.x), &(intcgm_cgm.vdc_ext.first.y),
+ &(intcgm_cgm.vdc_ext.second.x), &(intcgm_cgm.vdc_ext.second.y) );
+ if (err==CD_ABORT) return -1;
+ }
+
+ cgm_do_vdcext ( intcgm_cgm.vdc_ext.first, intcgm_cgm.vdc_ext.second );
+
+ return cgmt_ter();
+}
+
+int cgmt_bckcol ( void ) /* backgound colour */
+{
+ if ( cgmt_rgb ( &(intcgm_cgm.back_color.red), &(intcgm_cgm.back_color.green), &(intcgm_cgm.back_color.blue) ) ) return 1;
+
+ cgm_do_bckcol ( intcgm_cgm.back_color );
+
+ return cgmt_ter();
+}
+
+int cgmt_vdcipr ( void ) /* vdc integer precision */
+{
+ if ( cgmt_i ( &(intcgm_cgm.vdc_int.t_prec.minint) ) ) return 1;
+ if ( cgmt_i ( &(intcgm_cgm.vdc_int.t_prec.maxint) ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_vdcrpr ( void ) /* vdc real precision */
+{
+ if ( cgmt_r ( &(intcgm_cgm.vdc_real.t_prec.minreal) ) ) return 1;
+ if ( cgmt_r ( &(intcgm_cgm.vdc_real.t_prec.maxreal) ) ) return 1;
+ if ( cgmt_i ( &(intcgm_cgm.vdc_real.t_prec.digits) ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_auxcol ( void ) /* auxiliary colour */
+{
+ if ( cgmt_co ( &(intcgm_cgm.aux_color) ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_transp ( void ) /* transparency */
+{
+ const char *options[] = { "on", "off", NULL };
+
+ if ( cgmt_e ( &(intcgm_cgm.transparency), options ) ) return 1;
+
+ cgm_do_transp ( intcgm_cgm.transparency );
+
+ return cgmt_ter();
+}
+
+int cgmt_clprec ( void ) /* clip rectangle */
+{
+ if ( cgmt_p ( &(intcgm_cgm.clip_rect.first.x), &(intcgm_cgm.clip_rect.first.y) ) ) return 1;
+
+ if ( cgmt_p ( &(intcgm_cgm.clip_rect.second.x), &(intcgm_cgm.clip_rect.second.y) ) ) return 1;
+
+ cgm_do_clprec ( intcgm_cgm.clip_rect.first, intcgm_cgm.clip_rect.second );
+
+ return cgmt_ter();
+}
+
+int cgmt_clpind ( void ) /* clip indicator */
+{
+ const char *options[] = { "on", "off", NULL };
+
+ if ( cgmt_e ( &(intcgm_cgm.clip_ind), options ) ) return 1;
+
+ cgm_do_clpind ( intcgm_cgm.clip_ind );
+
+ return cgmt_ter();
+}
+
+static tpoint *get_points ( int *np )
+{
+ *np=0;
+
+ do
+ {
+ if ( cgmt_p ( &(intcgm_point_list[*np].x), &(intcgm_point_list[*np].y) ) ) return NULL;
+ ++(*np);
+ if ( *np==intcgm_npoints)
+ {
+ intcgm_npoints *= 2;
+ intcgm_point_list = (tpoint *) realloc ( intcgm_point_list, intcgm_npoints*sizeof(tpoint) );
+ }
+ } while ( cgmt_ter() );
+
+ return intcgm_point_list;
+}
+
+int cgmt_polyln ( void ) /* polyline */
+{
+ tpoint *pt;
+ int np;
+
+ pt = get_points( &np );
+ if ( pt == NULL ) return 1;
+
+ cgm_do_polyln ( np, pt );
+
+ return 0;
+}
+
+int cgmt_incply ( void ) /* incremental polyline */
+{
+ tpoint *pt;
+ int np;
+
+ pt = get_points( &np );
+ if ( pt == NULL ) return 1;
+
+ cgm_do_incply ( np, pt );
+
+ return 0;
+}
+
+int cgmt_djtply ( void ) /* disjoint polyline */
+{
+ tpoint *pt;
+ int np;
+
+ pt = get_points( &np );
+ if ( pt == NULL ) return 1;
+
+ cgm_do_djtply ( np, pt );
+
+ return 0;
+}
+
+int cgmt_indjpl ( void ) /* incremental disjoint polyline */
+{
+ tpoint *pt;
+ int np;
+
+ pt = get_points( &np );
+ if ( pt == NULL ) return 1;
+
+ cgm_do_indpl ( np, pt );
+
+ return 0;
+}
+
+int cgmt_polymk ( void ) /* polymarker */
+{
+ tpoint *pt;
+ int np;
+
+ pt = get_points( &np );
+ if ( pt == NULL ) return 1;
+
+ cgm_do_polymk ( np, pt );
+
+ return 0;
+}
+
+int cgmt_incplm ( void ) /* incremental polymarker */
+{
+ tpoint *pt;
+ int np;
+
+ pt = get_points( &np );
+ if ( pt == NULL ) return 1;
+
+ cgm_do_incplm ( np, pt );
+
+ return 0;
+}
+
+int cgmt_text ( void ) /* text */
+{
+ tpoint pos;
+ const char *options[] = { "final", "notfinal", NULL };
+ short flag;
+ char *string;
+
+ if ( cgmt_p ( &(pos.x), &(pos.y) ) ) return 1;
+
+ if ( cgmt_e ( &flag, options ) ) return 1;
+
+ if ( cgmt_s ( &string ) ) return 1;
+
+ cgm_do_text ( NORM_TEXT, string, pos );
+
+ free ( string );
+
+ return cgmt_ter();
+}
+
+int cgmt_rsttxt ( void ) /* restricted text */
+{
+ double width, height;
+ tpoint pos;
+ const char *options[] = { "final", "notfinal", NULL };
+ short flag;
+ char *string;
+
+ if ( cgmt_vdc ( &width ) ) return 1;
+
+ if ( cgmt_vdc ( &height ) ) return 1;
+
+ if ( cgmt_p ( &(pos.x), &(pos.y) ) ) return 1;
+
+ if ( cgmt_e ( &flag, options ) ) return 1;
+
+ if ( cgmt_s ( &string ) ) return 1;
+
+ intcgm_text_att.height = height;
+
+ cgm_do_text ( RESTRICTED_TEXT, string, pos );
+
+ if ( string!= NULL ) free ( string );
+
+ return cgmt_ter();
+}
+
+int cgmt_apdtxt ( void ) /* append text */
+{
+ const char *options[] = { "final", "notfinal", NULL };
+ short flag;
+ char *string;
+
+ if ( cgmt_e ( &flag, options ) ) return 1;
+
+ if ( cgmt_s ( &string ) ) return 1;
+
+ free ( string );
+
+ return cgmt_ter();
+}
+
+int cgmt_polygn ( void ) /* polygon */
+{
+ tpoint *pt;
+ int np;
+
+ pt = get_points( &np );
+ if ( pt == NULL ) return 1;
+
+ cgm_do_polygn ( np, pt );
+
+ return 0;
+}
+
+int cgmt_incplg ( void ) /* incremental polygon */
+{
+ tpoint *pt;
+ int np;
+
+ pt = get_points( &np );
+ if ( pt == NULL ) return 1;
+
+ cgm_do_incplg ( np, pt );
+
+ return 0;
+}
+
+static int get_point_set ( tpoint **pts, short **flags, int *np )
+{
+ int intcgm_block=500;
+ const char *options[] = { "invis", "vis", "closeinvis", "closevis", NULL };
+
+ *np=0;
+ *pts = (tpoint *) malloc ( intcgm_block*sizeof(tpoint) );
+ *flags = (short *) malloc ( intcgm_block*sizeof(short) );
+
+ do
+ {
+ if ( cgmt_p ( &((*pts)[*np].x), &((*pts)[*np].y) ) ) return 1;
+
+ if ( cgmt_e ( &((*flags)[*np]), options ) ) return 1;
+
+ ++(*np);
+ if ( *np==intcgm_block)
+ {
+ intcgm_block *= 2;
+ *pts = (tpoint *) realloc ( *pts, intcgm_block*sizeof(tpoint) );
+ *flags = (short *) realloc ( *flags, intcgm_block*sizeof(short) );
+ }
+ } while ( cgmt_ter() );
+
+ return 0;
+}
+
+int cgmt_plgset ( void ) /* polygon set */
+{
+ tpoint *pt;
+ short *flag;
+ int np;
+
+ if ( get_point_set ( &pt, &flag, &np ) ) return 1;
+
+ cgm_do_plgset( NO, np, pt, flag );
+
+ free ( pt );
+ free ( flag );
+
+ return 0;
+}
+
+int cgmt_inpgst ( void ) /* incremental polygon set */
+{
+ tpoint *pt;
+ short *flag;
+ int np;
+
+ if ( get_point_set ( &pt, &flag, &np ) ) return 1;
+
+ cgm_do_plgset( YES, np, pt, flag );
+
+ free ( pt );
+ free ( flag );
+
+ return 0;
+}
+
+int cgmt_cellar ( void ) /* cell array */
+{
+ tpoint corner1;
+ tpoint corner2;
+ tpoint corner3;
+ long nx, ny;
+ long local_color_prec;
+ tcolor *cell;
+ int i,k;
+
+ if ( cgmt_p ( &(corner1.x), &(corner1.y) ) ) return 1;
+ if ( cgmt_p ( &(corner2.x), &(corner2.y) ) ) return 1;
+ if ( cgmt_p ( &(corner3.x), &(corner3.y) ) ) return 1;
+
+ if ( cgmt_i ( &nx ) ) return 1;
+ if ( cgmt_i ( &ny ) ) return 1;
+
+ if ( cgmt_i ( &(local_color_prec) ) ) return 1;
+
+ cell = (tcolor *) malloc ( nx*ny*sizeof(tcolor) );
+
+ cgmt_getparentheses();
+
+ for ( k=0; k<ny; k++ )
+ {
+ for ( i=0; i<nx; i++ )
+ {
+ if ( cgmt_co ( &(cell[k*nx+i]) ) ) return 1;
+ }
+ cgm_getfilepos();
+ }
+
+ cgmt_getparentheses();
+
+ cgm_do_cellar ( corner1, corner2, corner3, nx, ny, local_color_prec, cell );
+
+ free(cell);
+
+ return cgmt_ter();
+}
+
+int cgmt_gdp ( void ) /* generalized drawing picture */
+{
+ long identifier;
+ tpoint *pt = NULL;
+ int intcgm_block = 500;
+ int np = 0;
+ char *data_rec;
+
+ pt = (tpoint *) malloc ( intcgm_block*sizeof(tpoint) );
+
+ if ( cgmt_i ( &identifier ) ) return 1;
+
+ while ( strstr(cgmt_getsep(),",")==NULL )
+ {
+ if ( cgmt_p ( &(pt[np].x), &(pt[np].y) ) )
+ {
+ if ( pt!=NULL ) free(pt);
+ return 1;
+ }
+ ++np;
+
+ if ( np==intcgm_block )
+ {
+ intcgm_block *= 2;
+ pt = (tpoint *) realloc ( pt, intcgm_block*sizeof(tpoint) );
+ }
+ }
+
+ if ( cgmt_s ( &data_rec ) ) return 1;
+
+ cgm_do_gdp ( identifier, pt, data_rec );
+
+ free ( data_rec );
+ free ( pt );
+
+ return cgmt_ter();
+}
+
+int cgmt_rect ( void ) /* rectangle */
+{
+ tpoint point1;
+ tpoint point2;
+
+ if ( cgmt_p ( &(point1.x), &(point1.y) ) ) return 1;
+ if ( cgmt_p ( &(point2.x), &(point2.y) ) ) return 1;
+
+ cgm_do_rect ( point1, point2 );
+
+ return cgmt_ter();
+}
+
+int cgmt_circle ( void ) /* circle */
+{
+ tpoint center;
+ double radius;
+
+ if ( cgmt_p ( &(center.x), &(center.y) ) ) return 1;
+
+ if ( cgmt_vdc ( &radius ) ) return 1;
+
+ cgm_do_circle ( center, radius );
+
+ return cgmt_ter();
+}
+
+int cgmt_circ3p ( void ) /* circular arc 3 point */
+{
+ tpoint starting;
+ tpoint intermediate;
+ tpoint ending;
+
+ if ( cgmt_p ( &(starting.x), &(starting.y) ) ) return 1;
+ if ( cgmt_p ( &(intermediate.x), &(intermediate.y) ) ) return 1;
+ if ( cgmt_p ( &(ending.x), &(ending.y) ) ) return 1;
+
+ cgm_do_circ3p ( starting, intermediate, ending );
+
+ return cgmt_ter();
+}
+
+int cgmt_cir3pc ( void ) /* circular arc 3 point close */
+{
+ tpoint starting;
+ tpoint intermediate;
+ tpoint ending;
+ const char *options[] = { "pie", "chord", NULL };
+ short close_type;
+
+ if ( cgmt_p ( &(starting.x), &(starting.y) ) ) return 1;
+ if ( cgmt_p ( &(intermediate.x), &(intermediate.y) ) ) return 1;
+ if ( cgmt_p ( &(ending.x), &(ending.y) ) ) return 1;
+
+ if ( cgmt_e ( &close_type, options ) ) return 1;
+
+ cgm_do_circ3pc ( starting, intermediate, ending, close_type );
+
+ return cgmt_ter();
+}
+
+int cgmt_circnt ( void ) /* circular arc centre */
+{
+ tpoint center;
+ tpoint start;
+ tpoint end;
+ double radius;
+
+ if ( cgmt_p ( &(center.x), &(center.y) ) ) return 1;
+
+ if ( cgmt_vdc ( &(start.x) ) ) return 1;
+ if ( cgmt_vdc ( &(start.y) ) ) return 1;
+
+ if ( cgmt_vdc ( &(end.x) ) ) return 1;
+ if ( cgmt_vdc ( &(end.y) ) ) return 1;
+
+ if ( cgmt_vdc ( &radius ) ) return 1;
+
+ cgm_do_circcnt ( center, start, end, radius );
+
+ return cgmt_ter();
+}
+
+int cgmt_ccntcl ( void ) /* circular arc centre close */
+{
+ tpoint center;
+ tpoint start;
+ tpoint end;
+ double radius;
+ const char *options[] = { "pie", "chord", NULL };
+ short close_type;
+
+ if ( cgmt_p ( &(center.x), &(center.y) ) ) return 1;
+
+ if ( cgmt_vdc ( &(start.x) ) ) return 1;
+ if ( cgmt_vdc ( &(start.y) ) ) return 1;
+
+ if ( cgmt_vdc ( &(end.x) ) ) return 1;
+ if ( cgmt_vdc ( &(end.y) ) ) return 1;
+
+ if ( cgmt_vdc ( &radius ) ) return 1;
+
+ if ( cgmt_e ( &close_type, options ) ) return 1;
+
+ cgm_do_ccntcl ( center, start, end, radius, close_type );
+
+ return cgmt_ter();
+}
+
+int cgmt_ellips ( void ) /* ellipse */
+{
+ tpoint center;
+ tpoint first_CDP;
+ tpoint second_CDP;
+
+ if ( cgmt_p ( &(center.x), &(center.y) ) ) return 1;
+
+ if ( cgmt_p ( &(first_CDP.x), &(first_CDP.y) ) ) return 1;
+ if ( cgmt_p ( &(second_CDP.x), &(second_CDP.y) ) ) return 1;
+
+ cgm_do_ellips ( center, first_CDP, second_CDP );
+
+ return cgmt_ter();
+}
+
+int cgmt_ellarc ( void ) /* elliptical arc */
+{
+ tpoint center;
+ tpoint first_CDP;
+ tpoint second_CDP;
+ tpoint start, end;
+
+ if ( cgmt_p ( &(center.x), &(center.y) ) ) return 1;
+
+ if ( cgmt_p ( &(first_CDP.x), &(first_CDP.y) ) ) return 1;
+ if ( cgmt_p ( &(second_CDP.x), &(second_CDP.y) ) ) return 1;
+
+ if ( cgmt_vdc ( &(start.x) ) ) return 1;
+ if ( cgmt_vdc ( &(start.y) ) ) return 1;
+
+ if ( cgmt_vdc ( &(end.x) ) ) return 1;
+ if ( cgmt_vdc ( &(end.y) ) ) return 1;
+
+ cgm_do_ellarc ( center, first_CDP, second_CDP, start, end );
+
+ return cgmt_ter();
+}
+
+int cgmt_ellacl ( void ) /* elliptical arc close */
+{
+ tpoint center;
+ tpoint first_CDP;
+ tpoint second_CDP;
+ tpoint start, end;
+ const char *options[] = { "pie", "chord", NULL };
+ short close_type;
+
+ if ( cgmt_p ( &(center.x), &(center.y) ) ) return 1;
+
+ if ( cgmt_p ( &(first_CDP.x), &(first_CDP.y) ) ) return 1;
+ if ( cgmt_p ( &(second_CDP.x), &(second_CDP.y) ) ) return 1;
+
+ if ( cgmt_vdc ( &(start.x) ) ) return 1;
+ if ( cgmt_vdc ( &(start.y) ) ) return 1;
+
+ if ( cgmt_vdc ( &(end.x) ) ) return 1;
+ if ( cgmt_vdc ( &(end.y) ) ) return 1;
+
+ if ( cgmt_e ( &close_type, options ) ) return 1;
+
+ cgm_do_ellacl ( center, first_CDP, second_CDP, start, end, close_type );
+
+ return cgmt_ter();
+}
+
+int cgmt_lnbdin ( void ) /* line bundle index */
+{
+ if ( cgmt_i ( &(intcgm_line_att.index) ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_lntype ( void ) /* line type */
+{
+ if ( cgmt_i ( &(intcgm_line_att.type) ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_lnwidt ( void ) /* line width */
+{
+ if ( intcgm_cgm.lnwsm==0 )
+ {
+ if ( cgmt_vdc ( &(intcgm_line_att.width) ) ) return 1;
+ }
+ else
+ {
+
+ if ( cgmt_r ( &(intcgm_line_att.width) ) ) return 1;
+ }
+
+ return cgmt_ter();
+}
+
+int cgmt_lncolr ( void ) /* line colour */
+{
+ if ( cgmt_co ( &(intcgm_line_att.color) ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_mkbdin ( void ) /* marker bundle index */
+{
+ if ( cgmt_i ( &(intcgm_marker_att.index) ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_mktype ( void ) /* marker type */
+{
+ if ( cgmt_i ( &(intcgm_marker_att.type) ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_mksize ( void ) /* marker size */
+{
+ if ( intcgm_cgm.mkssm == 0 )
+ {
+ if ( cgmt_vdc ( &(intcgm_marker_att.size) ) ) return 1;
+ }
+ else
+ {
+ if ( cgmt_r ( &(intcgm_marker_att.size) ) ) return 1;
+ }
+
+ return cgmt_ter();
+}
+
+int cgmt_mkcolr ( void ) /* marker colour */
+{
+ if ( cgmt_co ( &(intcgm_marker_att.color) ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_txbdin ( void ) /* text bundle index */
+{
+ if ( cgmt_i ( &(intcgm_text_att.index) ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_txftin ( void ) /* text font index */
+{
+ char *font;
+ char *font_array[] = {"SYSTEM", "COURIER", "TIMES", "HELVETICA", NULL};
+ char *style_array[] = {"BOLDITALIC", "ITALIC", "BOLD", "PLAIN", NULL};
+ int cdstyle[] = {CD_BOLD_ITALIC, CD_ITALIC, CD_BOLD, CD_PLAIN};
+ int i;
+
+ if ( cgmt_i ( &(intcgm_text_att.font_index) ) ) return 1;
+
+ font = (char *) cgm_GetList ( intcgm_text_att.font_list, intcgm_text_att.font_index );
+
+ if ( font==NULL ) font = "SYSTEM";
+
+ intcgm_text_att.font = 0;
+ for ( i=0; font_array[i]!=NULL; i++ )
+ {
+ if ( strstr( font, font_array[i] ) )
+ {
+ intcgm_text_att.font = i;
+ break;
+ }
+ }
+
+ intcgm_text_att.style = 0;
+ for ( i=0; style_array[i]!=NULL; i++ )
+ {
+ if ( strstr( font, style_array[i] ) )
+ {
+ intcgm_text_att.style = cdstyle[i];
+ break;
+ }
+ }
+
+ cgm_setfont ( intcgm_text_att.font, intcgm_text_att.style, intcgm_text_att.height );
+
+ return cgmt_ter();
+}
+
+int cgmt_txtprc ( void ) /* text precision */
+{
+ const char *options[] = { "string", "char", "stroke", NULL };
+
+ if ( cgmt_e ( &(intcgm_text_att.prec), options ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_chrexp ( void ) /* char expansion factor */
+{
+ if ( cgmt_r ( &(intcgm_text_att.exp_fact) ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_chrspc ( void ) /* char spacing */
+{
+ if ( cgmt_r ( &(intcgm_text_att.char_spacing) ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_txtclr ( void ) /* text colour */
+{
+ if ( cgmt_co ( &(intcgm_text_att.color) ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_chrhgt ( void ) /* char height */
+{
+ if ( cgmt_vdc ( &(intcgm_text_att.height) ) ) return 1;
+
+ cgm_do_text_height ( intcgm_text_att.height );
+
+ return cgmt_ter();
+}
+
+int cgmt_chrori ( void ) /* char orientation */
+{
+ if ( cgmt_vdc ( &(intcgm_text_att.char_up.x) ) ) return 1;
+ if ( cgmt_vdc ( &(intcgm_text_att.char_up.y) ) ) return 1;
+ if ( cgmt_vdc ( &(intcgm_text_att.char_base.x) ) ) return 1;
+ if ( cgmt_vdc ( &(intcgm_text_att.char_base.y) ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_txtpat ( void ) /* text path */
+{
+ const char *options[] = { "right", "left", "up", "down", NULL };
+
+ if ( cgmt_e ( &(intcgm_text_att.path), options ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_txtali ( void ) /* text alignment */
+{
+ const char *hor[] = { "normhoriz", "left", "ctr", "right", "conthoriz", NULL };
+ const char *ver[] = { "normvert", "top", "cap", "half", "base", "bottom",
+ "contvert", NULL };
+
+ if ( cgmt_e ( &(intcgm_text_att.alignment.hor), hor ) ) return 1;
+ if ( cgmt_e ( &(intcgm_text_att.alignment.ver), ver ) ) return 1;
+
+ if ( cgmt_r ( &(intcgm_text_att.alignment.cont_hor) ) ) return 1;
+ if ( cgmt_r ( &(intcgm_text_att.alignment.cont_ver) ) ) return 1;
+
+ cgm_do_txtalign ( intcgm_text_att.alignment.hor, intcgm_text_att.alignment.ver );
+
+ return cgmt_ter();
+}
+
+int cgmt_chseti ( void ) /* character set index */
+{
+ long set;
+
+ if ( cgmt_i ( &set ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_achsti ( void ) /* alternate character set index */
+{
+ long set;
+
+ if ( cgmt_i ( &set ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_fillin ( void ) /* fill bundle index */
+{
+ if ( cgmt_i ( &(intcgm_fill_att.index) ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_intsty ( void ) /* interior style */
+{
+ const char *options[] = { "hollow", "solid", "pat", "hatch", "empty", NULL };
+
+ if ( cgmt_e ( &(intcgm_fill_att.int_style), options ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_fillco ( void ) /* fill colour */
+{
+ if ( cgmt_co ( &(intcgm_fill_att.color) ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_hatind ( void ) /* hatch index */
+{
+ if ( cgmt_i ( &(intcgm_fill_att.hatch_index) ) ) return 1;
+ if ( intcgm_fill_att.hatch_index==3 ) intcgm_fill_att.hatch_index = 4;
+ else if ( intcgm_fill_att.hatch_index==4 ) intcgm_fill_att.hatch_index = 3;
+
+ return cgmt_ter();
+}
+
+int cgmt_patind ( void ) /* pattern index */
+{
+ if ( cgmt_i ( &(intcgm_fill_att.pat_index) ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_edgind ( void ) /* edge bundle index */
+{
+ if ( cgmt_i ( &(intcgm_edge_att.index) ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_edgtyp( void ) /* edge type */
+{
+ if ( cgmt_i ( &(intcgm_edge_att.type) ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_edgwid ( void ) /* edge width */
+{
+ if ( intcgm_cgm.edwsm==0 )
+ {
+ if ( cgmt_vdc ( &(intcgm_edge_att.width) ) ) return 1;
+ }
+ else
+ {
+ if ( cgmt_r ( &(intcgm_edge_att.width) ) ) return 1;
+ }
+
+ return cgmt_ter();
+}
+
+int cgmt_edgcol ( void ) /* edge colour */
+{
+ if ( cgmt_co ( &(intcgm_edge_att.color) ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_edgvis ( void ) /* edge visibility */
+{
+ const char *options[] = { "off", "on", NULL };
+
+ if ( cgmt_e ( &(intcgm_edge_att.visibility), options ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_fillrf ( void ) /* fill reference point */
+{
+ if ( cgmt_p ( &(intcgm_fill_att.ref_pt.x), &(intcgm_fill_att.ref_pt.y) ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_pattab ( void ) /* pattern table */
+{
+ long local_color_prec;
+ int i;
+ pat_table *pat, *p;
+
+ pat = (pat_table *) malloc ( sizeof(pat_table) );
+
+ if ( intcgm_fill_att.pat_list==NULL ) intcgm_fill_att.pat_list = cgm_NewList();
+
+ if ( cgmt_i ( &(pat->index) ) ) return 1;
+
+ if ( cgmt_i ( &(pat->nx) ) ) return 1;
+ if ( cgmt_i ( &(pat->ny) ) ) return 1;
+
+ if ( cgmt_i ( &(local_color_prec) ) ) return 1;
+
+ pat->pattern = (tcolor *) malloc ( pat->nx*pat->ny*sizeof(tcolor) );
+
+ cgmt_getparentheses();
+
+ for ( i=0; i<(pat->nx*pat->ny); i++ )
+ if ( cgmt_co ( &(pat->pattern[i]) ) ) return 1;
+
+ cgmt_getparentheses();
+
+ for ( i=0; (p=(pat_table *)cgm_GetList(intcgm_fill_att.pat_list,i))!=NULL; i++ )
+ {
+ if ( p->index==pat->index )
+ {
+ free(p->pattern);
+ cgm_DelList(intcgm_fill_att.pat_list,i);
+ break;
+ }
+ }
+
+ cgm_AppendList ( intcgm_fill_att.pat_list, pat );
+
+ return cgmt_ter();
+}
+
+int cgmt_patsiz ( void ) /* pattern size */
+{
+ if ( cgmt_vdc ( &(intcgm_fill_att.pat_size.height.x) ) ) return 1;
+ if ( cgmt_vdc ( &(intcgm_fill_att.pat_size.height.y) ) ) return 1;
+ if ( cgmt_vdc ( &(intcgm_fill_att.pat_size.width.x) ) ) return 1;
+ if ( cgmt_vdc ( &(intcgm_fill_att.pat_size.width.y) ) ) return 1;
+
+ return cgmt_ter();
+}
+
+int cgmt_coltab ( void ) /* colour table */
+{
+ long starting_index;
+
+ if ( cgmt_i ( &(starting_index) ) ) return 1;
+
+ while ( cgmt_ter() )
+ {
+ if ( cgmt_rgb ( &(intcgm_color_table[starting_index].red), &(intcgm_color_table[starting_index].green),
+ &(intcgm_color_table[starting_index].blue) ) ) return 1;
+ starting_index++;
+ }
+
+ return 0;
+}
+
+int cgmt_asf ( void ) /* asfs */
+{
+ const char *asf_value[] = { "bundled", "indiv", NULL };
+ const char *asf_type[] = { "linetype" , "linewidth" , "linecolr" ,
+ "markertype" , "markersize", "markercolr",
+ "textfontindex", "textprec" , "charexp" ,
+ "charspace" , "textcolr" , "intstyle" ,
+ "fillcolr" , "hatchindex", "patindex" ,
+ "edgetype" , "edgewidth" , "edgecolr" ,
+ "all" , "allline" , "allmarker" ,
+ "alltext" , "allfill" , "alledge", NULL };
+ tasf *pair;
+
+ if ( intcgm_asf_list==NULL ) intcgm_asf_list = cgm_NewList();
+
+ while( cgmt_ter() )
+ {
+ pair = (tasf *) malloc ( sizeof (tasf) );
+
+ if ( cgmt_e ( &(pair->type), asf_type ) ) return 1;
+ if ( cgmt_e ( &(pair->value), asf_value ) ) return 1;
+
+ cgm_AppendList ( intcgm_asf_list, pair );
+ }
+
+ return 0;
+}
+
+int cgmt_escape ( void ) /* escape */
+{
+ long identifier;
+ char *data_rec;
+
+ if ( cgmt_i ( &(identifier) ) ) return 1;
+
+ if ( cgmt_s ( &data_rec ) ) return 1;
+
+ free(data_rec);
+
+ return cgmt_ter();
+}
+
+int cgmt_messag ( void ) /* message */
+{
+ const char *options[] = { "noaction", "action", NULL };
+ char *text;
+ short flag;
+
+ if ( cgmt_e ( &flag, options ) ) return 1;
+
+ if ( cgmt_s ( &text ) ) return 1;
+
+ free(text);
+
+ return cgmt_ter();
+}
+
+int cgmt_appdta ( void ) /* application data */
+{
+ long identifier;
+ char *data_rec;
+
+ if ( cgmt_i ( &identifier ) ) return 1;
+
+ if ( cgmt_s ( &data_rec ) ) return 1;
+
+ free(data_rec);
+
+ return cgmt_ter();
+}
diff --git a/cd/src/intcgm/tparse.h b/cd/src/intcgm/tparse.h
new file mode 100755
index 0000000..c1292bc
--- /dev/null
+++ b/cd/src/intcgm/tparse.h
@@ -0,0 +1,101 @@
+#ifndef _TPARSE_H_
+#define _TPARSE_H_
+
+int cgmt_begmtf ( void );
+int cgmt_endmtf ( void );
+int cgmt_begpic ( void );
+int cgmt_begpib ( void );
+int cgmt_endpic ( void );
+int cgmt_mtfver ( void );
+int cgmt_mtfdsc ( void );
+int cgmt_vdctyp ( void );
+int cgmt_intpre ( void );
+int cgmt_realpr ( void );
+int cgmt_indpre ( void );
+int cgmt_colpre ( void );
+int cgmt_colipr ( void );
+int cgmt_maxcoi ( void );
+int cgmt_covaex ( void );
+int cgmt_mtfell ( void );
+int cgmt_bmtfdf (void );
+int cgmt_emtfdf ( void );
+int cgmt_fntlst ( void );
+int cgmt_chslst ( void );
+int cgmt_chcdac ( void );
+int cgmt_sclmde ( void );
+int cgmt_clslmd ( void );
+int cgmt_lnwdmd ( void );
+int cgmt_mkszmd ( void );
+int cgmt_edwdmd ( void );
+int cgmt_vdcext ( void );
+int cgmt_bckcol ( void );
+int cgmt_vdcipr ( void );
+int cgmt_vdcrpr ( void );
+int cgmt_auxcol ( void );
+int cgmt_transp ( void );
+int cgmt_clprec ( void );
+int cgmt_clpind ( void );
+int cgmt_polyln ( void );
+int cgmt_incply ( void );
+int cgmt_djtply ( void );
+int cgmt_indjpl ( void );
+int cgmt_polymk ( void );
+int cgmt_incplm ( void );
+int cgmt_text ( void );
+int cgmt_rsttxt ( void );
+int cgmt_apdtxt ( void );
+int cgmt_polygn ( void );
+int cgmt_incplg ( void );
+int cgmt_plgset ( void );
+int cgmt_inpgst ( void );
+int cgmt_cellar ( void );
+int cgmt_gdp ( void );
+int cgmt_rect ( void );
+int cgmt_circle ( void );
+int cgmt_circ3p ( void );
+int cgmt_cir3pc ( void );
+int cgmt_circnt ( void );
+int cgmt_ccntcl ( void );
+int cgmt_ellips ( void );
+int cgmt_ellarc ( void );
+int cgmt_ellacl ( void );
+int cgmt_lnbdin ( void );
+int cgmt_lntype ( void );
+int cgmt_lnwidt ( void );
+int cgmt_lncolr ( void );
+int cgmt_mkbdin ( void );
+int cgmt_mktype ( void );
+int cgmt_mksize ( void );
+int cgmt_mkcolr ( void );
+int cgmt_txbdin ( void );
+int cgmt_txftin ( void );
+int cgmt_txtprc ( void );
+int cgmt_chrexp ( void );
+int cgmt_chrspc ( void );
+int cgmt_txtclr ( void );
+int cgmt_chrhgt ( void );
+int cgmt_chrori ( void );
+int cgmt_txtpat ( void );
+int cgmt_txtali ( void );
+int cgmt_chseti ( void );
+int cgmt_achsti ( void );
+int cgmt_fillin ( void );
+int cgmt_intsty ( void );
+int cgmt_fillco ( void );
+int cgmt_hatind ( void );
+int cgmt_patind ( void );
+int cgmt_edgind ( void );
+int cgmt_edgtyp( void );
+int cgmt_edgwid ( void );
+int cgmt_edgcol ( void );
+int cgmt_edgvis ( void );
+int cgmt_fillrf ( void );
+int cgmt_pattab ( void );
+int cgmt_patsiz ( void );
+int cgmt_coltab ( void );
+int cgmt_asf ( void );
+int cgmt_escape ( void );
+int cgmt_messag ( void );
+int cgmt_appdta ( void );
+
+#endif
diff --git a/cd/src/intcgm/types.h b/cd/src/intcgm/types.h
new file mode 100755
index 0000000..6d6f65c
--- /dev/null
+++ b/cd/src/intcgm/types.h
@@ -0,0 +1,225 @@
+#ifndef _CGM_TYPES_H_
+#define _CGM_TYPES_H_
+
+typedef struct {
+ double xmin;
+ double xmax;
+ double ymin;
+ double ymax;
+ } tlimit;
+
+typedef struct {
+ unsigned long red;
+ unsigned long green;
+ unsigned long blue;
+ } trgb;
+
+typedef union {
+ int ind;
+ trgb rgb;
+ } tcolor;
+
+typedef struct {
+ double x;
+ double y;
+ } tpoint;
+
+typedef struct {
+ char *dados;
+ int size;
+ } tdados;
+
+typedef struct {
+ FILE *fp;
+
+ int (*cgmf)(void);
+
+ int file_size;
+
+ int first;
+
+ int mode; /* character, binary, clear text */
+
+ int len;
+
+ tdados buff;
+
+ short vdc_type;
+
+ union {
+ long b_prec; /* 8, 16, 24, 32 */
+ struct { long minint; long maxint; } t_prec ;
+ } int_prec;
+ union {
+ long b_prec; /* float*32, float*64, fixed*32, fixed*64 */
+ struct { double minreal; double maxreal; long digits; } t_prec;
+ } real_prec;
+ union {
+ long b_prec; /* 8, 16, 24, 32 */
+ struct { long minint; long maxint; } t_prec;
+ } ix_prec;
+ long cd_prec;
+ long cix_prec;
+ struct {
+ trgb black;
+ trgb white;
+ } color_ext;
+ long max_cix;
+
+ struct {
+ short mode;
+ double scale_factor;
+ } scaling_mode;
+
+ short drawing_mode;
+
+ short clrsm;
+ short lnwsm;
+ short mkssm;
+ short edwsm;
+
+ union {
+ long b_prec; /* 8, 16, 24, 32 */
+ struct { long minint; long maxint; } t_prec;
+ } vdc_int;
+ union {
+ long b_prec; /* float*32, float*64, fixed*32, fixed*64 */
+ struct { double minreal; double maxreal; long digits; } t_prec;
+ } vdc_real;
+
+ struct {
+ tpoint first;
+ tpoint second;
+ } vdc_ext;
+
+ trgb back_color;
+
+ tcolor aux_color;
+
+ short transparency;
+
+ struct {
+ tpoint first;
+ tpoint second;
+ } clip_rect;
+
+ short clip_ind;
+
+ int bc; /* byte count */
+ int pc; /* pixel count */
+
+ long bl; /* bytes lidos */
+
+ int cl; /* coluna para alinhamento */
+
+ } t_cgm;
+
+typedef struct {
+ long index;
+ long type;
+ double width;
+ tcolor color;
+ } _line_att;
+
+typedef struct {
+ long index;
+ long type;
+ double size;
+ tcolor color;
+ } _marker_att;
+
+typedef struct {
+ long index;
+ long font_index;
+ TList *font_list;
+ int font;
+ int style;
+ int size;
+ short prec;
+ double exp_fact;
+ double char_spacing;
+ tcolor color;
+ double height;
+ tpoint char_up;
+ tpoint char_base;
+ short path;
+ struct { short hor;
+ short ver;
+ double cont_hor;
+ double cont_ver;
+ } alignment;
+ } _text_att;
+
+typedef struct {
+ long index;
+ short int_style;
+ tcolor color;
+ long hatch_index;
+ long pat_index;
+ tpoint ref_pt;
+ TList *pat_list;
+ struct {
+ tpoint height;
+ tpoint width;
+ } pat_size;
+ } _fill_att;
+
+typedef struct {
+ long index;
+ long type;
+ double width;
+ tcolor color;
+ short visibility;
+ } _edge_att;
+
+enum { OFF, ON };
+
+enum { YES, NO };
+
+enum { INTEGER, REAL };
+
+enum { STRING, CHAR, STROKE };
+
+enum { ABSOLUTE, SCALED };
+
+enum { ABSTRACT, METRIC };
+
+enum { INDEXED, DIRECT };
+
+enum { MARK_DOT=1, MARK_PLUS=2, MARK_ASTERISK=3, MARK_CIRCLE=4, MARK_CROSS=5 };
+
+enum { LINE_SOLID=1, LINE_DASH=2, LINE_DOT=3, LINE_DASH_DOT=4,
+ LINE_DASH_DOT_DOT=5 };
+
+enum { EDGE_SOLID=1, EDGE_DASH=2, EDGE_DOT=3, EDGE_DASH_DOT=4,
+ EDGE_DASH_DOT_DOT=5 };
+
+enum { HOLLOW, SOLID, PATTERN, HATCH, EMPTY };
+
+enum { HORIZONTAL=1, VERTICAL=2, POSITIVE_SLOPE=3, NEGATIVE_SLOPE=4,
+ HV_CROSS=5, SLOPE_CROSS=6 };
+
+enum { PATH_RIGHT, PATH_LEFT, PATH_UP, PATH_DOWN };
+
+enum { NORMHORIZ, LEFT, CTR, RIGHT, CONTHORIZ };
+
+enum { NORMVERT, TOP, CAP, HALF, BASE, BOTTOM, CONTVERT };
+
+enum { LINE_TYPE, LINE_WIDTH, LINE_COLOUR, MARKER_TYPE, MARKER_SIZE,
+ MARKER_COLOUR, TEXT_FONT_INDEX, TEXT_PRECISION,
+ CHARACTER_EXPANSION_FACTOR, CHARACTER_SPACING, TEXT_COLOUR,
+ INTERIOR_STYLE, FILL_COLOUR, HATCH_INDEX, PATTERN_INDEX, EDGE_TYPE,
+ EDGE_WIDTH, EDGE_COLOUR, ALL, ALL_LINE, ALL_MARKER, ALL_TEXT, ALL_FILL,
+ ALL_EDGE };
+
+enum { INDIVIDUAL, BUNDLED };
+
+enum { INVISIBLE, VISIBLE, CLOSE_INVISIBLE, CLOSE_VISIBLE };
+
+enum { PIE, CHORD };
+
+enum { OPEN, CLOSED_PIE, CLOSED_CHORD };
+
+enum { NORM_TEXT, RESTRICTED_TEXT };
+
+#endif