From: fred Date: Tue, 26 Mar 2002 21:27:03 +0000 (+0000) Subject: lilypond-1.0.13 X-Git-Tag: release/1.5.59~2852 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=3ecaa2ecdb990b1b7b4cdc8cbaad2888f9679c4b;p=lilypond.git lilypond-1.0.13 --- diff --git a/lily/include/lookup.hh b/lily/include/lookup.hh index 5dc56d279c..a1bedc7a24 100644 --- a/lily/include/lookup.hh +++ b/lily/include/lookup.hh @@ -3,11 +3,12 @@ source file of the GNU LilyPond music typesetter - (c) 1997--1998 Han-Wen Nienhuys + (c) 1997--1998 Han-Wen Nienhuys + Jan Nieuwenhuizen */ -#ifndef LOOKUPSYMS_HH -#define LOOKUPSYMS_HH +#ifndef LOOKUP_HH +#define LOOKUP_HH #include "atom.hh" #include "fproto.hh" @@ -15,49 +16,53 @@ #include "direction.hh" #include "curve.hh" #include "afm.hh" +#include "symtable.hh" /** handy interface to symbol table */ -struct Lookup { - Paper_def * paper_l_; - Symtables *symtables_p_; - String font_; - String font_path_; - Adobe_font_metric * afm_p_; +class Lookup +{ +public: + Lookup (); + Lookup (Lookup const&); + Lookup (Symtables const&); + virtual ~Lookup (); - - Lookup(); - Lookup (Lookup const &); - ~Lookup(); - - void add (String, Symtable*); - void print() const; - Atom afm_find (String) const; - - Atom fill (Box b) const; - Atom beam (Real,Real, Real) const; - Atom ps_beam (Real, Real, Real) const; - Atom streepje (int type) const; - Atom vbrace (Real &dy) const; - Atom vbracket (Real &dy) const; - Atom time_signature (Array) const; - Atom special_time_signature (String) const; - Atom stem (Real y1_pos, Real y2_pos) const; - Atom rule_symbol (Real height, Real width) const; Atom accidental (int) const; + void add (String, Symtable*); + virtual Atom afm_find (String s) const = 0; + Atom afm_find (String, String) const; Atom ball (int) const; - Atom flag (int, Direction) const; - Atom rest (int, bool outside) const; - Atom clef (String) const; Atom bar (String, Real height) const; + Atom beam (Real,Real, Real) const; + Atom clef (String) const; + virtual Atom dashed_slur (Array controls, Real thick, Real dash) const = 0; Atom dots () const; - Atom dashed_slur (Array controls, Real thick, Real dash) const; - Atom slur (Array controls) const; - Atom plet (Real dy, Real dx, Direction dir) const; - Atom text (String style, String text) const; - Atom script (String idx) const; - Atom hairpin (Real width, bool decresc, bool continued) const; Atom dynamic (String) const; + Atom fill (Box b) const; + Atom flag (int, Direction) const; + virtual Atom hairpin (Real width, bool decresc, bool continued) const = 0; + virtual Atom plet (Real dy, Real dx, Direction dir) const = 0; + void print () const; + virtual Atom ps_beam (Real slope, Real width, Real thick) const = 0; + Atom rest (int, bool outside) const; + Atom rule_symbol (Real height, Real width) const; + Atom script (String idx) const; + virtual Atom stem (Real y1_pos, Real y2_pos) const = 0; + Atom stem (Real y1_pos, Real y2_pos, String) const; + virtual Atom slur (Array controls) const = 0; + Atom streepje (int type) const; + Atom text (String style, String text) const; + Atom vbrace (Real &dy) const; + virtual Atom vbracket (Real &dy) const = 0; + Atom special_time_signature (String, Array) const; + Atom time_signature (Array) const; + + Paper_def * paper_l_; + Symtables *symtables_p_; + String font_; + String font_path_; + Adobe_font_metric * afm_p_; }; -#endif // LOOKUPSYMS_HH +#endif // LOOKUP_HH diff --git a/lily/lookup.cc b/lily/lookup.cc index b03cc59de9..fc6843a497 100644 --- a/lily/lookup.cc +++ b/lily/lookup.cc @@ -5,11 +5,11 @@ (c) 1997--1998 Han-Wen Nienhuys - TODO - This doth suck. We should have PS output, and read spacing info from AFMs - - Glissando, + Jan Nieuwenhuizen + TODO + Read spacing info from AFMs + Glissando */ #include "lookup.hh" @@ -22,14 +22,14 @@ #include "string-convert.hh" #include "main.hh" -Lookup::Lookup() +Lookup::Lookup () { paper_l_ = 0; symtables_p_ = new Symtables; afm_p_ =0; } -Lookup::Lookup (Lookup const &s) +Lookup::Lookup (Lookup const& s) { font_ = s.font_; font_path_ = s.font_path_; @@ -38,119 +38,101 @@ Lookup::Lookup (Lookup const &s) afm_p_ = 0; } -Lookup::~Lookup() +Lookup::Lookup (Symtables const& s) +{ + font_ = s.font_; + font_path_ = s.font_path_; + paper_l_ = 0; + symtables_p_ = new Symtables (s); + afm_p_ = 0; +} + +Lookup::~Lookup () { delete afm_p_; delete symtables_p_; } Atom -Lookup::afm_find (String s) const +Lookup::accidental (int j) const +{ + return afm_find (String ("accidentals") + String ("-") + to_str (j)); +} + +void +Lookup::add (String s, Symtable*p) +{ + symtables_p_->add (s, p); +} + +Atom +Lookup::afm_find (String s, String str) const { if (!afm_p_) { *mlog << "[" << font_path_; - ((Lookup*)this)->afm_p_ = new Adobe_font_metric (read_afm (font_path_)); + ( (Lookup*)this)->afm_p_ = new Adobe_font_metric (read_afm (font_path_)); *mlog << "]" << flush ; DOUT << this->afm_p_->str (); } Adobe_font_char_metric m = afm_p_->find_char (s); Atom a; - a.tex_ = String_convert::form_str ("\\char%d", m.code ()); + if (m.width () ==0) + return a; + a.dim_ = m.B_; a.dim_[X_AXIS] *= 1 / 1000.0; a.dim_[Y_AXIS] *= 1 / 1000.0; + a.str_ = String_convert::form_str (str.ch_C (), m.code ()); a.font_ = font_; return a; } -void -Lookup::add (String s, Symtable*p) -{ - symtables_p_->add (s, p); -} - -void -Lookup::print() const -{ -#ifndef NPRINT - DOUT << "Lookup {\n"; - symtables_p_->print(); - DOUT << "}\n"; -#endif -} - -Atom -Lookup::text (String style, String text) const -{ - Array a; - - a.push (text); - Atom tsym = (*symtables_p_)("style")->lookup (style); - tsym.tex_ = substitute_args (tsym.tex_,a); - tsym.font_ = font_; - - return tsym; -} - - - Atom Lookup::ball (int j) const { if (j > 2) j = 2; - Atom s = afm_find (String ("balls") + String ("-") + to_str (j)); - return s; -} - -Atom -Lookup::rest (int j, bool o) const -{ - Atom s =afm_find (String ("rests") - + String ("-") + to_str (j) + (o ? "o" : "")); - - return s; + return afm_find (String ("balls") + String ("-") + to_str (j)); } Atom -Lookup::fill (Box b) const +Lookup::bar (String str, Real h) const { - Atom s; - s.tex_ = ""; - s.dim_ = b; - + Array a; + a.push (print_dimen (h)); + Atom s = (*symtables_p_) ("bars")->lookup (str); + s.str_ = substitute_args (s.str_, a); + s.dim_.y () = Interval (-h/2, h/2); + s.font_ = font_; return s; } -Atom -Lookup::accidental (int j) const +Atom +Lookup::beam (Real slope, Real width, Real thick) const { - Atom s= afm_find (String ("accidentals") + String ("-") + to_str (j)); - return s; + Atom a (ps_beam (slope, width, thick)); + Real height = slope * width; + Real min_y = (0 ? height) + thick/2; + + a.dim_[X_AXIS] = Interval (0, width); + a.dim_[Y_AXIS] = Interval (min_y, max_y); + return a; } - Atom -Lookup::bar (String s, Real h) const +Lookup::clef (String st) const { - Array a; - a.push (print_dimen (h)); - Atom ret=(*symtables_p_)("bars")->lookup (s); - ret.tex_ = substitute_args (ret.tex_, a); - ret.dim_.y() = Interval (-h/2, h/2); - ret.font_ = font_; - return ret; + return afm_find (String ("clefs") + String ("-") + st); } Atom -Lookup::script (String st) const +Lookup::dots () const { - Atom s= afm_find (String ("scripts") + String ("-") + st); - - return s; + return afm_find (String ("dots") + String ("-") + String ("dot")); } Atom @@ -160,151 +142,73 @@ Lookup::dynamic (String st) const } Atom -Lookup::clef (String st) const -{ - Atom s=afm_find (String ("clefs") + String ("-") + st); - - return s; -} - -Atom -Lookup::dots () const +Lookup::fill (Box b) const { - Atom s=afm_find (String ("dots") + String ("-") + String("dot")); - - return s; + Atom a; + a.dim_ = b; + return a; } Atom Lookup::flag (int j, Direction d) const { char c = (d == UP) ? 'u' : 'd'; - Atom s=afm_find (String ("flags") + String ("-") + to_str (c) + to_str (j)); - - return s; -} - -Atom -Lookup::dashed_slur (Array controls, Real thick, Real dash) const -{ - assert (controls.size () == 8); - - String ps = "\\embeddedps{\n"; - - Real dx = controls[3].x () - controls[0].x (); - Real dy = controls[3].y () - controls[0].y (); - - for (int i = 1; i < 4; i++) - ps += String_convert::double_str (controls[i].x ()) + " " - + String_convert::double_str (controls[i].y ()) + " "; - - ps += String_convert::double_str (controls[0].x ()) + " " - + String_convert::double_str (controls[0].y ()) + " "; - - ps += String_convert::double_str (thick) + " "; - Real on = dash > 1? thick * dash - thick : 0; - Real off = 2 * thick; - ps += "[" + String_convert::double_str (on) + " "; - ps += String_convert::double_str (off) + "] "; - ps += String_convert::int_str (0) + " "; - ps += " draw_dashed_slur}"; - - Atom s; - s.tex_ = ps; - - s.dim_[X_AXIS] = Interval (0, dx); - s.dim_[Y_AXIS] = Interval (0 ? dy); - s.font_ = font_; - return s; + return afm_find (String ("flags") + String ("-") + to_str (c) + to_str (j)); } -Atom -Lookup::slur (Array controls) const +void +Lookup::print () const { - assert (controls.size () == 8); - - String ps = "\\embeddedps{\n"; - - Real dx = controls[3].x () - controls[0].x (); - Real dy = controls[3].y () - controls[0].y (); - - for (int i = 5; i < 8; i++) - ps += String_convert::double_str (controls[i].x ()) + " " - + String_convert::double_str (controls[i].y ()) + " "; - - ps += String_convert::double_str (controls[4].x ()) + " " - + String_convert::double_str (controls[4].y ()) + " "; - - for (int i = 1; i < 4; i++) - ps += String_convert::double_str (controls[i].x ()) + " " - + String_convert::double_str (controls[i].y ()) + " "; - - ps += String_convert::double_str (controls[0].x ()) + " " - + String_convert::double_str (controls[0].y ()) + " "; - - ps += " draw_slur}"; - - Atom s; - s.tex_ = ps; - - s.dim_[X_AXIS] = Interval (0, dx); - s.dim_[Y_AXIS] = Interval (0 ? dy); - s.font_ = font_; - return s; - +#ifndef NPRINT + DOUT << "Lookup {\n"; + symtables_p_->print (); + DOUT << "}\n"; +#endif } Atom -Lookup::streepje (int type) const +Lookup::rest (int j, bool o) const { - if (type > 2) - type = 2; - - return afm_find ("balls-" + to_str (type) + "l"); + return afm_find (String ("rests") + + String ("-") + to_str (j) + (o ? "o" : "")); } Atom -Lookup::hairpin (Real width, bool decresc, bool continued) const +Lookup::rule_symbol (Real height, Real width) const { - String embed; - Atom ret; - Real height = paper_l_->staffheight_f () / 6; - embed = "\\embeddedps{\n" ; - embed += to_str (width) + " " - + to_str (height) + " " - + to_str (continued ? height/2 : 0) + - + " draw_" + String(decresc ? "de" : "") + "cresc}\n"; - ret.tex_ = embed; - - - ret.dim_.x () = Interval (0, width); - ret.dim_.y () = Interval (-2*height, 2*height); - ret.font_ = font_; - return ret; + Atom bs= (*symtables_p_) ("param")->lookup ("rule"); + Array args; + args.push (print_dimen (height)); + args.push (print_dimen (width)); + bs.str_ = substitute_args (bs.str_,args); + bs.dim_.x () = Interval (0,width); + bs.dim_.y () = Interval (0,height); + return bs; } Atom -Lookup::time_signature (Array a) const +Lookup::script (String str) const { - Atom s((*symtables_p_)("param")->lookup ("time_signature")); - s.tex_ = substitute_args (s.tex_,a); - - return s; + return afm_find (String ("scripts") + String ("-") + str); } - - Atom -Lookup::special_time_signature (String s) const +Lookup::special_time_signature (String s, Array arr) const { - Atom a (afm_find ("timesig-"+ s)); - return a; + String symbolname="timesig-"+s+"%/%"; + Atom a (afm_find (substitute_args(symbolname,arr))); + if (!a.empty()) + return a; + // Try if the full name was given + a=afm_find ("timesig-"+s); + if (!a.empty()) + return a; + // Resort to default layout with numbers + return time_signature(arr); } - - Atom -Lookup::stem (Real y1,Real y2) const +Lookup::stem (Real y1, Real y2, String str) const { if (y1 > y2) { @@ -314,26 +218,55 @@ Lookup::stem (Real y1,Real y2) const } Atom s; - s.dim_.x() = Interval (0,0); - s.dim_.y() = Interval (y1,y2); + s.dim_.x () = Interval (0,0); + s.dim_.y () = Interval (y1,y2); Array a; - Real stem_width = paper_l_->get_var ("stemthickness"); a.push (print_dimen (-stem_width /2)); a.push (print_dimen (stem_width)); a.push (print_dimen (y2)); a.push (print_dimen (-y1)); - String src = "\\kern %\\vrule width % height % depth %"; - s.tex_ = substitute_args (src,a); + s.str_ = substitute_args (str, a); + s.font_ = font_; + return s; +} + +Atom +Lookup::streepje (int type) const +{ + if (type > 2) + type = 2; + + return afm_find ("balls" + String ("-") +to_str (type) + "l"); +} + +Atom +Lookup::text (String style, String text) const +{ + Array a; + + a.push (text); + Atom s = (*symtables_p_) ("style")->lookup (style); + s.str_ = substitute_args (s.str_,a); s.font_ = font_; + + return s; +} + +Atom +Lookup::time_signature (Array a) const +{ + Atom s ((*symtables_p_) ("param")->lookup ("time_signature")); + s.str_ = substitute_args (s.str_, a); + return s; } /* - should be handled via Tex_ code and Lookup::bar() + should be handled via Tex_ code and Lookup::bar () */ Atom Lookup::vbrace (Real &y) const @@ -358,12 +291,12 @@ Lookup::vbrace (Real &y) const } - int idx = int (rint ((y- min_y)/step)) + 1; + int idx = int (rint ( (y- min_y)/step)) + 1; { Array a; a.push (to_str (idx)); - brace.tex_ = substitute_args (brace.tex_,a); + brace.str_ = substitute_args (brace.str_,a); brace.dim_[Y_AXIS] = Interval (-y/2,y/2); } @@ -372,53 +305,4 @@ Lookup::vbrace (Real &y) const return brace; } -Atom -Lookup::vbracket (Real &y) const -{ - Atom psbracket; - Real min_y = paper_l_->staffheight_f (); - if (y < min_y) - { - warning (_ ("bracket") - + " " + _ ("too small") + "(" + print_dimen (y) + ")"); -// y = min_y; - } - psbracket.tex_ = String ("\\embeddedps{ ") + to_str (y) + " draw_bracket}"; - psbracket.dim_[Y_AXIS] = Interval (-y/2,y/2); - psbracket.dim_[X_AXIS] = Interval (0,4 PT); - return psbracket; -#if 0 - Atom bracket = afm_find (String ("param") + "bracket"); - Interval ydims = bracket.dim_[Y_AXIS]; - - Real min_y = ydims[LEFT]; - Real max_y = ydims[RIGHT]; - Real step = 1.0 PT; - - if (y < min_y) - { - warning (_ ("bracket") - + " " + _ ("too small") + " (" + print_dimen (y) + ")"); - y = min_y; - } - if (y > max_y) - { - warning (_ ("bracket") - + " " + _ ("too big") + " (" + print_dimen (y) + ")"); - y = max_y; - } - - - int idx = int (rint ((y- min_y)/step)) + 1; - - { - Array a; - a.push (to_str (idx)); - bracket.tex_ = substitute_args (bracket.tex_,a); - bracket.dim_[Y_AXIS] = Interval (-y/2,y/2); - } - - return bracket; -#endif -}