format.h - abc2ps - A powerful sheet setting tool using the simple abc notation
(HTM) git clone git://vernunftzentrum.de/abc2ps.git
(DIR) Log
(DIR) Files
(DIR) Refs
---
format.h (16143B)
---
1 /*
2 * This file is part of abc2ps,
3 * Copyright (C) 1996,1997,1998 Michael Methfessel
4 * See file abc2ps.c for details.
5 */
6
7 /* subroutines connected with page layout */
8
9
10 /* ----- fontspec ----- */
11 void fontspec (f,name,size,box)
12 char name [];
13 float size;
14 int box;
15 struct FONTSPEC *f;
16 {
17 strcpy (f->name, name);
18 f->size = size;
19 f->box = box;
20 }
21
22 /* ----- add_font ----- */
23 /* checks font list, adds font if new */
24 int add_font (f)
25 struct FONTSPEC *f;
26 {
27 int i,i0,fnum;
28
29 i0=-1;
30 for (i=0;i<nfontnames;i++) {
31 if (!strcmp(f->name,fontnames[i])) i0=i;
32 }
33
34 if (i0>=0) {
35 fnum=i0;
36 if (vb>=10) printf("Already at %d: font %s\n",fnum,f->name);
37 }
38 else {
39 fnum=nfontnames;
40 strcpy(fontnames[fnum],f->name);
41 if (vb>=10) printf("Add new at %d: font %s\n",fnum,f->name);
42 nfontnames++;
43 }
44 return fnum;
45 }
46
47
48 /* ----- make_font_list ----- */
49 void make_font_list (f)
50 struct FORMAT *f;
51 {
52 if (vb>=10) printf ("Adding fonts from format..\n");
53 add_font (&f->titlefont);
54 add_font (&f->subtitlefont);
55 add_font (&f->composerfont);
56 add_font (&f->partsfont);
57 add_font (&f->tempofont);
58 add_font (&f->vocalfont);
59 add_font (&f->textfont);
60 add_font (&f->wordsfont);
61 add_font (&f->gchordfont);
62 add_font (&f->voicefont);
63 add_font (&f->barnumfont);
64 add_font (&f->barlabelfont);
65 }
66
67
68 /* ----- set_standard_format ----- */
69 void set_standard_format (f)
70 struct FORMAT *f;
71 {
72 strcpy (f->name, "standard");
73 f->pageheight = PAGEHEIGHT * CM;
74 f->staffwidth = STAFFWIDTH * CM;
75 f->leftmargin = LEFTMARGIN * CM;
76 f->topmargin = 1.0 * CM;
77 f->botmargin = 1.0 * CM;
78 f->topspace = 0.8 * CM;
79 f->titlespace = 0.2 * CM;
80 f->subtitlespace = 0.1 * CM;
81 f->composerspace = 0.2 * CM;
82 f->musicspace = 0.2 * CM;
83 f->partsspace = 0.3 * CM;
84 f->staffsep = 46.0 * PT;
85 f->sysstaffsep = 40.0 * PT;
86 f->systemsep = 55.0 * PT;
87 f->vocalspace = 23.0 * PT;
88 f->textspace = 0.5 * CM;
89 f->wordsspace = 0.0 * CM;
90 f->scale = 0.70;
91 f->maxshrink = 0.65;
92 f->landscape = 0;
93 f->titleleft = 0;
94 f->stretchstaff = 1;
95 f->stretchlast = 0;
96 f->continueall = 0;
97 f->breakall = 0;
98 f->writehistory = 0;
99 f->withxrefs = 0;
100 f->oneperpage = 0;
101 f->titlecaps = 0;
102 f->barsperstaff = 0;
103 f->barnums = -1;
104 f->lineskipfac = 1.1;
105 f->parskipfac = 0.4;
106 f->strict1 = 0.5;
107 f->strict2 = 0.8;
108 f->indent = 0.0;
109 fontspec (&f->titlefont, "Times-Roman", 15.0, 0);
110 fontspec (&f->subtitlefont, "Times-Roman", 12.0, 0);
111 fontspec (&f->composerfont, "Times-Italic", 11.0, 0);
112 fontspec (&f->partsfont, "Times-Roman", 11.0, 0);
113 fontspec (&f->tempofont, "Times-Bold", 10.0, 0);
114 fontspec (&f->vocalfont, "Times-Bold", 13.0, 0);
115 fontspec (&f->textfont, "Times-Roman", 12.0, 0);
116 fontspec (&f->wordsfont, "Times-Roman", 12.0, 0);
117 fontspec (&f->gchordfont, "Helvetica", 12.0, 0);
118 fontspec (&f->voicefont, "Times-Roman", 12.0, 0);
119 fontspec (&f->barnumfont, "Times-Italic", 12.0, 0);
120 fontspec (&f->barlabelfont, "Times-Bold", 18.0, 0);
121 fontspec (&f->indexfont, "Times-Roman", 11.0, 0);
122 if (vb>=10) printf ("Loading format \"%s\"\n",f->name);
123 }
124
125 /* ----- set_pretty_format ----- */
126 void set_pretty_format (f)
127 struct FORMAT *f;
128 {
129 set_standard_format (f);
130 strcpy (f->name, "pretty");
131 f->titlespace = 0.4 * CM;
132 f->composerspace = 0.25 * CM;
133 f->musicspace = 0.25 * CM;
134 f->partsspace = 0.3 * CM;
135 f->staffsep = 50.0 * PT;
136 f->sysstaffsep = 45.0 * PT;
137 f->systemsep = 55.0 * PT;
138 f->scale = 0.75;
139 f->maxshrink = 0.55;
140 f->parskipfac = 0.1;
141 fontspec (&f->titlefont, "Times-Roman", 18.0, 0);
142 fontspec (&f->subtitlefont, "Times-Roman", 15.0, 0);
143 fontspec (&f->composerfont, "Times-Italic", 12.0, 0);
144 fontspec (&f->partsfont, "Times-Roman", 12.0, 0);
145 fontspec (&f->tempofont, "Times-Bold", 10.0, 0);
146 fontspec (&f->vocalfont, "Times-Bold", 14.0, 0);
147 fontspec (&f->textfont, "Times-Roman", 10.0, 0);
148 fontspec (&f->wordsfont, "Times-Roman", 10.0, 0);
149 fontspec (&f->gchordfont, "Helvetica", 12.0, 0);
150 fontspec (&f->voicefont, "Times-Roman", 12.0, 0);
151 }
152
153 /* ----- set_pretty2_format ----- */
154 void set_pretty2_format (f)
155 struct FORMAT *f;
156 {
157 set_standard_format (f);
158 strcpy (f->name, "pretty2");
159 f->titlespace = 0.4 * CM;
160 f->composerspace = 0.3 * CM;
161 f->musicspace = 0.25 * CM;
162 f->partsspace = 0.2 * CM;
163 f->staffsep = 55.0 * PT;
164 f->sysstaffsep = 45.0 * PT;
165 f->systemsep = 55.0 * PT;
166 f->textspace = 0.2 * CM;
167 f->scale = 0.70;
168 f->maxshrink = 0.55;
169 f->titleleft = 1;
170 f->parskipfac = 0.1;
171 fontspec (&f->titlefont, "Helvetica-Bold", 16.0, 0);
172 fontspec (&f->subtitlefont, "Helvetica-Bold", 13.0, 0);
173 fontspec (&f->composerfont, "Helvetica", 10.0, 0);
174 fontspec (&f->partsfont, "Times-Roman", 12.0, 0);
175 fontspec (&f->tempofont, "Times-Bold", 10.0, 0);
176 fontspec (&f->vocalfont, "Times-Bold", 13.0, 0);
177 fontspec (&f->textfont, "Times-Roman", 10.0, 0);
178 fontspec (&f->wordsfont, "Times-Roman", 10.0, 0);
179 fontspec (&f->gchordfont, "Helvetica", 12.0, 0);
180 fontspec (&f->voicefont, "Times-Roman", 12.0, 0);
181 fontspec (&f->barnumfont, "Times-Roman", 11.0, 1);
182 fontspec (&f->barlabelfont, "Times-Bold", 18.0, 1);
183 }
184
185
186 /* ----- print_font ----- */
187 void print_font (str,fs)
188 char *str;
189 struct FONTSPEC fs;
190 {
191 printf (" %-14s %s %.1f", str, fs.name, fs.size);
192 if (fs.box) printf (" box");
193 printf ("\n");
194 }
195
196
197 /* ----- print_format ----- */
198 void print_format (f)
199 struct FORMAT f;
200 {
201 char yn[2][5]={"no","yes"};
202
203 printf ("\nFormat \"%s\":\n", f.name);
204 printf (" pageheight %.2fcm\n", f.pageheight/CM);
205 printf (" staffwidth %.2fcm\n", f.staffwidth/CM);
206 printf (" topmargin %.2fcm\n", f.topmargin/CM);
207 printf (" botmargin %.2fcm\n", f.botmargin/CM);
208 printf (" leftmargin %.2fcm\n", f.leftmargin/CM);
209 printf (" topspace %.2fcm\n", f.topspace/CM);
210 printf (" titlespace %.2fcm\n", f.titlespace/CM);
211 printf (" subtitlespace %.2fcm\n", f.subtitlespace/CM);
212 printf (" composerspace %.2fcm\n", f.composerspace/CM);
213 printf (" musicspace %.2fcm\n", f.musicspace/CM);
214 printf (" partsspace %.2fcm\n", f.partsspace/CM);
215 printf (" wordsspace %.2fcm\n", f.wordsspace/CM);
216 printf (" textspace %.2fcm\n", f.textspace/CM);
217 printf (" vocalspace %.1fpt\n", f.vocalspace);
218 printf (" staffsep %.1fpt\n", f.staffsep);
219 printf (" sysstaffsep %.1fpt\n", f.sysstaffsep);
220 printf (" systemsep %.1fpt\n", f.systemsep);
221 printf (" scale %.2f\n", f.scale);
222 printf (" maxshrink %.2f\n", f.maxshrink);
223 printf (" strictness1 %.2f\n", f.strict1);
224 printf (" strictness2 %.2f\n", f.strict2);
225 printf (" indent %.1fpt\n", f.indent);
226
227 print_font("titlefont", f.titlefont);
228 print_font("subtitlefont", f.subtitlefont);
229 print_font("composerfont", f.composerfont);
230 print_font("partsfont", f.partsfont);
231 print_font("tempofont", f.tempofont);
232 print_font("vocalfont", f.vocalfont);
233 print_font("gchordfont", f.gchordfont);
234 print_font("textfont", f.textfont);
235 print_font("wordsfont", f.wordsfont);
236 print_font("voicefont", f.voicefont);
237 print_font("barnumberfont",f.barnumfont);
238 print_font("barlabelfont", f.barlabelfont);
239 print_font("indexfont", f.indexfont);
240
241 printf (" lineskipfac %.1f\n", f.lineskipfac);
242 printf (" parskipfac %.1f\n", f.parskipfac);
243 printf (" barsperstaff %d\n", f.barsperstaff);
244 printf (" barnumbers %d\n", f.barnums);
245 printf (" landscape %s\n", yn[f.landscape]);
246 printf (" titleleft %s\n", yn[f.titleleft]);
247 printf (" titlecaps %s\n", yn[f.titlecaps]);
248 printf (" stretchstaff %s\n", yn[f.stretchstaff]);
249 printf (" stretchlast %s\n", yn[f.stretchlast]);
250 printf (" writehistory %s\n", yn[f.writehistory]);
251 printf (" continueall %s\n", yn[f.continueall]);
252 printf (" breakall %s\n", yn[f.breakall]);
253 printf (" oneperpage %s\n", yn[f.oneperpage]);
254 printf (" withxrefs %s\n", yn[f.withxrefs]);
255
256 }
257
258
259 /* ----- g_unum: read a number with a unit ----- */
260 void g_unum (l,s,num)
261 char *l,*s;
262 float *num;
263 {
264 float a,b;
265 char unit[81];
266
267 strcpy(unit,"pt");
268 sscanf(s,"%f%s", &a, unit);
269
270 if (!strcmp(unit,"cm")) b=a*CM;
271 else if (!strcmp(unit,"mm")) b=a*CM*0.1;
272 else if (!strcmp(unit,"in")) b=a*IN;
273 else if (!strcmp(unit,"pt")) b=a*PT;
274 else {
275 printf ("+++ Unknown unit \"%s\" in line: %s\n",unit,l);
276 exit (3);
277 }
278 *num = b;
279 }
280
281 /* ----- g_logv: read a logical variable ----- */
282 void g_logv (l,s,v)
283 char *l,*s;
284 int *v;
285 {
286 int k;
287 char t[31];
288
289 strcpy(t,"1");
290 sscanf (s,"%s", t);
291 if (!strcmp(t,"1") || !strcmp(t,"yes") || !strcmp(t,"true"))
292 k=1;
293 else if (!strcmp(t,"0") || !strcmp(t,"no") || !strcmp(t,"false"))
294 k=0;
295 else {
296 printf ("\n+++ Unknown logical value \"%s\" near \"%s\"\n",t,l);
297 exit (3);
298 }
299 *v = k;
300 }
301
302
303 /* ----- g_fltv: read a float variable, no units ----- */
304 void g_fltv (l,nch,v)
305 char *l;
306 int nch;
307 float *v;
308 {
309 float k;
310
311 sscanf (l+nch,"%f", &k);
312 *v = k;
313 }
314
315 /* ----- g_intv: read an int variable, no units ----- */
316 void g_intv (l,nch,v)
317 char *l;
318 int nch;
319 int *v;
320 {
321 int k;
322
323 sscanf (l+nch,"%d", &k);
324 *v = k;
325 }
326
327
328
329 /* ----- g_fspc: read a font specifier ----- */
330 void g_fspc (l,nch,fn)
331 char *l;
332 int nch;
333 struct FONTSPEC *fn;
334 {
335 char fname[101],ssiz[101],sbox[101];
336 float fsize;
337
338 fsize=fn->size;
339 strcpy(sbox,"SnOt");
340 strcpy(ssiz,"SnOt");
341
342 sscanf (l+nch,"%s %s %s", fname, ssiz, sbox);
343 if (strcmp(fname,"*")) strcpy (fn->name, fname);
344
345 if (strcmp(ssiz,"*")) sscanf(ssiz,"%f",&fsize);
346 fn->size = fsize;
347
348 if (!strcmp(sbox,"box")) fn->box=1;
349 else if (!strcmp(sbox,"SnOt")) ;
350 else wng ("incorrect font spec: ", l+nch);
351
352 if (!file_initialized) add_font (fn);
353 }
354
355
356 /* ----- interpret_format_line ----- */
357 /* read a line with a format directive, set in format struct f */
358 int interpret_format_line (l,f)
359 char l[];
360 struct FORMAT *f;
361 {
362 char w[81],fnm[81];
363 int nch,i,fnum;
364 char *s;
365 struct FONTSPEC tempfont;
366
367 strcpy(w,"");
368 sscanf(l,"%s%n", w, &nch);
369 if (!strcmp(w,"")) return 0;
370 if (w[0]=='%') return 0;
371 if (vb>=6) printf ("Interpret format line: %s\n", l);
372 if (!strcmp(w,"end")) return 1;
373 s=l+nch;
374
375 if (!strcmp(w,"pageheight")) g_unum(l,s,&f->pageheight);
376 else if (!strcmp(w,"staffwidth")) g_unum(l,s,&f->staffwidth);
377 else if (!strcmp(w,"topmargin")) g_unum(l,s,&f->topmargin);
378 else if (!strcmp(w,"botmargin")) g_unum(l,s,&f->botmargin);
379 else if (!strcmp(w,"leftmargin")) g_unum(l,s,&f->leftmargin);
380 else if (!strcmp(w,"topspace")) g_unum(l,s,&f->topspace);
381 else if (!strcmp(w,"wordsspace")) g_unum(l,s,&f->wordsspace);
382 else if (!strcmp(w,"titlespace")) g_unum(l,s,&f->titlespace);
383 else if (!strcmp(w,"subtitlespace")) g_unum(l,s,&f->subtitlespace);
384 else if (!strcmp(w,"composerspace")) g_unum(l,s,&f->composerspace);
385 else if (!strcmp(w,"musicspace")) g_unum(l,s,&f->musicspace);
386 else if (!strcmp(w,"partsspace")) g_unum(l,s,&f->partsspace);
387 else if (!strcmp(w,"staffsep")) g_unum(l,s,&f->staffsep);
388 else if (!strcmp(w,"sysstaffsep")) g_unum(l,s,&f->sysstaffsep);
389 else if (!strcmp(w,"systemsep")) g_unum(l,s,&f->systemsep);
390 else if (!strcmp(w,"vocalspace")) g_unum(l,s,&f->vocalspace);
391 else if (!strcmp(w,"textspace")) g_unum(l,s,&f->textspace);
392
393 else if (!strcmp(w,"scale")) g_fltv(l,nch,&f->scale);
394 else if (!strcmp(w,"maxshrink")) g_fltv(l,nch,&f->maxshrink);
395 else if (!strcmp(w,"lineskipfac")) g_fltv(l,nch,&f->lineskipfac);
396 else if (!strcmp(w,"parskipfac")) g_fltv(l,nch,&f->parskipfac);
397 else if (!strcmp(w,"barsperstaff")) g_intv(l,nch,&f->barsperstaff);
398 else if (!strcmp(w,"barnumbers")) g_intv(l,nch,&f->barnums);
399 else if (!strcmp(w,"strictness1")) g_fltv(l,nch,&f->strict1);
400 else if (!strcmp(w,"strictness2")) g_fltv(l,nch,&f->strict2);
401 else if (!strcmp(w,"strictness")) {
402 g_fltv(l,nch,&f->strict1); f->strict2=f->strict1; }
403 else if (!strcmp(w,"indent")) g_unum(l,s,&f->indent);
404
405 else if (!strcmp(w,"titleleft")) g_logv(l,s,&f->titleleft);
406 else if (!strcmp(w,"titlecaps")) g_logv(l,s,&f->titlecaps);
407 else if (!strcmp(w,"landscape")) g_logv(l,s,&f->landscape);
408 else if (!strcmp(w,"stretchstaff")) g_logv(l,s,&f->stretchstaff);
409 else if (!strcmp(w,"stretchlast")) g_logv(l,s,&f->stretchlast);
410 else if (!strcmp(w,"continueall")) g_logv(l,s,&f->continueall);
411 else if (!strcmp(w,"breakall")) g_logv(l,s,&f->breakall);
412 else if (!strcmp(w,"writehistory")) g_logv(l,s,&f->writehistory);
413 else if (!strcmp(w,"withxrefs") ) g_logv(l,s,&f->withxrefs);
414 else if (!strcmp(w,"oneperpage") ) g_logv(l,s,&f->oneperpage);
415
416 else if (!strcmp(w,"titlefont")) g_fspc(l,nch,&f->titlefont);
417 else if (!strcmp(w,"subtitlefont")) g_fspc(l,nch,&f->subtitlefont);
418 else if (!strcmp(w,"vocalfont")) g_fspc(l,nch,&f->vocalfont);
419 else if (!strcmp(w,"partsfont")) g_fspc(l,nch,&f->partsfont);
420 else if (!strcmp(w,"tempofont")) g_fspc(l,nch,&f->tempofont);
421 else if (!strcmp(w,"textfont")) g_fspc(l,nch,&f->textfont);
422 else if (!strcmp(w,"composerfont")) g_fspc(l,nch,&f->composerfont);
423 else if (!strcmp(w,"wordsfont")) g_fspc(l,nch,&f->wordsfont);
424 else if (!strcmp(w,"gchordfont")) g_fspc(l,nch,&f->gchordfont);
425 else if (!strcmp(w,"voicefont")) g_fspc(l,nch,&f->voicefont);
426 else if (!strcmp(w,"barnumberfont")) g_fspc(l,nch,&f->barnumfont);
427 else if (!strcmp(w,"barlabelfont")) g_fspc(l,nch,&f->barlabelfont);
428 else if (!strcmp(w,"indexfont")) g_fspc(l,nch,&f->indexfont);
429
430 else if (!strcmp(w,"font")) {
431 sscanf(l,"%*s %s", fnm);
432 fnum=-1;
433 for (i=0;i<nfontnames;i++) {
434 if (!strcmp(fnm,fontnames[i])) fnum=i;
435 }
436 if (fnum<0) {
437 if (file_initialized) {
438 printf ("+++ Cannot predefine when output file open: %s\n", l);
439 exit (3);
440 }
441 tempfont.size=12.0;
442 g_fspc(l,nch,&tempfont);
443 }
444 }
445
446 else {
447 if (vb>=5) printf ("Ignore format line: %s\n", l);
448 return 2;
449 }
450 return 0;
451 }
452
453 /* ----- read_fmt_file ----- */
454 int read_fmt_file (filename,dirname,f)
455 char filename [],dirname[];
456 struct FORMAT *f;
457 {
458 FILE *fp;
459 char line[BSIZE],fname[201];
460 int i,end;
461
462 strcpy(fname,filename);
463 if ((fp = fopen (fname,"r")) == NULL) {
464 if (strlen(dirname)==0)
465 return 0;
466 else {
467 strcpy(fname,dirname);
468 strcat(fname,"/");
469 strcat(fname,filename);
470 if ((fp = fopen (fname,"r")) == NULL) return 0;
471 }
472 }
473
474 if (vb>=4) printf ("Reading format file %s:\n", fname);
475 printf ("%s .. ", fname);
476 strcpy (line, "");
477 abc2ps_getline(line, BSIZE, fp);
478 for (i=0;i<200;i++) {
479 end=interpret_format_line (line,f);
480 if (end==1) return 1;
481 strcpy (line, "");
482 if (feof(fp)) return 1;
483 if (!abc2ps_getline(line, BSIZE, fp)) return 1 ;
484 }
485 fclose (fp);
486 return 1;
487 }
488
489