1 % A Native PDF version of lily-ps-defs.tex, in which the language
2 % features of the PS code are handled by TeX. This takes the place of
3 % lilyponddefs.ps, lily.ps, and lily-ps-defs.tex for PDFTeX.
5 % Note that this file will probably require changes if the lily.ps
6 % file changes, which is annoying in the long run. It might be best
7 % if sometime the intelligence embodied in lily.ps could be moved up
8 % to the GUILE level, so that the \embeddedps commands could consist
9 % simply of moveto, lineto, curveto, fill, and stroke commands, with
10 % numeric arguments. Such a setup would allow this file to be simpler
11 % and probably cause the resulting PostScript code to be faster as
14 % Redefine @ and _ so we can use them in definition names here.
18 % Define a helper procedure for PDF coding. This file really
19 % shouldn't be read if \pdfliteral is undefined, but the alternate
20 % definition is nice for testing.
22 \ifx\pdfliteral\undefined
23 \def\LYPDF#1{\message{[ignored pdfliteral:
#1]}}
25 \let\LYPDF=
\pdfliteral
28 % Strip 'pt' off of dimensions. Borrowed from latex.
33 \def\x{\def\lypdf@rempt#
#1.#
#2PT
{#
#1\ifnum#
#2>
\z@.#
#2\fi}}}
34 \expandafter\endgroup\x
35 \def\lypdf@strippt
{\expandafter\lypdf@rempt
\the}
37 \def\LYDIM#1{\expandafter\lypdf@strippt
\dimen#1\space}
39 \def\lypdf@correctfactor
{65536}
40 \def\lypdf@divcorrect
#1{\multiply\dimen#1 \lypdf@correctfactor
\relax}
42 %% Stack handling. The design for this is borrowed from supp-pdf.tex
44 \newcount\nofLYPDFargs
47 % Add an argument to the `stack'
49 \advance\nofLYPDFargs by
1
51 \csname\@@LYPDF
\the\nofLYPDFargs\endcsname
55 % Get the values for stack variables. The a form includes a closing
56 % \space and is thus useful for embedding in \LYPDF macros.
58 {\csname\@@LYPDF
#1\endcsname\space}
60 {\csname\@@LYPDF
#1\endcsname}
62 % Reset the stack back to normal.
63 \def\resetLYPDFstack{\nofLYPDFargs=
0}
65 % A translator for \embeddedps commands. This simply stacks up the
66 % arguments and then passes the last arg to the appropriate lypdf@name
70 \lypdf@handleArgs
#1 \\
}
72 %% Handle the argument list. Note: when working with arrays, just
73 %% keep tacking things onto a string until we get a close bracket.
74 %% The various LYPDFarray... variables are used for that.
76 \def\LYPDFarraystart{[}
78 \def\LYPDFarraystring{}
81 \def\lypdf@handleArgs
#1 #2\\
{
83 \csname\lypdf@
#1\endcsname
88 \edef\LYPDFarraystring{\LYPDFarraystring\space\argstring}
89 \ifx\argstring\LYPDFarrayend%
91 \setLYPDFarg{\LYPDFarraystring}
94 \ifx\argstring\LYPDFarraystart%
96 \edef\LYPDFarraystring{[}
101 \lypdf@handleArgs
#2\\
104 % Here turning on PostScript sets up the bracket stuff. This should
105 % probably be called by a more generic header macro.
106 \def\turnOnPostScript{\lypdf@load_bracket_dimens
}%
107 \def\turnOnExperimentalFeatures{}%
109 %% TODO: lily-ps-defs sets a linecap of 1. I'm not yet sure how to do that
110 %% for the Page Description level in PDFTeX.
112 %% What follows are the definitions for the embeddedps commands.
113 %% Notes that in general, \dimen0 and \dimen1 are the x and y
114 %% positions of the cursor (used for rlineto handling), and dimen2-9
115 %% are used for local dimension handling in the various commands.
117 \def\lypdf@resetstring
{\edef\lypdf@curstring
{}}
119 \def\lypdf@moveto
#1#2{
122 \edef\lypdf@curstring
{\lypdf@curstring
\space\LYDIM0 \LYDIM1 m
}
125 \def\lypdf@rmoveto
#1#2{
126 \advance\dimen0 by
#1 pt
127 \advance\dimen1 by
#2 pt
128 \edef\lypdf@curstring
{\lypdf@curstring
\space\LYDIM0 \LYDIM1 m
}
131 \def\lypdf@rlineto
#1#2{
132 \advance\dimen0 by
#1 pt
133 \advance\dimen1 by
#2 pt
134 \edef\lypdf@curstring
{\lypdf@curstring
\space\LYDIM0 \LYDIM1 l
}
137 \def\lypdf@draw_beam
{% takes width, slope, thick
138 \dimen2=
\gLYPDFa3 pt
\divide\dimen2 by
2
139 \dimen3=
\gLYPDFa1 pt
\dimen3=
\gLYPDFa2 \dimen3
141 \lypdf@moveto
{0}{-
\LYDIM2}
142 \lypdf@rlineto
{\gLYPDFa1}{\LYDIM3}
143 \lypdf@rlineto
{0}{\gLYPDFa3}
144 \LYPDF{\lypdf@curstring
\space 0 \LYDIM2 l b
}
147 \def\lypdf@draw_decrescendo
{% takes width, ht, cont, thick
149 \gLYPDFa1 \gLYPDFa3 m
0 \gLYPDFa2 l S
150 \gLYPDFa1 -
\gLYPDFa3 m
0 -
\gLYPDFa2 l S
}
152 \def\lypdf@draw_crescendo
{% takes width, ht, cont, thick
154 0 \gLYPDFa3 m
\gLYPDFa1 \gLYPDFa2 l S -
\gLYPDFa3 m
155 \gLYPDFa1 -
\gLYPDFa2 l S
}
158 \def\lypdf@draw_tuplet
{% takes height, gap, dx, dy, thickness, dir
159 \dimen2=
\gLYPDFa1 pt
\multiply\dimen2 by
\gLYPDFa6 \relax
161 \dimen3=
\gLYPDFa2 pt
% tuplet_gapx
163 \dimen4=
\gLYPDFa4 \dimen3 \divide\dimen4 by
\dimen0
164 \lypdf@divcorrect4
% tuplet_gapy
165 \dimen5=
\gLYPDFa3 pt
\advance\dimen5 by-
\dimen3
166 \divide\dimen5 by
2 % (dx-gx)/2
167 \dimen6=
\gLYPDFa4 pt
\advance\dimen6 by-
\dimen4
168 \divide\dimen6 by
2 % (dx-gx)/2
172 \lypdf@rlineto
{0}{\LYDIM2}
173 \lypdf@rlineto
{\LYDIM5}{\LYDIM6}
174 \lypdf@rmoveto
{\LYDIM3}{\LYDIM4}
175 \lypdf@rlineto
{\LYDIM5}{\LYDIM6}
176 \lypdf@rlineto
{0}{-
\LYDIM2}
177 \LYPDF{\gLYPDFa5 w
1 j
1 J
\lypdf@curstring
}
180 \def\lypdf@draw_volta
{% takes height, width, thickness, v_start, v_end
181 \dimen2=
\gLYPDFa1 pt
% volta height
183 \edef\vstartstr{0 0 m
0 \LYDIM2 l
\space}
185 \edef\vstartstr{0 \LYDIM2 m
\space}
188 \edef\vendstr{\gLYPDFa2 0 l
\space}
192 \LYPDF{\gLYPDFa3 w
1 J
1 j
\vstartstr \gLYPDFa2 \LYDIM2 l
\vendstr S
}
195 \def\lypdf@draw_bezier_sandwich
{% sixteen coords, thickness
197 \gLYPDFa15 \gLYPDFa16 m
198 \gLYPDFa9 \gLYPDFa10 \gLYPDFa11 \gLYPDFa12 \gLYPDFa13 \gLYPDFa14 c
199 \gLYPDFa7 \gLYPDFa8 l
200 \gLYPDFa1 \gLYPDFa2 \gLYPDFa3 \gLYPDFa4 \gLYPDFa5 \gLYPDFa6 c
203 \def\lypdf@draw_dashed_slur
{%
204 \LYPDF{1 J
1 j
\gLYPDFa10 \gLYPDFa11 d
\gLYPDFa9 w
205 \gLYPDFa1 \gLYPDFa2 m
206 \gLYPDFa3 \gLYPDFa4 \gLYPDFa5 \gLYPDFa6 \gLYPDFa7 \gLYPDFa8 c
209 %% Definitions for the various dimensions used by the brackets.
210 \newdimen\lypdf@interline
211 \newdimen\lypdf@bracket_b
212 \newdimen\lypdf@bracket_w
213 \newdimen\lypdf@bracket_v
214 \newdimen\lypdf@bracket_u
215 \newdimen\lypdf@bracket_t
217 \def\lypdf@load_bracket_dimens
{
218 \lypdf@interline=
\mudelapaperinterline pt
219 \lypdf@bracket_b=
0.3333\lypdf@interline
220 \lypdf@bracket_w=
2\lypdf@interline
221 \lypdf@bracket_v=
1.5\lypdf@interline
222 \lypdf@bracket_u=
\lypdf@bracket_v
223 \lypdf@bracket_t=
\mudelapaperstaffline pt
224 \lypdf@bracket_t=
2\lypdf@bracket_t
228 %alpha=50. We calculate the sin and cos directly because TeX can't.
229 \def\lypdf@bracket_sin
{0.76604}%
230 \def\lypdf@bracket_cos
{0.64279}%
232 \def\lypdf@draw_half_bracket
{% dimen2 is the bracket height
233 \dimen3=
\dimen2\advance\dimen3 by -
\lypdf@bracket_t
% h - t
235 % Here, dimen0 and dimen1 are the end points of the bracket
236 \dimen0=
\lypdf@bracket_b
\relax\advance\dimen0 by
\lypdf@bracket_v
237 \dimen1=
\dimen3\advance\dimen1 by
\lypdf@bracket_u
239 % bottom of half bracket and inner side
240 \edef\lypdf@halfbrack
{0 0 m
\lypdf@strippt
\lypdf@bracket_b
\space 0 l
241 \lypdf@strippt
\lypdf@bracket_b
\space \LYDIM3 l
}
243 % inner curve -- first control point is just 0.4*v to the right
244 \dimen4=
\lypdf@bracket_b
\advance\dimen4 by
0.4\lypdf@bracket_v
245 % ... second point is calc'd using alpha
246 \dimen5=-
0.25\lypdf@bracket_v
\relax
247 \dimen6=
\dimen0\advance\dimen6 by
\lypdf@bracket_cos
\dimen5\relax
248 \dimen7=
\dimen1\advance\dimen7 by
\lypdf@bracket_sin
\dimen5\relax
250 \edef\lypdf@halfbrack
251 {\lypdf@halfbrack
\space\LYDIM4 \LYDIM3 \LYDIM6 \LYDIM7 \LYDIM0 \LYDIM1 c
}
253 % outer curve -- second control point is just .5*v to the right
255 \dimen4=
0.5\lypdf@bracket_v
\advance\dimen4 by
1pt
256 % ... first point is calc'd using alpha
257 \dimen5=-
0.15\lypdf@bracket_v
\relax
258 \dimen6=
\dimen0\advance\dimen6 by
\lypdf@bracket_cos
\dimen5\relax
259 \dimen7=
\dimen1\advance\dimen7 by
\lypdf@bracket_sin
\dimen5\relax
260 % draw the curve, close, stroke, fill
261 \edef\lypdf@halfbrack
262 {\lypdf@halfbrack
\space\LYDIM6 \LYDIM7 \LYDIM4 \LYDIM2 0 \LYDIM2 c b
}
265 \def\lypdf@draw_bracket
{% height
266 \dimen2=
\gLYPDFa1 pt
\divide\dimen2 by
2
267 \advance\dimen2 by
\lypdf@bracket_b
\relax
268 % calculate the half bracket
269 \lypdf@draw_half_bracket
270 % set up graphics state, gsave, and flip the coord system
271 % then draw both half brackets.
272 \LYPDF{\lypdf@strippt
\lypdf@bracket_t
\space w
273 1 J
1 j q
1 0 0 -
1 0 0 cm
274 \lypdf@halfbrack
\space Q
\lypdf@halfbrack
}
278 %% Clean up after ourselves.