1 #include <stdlib.h>
2 #include <stdarg.h>
3 #include <stdio.h>
4 #include <string.h>
5 #include <locale.h>
6 #include <libps/pslib.h>
7 #ifdef MEMORY_DEBUGGING
8 #include <libps/pslib-mp.h>
9 #endif
10
my_malloc(PSDoc * p,size_t size,const char * caller)11 void * my_malloc(PSDoc *p, size_t size, const char *caller) {
12 void *a;
13 a = (void *) malloc(size);
14 // printf("Allocating %d bytes at 0x%X (%s)\n", size, a, caller);
15 return(a);
16 }
17
my_realloc(PSDoc * p,void * mem,size_t size,const char * caller)18 void * my_realloc(PSDoc *p, void *mem, size_t size, const char *caller) {
19 return((void *) realloc(mem, size));
20 }
21
my_free(PSDoc * p,void * mem)22 void my_free(PSDoc *p, void *mem) {
23 // printf("Freeing memory at 0x%X\n", mem);
24 free(mem);
25 }
26
27
main()28 int main() {
29 PSDoc *psdoc;
30 int fraktur, antiqua;
31 float boxwidth, boxheight, baseline, colsep, leftmargin, x;
32 float textwidth, fontsize;
33 int rest, boxed;
34 char text[12000], *str;
35 FILE *fp;
36
37 boxwidth = 200;
38 boxheight = 630;
39 baseline = 100;
40 colsep = 20;
41 leftmargin = 100;
42 boxed = 0;
43 fontsize = 10.0;
44
45 #ifdef MEMORY_DEBUGGING
46 PS_mp_init();
47 #endif
48 PS_boot();
49 #ifdef MEMORY_DEBUGGING
50 psdoc = PS_new2(NULL, PS_mp_malloc, PS_mp_realloc, PS_mp_free, NULL);
51 #else
52 psdoc = PS_new();
53 #endif
54 PS_open_file(psdoc, "einstein.ps");
55 PS_set_info(psdoc, "Creator", __FILE__);
56 PS_set_info(psdoc, "Author", "Uwe Steinmann");
57 PS_set_info(psdoc, "Title", "Long Text Examples");
58 PS_set_info(psdoc, "Keywords", "boxed text, Einstein");
59 PS_set_info(psdoc, "BoundingBox", "0 0 596 842");
60
61 fraktur = PS_findfont(psdoc, "AlteSchwabacher", "AlteSchwabacher.enc", 1);
62 antiqua = PS_findfont(psdoc, "Helvetica", "", 0);
63 PS_begin_page(psdoc, 596, 842);
64
65 PS_setfont(psdoc, fraktur, 15.0);
66 PS_set_value(psdoc, "charspacing", 2);
67 strcpy(text, "Was ist Relativit�ts-Theorie?");
68 textwidth = PS_stringwidth(psdoc, text, fraktur, 15.0);
69 PS_show_xy2(psdoc, text, strlen(text), leftmargin+boxwidth+colsep/2-textwidth/2, baseline+boxheight+20);
70 PS_set_value(psdoc, "charspacing", 0.0);
71
72 PS_setfont(psdoc, fraktur, fontsize);
73 PS_set_value(psdoc, "leading", 14);
74
75 fp = fopen("einstein.txt", "r");
76 str = text;
77 while(!feof(fp)) {
78 fread(str++, 1, 1, fp);
79 }
80 str--;
81 *str = '\0';
82 fclose(fp);
83
84 PS_set_parameter(psdoc, "hyphenation", "true");
85 PS_set_parameter(psdoc, "hyphendict", "hyph_de.dic");
86 PS_set_value(psdoc, "hyphenminchars", 2);
87 PS_set_value(psdoc, "parindent", fontsize*1.2);
88 PS_set_value(psdoc, "parskip", 14 /* fontsize*1.2 */);
89 PS_set_value(psdoc, "parindentskip", 0);
90 // PS_set_value(psdoc, "numindentlines", 1);
91 x = leftmargin;
92 if(boxed) {
93 PS_rect(psdoc, x, baseline, boxwidth, boxheight);
94 PS_stroke(psdoc);
95 }
96 str = text;
97 rest = PS_show_boxed(psdoc, str, x, baseline, boxwidth, boxheight, "fulljustify", "");
98 PS_set_value(psdoc, "parindentskip", 1);
99 if(rest) {
100 str += strlen(str)-rest;
101 x = leftmargin+boxwidth+colsep;
102 if(boxed) {
103 PS_rect(psdoc, x, baseline, boxwidth, boxheight);
104 PS_stroke(psdoc);
105 }
106 rest = PS_show_boxed(psdoc, str, x, baseline, boxwidth, boxheight, "fulljustify", "");
107 }
108 PS_setfont(psdoc, antiqua, 8.0);
109 PS_show_boxed(psdoc, "Albert Einstein, Was ist Relativit�ts-Theorie? The collected Papers of Albert Einstein. Volume7, Seiten 206��211, Princeton University Press, 2002", leftmargin, baseline-30, colsep+2*boxwidth, 20, "left", "");
110 PS_setfont(psdoc, fraktur, fontsize);
111 PS_end_page(psdoc);
112
113 while(rest) {
114 str += strlen(str)-rest;
115 PS_begin_page(psdoc, 596, 842);
116 PS_setfont(psdoc, fraktur, fontsize);
117 PS_set_value(psdoc, "leading", 14);
118 x = leftmargin;
119 if(boxed) {
120 PS_rect(psdoc, x, baseline, boxwidth, boxheight);
121 PS_stroke(psdoc);
122 }
123 rest = PS_show_boxed(psdoc, str, x, baseline, boxwidth, boxheight, "fulljustify", "");
124 if(rest) {
125 x = leftmargin+boxwidth+colsep;
126 str += strlen(str)-rest;
127 if(boxed) {
128 PS_rect(psdoc, x, baseline, boxwidth, boxheight);
129 PS_stroke(psdoc);
130 }
131 rest = PS_show_boxed(psdoc, str, x, baseline, boxwidth, boxheight, "fulljustify", "");
132 }
133 if(!rest) {
134 PS_set_value(psdoc, "textx", x+boxwidth-PS_stringwidth(psdoc, "Albert Einstein", fraktur, fontsize));
135 PS_continue_text(psdoc, "Albert Einstein");
136 }
137 PS_end_page(psdoc);
138 }
139 PS_deletefont(psdoc, fraktur);
140 PS_deletefont(psdoc, antiqua);
141 PS_close(psdoc);
142 PS_delete(psdoc);
143 #ifdef MEMORY_DEBUGGING
144 PS_mp_list_unfreed();
145 #endif
146 PS_shutdown();
147 exit(0);
148 }
149