From 7b52cc13af4e85f1ca2deb6b6c77de9c95ea0dcf Mon Sep 17 00:00:00 2001 From: scuri Date: Fri, 17 Oct 2008 06:10:33 +0000 Subject: First commit - moving from LuaForge to SourceForge --- src/intcgm/bparse.c | 1660 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/intcgm/bparse.h | 117 ++++ src/intcgm/circle.c | 100 +++ src/intcgm/circle.h | 3 + src/intcgm/ellipse.c | 143 +++++ src/intcgm/ellipse.h | 3 + src/intcgm/intcgm.h | 84 +++ src/intcgm/intcgm1.c | 291 +++++++++ src/intcgm/intcgm2.c | 1653 +++++++++++++++++++++++++++++++++++++++++++++++++ src/intcgm/intcgm2.h | 52 ++ src/intcgm/intcgm4.c | 1265 ++++++++++++++++++++++++++++++++++++++ src/intcgm/intcgm4.h | 28 + src/intcgm/intcgm6.c | 253 ++++++++ src/intcgm/intcgm6.h | 15 + src/intcgm/list.c | 117 ++++ src/intcgm/list.h | 30 + src/intcgm/sism.c | 392 ++++++++++++ src/intcgm/sism.h | 3 + src/intcgm/tparse.c | 1370 +++++++++++++++++++++++++++++++++++++++++ src/intcgm/tparse.h | 101 +++ src/intcgm/types.h | 225 +++++++ 21 files changed, 7905 insertions(+) create mode 100644 src/intcgm/bparse.c create mode 100644 src/intcgm/bparse.h create mode 100644 src/intcgm/circle.c create mode 100644 src/intcgm/circle.h create mode 100644 src/intcgm/ellipse.c create mode 100644 src/intcgm/ellipse.h create mode 100644 src/intcgm/intcgm.h create mode 100644 src/intcgm/intcgm1.c create mode 100644 src/intcgm/intcgm2.c create mode 100644 src/intcgm/intcgm2.h create mode 100644 src/intcgm/intcgm4.c create mode 100644 src/intcgm/intcgm4.h create mode 100644 src/intcgm/intcgm6.c create mode 100644 src/intcgm/intcgm6.h create mode 100644 src/intcgm/list.c create mode 100644 src/intcgm/list.h create mode 100644 src/intcgm/sism.c create mode 100644 src/intcgm/sism.h create mode 100644 src/intcgm/tparse.c create mode 100644 src/intcgm/tparse.h create mode 100644 src/intcgm/types.h (limited to 'src/intcgm') diff --git a/src/intcgm/bparse.c b/src/intcgm/bparse.c new file mode 100644 index 0000000..ad08179 --- /dev/null +++ b/src/intcgm/bparse.c @@ -0,0 +1,1660 @@ +#include /* FILE, ftell, fseek, fputc, fopen, fclose, fputs, fprintf */ +#include /* strlen, strncpy */ +#include /* 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, 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> 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, 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 *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; iindex) ) ) 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; itype) ) ) 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 +#include + +#include + +#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/src/intcgm/circle.h b/src/intcgm/circle.h new file mode 100644 index 0000000..3209c0f --- /dev/null +++ b/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/src/intcgm/ellipse.c b/src/intcgm/ellipse.c new file mode 100644 index 0000000..8d6889c --- /dev/null +++ b/src/intcgm/ellipse.c @@ -0,0 +1,143 @@ +#include +#include + +#include + +#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/src/intcgm/ellipse.h b/src/intcgm/ellipse.h new file mode 100644 index 0000000..80980ff --- /dev/null +++ b/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/src/intcgm/intcgm.h b/src/intcgm/intcgm.h new file mode 100644 index 0000000..c106ee0 --- /dev/null +++ b/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/src/intcgm/intcgm1.c b/src/intcgm/intcgm1.c new file mode 100644 index 0000000..d4b2399 --- /dev/null +++ b/src/intcgm/intcgm1.c @@ -0,0 +1,291 @@ +#define _INTCGM1_C_ + +#include /* FILE, ftell, fseek, fputc, fopen, fclose, fputs, fprintf */ +#include /* malloc, free */ +#include /* strlen */ +#include /* floor */ + +#ifdef SunOS +#include /* SEEK_SET, SEEK_END */ +#endif + +#include /* FLT_MIN, FLT_MAX */ +#include /* 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/src/intcgm/intcgm2.c b/src/intcgm/intcgm2.c new file mode 100644 index 0000000..f16c916 --- /dev/null +++ b/src/intcgm/intcgm2.c @@ -0,0 +1,1653 @@ +#include /* FILE, ftell, fseek, fputc, fopen, fclose, fputs, fprintf */ +#include /* strlen */ +#include +#include +#include +#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 ( errointcgm_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 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; inome )==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/src/intcgm/intcgm2.h b/src/intcgm/intcgm2.h new file mode 100644 index 0000000..d7f5204 --- /dev/null +++ b/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/src/intcgm/intcgm4.c b/src/intcgm/intcgm4.c new file mode 100644 index 0000000..4c8afe0 --- /dev/null +++ b/src/intcgm/intcgm4.c @@ -0,0 +1,1265 @@ +#define _INTCGM4_C_ + +#include +#include +#include + +#include +#include + +#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 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 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 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 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 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 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 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 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 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 ( cx1cy3 ) + { + for ( i=0; icx3 && cy2==cy3 ) + { + tmp = nx; nx = ny; ny = tmp; + for ( i=0; icy3 && cx2>cx3 && cy2==cy3 ) + { + tmp = nx; nx = ny; ny = tmp; + for ( i=0; icx3 && cy1==cy3 && cx2==cx3 && cy2>cy3 ) + { + for ( i=0; icy3 && cx2cx3 && cy1==cy3 && cx2==cx3 && cy2cx2 ) + { + 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 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 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 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 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/src/intcgm/intcgm4.h b/src/intcgm/intcgm4.h new file mode 100644 index 0000000..4b12873 --- /dev/null +++ b/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/src/intcgm/intcgm6.c b/src/intcgm/intcgm6.c new file mode 100644 index 0000000..c23afee --- /dev/null +++ b/src/intcgm/intcgm6.c @@ -0,0 +1,253 @@ +#include +#include +#include +#include + +#include + +#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; iindex==intcgm_fill_att.pat_index ) break; + } + + p = (long int *) malloc ( pat->nx*pat->ny*sizeof(long int) ); + + for ( i=0; inx*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 *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 *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/src/intcgm/intcgm6.h b/src/intcgm/intcgm6.h new file mode 100644 index 0000000..fde660e --- /dev/null +++ b/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/src/intcgm/list.c b/src/intcgm/list.c new file mode 100644 index 0000000..6fefbbc --- /dev/null +++ b/src/intcgm/list.c @@ -0,0 +1,117 @@ +/* +* list.c +* Generic List Manager +* TeCGraf +* +*/ + +#include +#include +#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) ? 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/src/intcgm/list.h b/src/intcgm/list.h new file mode 100644 index 0000000..c661a7c --- /dev/null +++ b/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/src/intcgm/sism.c b/src/intcgm/sism.c new file mode 100644 index 0000000..9946ac3 --- /dev/null +++ b/src/intcgm/sism.c @@ -0,0 +1,392 @@ +#include +#include +#include +#include +#include +#include + +#include + +#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, &_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; imn && samp2mx) + { + 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 && samp1mn && samp2mn && samp1mx ) + { + 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 && samp2mn ) + { + 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 && samp10 ) + { + 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; jnegclp && 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)) ); + cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(posclp + dx), cgm_vdcy2canvas(interpl(i,y1,y2,posclp)) ); + } + else if ( sample[i]>negclp && sample[i]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]negclp ) + cdCanvasVertex (intcgm_canvas, cgm_vdcx2canvas(posclp + dx), cgm_vdcy2canvas(interpl(i,y1,y2,posclp)) ); + else if ( sample[i]>posclp && sample[i+1]negclp && sample[i] 7 ) + coind = (long *) malloc ( n_samp*sizeof(long) ); + + for ( i=0; i= 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/src/intcgm/sism.h b/src/intcgm/sism.h new file mode 100644 index 0000000..f2f08f0 --- /dev/null +++ b/src/intcgm/sism.h @@ -0,0 +1,3 @@ +void cgm_sism4 ( tpoint *, char * ); +void cgm_sism5 ( char * ); + diff --git a/src/intcgm/tparse.c b/src/intcgm/tparse.c new file mode 100644 index 0000000..0402ce6 --- /dev/null +++ b/src/intcgm/tparse.c @@ -0,0 +1,1370 @@ +#define _INTCGM2_C_ + +#include +#include +#include + +#include +#include + +#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; kindex) ) ) 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/src/intcgm/tparse.h b/src/intcgm/tparse.h new file mode 100644 index 0000000..c1292bc --- /dev/null +++ b/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/src/intcgm/types.h b/src/intcgm/types.h new file mode 100644 index 0000000..6d6f65c --- /dev/null +++ b/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 -- cgit v1.2.3