home *** CD-ROM | disk | FTP | other *** search
- #include "plplot.h"
- #include <stdio.h>
-
- static int orient, select=0, curwid;
- static long bmapx, bmapy, bmapxmax, bmapymax, xdpi, ydpi;
- static long dwidth, dheight;
-
- void prefsetup(xddpi, yddpi, xwid, ywid)
- PLINT xwid, ywid;
- PLFLT xddpi, yddpi;
- {
- /* Ignore these and use preferences data instead. */
- }
-
- void prefselect(ori, name)
- PLINT ori;
- char *name;
- {
- orient = ori;
- select = 1;
- }
-
- /* Most of the code is in plsupport.c where it is shared with the menu
- selection printer dump. */
- void prefinit()
- {
- char line[10];
- int mode, openprinter(), mapinit(), queryprint();
- void closeprinter();
-
- if(!select) {
- printf("Landscape or portrait orientation? (0 or 1) ");
- fgets(line,sizeof(line),stdin);
- if(sscanf(line,"%d",&orient) != 1)
- orient = 0;
- }
- select = 0;
-
- if(openprinter()) plexit("");
-
- mode = queryprint(&bmapx, &bmapy, &bmapxmax, &bmapymax, &xdpi, &ydpi);
-
- /* If mode == 1 we want to adjust the bitmap size so that the aspect
- ratio is maintained. */
- if(mode) {
- if((float)bmapxmax*bmapy > (float)bmapymax*bmapx)
- bmapy = (int)(((float)bmapx*bmapymax)/bmapxmax + .5);
- else
- bmapx = (int)(((float)bmapy*bmapxmax)/bmapymax + .5);
- }
-
- /* Leave a little space for pen width. */
- dwidth = bmapx - 2;
- dheight = bmapy - 2;
-
- if(!orient) {
- setpxl((PLFLT)(ydpi/25.4), (PLFLT)(xdpi/25.4));
- setphy(0,bmapymax,0,bmapxmax);
- }
- else {
- setpxl((PLFLT)(xdpi/25.4), (PLFLT)(ydpi/25.4));
- setphy(0,bmapxmax,0,bmapymax);
- }
-
- scol(1);
- swid(1);
- smod(0);
-
- /* Allocate bitmap and initial for line drawing */
- if(mapinit(bmapx, bmapy)) {
- closeprinter();
- plexit("");
- }
- }
-
- void preftext()
- {
- }
-
- void prefgraph()
- {
- }
-
- void prefclear()
- {
- void ejectpage(), dmpport();
-
- dmpport(0L,bmapx,bmapy);
- /* Eject the page. */
- ejectpage();
- }
-
- void prefpage()
- {
- void mapclear();
-
- mapclear();
- }
-
- void prefwidth(width)
- PLINT width;
- {
- if(width < 1)
- curwid = 1;
- else if(width > 3)
- curwid = 3;
- else
- curwid = width;
- }
-
- void prefcolor(color)
- PLINT color;
- {
- }
-
- void prefline(x1,y1,x2,y2)
- PLINT x1, y1, x2, y2;
- {
- long xn1, yn1, xn2, yn2;
- void mapline();
-
- if(!orient) {
- xn1 = (x1*dheight)/bmapymax;
- yn1 = (y1*dwidth)/bmapxmax;
- xn2 = (x2*dheight)/bmapymax;
- yn2 = (y2*dwidth)/bmapxmax;
- switch(curwid) {
- case 3:
- mapline(yn1,xn1,yn2,xn2);
- case 2:
- mapline(yn1+2,xn1+2,yn2+2,xn2+2);
- case 1:
- default:
- mapline(yn1+1,xn1+1,yn2+1,xn2+1);
- }
- }
- else {
- xn1 = (x1*dwidth)/bmapxmax;
- yn1 = (y1*dheight)/bmapymax;
- xn2 = (x2*dwidth)/bmapxmax;
- yn2 = (y2*dheight)/bmapymax;
- switch(curwid) {
- case 3:
- mapline(xn1,dheight-yn1,xn2,dheight-yn2);
- case 2:
- mapline(xn1+2,dheight-yn1+2,xn2+2,dheight-yn2+2);
- case 1:
- default:
- mapline(xn1+1,dheight-yn1+1,xn2+1,dheight-yn2+1);
- }
- }
- }
-
- void preftidy()
- {
- void dmpport(), mapfree(), closeprinter();
-
- dmpport(0L,bmapx,bmapy);
- mapfree();
- closeprinter();
- }
-