/* FUNCTION: mimPgxhp_outline.c */ /* Sheeja Malaveetil */ /* Census, GEO, MOB/CMT */ /* June 02, 1995 */ /* Output is specific to HPGL */ /* Function takes a pointer to an array of type POLYSTRT (an array of polygons) */ /* which contains arrays of type MIMPOINT (an array of points in polygon) */ /* and processes it to produce the line type specified by *ltp. This function */ /* uses the points to draw a string which represents the outside of the polygon */ /* All line conditions except for *ltp are assumed to be set */ /* before mimPgxhp_outline is called. */ /* */ /* The logic of this program is largely based on the function mimStrps.c */ /* which produces postscript output that displays a line (*str) with the */ /* specified attributes, include *lts. It was written by */ /* F.R.Broome 20 June 1994 */ #include #include #include #include #include "mim2hpll.h" #include /* There should be a header file in the main program that contains the following global data type. typedef struct { float x, y; } MIMPOINT; */ #define DOUBLEQUOTE 34 #ifndef MIM_POINTS #define MIM_POINTS 1 typedef struct { float x, y; } MIMPOINT; #define POLY_STRTS 1 typedef struct { int poly_points_tot; MIMPOINT *points_ptr; } POLYSTRT; #endif int mimPgxhp_outline(POLYSTRT *poly_ptr,int num_polys,int solidLineFlag,char pgx_src); void getPtsFromDist(float xa, float xb, float ya, float yb, float s,float *x, float *y); int mimPgxhp_outline(POLYSTRT *poly_ptr,int num_polys,int solidLineFlag,char pgx_src) /* *poly_ptr = A malloc'd array of type POLYSTRT */ /* num_polys = number of polys in this *pgX command */ /* solidLineFlag = 0 = dashed, 1 = solid. */ /* pgx_src = "V" if polygon to outline is text (vtx), any other value, */ /* especially "P", stands for a regular polygon, ie pgX */ { extern FILE *hpfile; extern float offsetX, offsetY, deviceFactor; extern float ltsValues[64]; extern char ltp[32]; extern char ltv[32]; MIMPOINT mimPoint; MIMPOINT *mimPts; /* A malloc'd array type MIMPOINT */ long numPts; /* An single variable of points this line. */ POLYSTRT poly_rec; int ltsFlag, workFlag, numValues, lineTypeFlag, num = 0; int firstPointFlag = 1; long i, n = 0; float x, y, xd, yd, ltLength, ltypeLength; float segLength, fromX, fromY; int poly_ct=0; char lt_to_use[32]; /* fprintf(hpfile, "CO%cProcessing *pgX-outlined*%c;\n",DOUBLEQUOTE,DOUBLEQUOTE); printf("You are now in mimPgxhp_outline.c!\n"); printf(" mimPgxhp_outline.c: num_polys=%d solidLineFlag=%d pgx_src=%c!\n",num_polys,solidLineFlag,pgx_src); */ if(solidLineFlag) { for(poly_ct=0;poly_ct < num_polys; poly_ct++) { poly_rec = *(poly_ptr+poly_ct); /* get the (poly_ct)th poly from the array */ numPts = poly_rec.poly_points_tot; mimPts = poly_rec.points_ptr; firstPointFlag = 1; for(i = 0; i < numPts; i++) /* For this many points.*/ { mimPoint = *(mimPts+i); /* Get the nth point from the array. */ if (pgx_src != 'V') { /* polygon is not representing an ascii character, values coming in are raw values, no devicefactors or offsets were applied so apply them now */ x = (mimPoint.x + offsetX) * deviceFactor; y = (mimPoint.y + offsetY) * deviceFactor; } else { /* polygon represents an ascii character, values coming in are not raw values, they were calculated using devicefactors and offsets, as well as other factors necessary for representation of text in certain fonts. Use these values as they are */ x = mimPoint.x; x = mimPoint.y; } if( firstPointFlag ) { fprintf(hpfile, "PU%1.3f,%1.3f;",x,y); fprintf(hpfile, "PD%1.3f,%1.3f",x,y); firstPointFlag = 0; } else { fprintf(hpfile, ",%1.3f,%1.3f",x,y); } n++; /* Increment array pointer. */ } /*End for-loop reading one parts worth of points. */ fprintf(hpfile, ";"); } /* End for-loop reading polygons */ } /* End if solid */ else/* Not solid, so break according to lts rules. */ { if (pgx_src != 'V') { strcpy(lt_to_use,ltp); /* polygon is not representing text, use ltp */ /* printf(" using ltp!\n"); */ } else { strcpy(lt_to_use,ltv); /* polygon is representing text, use ltv */ /* printf(" using ltv!\n"); */ } /* printf(" mimPgxhp_outline.c: ltp=%s ltv=%s lt_to_use=%s!\n",ltp,ltv,lt_to_use); */ for(poly_ct=0;poly_ct < num_polys; poly_ct++) { poly_rec = *(poly_ptr+poly_ct); /* get the (poly_ct)th poly from the array */ numPts = poly_rec.poly_points_tot; mimPts = poly_rec.points_ptr; i = MIMlinetypeSearch( lt_to_use, &num, ltsValues ); ltypeLength = ltsValues[0]; /*Initialize*/ ltsFlag = 1; firstPointFlag = 1; /*Very tricky processing one point pair at a time, but will try.*/ /* printf("Poly number: %d #points in poly = %d!\n",poly_ct,numPts); */ for(i = 0; i < numPts; i++) { mimPoint = *(mimPts+i); /* Get the nth point from the array. */ if (pgx_src != 'V') { /* polygon is not representing an ascii character, values coming in are raw values, no devicefactors or offsets were applied so use them as they are */ x = mimPoint.x; /* Use raw coordinates. */ y = mimPoint.y; /* printf(" Calculating x,y by x=mimPoint.x!\n"); */ } else { /* polygon represents an ascii character, values coming in are not raw values, they were calculated using devicefactors and offsets, as well as other factors necessary for representation of text in certain fonts. Modify incoming values to remove device factors & offsets */ x = (mimPoint.x / deviceFactor) - offsetX; y = (mimPoint.y / deviceFactor) - offsetY; /* printf(" Calculating x,y by x=(mimPoint.x / deviceFactor) - offsetX!\n"); */ } /* printf("mimPgxhp_outline.c: i=%d x=%1.3f y=%1.3f \n",i,x,y); */ /* BEGIN LINE TYPE PROCESSING */ if( firstPointFlag ) { fromX = x; fromY = y; segLength = 0; numValues = 0; ltLength = fabs(ltsValues[0]); if( ltsValues[0] < 0.0 ) lineTypeFlag = 1; /*Set to draw (pen down). */ else lineTypeFlag = 0; /*Set to no-draw (pen up).*/ /* printf(" offsetX=%1.3f offsetY=%1.3f deviceFactor=%1.3f!\n",offsetX, offsetY,deviceFactor); */ x = ( x + offsetX ) * deviceFactor; /* Convert to display */ y = ( y + offsetY ) * deviceFactor; firstPointFlag = 0; fprintf(hpfile, "PU%1.3f,%1.3f;",x,y); fprintf(hpfile, "PD%1.3f,%1.3f",x,y); /* printf(" first point!!IN MIMpgX_outline.C:: i= %d ltp=%s ltLength = %1.3f fromX=%1.3f x=%1.3f fromY=%1.3f y=%1.3f!\n",i,ltp,ltLength,fromX,x,fromY,y); */ } else /* not first point, so process segment. */ { segLength = sqrt((x-fromX)*(x-fromX) + (y-fromY)*(y-fromY)); if( segLength > ltLength ) { workFlag = 1; while( workFlag ) { /* Subtract dash length used from seg length. */ segLength -= ltLength; /* Check remaining segLength now so can process short */ /* if necessary */ if( segLength < 0.0 ) { /* printf(" segLength is less than zero!\n"); */ segLength += ltLength; /* Restore to positive length.*/ /* Process the remainder of the segment to the end x,y */ xd = (x + offsetX) * deviceFactor; /*Convert to display*/ /* printf(" offsetX=%1.3f x=%1.3f deviceFactor=%1.3f xd=%1.3f!\n",offsetX, x,deviceFactor,xd); */ yd = (y + offsetY) * deviceFactor; /* printf(" MIMPGXHP_OUTLINE.C:: i= %d ltp=%s ltLength = %1.3f xd=%1.3f yd=%1.3f!\n",i,ltp,ltLength,xd,yd); */ if( lineTypeFlag ) fprintf(hpfile, ",%1.3f,%1.3f",xd,yd); else { fprintf(hpfile, ";PU%1.3f,%1.3f;",xd,yd); fprintf(hpfile, "PD%1.3f,%1.3f",xd,yd); } fromX = x; fromY = y; workFlag = 0; ltLength -= segLength; /*Note subtract used part.*/ continue; } /* Compute x,y-coordinates of dash along seg line. */ getPtsFromDist( fromX, x, fromY, y, ltLength, &xd, &yd ); fromX = xd; /* Set new dash start point. */ fromY = yd; /* Output this dash. */ /* printf(" offsetX=%1.3f x=%1.3f deviceFactor=%1.3f xd=%1.3f!\n",offsetX, x,deviceFactor,xd); */ xd = (xd + offsetX) * deviceFactor; /*Convert to display*/ yd = (yd + offsetY) * deviceFactor; /* printf("IN MIMPGXHP_OUTLINE.C:: i= %d ltp=%s ltLength = %1.3f xd=%1.3f yd=%1.3f!\n",i,ltp,ltLength,xd,yd); */ if( lineTypeFlag ) fprintf(hpfile, ",%1.3f,%1.3f",xd,yd); else { fprintf(hpfile, ";PU%1.3f,%1.3f;",xd,yd); fprintf(hpfile, "PD%1.3f,%1.3f",xd,yd); } /* Get next ltLength (Circular indexing.) */ numValues++; if( !(numValues % num) ) numValues = 0; ltLength = fabs(ltsValues[numValues]); if( ltsValues[numValues] < 0.0 ) lineTypeFlag = 1; /*Set to draw (pen down). */ else lineTypeFlag = 0; /*Set to no-draw (pen up).*/ } /* End while condition. */ } else /* segLength is < ltLength so, */ { fromX = x; /* Save new from x,y-point. */ fromY = y; xd = (x + offsetX) * deviceFactor; /*Convert to display*/ yd = (y + offsetY) * deviceFactor; /* printf("IN MIMPGXHP_OUTLINE.C:: i= %d ltp=%s ltLength = %1.3f xd=%1.3f yd=%1.3f!\n",i,ltp,ltLength,xd,yd); */ /* Output this dash. */ if( lineTypeFlag ) fprintf(hpfile, ",%1.3f,%1.3f",xd,yd); /* Output pt. */ else { fprintf(hpfile, ";PU%1.3f,%1.3f;",xd,yd); fprintf(hpfile, "PD%1.3f,%1.3f",xd,yd); } ltLength -= segLength; /* Shorten dash by segLength. */ } } /*End not-first point if. */ } /*End for-loop reading one line of points. */ fprintf(hpfile,";"); } /* End of for-loop for read polys associated with a *pgX */ } /* fprintf(hpfile, "CO%cEnd Processing *pgx outlined*%c;\n",DOUBLEQUOTE,DOUBLEQUOTE); printf(" mimPgxhp_outline.c: num_polys=%d solidLineFlag=%d pgx_src=%c!\n",num_polys,solidLineFlag,pgx_src); printf("You are now leaving mimPgxhp_outline.c!\n"); */ return(1); }