1 #include <stdlib.h>
2 #include <stdarg.h>
3 #include <stdio.h>
4 #include <time.h>
5 #include <libps/pslib.h>
6 #ifdef MEMORY_DEBUGGING
7 #include <libps/pslib-mp.h>
8 #endif
9
10 #define LEFT_BORDER 50
11
errorhandler(PSDoc * p,int error,const char * str,void * data)12 void errorhandler(PSDoc *p, int error, const char *str, void *data) {
13 fprintf(stderr, "PSLib: %s\n", str);
14 }
15
writeproc(PSDoc * p,void * data,size_t size)16 size_t writeproc(PSDoc *p, void *data, size_t size) {
17 return fwrite(data, 1, size, stdout);
18 }
19
footer(PSDoc * p,const char * text)20 void footer(PSDoc *p, const char *text) {
21 int psfont;
22 char buffer[100];
23 psfont = PS_findfont(p, "Helvetica", "", 0);
24 PS_setfont(p, psfont, 8.0);
25 sprintf(buffer, "This file has been created with pslib %s", PS_get_parameter(p, "dottedversion", 0.0));
26 PS_show_xy(p, buffer, LEFT_BORDER, 25);
27 }
28
main()29 int main() {
30 PSDoc *ps;
31
32 PS_boot();
33 #ifdef MEMORY_DEBUGGING
34 PS_mp_init();
35 #endif
36
37 #ifdef MEMORY_DEBUGGING
38 ps = PS_new2(errorhandler, PS_mp_malloc, PS_mp_realloc, PS_mp_free, NULL);
39 #else
40 ps = PS_new();
41 #endif
42
43 if (0 > PS_open_file(ps, "overprint.ps")) {
44 // if (0 > PS_open_mem(ps, writeproc)) {
45 printf("Cannot open PostScript file\n");
46 exit(1);
47 }
48
49 PS_set_parameter(ps, "warning", "true");
50
51 PS_set_info(ps, "Creator", __FILE__);
52 PS_set_info(ps, "Author", "Uwe Steinmann");
53 PS_set_info(ps, "Title", "Overprint demonstration");
54 PS_set_info(ps, "Keywords", "Overprint");
55
56 PS_begin_page(ps, 596, 842);
57 footer(ps, "");
58
59 PS_setcolor(ps, "fill", "cmyk", 1.0, 0.0, 0.0, 0.0);
60 PS_rect(ps, 100, 100, 200, 200);
61 PS_fill(ps);
62
63 PS_setoverprintmode(ps, 1);
64
65 // PS_setcolor(ps, "fill", "cmyk", 0.0, 1.0, 0.0, 0.0);
66 PS_rect(ps, 120, 120, 100, 100);
67 PS_fill(ps);
68
69 PS_end_page(ps);
70
71 PS_close(ps);
72 PS_delete(ps);
73
74 #ifdef MEMORY_DEBUGGING
75 PS_mp_list_unfreed();
76 #endif
77 PS_shutdown();
78
79 exit(0);
80 }
81