2 lookup.cc -- implement simple Lookup methods.
4 source file of the GNU LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
9 This doth suck. We should have PS output, and read spacing info from TFMs
17 #include "symtable.hh"
21 #include "paper-def.hh"
27 texsetting
= "\\unknowntexsetting";
28 symtables_p_
= new Symtables
;
31 Lookup::Lookup (Lookup
const &s
)
33 paper_l_
= s
.paper_l_
;
34 texsetting
= s
.texsetting
;
35 symtables_p_
= new Symtables (*s
.symtables_p_
);
43 Lookup::add (String s
, Symtable
*p
)
45 symtables_p_
->add (s
, p
);
52 DOUT
<< "Lookup: " << texsetting
<< " {\n";
53 symtables_p_
->print();
59 Lookup::text (String style
, String text
, int dir
) const
64 Atom tsym
= (*symtables_p_
)("style")->lookup (style
);
65 a
[0] = substitute_args (tsym
.tex_
,a
);
67 Atom s
= (*symtables_p_
)("align")->lookup (dir
);
68 s
.tex_
= substitute_args (s
.tex_
,a
);
76 Lookup::ball (int j
) const
81 Symtable
* st
= (*symtables_p_
)("balls");
82 return st
->lookup (String (j
));
86 Lookup::rest (int j
, bool o
) const
88 return (*symtables_p_
)("rests")->lookup (String (j
) + (o
? "o" : ""));
92 Lookup::fill (Box b
) const
94 Atom
s ((*symtables_p_
)("param")->lookup ("fill"));
100 Lookup::accidental (int j
) const
102 return (*symtables_p_
)("accidentals")->lookup (String (j
));
107 Lookup::bar (String s
, Real h
) const
110 a
.push (print_dimen (h
));
111 Atom ret
=(*symtables_p_
)("bars")->lookup (s
);
112 ret
.tex_
= substitute_args (ret
.tex_
, a
);
113 ret
.dim_
.y() = Interval (-h
/2, h
/2);
118 Lookup::script (String s
) const
120 return (*symtables_p_
)("scripts")->lookup (s
);
124 Lookup::dynamic (String s
) const
126 return (*symtables_p_
)("dynamics")->lookup (s
);
130 Lookup::clef (String s
) const
132 return (*symtables_p_
)("clefs")->lookup (s
);
136 Lookup::dots () const
138 return (*symtables_p_
)("dots")->lookup ("dot");
142 Lookup::flag (int j
, Direction d
) const
144 char c
= (d
== UP
) ? 'u' : 'd';
145 return (*symtables_p_
)("flags")->lookup (c
+ String (j
));
149 Lookup::streepje (int type
) const
154 Symtable
* st
= (*symtables_p_
)("balls");
156 return st
->lookup (String (type
) + 'l');
160 Lookup::hairpin (Real
&wid
, bool decresc
, bool continued
) const
162 bool embedded_b
= postscript_global_b
;
165 Real height
= paper_l_
->get_var ("barsize") / 6;
168 embed
= "\\embeddedps{\n" ;
169 embed
+= String (wid
) + " "
170 + String (height
) + " "
171 + String (continued
? height
/2 : 0) +
172 + " draw_" + String(decresc
? "de" : "") + "cresc}\n";
179 warning (_("Crescendo too long (") + print_dimen (wid
)
180 +_( ") shrinking (ugh)"));
183 int idx
= int (rint (wid
/ 6 PT
));
186 String idxstr
= (decresc
)? "decrescendosym" : "crescendosym";
187 ret
=(*symtables_p_
)("param")->lookup (idxstr
);
191 ret
.tex_
= substitute_args (ret
.tex_
, a
);
194 ret
.dim_
.x () = Interval (0,wid
);
195 ret
.dim_
.y () = Interval (-2*height
,2*height
);
196 // ret.translate_axis (ret.dim_[Y_AXIS][DOWN], Y_AXIS);
201 Lookup::meter (Array
<Scalar
> a
) const
203 Atom
s((*symtables_p_
)("param")->lookup ("meter"));
204 s
.tex_
= substitute_args (s
.tex_
,a
);
210 Lookup::stem (Real y1
,Real y2
) const
220 s
.dim_
.x() = Interval (0,0);
221 s
.dim_
.y() = Interval (y1
,y2
);
224 a
.push (print_dimen (y1
));
225 a
.push (print_dimen (y2
));
227 String src
= (*symtables_p_
)("param")->lookup ("stem").tex_
;
228 s
.tex_
= substitute_args (src
,a
);
233 should be handled via Tex_ code and Lookup::bar()
236 Lookup::vbrace (Real
&y
) const
238 Atom brace
= (*symtables_p_
)("param")->lookup ("brace");
239 Interval ydims
= brace
.dim_
[Y_AXIS
];
240 Real min_y
= ydims
[LEFT
];
241 Real max_y
= ydims
[RIGHT
];
246 warning (_("piano brace too small (") + print_dimen (y
)+ ")");
251 warning (_("piano brace too big (") + print_dimen (y
)+ ")");
256 int idx
= int (rint ((y
- min_y
)/step
)) + 1;
261 brace
.tex_
= substitute_args (brace
.tex_
,a
);
262 brace
.dim_
[Y_AXIS
] = Interval (-y
/2,y
/2);
269 Lookup::vbracket (Real
&y
) const
271 Atom bracket
= (*symtables_p_
)("param")->lookup ("bracket");
272 Interval ydims
= bracket
.dim_
[Y_AXIS
];
273 Real min_y
= ydims
[LEFT
];
274 Real max_y
= ydims
[RIGHT
];
279 warning (_("bracket too small (") + print_dimen (y
)+ ")");
284 warning (_("bracket too big (") + print_dimen (y
)+ ")");
289 int idx
= int (rint ((y
- min_y
)/step
)) + 1;
294 bracket
.tex_
= substitute_args (bracket
.tex_
,a
);
295 bracket
.dim_
[Y_AXIS
] = Interval (-y
/2,y
/2);