문제

How can I create a PS (PostScript) file in C language?

For example, I want create file myfile.ps and draw to PostScript this code:

%!
newpath
0 0 moveto
120 120 lineto
144 120 lineto
200 122 lineto
0 0 lineto
stroke 
showpage
도움이 되었습니까?

해결책

Normally postscript is just ascii text, so the standard text-output facilities will work just fine.

#include <stdio.h>

int main(void) {
    FILE *outfile;
    outfile = fopen("myfile.ps", "w");
    fprintf(outfile,
        "%%!\n"
        "%d %d moveto\n"
        "%d %d lineto\n"
        "%d %d lineto\n"
        "%d %d lineto\n"
        "%d %d lineto\n"
        "stroke\n"
        "showpage\n",
        0, 0,
        120, 120,
        144, 120,
        200, 122,
        0, 0
    );
    return 0;
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top