/* * This file is part of jcabc2ps, * Copyright (C) 1996,1997,1998 Michael Methfessel * See file jcabc2ps.c for details. */ #include "jcabc2ps.h" #include "syms.h" /* subroutines to define postscript macros which draw symbols */ /* ----- def_misc ------- */ void def_misc (fp) FILE *fp; { fprintf(fp,"\n/accdraw 0 def\n"); fprintf(fp,"\n"); fprintf(fp,"/Accent {\n"); fprintf(fp," accbasec glyphshow\n"); fprintf(fp," gsave \n"); fprintf(fp," accbasew dup neg 0 rmoveto\n"); fprintf(fp," accwidth sub 2 div 2.7 currentfont /ScaleMatrix get 0 get mul 12 div rmoveto\n"); fprintf(fp," accchar glyphshow\n"); fprintf(fp," grestore\n"); fprintf(fp,"} bind def\n"); fprintf(fp,"\n"); fprintf(fp,"/accent {\n"); fprintf(fp," accbasec glyphshow\n"); fprintf(fp," gsave\n"); fprintf(fp," accbasew dup neg 0 rmoveto\n"); fprintf(fp," accwidth sub 2 div 0 rmoveto\n"); fprintf(fp," accchar glyphshow\n"); fprintf(fp," grestore\n"); fprintf(fp,"} bind def\n"); fprintf(fp,"\n"); fprintf(fp,"/laccent {\n"); fprintf(fp," accbasec glyphshow\n"); fprintf(fp," gsave \n"); fprintf(fp," accbasew dup neg 0 rmoveto\n"); fprintf(fp," accwidth sub 2 div -2.4 currentfont /ScaleMatrix get 0 get mul 12 div rmoveto\n"); fprintf(fp," accchar glyphshow\n"); fprintf(fp," grestore\n"); fprintf(fp,"} bind def\n"); fprintf(fp,"\n"); fprintf(fp,"/testacc {\n"); fprintf(fp," pop %% drop height\n"); fprintf(fp," 1 index dup %% get encoding integer\n"); fprintf(fp," 145 ge exch 159 le and { %% it's an accent (145-159)\n"); fprintf(fp," /accdraw 1 def\n"); fprintf(fp," /accwidth exch def\n"); fprintf(fp," ISOLatin1Encoding exch get /accchar exch def\n"); fprintf(fp," } { %% or something else\n"); fprintf(fp," accdraw 1 eq { %% we have to draw it with accent\n"); fprintf(fp," /accbasew exch def %% save base char's width\n"); fprintf(fp," dup ISOLatin1Encoding exch get /accbasec exch def %% and the char\n"); fprintf(fp," accchar dup /cedilla eq exch /ogonek eq or { %% the accent goes below the char (cedilla or ogonek)\n"); fprintf(fp," accbasec /g eq %% check for underlength: g\n"); fprintf(fp," accbasec /j eq or %% j\n"); fprintf(fp," accbasec /p eq or %% p\n"); fprintf(fp," accbasec /q eq or %% q\n"); fprintf(fp," accbasec /y eq or %% y\n"); fprintf(fp," { \n"); fprintf(fp," laccent %% then place it somewhat lower\n"); fprintf(fp," } {\n"); fprintf(fp," accent\n"); fprintf(fp," } ifelse\n"); fprintf(fp," } { %% accent goes above\n"); fprintf(fp," dup dup 65 ge exch 90 le and %% a capital letter\n"); fprintf(fp," exch dup 48 ge exch 57 le and or %% or a number\n"); fprintf(fp," accbasec /b eq or %% or a b\n"); fprintf(fp," accbasec /d eq or %% d\n"); fprintf(fp," accbasec /f eq or %% f\n"); fprintf(fp," accbasec /h eq or %% h\n"); fprintf(fp," accbasec /k eq or %% k\n"); fprintf(fp," accbasec /l eq or %% l\n"); fprintf(fp," accbasec /t eq or %% or t\n"); fprintf(fp," {\n"); fprintf(fp," Accent %% then place it somewhat higher\n"); fprintf(fp," } {\n"); fprintf(fp," accbasec /i eq %% replace i by dotless i\n"); fprintf(fp," { /accbasec /dotlessi def } if\n"); fprintf(fp," accent\n"); fprintf(fp," } ifelse\n"); fprintf(fp," } ifelse\n"); fprintf(fp," } {\n"); fprintf(fp," pop dup 1 eq {\n"); fprintf(fp," gsave /dcroat glyphshow grestore \n"); fprintf(fp," } {\n"); fprintf(fp," dup 2 eq\n"); fprintf(fp," {\n"); fprintf(fp," gsave /Dcroat glyphshow grestore \n"); fprintf(fp," } {\n"); fprintf(fp," ISOLatin1Encoding exch get glyphshow\n"); fprintf(fp," } ifelse } ifelse\n"); fprintf(fp," } ifelse\n"); fprintf(fp," /accdraw 0 def\n"); fprintf(fp," } ifelse\n"); fprintf(fp,"} bind def\n"); fflush(fp); fprintf(fp,"\n/stringwidth { \n"); fprintf(fp," 0 exch 0 exch \n"); fprintf(fp," { dup dup dup dup 145 ge exch 159 le and exch 1 eq or exch 2 eq or { \n"); fprintf(fp," pop \n"); fprintf(fp," }{\n"); fprintf(fp," /st ( ) def st exch 0 exch put st stringwidth 3 -1 roll add 3 1 roll add exch\n"); fprintf(fp," } ifelse\n"); fprintf(fp," } forall } bind def\n"); fprintf(fp,"\n/show { /testacc load cshow } bind def\n"); fprintf(fp,"\n/cshow { %% usage: string cshow - center at current pt\n"); fprintf(fp," dup stringwidth pop 2 div neg 0 rmoveto\n"); fprintf(fp," bx {box} if show\n"); fprintf(fp,"} bind def\n"); fprintf(fp,"\n/lshow { %% usage: string lshow - show left-aligned\n"); fprintf(fp," dup stringwidth pop neg 0 rmoveto bx {box} if show\n"); fprintf(fp,"} bind def\n"); fprintf(fp,"\n/rshow { %% usage: string rshow - show right-aligned\n"); fprintf(fp," bx {box} if show\n"); fprintf(fp,"} bind def\n"); fflush(fp); fprintf(fp,"\n/box { %% usage: str box - draw box around string\n"); fprintf(fp," gsave 1.5 setlinewidth dup stringwidth pop\n"); fprintf(fp," -2 -2 rmoveto 4 add fh 4 add 2 copy\n"); fprintf(fp," 0 exch rlineto 0 rlineto neg 0 exch rlineto neg 0 rlineto\n"); fprintf(fp," closepath stroke grestore\n"); fprintf(fp,"} bind def\n"); fflush(fp); fprintf(fp,"\n/wd { moveto bx {box} if show } bind def\n"); fprintf(fp,"/wln {\n"); fprintf(fp,"dup 3 1 roll moveto gsave 0.6 setlinewidth lineto stroke grestore\n"); fprintf(fp,"} bind def\n"); fflush(fp); fprintf (fp,"/whf {moveto gsave 0.5 1.2 scale (-) show grestore} bind def\n"); fflush(fp); } /* ----- def_typset ------- */ void def_typeset(fp) FILE *fp; { fflush(fp); fprintf(fp,"\n/WS { %%usage: w nspaces str WS\n"); fprintf(fp," dup stringwidth pop 4 -1 roll\n"); fprintf(fp," sub neg 3 -1 roll div 0 8#040 4 -1 roll\n"); fprintf(fp," widthshow\n"); fprintf(fp,"} bind def\n"); fflush(fp); fprintf(fp,"\n/W1 { show pop pop } bind def\n"); fprintf(fp,"\n/str 50 string def\n"); fprintf(fp,"/W0 {\n"); fprintf(fp," dup stringwidth pop str cvs exch show ( ) show show pop pop\n"); fprintf(fp,"} bind def\n"); fflush(fp); fprintf(fp,"\n/WC { counttomark 1 sub dup 0 eq { 0 }\n"); fprintf(fp," { ( ) stringwidth pop neg 0 3 -1 roll\n"); fprintf(fp," { dup 3 add index stringwidth pop ( ) stringwidth pop add\n"); fprintf(fp," dup 3 index add 4 index lt 2 index 1 lt or\n"); fprintf(fp," {3 -1 roll add exch 1 add} {pop exit} ifelse\n"); fprintf(fp," } repeat } ifelse\n"); fprintf(fp,"} bind def\n"); fflush(fp); fprintf(fp,"\n/P1 {\n"); fprintf(fp," { WC dup 0 le {exit} if\n"); fprintf(fp," exch pop gsave { exch show ( ) show } repeat grestore LF\n"); fprintf(fp," } loop pop pop pop pop\n"); fprintf(fp,"} bind def\n"); fflush(fp); fprintf(fp,"\n/P2 {\n"); fprintf(fp," { WC dup 0 le {exit} if\n"); fprintf(fp," dup 1 sub dup 0 eq\n"); fprintf(fp," { pop exch pop 0.0 }\n"); fprintf(fp," { 3 2 roll 3 index exch sub exch div } ifelse\n"); fprintf(fp," counttomark 3 sub 2 index eq { pop 0 } if exch gsave\n"); fprintf(fp," { 3 2 roll show ( ) show dup 0 rmoveto } repeat\n"); fprintf(fp," grestore LF pop\n"); fprintf(fp," } loop pop pop pop pop\n"); fprintf(fp,"} bind def\n"); fflush(fp); } /* ----- define_font ------- */ void define_font (fp,name,num) FILE *fp; char name[]; int num; { if (!strcmp(name,"Symbol")) { fprintf(fp,"/F%d { 1 eq {/bx true def} { /bx false def} ifelse\n",num); fprintf(fp," dup 0.72 mul /fh exch def\n"); fprintf(fp," /%s exch selectfont } bind def\n",name); return; } fprintf(fp,"\n/%s findfont\n",name); fprintf(fp,"dup length dict begin\n"); fprintf(fp," {1 index /FID ne {def} {pop pop} ifelse} forall\n"); fprintf(fp," /Encoding ISOLatin1Encoding def\n"); fprintf(fp," currentdict\n"); fprintf(fp,"end\n"); fprintf(fp,"/%s-ISO exch definefont pop\n",name); fprintf(fp,"/F%d { 1 eq {/bx true def} { /bx false def} ifelse\n",num); fprintf(fp," dup 0.72 mul /fh exch def\n"); fprintf(fp," /%s-ISO exch selectfont } bind def\n",name); fflush(fp); } /* ----- def_tsig ------- */ void def_tsig (fp) FILE *fp; { fprintf(fp,"\n/tsig { %% usage: x (top) (bot) tsig -- draw time signature\n"); fprintf(fp," 3 -1 roll 0 moveto /bx false def\n"); fprintf(fp," gsave /Times-Courier 16 selectfont 1.2 1 scale\n"); fprintf(fp," 0 1.0 rmoveto currentpoint 3 -1 roll cshow\n"); fprintf(fp," moveto 0 12 rmoveto cshow grestore\n"); fprintf(fp,"} bind def\n"); fflush(fp); } /* ----- add_cv ------- */ void add_cv (FILE *fp, float f1, float f2, float p[][2], int i0, int ncv) { int i,i1,m; i1=i0; for (m=0; m