home *** CD-ROM | disk | FTP | other *** search
- From: kontron!optilink!cramer@pyramid.com (Clayton Cramer)
- Newsgroups: comp.binaries.ibm.pc,comp.lang.postscript
- Subject: Speed Up Printing AUTOCAD Files To PostScript Printers, C source
- Date: 17 Sep 88 17:00:25 GMT
- Summary: Speed Up Printing AUTOCAD Files To PostScript Printers, C source
- Approved: dhesi@bsu-cs.UUCP
-
- I wrote this program a while back. AutoCad plot files produced for
- PostScript printers are quite inefficient, so I wrote a quick filter to
- speed things up. The resulting plot files are 22% smaller and 22%
- faster to print. If you are printing directly to a PostScript printer
- from a PC, it might not save you anything to print the plot file to
- disk then filter it, but if you are sharing a PostScript printer over a
- network, or printing AutoCad plot files from a UNIX system (as we are)
- you might find some useful way to use this program.
-
- I offered it to AutoDesk, as an example of how to improve their
- PostScript driver, suggesting that they pay me what it was worth to
- them (I suggested something around $100). I guess they decided it
- wasn't worth a hundred bucks to save their customers time, because they
- never pursued it.
-
- There are two files, an include file called "stdmacro.h", and a C file
- called "autocad.c".
-
- -----cut here stdmacro.h--------------------------------------------------
- #define _CountOf_(A) ((sizeof (A))/(sizeof (A[0])))
- #define _InRange_(Low, Value, High) ((((int)Low) <= ((int)Value)) && (((int)Val
- ue) < ((int)High)))
- #define _RangeCheck_(Low, Value, High) ((((int)Low) <= ((int)Value)) && (((int)
- Value) < ((int)High)))
- #define FALSE 0
- #define TRUE 1
- typedef char boolean;
- #define _Max_(A,B) (((A) > (B)) ? (A) : (B))
- -----cut here--------------------------------------------------
-
- Here is the autocad.c file.
- -----cut here--------------------------------------------------
- #include <stdio.h>
- #include "stdmacro.h"
-
- main (Argc, Argv)
-
- int Argc;
- char *Argv[];
-
- {
- FILE* CadFile;
- int I;
-
- for (I = 1; I < Argc; I++)
- {
- if (NULL != (CadFile = fopen(Argv[I], "r")))
- {
- ProcessFile(CadFile);
- fclose(CadFile);
- }
- }
- }
-
- ProcessFile (FilePtr)
-
- FILE* FilePtr;
-
- {
- char Buffer1[256], Buffer2[256];
- boolean XMatch, YMatch;
- int StartX, NextX, StartY, NextY;
-
- while (!feof(FilePtr))
- {
- fgets(Buffer1, sizeof(Buffer1)-1, FilePtr);
- if (!feof(FilePtr))
- {
- if (0 == strncmp (Buffer1, "/n", 2))
- {
- fputs(Buffer1, stdout);
- printf("/p {/Y exch def /X exch def X Y m X Y l} def\n");
- printf("/x {/NextY exch def /StartY exch def /X exch def\n");
- printf(" X StartY moveto X NextY lineto} def\n");
- printf("/y {/Y exch def /NextX exch def /StartX exch def\n");
- printf(" StartX Y moveto NextX Y lineto} def\n");
- }
- else if (Buffer1[strlen(Buffer1)-2] == 'm')
- {
- fgets(Buffer2, sizeof(Buffer2)-1, FilePtr);
- if (!feof(FilePtr))
- {
- if(Buffer2[strlen(Buffer2)-2] == 'l')
- {
- XMatch = YMatch = FALSE;
- sscanf(Buffer1, "%d %d", &StartX, &StartY);
- sscanf(Buffer2, "%d %d", &NextX, &NextY);
- if (StartX == NextX)
- XMatch = TRUE;
- if (StartY == NextY)
- YMatch = TRUE;
- if (XMatch && YMatch)
- printf("%d %d p\n", StartX, StartY);
- else if (XMatch)
- printf("%d %d %d x\n", StartX, StartY, NextY);
- else if (YMatch)
- printf("%d %d %d y\n", StartX, NextX, StartY);
- else
- printf("%s%s", Buffer1, Buffer2);
- }
- else
- printf("%s%s", Buffer1, Buffer2);
- }
- else
- printf("%s", Buffer1);
- }
- else
- printf("%s", Buffer1);
- }
- }
- }
- -----cut here--------------------------------------------------
-