From e99a6533b0a5cfdf1d8ec5b00ed4010459285deb Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sun, 4 Oct 1998 21:47:50 +0300 Subject: [PATCH] patch::: 1.0.12.jcn2: opniewvisite pl 12.jcn2 - Lookup abstract base class - Lookup/Symtable(s): separation of input/output --- NEWS | 9 + VERSION | 2 +- lily/abbrev.cc | 1 - lily/atom.cc | 31 +-- lily/dynamic-engraver.cc | 2 +- lily/header.cc | 30 ++- lily/identifier.cc | 5 - lily/include/atom.hh | 2 +- lily/include/header.hh | 7 +- lily/include/identifier.hh | 3 - lily/include/lily-proto.hh | 21 +- lily/include/lookup.hh | 81 +++---- lily/include/main.hh | 1 + lily/include/p-score.hh | 8 +- lily/include/paper-def.hh | 5 +- lily/include/paper-outputter.hh | 37 ++++ lily/include/paper-stream.hh | 37 ++++ lily/include/ps-lookup.hh | 32 +++ lily/include/ps-outputter.hh | 27 +++ lily/include/ps-stream.hh | 21 ++ lily/include/symtable.hh | 20 +- lily/include/tex-lookup.hh | 34 +++ lily/include/tex-outputter.hh | 35 +--- lily/include/tex-stream.hh | 33 +-- lily/lookup.cc | 361 +++++++++++--------------------- lily/main.cc | 2 + lily/p-score.cc | 88 ++++++-- lily/paper-def.cc | 20 +- lily/paper-outputter.cc | 52 +++++ lily/paper-stream.cc | 108 ++++++++++ lily/parser.yy | 20 +- lily/ps-lookup.cc | 184 ++++++++++++++++ lily/ps-outputter.cc | 81 +++++++ lily/ps-plet.cc | 32 --- lily/ps-stream.cc | 54 +++++ lily/symtable.cc | 2 + lily/tex-beam.cc | 65 ------ lily/tex-lookup.cc | 93 ++++++++ lily/tex-outputter.cc | 29 +-- lily/tex-stream.cc | 91 +------- lily/time-signature.cc | 4 +- make/STATE-VECTOR | 2 + 42 files changed, 1151 insertions(+), 621 deletions(-) create mode 100644 lily/include/paper-outputter.hh create mode 100644 lily/include/paper-stream.hh create mode 100644 lily/include/ps-lookup.hh create mode 100644 lily/include/ps-outputter.hh create mode 100644 lily/include/ps-stream.hh create mode 100644 lily/include/tex-lookup.hh create mode 100644 lily/paper-outputter.cc create mode 100644 lily/paper-stream.cc create mode 100644 lily/ps-lookup.cc create mode 100644 lily/ps-outputter.cc create mode 100644 lily/ps-stream.cc create mode 100644 lily/tex-lookup.cc diff --git a/NEWS b/NEWS index 96802004bc..0011d46a84 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,13 @@ +pl 12.jcn2 + - Lookup abstract base class + - Lookup/Symtable(s): separation of input/output +pl 12.jcn1 + - applied to 12.hwn2 patch + - redo of 11.jcn2's lookup/identifier + +pl 11.jcn2 + - preparations for braindead PostScript output pl 12.hwn1 - \remove "Engraver_type"; diff --git a/VERSION b/VERSION index abbd6eab86..6b5e3eac28 100644 --- a/VERSION +++ b/VERSION @@ -2,7 +2,7 @@ PACKAGE_NAME=LilyPond MAJOR_VERSION=1 MINOR_VERSION=0 PATCH_LEVEL=12 -MY_PATCH_LEVEL=hwn2 +MY_PATCH_LEVEL=jcn2 # use the above to send patches: MY_PATCH_LEVEL is always empty for a # released version. diff --git a/lily/abbrev.cc b/lily/abbrev.cc index 323bf8ddd8..b5cf16e378 100644 --- a/lily/abbrev.cc +++ b/lily/abbrev.cc @@ -33,7 +33,6 @@ Abbreviation::brew_molecule_p () const Real interbeam_f = paper ()->interbeam_f (stem_l_->mult_i_); Real w = 1.5 * lookup_l ()->ball (2).dim_.x ().length (); Real internote_f = paper ()->internote_f (); - Real interline_f = paper ()->interline_f (); Real beam_f = paper ()->beam_thickness_f (); int beams_i = 0; diff --git a/lily/atom.cc b/lily/atom.cc index 48b5c73720..ff2e75626a 100644 --- a/lily/atom.cc +++ b/lily/atom.cc @@ -29,12 +29,12 @@ Atom::check_infinity_b ()const if (abs (off_[ax]) >= 100 CM) { warning (_f ("ridiculous dimension: %s, %s", axis_name_str (ax), - print_dimen(off_[ax]))); + print_dimen (off_[ax]))); if (experimental_features_global_b) assert (false); - ((Atom*)this)->off_[ax] = 0.0; + ( (Atom*)this)->off_[ax] = 0.0; ridiculous = true; } } @@ -44,21 +44,21 @@ Atom::check_infinity_b ()const void -Atom::print() const +Atom::print () const { #ifndef NPRINT - DOUT << "texstring: " << tex_ << '\n'; + DOUT << "string: " << str_ << '\n'; DOUT << "dim:"; - for (Axis i=X_AXIS; i < NO_AXES; incr(i)) - DOUT << axis_name_str(i) << " = " << dim_[i].str(); + for (Axis i=X_AXIS; i < NO_AXES; incr (i)) + DOUT << axis_name_str (i) << " = " << dim_[i].str (); DOUT << "\noffset: " << off_.str (); #endif } Box -Atom::extent() const +Atom::extent () const { Box b (dim_); b.translate (off_); @@ -66,23 +66,30 @@ Atom::extent() const } -Atom::Atom() +Atom::Atom () : dim_ (Interval (0,0),Interval (0,0)) { - tex_ = "\\unknown"; + /* + urg + We should probably make Atom an abstract base class to + derive Ps_atom and Tex_atom from. + But Atom is used as a simple type *everywhere*, + and we don't have virtual contructors. + */ + str_ = ps_output_global_b ? "unknown" : "\\unknown"; } Atom::Atom (String s, Box b) : dim_ (b) { - tex_ = s; + str_ = s; } String -Atom::str() const +Atom::str () const { - return String ("Atom (\'") + tex_ + "\', (" + dim_.x().str () + ", " + return String ("Atom (\'") + str_ + "\', (" + dim_.x ().str () + ", " + dim_.y ().str () + "))"; } diff --git a/lily/dynamic-engraver.cc b/lily/dynamic-engraver.cc index 9fc4704f2c..1b7107f80d 100644 --- a/lily/dynamic-engraver.cc +++ b/lily/dynamic-engraver.cc @@ -72,7 +72,7 @@ Dynamic_engraver::do_process_requests() Text_def * td_p = new Text_def; td_p->align_dir_ = CENTER; String loud = dreq_l->access_Absolute_dynamic_req ()->loudness_str (); - td_p->text_str_ = paper ()->lookup_l (0)->dynamic (loud).tex_; + td_p->text_str_ = paper ()->lookup_l (0)->dynamic (loud).str_; td_p->style_str_ = "dynamic"; diff --git a/lily/header.cc b/lily/header.cc index 2a38c5e597..680245dc1a 100644 --- a/lily/header.cc +++ b/lily/header.cc @@ -4,6 +4,7 @@ source file of the GNU LilyPond music typesetter (c) 1997--1998 Han-Wen Nienhuys + Jan Nieuwenhuizen */ #include "string.hh" @@ -11,25 +12,36 @@ #include "header.hh" #include "main.hh" -extern char const *lily_version_number_sz(); +extern char const *lily_version_number_sz (); +Header::Header () +{ + lily_id_str_ = "Lily was here, " + + String (lily_version_number_sz ()); +} +//urg String -Header::TeX_string() const +Header::tex_string () const { String s; s+= "\\def\\LilyIdString{" + lily_id_str_ + "}"; - for (Dictionary_iter i(*this); i.ok(); i++) - { - s += "\\def\\mudela" + i.key() + "{" + i.val() + "}"; - } + for (Dictionary_iter i (*this); i.ok (); i++) + s += "\\def\\mudela" + i.key () + "{" + i.val () + "}"; return s; } -Header::Header () +String +Header::ps_string () const { - lily_id_str_ = "Lily was here, " + - String (lily_version_number_sz ()); + String s; + + s+= "/lily_id_string\n{" + lily_id_str_ + "} bind def\n"; + + for (Dictionary_iter i (*this); i.ok (); i++) + s += "/mudela" + i.key () + "{" + i.val () + "} bind def"; + return s; } + diff --git a/lily/identifier.cc b/lily/identifier.cc index c5dbee2c00..bdd40f69a4 100644 --- a/lily/identifier.cc +++ b/lily/identifier.cc @@ -14,7 +14,6 @@ #include "my-lily-lexer.hh" #include "debug.hh" #include "symtable.hh" -#include "lookup.hh" #include "script-def.hh" #include "request.hh" #include "translator.hh" @@ -85,7 +84,6 @@ Class ## _identifier::do_print () const { \ DEFAULT_PRINT(General_script_def); -DEFAULT_PRINT(Lookup); DEFAULT_PRINT(Translator); DEFAULT_PRINT(Symtables); DEFAULT_PRINT(Music); @@ -104,7 +102,6 @@ Class ## _identifier::do_str () const { \ DUMMY_STR(Notename_table); DUMMY_STR(General_script_def); -DUMMY_STR(Lookup); DUMMY_STR(Translator); DUMMY_STR(Symtables); DUMMY_STR(Music); @@ -179,7 +176,6 @@ IMPLEMENT_ID_CLASS(int); IMPLEMENT_ID_CLASS(Real); IMPLEMENT_ID_CLASS(String); IMPLEMENT_ID_CLASS(General_script_def); -IMPLEMENT_ID_CLASS(Lookup); IMPLEMENT_ID_CLASS(Symtables); IMPLEMENT_ID_CLASS(Music); IMPLEMENT_ID_CLASS(Score); @@ -196,7 +192,6 @@ DEFAULT_ACCESSOR(Duration); DEFAULT_ACCESSOR(int); DEFAULT_ACCESSOR(Real); DEFAULT_ACCESSOR(String); -DEFAULT_ACCESSOR(Lookup); DEFAULT_ACCESSOR(Symtables); DEFAULT_ACCESSOR(Score); DEFAULT_ACCESSOR(Midi_def); diff --git a/lily/include/atom.hh b/lily/include/atom.hh index d7c31ee35c..774e185d36 100644 --- a/lily/include/atom.hh +++ b/lily/include/atom.hh @@ -18,7 +18,7 @@ class Atom { Offset off_; public: - String tex_; + String str_; String font_; Box dim_; diff --git a/lily/include/header.hh b/lily/include/header.hh index a6b37dba9f..288ca7a671 100644 --- a/lily/include/header.hh +++ b/lily/include/header.hh @@ -19,9 +19,12 @@ information. */ struct Header : Dictionary { - String lily_id_str_; - String TeX_string() const; Header (); + + String tex_string () const; + String ps_string () const; + + String lily_id_str_; }; #endif // HEADER_HH diff --git a/lily/include/identifier.hh b/lily/include/identifier.hh index ab6f25edd7..63083109f7 100644 --- a/lily/include/identifier.hh +++ b/lily/include/identifier.hh @@ -22,7 +22,6 @@ class General_script_def_identifier; class Symtables_identifier; class Midi_def_identifier; class Paper_def_identifier; -class Lookup_identifier; class Real_identifier; class int_identifier; class String_identifier; @@ -61,7 +60,6 @@ struct Identifier : public Input { IDACCESSOR(Symtables) IDACCESSOR(Midi_def) IDACCESSOR(Paper_def) - IDACCESSOR(Lookup) IDACCESSOR(Real) IDACCESSOR(String) IDACCESSOR(Request) @@ -99,7 +97,6 @@ DECLARE_ID_CLASS(Notename_table); DECLARE_ID_CLASS(Real); DECLARE_ID_CLASS(String); DECLARE_ID_CLASS(General_script_def); -DECLARE_ID_CLASS(Lookup); DECLARE_ID_CLASS(Symtables); DECLARE_ID_CLASS(Music); DECLARE_ID_CLASS(int); diff --git a/lily/include/lily-proto.hh b/lily/include/lily-proto.hh index f80f11dece..25682a4cc4 100644 --- a/lily/include/lily-proto.hh +++ b/lily/include/lily-proto.hh @@ -73,6 +73,7 @@ struct Dynamic; struct Dynamic_req; struct Element_group; struct Element_group_item; +struct Engraver_group_engraver; struct General_script_def; struct Graphical_element; struct Graphical_axis_group; @@ -145,6 +146,8 @@ struct Music_list; struct Musical_req; struct Music; struct Music_sequence; +struct Music_wrapper_iterator; +struct Music_wrapper; struct My_lily_parser; struct Note_column; struct Note_column_engraver; @@ -154,28 +157,29 @@ struct Note_head; struct Note_head_engraver; struct Notename_table; struct Offset; -struct Outputter; -struct Performer; struct Paper_column; -struct Paper_score; struct Paper_def; +struct Paper_outputter; +struct Paper_score; +struct Paper_stream; struct Partial_measure_req; +struct Performer; struct Plet; struct Plet_engraver; struct Plet_req; struct Plet_spanner; struct Rational; -struct Music_wrapper_iterator; -struct Music_wrapper; -struct Relative_octave_music; -struct Engraver_group_engraver; struct Piano_brace; struct Performer; struct Performer_group_performer; struct Property_iterator; +struct Ps_lookup; +struct Ps_outputter; +struct Ps_stream; struct Request; struct Request_column; struct Engraver; +struct Relative_octave_music; struct Rest; struct Rest_collision; struct Rest_collision_engraver; @@ -223,6 +227,8 @@ struct Symtables; struct Super_element; struct Translation_property; struct Tempo_req; +struct Tex_lookup; +struct Tex_outputter; struct Tex_stream; struct Text_def; struct Text_gob; @@ -231,7 +237,6 @@ struct Text_engraver; struct Text_req; struct Text_spanner; struct Tie; -struct Tex_outputter; struct Tie_engraver; struct Tie_req; struct Time_description; diff --git a/lily/include/lookup.hh b/lily/include/lookup.hh index 5dc56d279c..3993b9e9a7 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) 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/include/main.hh b/lily/include/main.hh index da5e0a53ef..f5be0ca9ab 100644 --- a/lily/include/main.hh +++ b/lily/include/main.hh @@ -24,6 +24,7 @@ extern bool no_timestamps_global_b; extern bool find_quarts_global_b; extern int exit_status_i_; extern bool experimental_features_global_b; +extern bool ps_output_global_b; extern bool dependency_global_b; extern bool version_ignore_global_b; diff --git a/lily/include/p-score.hh b/lily/include/p-score.hh index 6cdfc5cda3..553cc89375 100644 --- a/lily/include/p-score.hh +++ b/lily/include/p-score.hh @@ -22,8 +22,10 @@ */ class Paper_score : public Music_output { - Tex_outputter *open_tex_outputter (Tex_stream*); - Tex_stream *open_output_stream (); + Paper_outputter *open_paper_outputter (Paper_stream*); + Paper_outputter *open_ps_outputter (Ps_stream*); + Paper_outputter *open_tex_outputter (Tex_stream*); + Paper_stream *open_output_stream (); public: Paper_def *paper_l_; @@ -37,7 +39,7 @@ public: /// other elements Pointer_list elem_p_list_; - Outputter *outputter_l_; + Paper_outputter *outputter_l_; Line_of_score * line_l_; Paper_score (); diff --git a/lily/include/paper-def.hh b/lily/include/paper-def.hh index 9c4a6b58fc..87bfe54573 100644 --- a/lily/include/paper-def.hh +++ b/lily/include/paper-def.hh @@ -38,6 +38,7 @@ class Paper_def : public Music_output_def { Assoc *lookup_p_assoc_p_; static int default_count_i_; + bool ps_b_; protected: VIRTUAL_COPY_CONS(Paper_def,Music_output_def); @@ -91,7 +92,9 @@ public: Real arithmetic_constant (Moment minimal_mom) const; Real arithmetic_spacing (Moment mom,Real constant) const; virtual int get_next_default_count () const; - String TeX_output_settings_str () const; + //urg + String tex_output_settings_str () const; + String ps_output_settings_str () const; // urg friend int yyparse (void*); }; diff --git a/lily/include/paper-outputter.hh b/lily/include/paper-outputter.hh new file mode 100644 index 0000000000..5fa1204b2f --- /dev/null +++ b/lily/include/paper-outputter.hh @@ -0,0 +1,37 @@ +/* + paper-outputter.hh -- declare Paper_outputter + + source file of the GNU LilyPond music typesetter + + (c) 1997--1998 Han-Wen Nienhuys +*/ + + +#ifndef PAPER_OUTPUTTER_HH +#define PAPER_OUTPUTTER_HH + +#include "lily-proto.hh" +#include "array.hh" +#include "string.hh" + +/** + Abstract interface for a Score_element to output itself. + */ +class Paper_outputter +{ +public: + Paper_outputter (Paper_stream *); + virtual ~Paper_outputter (); + + virtual void output_molecule (Molecule const *, Offset, char const *)=0; + void output_molecule (Molecule const *, Offset, char const *, String); + virtual void start_line ()=0; + virtual void stop_line ()=0; + virtual void switch_to_font (String fontname)=0; + + Array font_arr_; + String current_font_; + Paper_stream* outstream_l_; +}; + +#endif // PAPER_OUTPUTTER_HH diff --git a/lily/include/paper-stream.hh b/lily/include/paper-stream.hh new file mode 100644 index 0000000000..dc5b08541e --- /dev/null +++ b/lily/include/paper-stream.hh @@ -0,0 +1,37 @@ +#ifndef PAPER_STREAM_HH +#define PAPER_STREAM_HH + +#include +#include "string.hh" + +/** Paper output + Baseclass for writing to a PostScript or TeX file. + It counts braces to prevent nesting errors, and + it will add a comment sign before each newline. + */ + +class Paper_stream +{ +public: + bool outputting_comment; + ostream *os; + int nest_level; + /// to check linelen in output. TeX has limits. + int line_len_i_; + + /// open a file for writing + Paper_stream (String filename); + virtual void header () = 0; + + /// delegate conversion to scalar class + virtual Paper_stream &operator <<(Scalar); + + /// close the file + virtual ~Paper_stream(); + +private: + Paper_stream (Paper_stream const&); + void break_line(); +}; + +#endif // PAPER_STREAM_HH diff --git a/lily/include/ps-lookup.hh b/lily/include/ps-lookup.hh new file mode 100644 index 0000000000..3e2c5e0821 --- /dev/null +++ b/lily/include/ps-lookup.hh @@ -0,0 +1,32 @@ +/* + tex-lookup.hh -- declare Tex_lookup + + source file of the GNU LilyPond music typesetter + + (c) 1997--1998 Jan Nieuwenhuizen +*/ + +#ifndef PS_LOOKUP_HH +#define PS_LOOKUP_HH + +#include "lookup.hh" + +class Ps_lookup : public Lookup +{ +public: + Ps_lookup (); + Ps_lookup (Lookup const& s); + Ps_lookup (Symtables const& s); + virtual ~Ps_lookup (); + + virtual Atom afm_find (String s) const; + virtual Atom Ps_lookup::dashed_slur (Array controls, Real thick, Real dash) const; + virtual Atom Ps_lookup::hairpin (Real width, bool decresc, bool continued) const; + virtual Atom Ps_lookup::plet (Real dy , Real dx, Direction dir) const; + virtual Atom Ps_lookup::ps_beam (Real slope, Real width, Real thick) const; + virtual Atom Ps_lookup::slur (Array controls) const; + virtual Atom stem (Real y1, Real y2) const; + virtual Atom Ps_lookup::vbracket (Real &y) const; +}; + +#endif // PS_LOOKUP_HH diff --git a/lily/include/ps-outputter.hh b/lily/include/ps-outputter.hh new file mode 100644 index 0000000000..8cbcf183d9 --- /dev/null +++ b/lily/include/ps-outputter.hh @@ -0,0 +1,27 @@ +/* + ps-outputter.hh -- declare Ps_outputter + + source file of the GNU LilyPond music typesetter + + (c) 1997--1998 Han-Wen Nienhuys +*/ + + +#ifndef PS_OUTPUTTER_HH +#define PS_OUTPUTTER_HH + +#include "paper-outputter.hh" + +class Ps_outputter : public Paper_outputter +{ +public: + Ps_outputter (Paper_stream *); + virtual ~Ps_outputter (); + + void switch_to_font (String); + virtual void output_molecule (Molecule const*, Offset, char const*); + virtual void start_line (); + virtual void stop_line (); +}; + +#endif // PS_OUTPUTTER_HH diff --git a/lily/include/ps-stream.hh b/lily/include/ps-stream.hh new file mode 100644 index 0000000000..a61be0ad5b --- /dev/null +++ b/lily/include/ps-stream.hh @@ -0,0 +1,21 @@ +#ifndef PS_STREAM_HH +#define PS_STREAM_HH + +#include "paper-stream.hh" + +/** PS output. + Use this class for writing to a PS file. + It counts braces to prevent nesting errors, and + it will add a comment sign before each newline. + */ +class Ps_stream : public Paper_stream +{ +public: + Ps_stream (String filename); + virtual ~Ps_stream(); + + virtual void header(); + virtual Paper_stream &operator <<(Scalar); +}; + +#endif // PS_STREAM_HH diff --git a/lily/include/symtable.hh b/lily/include/symtable.hh index 12cf34b11e..2c19d3e9b0 100644 --- a/lily/include/symtable.hh +++ b/lily/include/symtable.hh @@ -22,14 +22,18 @@ struct Symtable : public Dictionary { }; -struct Symtables : private Dictionary { - - Symtable* operator()(String s); - ~Symtables(); - Symtables(); - Symtables (Symtables const&); - void add (String, Symtable*); - void print() const; +struct Symtables : private Dictionary +{ + Symtables(); + Symtables (Symtables const&); + ~Symtables(); + + Symtable* operator()(String s); + void add (String, Symtable*); + void print() const; + + String font_; + String font_path_; }; diff --git a/lily/include/tex-lookup.hh b/lily/include/tex-lookup.hh new file mode 100644 index 0000000000..fb306b927d --- /dev/null +++ b/lily/include/tex-lookup.hh @@ -0,0 +1,34 @@ +/* + tex-lookup.hh -- declare Tex_lookup + + source file of the GNU LilyPond music typesetter + + (c) 1997--1998 Han-Wen Nienhuys + Jan Nieuwenhuizen +*/ + +#ifndef TEX_LOOKUP_HH +#define TEX_LOOKUP_HH + +#include "ps-lookup.hh" + +class Tex_lookup : public Ps_lookup +{ +public: + Tex_lookup (); + Tex_lookup (Lookup const& s); + Tex_lookup (Symtables const& s); + virtual ~Tex_lookup(); + + virtual Atom afm_find (String s) const; + virtual Atom dashed_slur (Array controls, Real thick, Real dash) const; + Atom embed (Atom a) const; + virtual Atom hairpin (Real width, bool decresc, bool continued) const; + virtual Atom plet (Real dy , Real dx, Direction dir) const; + virtual Atom ps_beam (Real slope, Real width, Real thick) const; + virtual Atom slur (Array controls) const; + virtual Atom stem (Real y1, Real y2) const; + virtual Atom vbracket (Real &y) const; +}; + +#endif // TEX_LOOKUP_HH diff --git a/lily/include/tex-outputter.hh b/lily/include/tex-outputter.hh index ce9f772917..d4461c2bac 100644 --- a/lily/include/tex-outputter.hh +++ b/lily/include/tex-outputter.hh @@ -1,5 +1,5 @@ /* - outputter.hh -- declare Outputter + tex-outputter.hh -- declare Tex_outputter source file of the GNU LilyPond music typesetter @@ -7,38 +7,21 @@ */ -#ifndef OUTPUTTER_HH -#define OUTPUTTER_HH +#ifndef TEX_OUTPUTTER_HH +#define TEX_OUTPUTTER_HH -#include "lily-proto.hh" -#include "array.hh" -#include "string.hh" +#include "paper-outputter.hh" -/** - Abstract interface for a Score_element to output itself. - */ -struct Outputter +class Tex_outputter : public Paper_outputter { - virtual ~Outputter(){} - virtual void start_line ()=0; - virtual void output_molecule (Molecule const *, Offset, char const *)=0; - virtual void stop_line ()=0; -}; +public: + Tex_outputter (Paper_stream *); + virtual ~Tex_outputter (); -/** - Output a line of score using TeX strings - */ -struct Tex_outputter : Outputter -{ - Array font_arr_; - String current_font_; - - Tex_outputter (Tex_stream *); - Tex_stream * outstream_l_; void switch_to_font (String); virtual void output_molecule (Molecule const*, Offset, char const*); virtual void start_line (); virtual void stop_line (); }; -#endif // OUTPUTTER_HH +#endif // TEX_OUTPUTTER_HH diff --git a/lily/include/tex-stream.hh b/lily/include/tex-stream.hh index e26c8328cb..7f94aec2b1 100644 --- a/lily/include/tex-stream.hh +++ b/lily/include/tex-stream.hh @@ -1,34 +1,21 @@ -#ifndef TSTREAM__HH -#define TSTREAM__HH - -#include -#include "string.hh" +#ifndef TEX_STREAM_HH +#define TEX_STREAM_HH +#include "paper-stream.hh" /** TeX output. Use this class for writing to a TeX file. It counts braces to prevent nesting errors, and it will add a comment sign before each newline. */ -class Tex_stream { - void break_line(); +class Tex_stream : public Paper_stream +{ public: - bool outputting_comment; - ostream *os; - int nest_level; - /// to check linelen in output. TeX has limits. - int line_len_i_; - - /// open a file for writing Tex_stream (String filename); - void header(); - - /// delegate conversion to scalar class - Tex_stream &operator <<(Scalar); + virtual ~Tex_stream(); - /// close the file - ~Tex_stream(); -private: - Tex_stream (Tex_stream const&); + virtual void header(); + virtual Paper_stream &operator <<(Scalar); }; -#endif + +#endif // TEX_STREAM_HH diff --git a/lily/lookup.cc b/lily/lookup.cc index b03cc59de9..afb9ee10dc 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,98 @@ 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 ()); 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; + return afm_find (String ("balls") + String ("-") + to_str (j)); } Atom -Lookup::rest (int j, bool o) const +Lookup::bar (String str, Real h) const { - Atom s =afm_find (String ("rests") - + String ("-") + to_str (j) + (o ? "o" : "")); - + 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::fill (Box b) const +Atom +Lookup::beam (Real slope, Real width, Real thick) const { - Atom s; - s.tex_ = ""; - s.dim_ = b; - - 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::accidental (int j) const +Lookup::clef (String st) const { - Atom s= afm_find (String ("accidentals") + String ("-") + to_str (j)); - return s; + return afm_find (String ("clefs") + String ("-") + st); } - Atom -Lookup::bar (String s, Real h) const +Lookup::dots () 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; -} - -Atom -Lookup::script (String st) const -{ - Atom s= afm_find (String ("scripts") + String ("-") + st); - - return s; + return afm_find (String ("dots") + String ("-") + String ("dot")); } Atom @@ -160,140 +139,56 @@ 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 { @@ -301,10 +196,8 @@ Lookup::special_time_signature (String s) const return a; } - - Atom -Lookup::stem (Real y1,Real y2) const +Lookup::stem (Real y1, Real y2, String str) const { if (y1 > y2) { @@ -314,26 +207,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 +280,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 +294,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 -} diff --git a/lily/main.cc b/lily/main.cc index 5467b79e21..e07e46c750 100644 --- a/lily/main.cc +++ b/lily/main.cc @@ -30,6 +30,7 @@ bool version_ignore_global_b = false; bool no_paper_global_b = false; bool no_timestamps_global_b = false; bool find_quarts_global_b = false; +bool ps_output_global_b = false; String default_outname_base_global = "lelie"; int default_count_global; File_path global_path; @@ -234,6 +235,7 @@ main (int argc, char **argv) { case 't': experimental_features_global_b = true; + ps_output_global_b = true; break; case 'o': outname_str = oparser.optional_argument_ch_C_; diff --git a/lily/p-score.cc b/lily/p-score.cc index df037f7a7d..0ab995f15c 100644 --- a/lily/p-score.cc +++ b/lily/p-score.cc @@ -16,11 +16,15 @@ #include "plist.hh" #include "p-col.hh" #include "p-score.hh" -#include "tex-stream.hh" #include "p-col.hh" #include "header.hh" #include "word-wrap.hh" #include "gourlay-breaking.hh" +#include "paper-stream.hh" +#include "ps-stream.hh" +#include "tex-stream.hh" +#include "paper-outputter.hh" +#include "ps-outputter.hh" #include "tex-outputter.hh" #include "file-results.hh" #include "misc.hh" @@ -203,8 +207,8 @@ Paper_score::process () line_l_->space_processing (); Array breaking = calc_breaking (); - Tex_stream *tex_stream_p = open_output_stream (); - outputter_l_=open_tex_outputter (tex_stream_p); + Paper_stream *paper_stream_p = open_output_stream (); + outputter_l_ = open_paper_outputter (paper_stream_p); Link_array lines; for (int i=0; i < breaking.size (); i++) @@ -230,9 +234,14 @@ Paper_score::process () remove_line (line_l); } - *tex_stream_p << "\n\\EndLilyPondOutput"; + + if (ps_output_global_b) + *paper_stream_p << "\nshowpage\n"; + else + *paper_stream_p << "\n\\EndLilyPondOutput"; + delete outputter_l_; - delete tex_stream_p; + delete paper_stream_p; outputter_l_ = 0; } @@ -267,7 +276,7 @@ Paper_score::remove_line (Line_of_score *l) } } -Tex_stream * +Paper_stream * Paper_score::open_output_stream () { // output @@ -284,36 +293,75 @@ Paper_score::open_output_stream () } String outname = base_outname; - if (outname != "-") - outname += ".tex"; - target_str_global_array.push (outname); - *mlog << _f ("TeX output to %s...", - outname == "-" ? String ("") : outname ) << endl; + Paper_stream* p; + if (ps_output_global_b) + { + if (outname != "-") + outname += ".ps"; + *mlog << _f ("PostScript output to %s...", + outname == "-" ? String ("") : outname ) << endl; + p = new Ps_stream (outname); + } + else + { + if (outname != "-") + outname += ".tex"; + *mlog << _f ("TeX output to %s...", + outname == "-" ? String ("") : outname ) << endl; + p = new Tex_stream (outname); + } + target_str_global_array.push (outname); + return p; +} - return new Tex_stream (outname); +// urg +Paper_outputter* +Paper_score::open_paper_outputter (Paper_stream* paper_stream_p) +{ + if (ps_output_global_b) + return open_ps_outputter ((Ps_stream*)paper_stream_p); + else + return open_tex_outputter ((Tex_stream*)paper_stream_p); } +// urg urg urg +Paper_outputter* +Paper_score::open_ps_outputter (Ps_stream *ps_out_p) +{ + Ps_outputter *interfees_p = new Ps_outputter (ps_out_p); + + if (header_global_p) + *ps_out_p << header_global_p->ps_string (); + + *ps_out_p << _ ("% outputting Score, defined at: ") << origin_str_ << '\n'; + // urg + if (header_l_) + *ps_out_p << header_l_->ps_string (); + //aaarg + *ps_out_p << paper_l_->ps_output_settings_str (); -Tex_outputter * + if (experimental_features_global_b) + *ps_out_p << "turnOnExperimentalFeatures\n"; + + return interfees_p; +} + +Paper_outputter* Paper_score::open_tex_outputter (Tex_stream *tex_out_p) { Tex_outputter *interfees_p= new Tex_outputter (tex_out_p); if (header_global_p) - { - *tex_out_p << header_global_p->TeX_string (); - } + *tex_out_p << header_global_p->tex_string (); *tex_out_p << _ ("% outputting Score, defined at: ") << origin_str_ << '\n'; if (header_l_) - { - *tex_out_p << header_l_->TeX_string(); - } - *tex_out_p << paper_l_->TeX_output_settings_str (); + *tex_out_p << header_l_->tex_string(); + *tex_out_p << paper_l_->tex_output_settings_str (); if (experimental_features_global_b) diff --git a/lily/paper-def.cc b/lily/paper-def.cc index e6294c3740..2c006ad097 100644 --- a/lily/paper-def.cc +++ b/lily/paper-def.cc @@ -13,6 +13,8 @@ #include "paper-def.hh" #include "debug.hh" #include "lookup.hh" +#include "ps-lookup.hh" +#include "tex-lookup.hh" #include "dimension.hh" #include "assoc-iter.hh" #include "score-engraver.hh" @@ -45,12 +47,11 @@ Paper_def::Paper_def (Paper_def const&s) lookup_p_assoc_p_ = new Assoc; for (Assoc_iter ai(*s.lookup_p_assoc_p_); ai.ok (); ai++) { - Lookup * l=new Lookup (*ai.val ()); + Lookup * l = ps_output_global_b ? new Ps_lookup (*ai.val ()) + : new Tex_lookup (*ai.val ()); l->paper_l_ = this; set_lookup (ai.key(), l); } - - } Real @@ -212,7 +213,18 @@ Paper_def::lookup_l (int i) const IMPLEMENT_IS_TYPE_B1 (Paper_def, Music_output_def); String -Paper_def::TeX_output_settings_str () const +Paper_def::ps_output_settings_str () const +{ + String s ("\n "); + for (Assoc_iter i (*scope_p_); i.ok (); i++) + s += String ("/mudelapaper") + i.key () + + "{" + i.val ()->str () + "} bind def\n"; + s += *scope_p_->elem ("texsetting")->access_String (); + return s; +} + +String +Paper_def::tex_output_settings_str () const { String s ("\n "); for (Assoc_iter i (*scope_p_); i.ok (); i++) diff --git a/lily/paper-outputter.cc b/lily/paper-outputter.cc new file mode 100644 index 0000000000..2c47177b43 --- /dev/null +++ b/lily/paper-outputter.cc @@ -0,0 +1,52 @@ +/* + paper-outputter.cc -- implement Paper_outputter + + source file of the GNU LilyPond music typesetter + + (c) 1997--1998 Han-Wen Nienhuys + Jan Nieuwenhuizen +*/ + +#include "paper-outputter.hh" +#include "paper-stream.hh" +#include "molecule.hh" +#include "atom.hh" +#include "array.hh" +#include "dimension.hh" +// urg, silly name +#include "tex.hh" +#include "string-convert.hh" +#include "debug.hh" + +Paper_outputter::Paper_outputter (Paper_stream *s) +{ + outstream_l_ = s; +} + +Paper_outputter::~Paper_outputter () +{ +} + +void +Paper_outputter::output_molecule (Molecule const*m, Offset o, char const *nm, String s) +{ + if (check_debug) + *outstream_l_ << String ("\n%start: ") << nm << "\n"; + + for (PCursor i (m->atoms_); i.ok (); i++) + { + Offset a_off = i->offset (); + a_off += o; + + switch_to_font (i->font_); + + Array a; + String r; + + a.push (print_dimen (a_off.y())); + a.push (print_dimen (a_off.x())); + a.push (i->str_); + r += substitute_args (s, a); + *outstream_l_ << r; + } +} diff --git a/lily/paper-stream.cc b/lily/paper-stream.cc new file mode 100644 index 0000000000..c878f4b4d0 --- /dev/null +++ b/lily/paper-stream.cc @@ -0,0 +1,108 @@ +/* + paper-stream.cc -- implement Paper_stream + + source file of the GNU LilyPond music typesetter + + (c) 1997--1998 Han-Wen Nienhuys +*/ + +#include +#include + +//#include "tex.hh" +#include "main.hh" +#include "paper-stream.hh" +#include "debug.hh" + +const int MAXLINELEN = 200; + +Paper_stream::Paper_stream (String filename) +{ + if (filename.length_i () && (filename != "-")) + os = new ofstream (filename.ch_C ()); + else +// os = new ostream (cout.ostreambuf ()); + os = new ostream (cout._strbuf); + if (!*os) + error (_f ("can't open file: `%s\'", filename)); + nest_level = 0; + line_len_i_ = 0; + outputting_comment=false; + // header (); +} + +Paper_stream::~Paper_stream () +{ + *os << flush; + if (!*os) + { + warning (_ ("error syncing file (disk full?)")); + exit_status_i_ = 1; + } + delete os; + assert (nest_level == 0); +} + +// print string. don't forget indent. +Paper_stream& +Paper_stream::operator << (Scalar s) +{ + for (char const *cp = s.ch_C (); *cp; cp++) + { + if (outputting_comment) + { + *os << *cp; + if (*cp == '\n') + { + outputting_comment=false; + + } + continue; + } + line_len_i_ ++; + switch (*cp) + { + case '%': + outputting_comment = true; + *os << *cp; + break; + case '{': + nest_level++; + *os << *cp; + break; + case '}': + nest_level--; + *os << *cp; + + if (nest_level < 0) + { + delete os; // we want to see the remains. + assert (nest_level>=0); + } + /* FALLTHROUGH */ + + case '\n': + break_line (); + break; + case ' ': + *os << ' '; + if (line_len_i_ > MAXLINELEN) + break_line (); + + break; + default: + *os << *cp; + break; + } + } + return *this; +} + +void +Paper_stream::break_line () +{ + *os << "%\n"; + *os << to_str (' ', nest_level); + line_len_i_ = 0; +} + diff --git a/lily/parser.yy b/lily/parser.yy index 45a5f2ba03..99af0e5ec1 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -16,6 +16,8 @@ #include "script-def.hh" #include "symtable.hh" #include "lookup.hh" +#include "ps-lookup.hh" +#include "tex-lookup.hh" #include "misc.hh" #include "my-lily-lexer.hh" #include "paper-def.hh" @@ -95,8 +97,6 @@ Paper_def* current_paper = 0; Score *score; Header *header; Interval *interval; - Lookup*lookup; - Musical_req* musreq; Music_output_def * outputdef; Musical_pitch * pitch; @@ -112,7 +112,7 @@ Paper_def* current_paper = 0; String *string; Atom * symbol; Symtable * symtable; - Symtables * symtables; + Symtables* symtables; Text_def * textdef; Tempo_req *tempo; char c; @@ -234,7 +234,7 @@ yylex (YYSTYPE *s, void * v_l) %type entered_notemode_duration explicit_duration %type dinterval %type intastint_list int_list -%type symtables symtables_body +%type symtables symtables_body %type explicit_musical_pitch steno_musical_pitch musical_pitch absolute_musical_pitch %type steno_notepitch @@ -395,8 +395,7 @@ identifier_init: } | symtables { - $$ = new Lookup_identifier ($1, IDENTIFIER); - + $$ = new Symtables_identifier ($1, IDENTIFIER); } | post_request { $$ = new Request_identifier ($1, POST_REQUEST_IDENTIFIER); @@ -562,7 +561,9 @@ paper_def_body: $$ = p; } | paper_def_body int '=' symtables { // ugh, what a syntax - $$->set_lookup ($2, $4); + Lookup * l = ps_output_global_b ? new Ps_lookup (*$4) + : new Tex_lookup (*$4); + $$->set_lookup ($2, l); } | paper_def_body STRING '=' simple_identifier_init ';' { THIS->lexer_p_->set_identifier (*$2, $4); @@ -1367,10 +1368,10 @@ symtables: symtables_body: { - $$ = new Lookup; + $$ = new Symtables; } | IDENTIFIER { - $$ = $1->access_Lookup (true); + $$ = $1->access_Symtables (true); } | symtables_body FONT STRING { $$->font_ = *$3; @@ -1440,3 +1441,4 @@ My_lily_parser::do_yyparse () yyparse ((void*)this); } + diff --git a/lily/ps-lookup.cc b/lily/ps-lookup.cc new file mode 100644 index 0000000000..fd9d887350 --- /dev/null +++ b/lily/ps-lookup.cc @@ -0,0 +1,184 @@ +/* + ps-lookup.cc -- implement Ps_lookup + + source file of the GNU LilyPond music typesetter + + (c) 1997--1998 Jan Nieuwenhuizen +*/ + +#include "ps-lookup.hh" +#include "debug.hh" +#include "symtable.hh" +#include "dimension.hh" +#include "tex.hh" +#include "scalar.hh" +#include "paper-def.hh" +#include "string-convert.hh" +#include "main.hh" + +Ps_lookup::Ps_lookup () + : Lookup () +{ +} + +Ps_lookup::Ps_lookup (Lookup const& s) + : Lookup (s) +{ +} + +Ps_lookup::Ps_lookup (Symtables const& s) + : Lookup (s) +{ +} + +Ps_lookup::~Ps_lookup () +{ +} + +Atom +Ps_lookup::afm_find (String s) const +{ + return Lookup::afm_find (s, String ("(%d)")); +} + +Atom +Ps_lookup::dashed_slur (Array controls, Real thick, Real dash) const +{ + assert (controls.size () == 8); + + String ps; + + 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 a; + a.str_ = ps; + + a.dim_[X_AXIS] = Interval (0, dx); + a.dim_[Y_AXIS] = Interval (0 ? dy); + a.font_ = font_; + return a; +} + +Atom +Ps_lookup::hairpin (Real width, bool decresc, bool continued) const +{ + Atom a; + Real height = paper_l_->staffheight_f () / 6; + String ps; + ps += to_str (width) + " " + + to_str (height) + " " + + to_str (continued ? height/2 : 0) + + + " draw_" + String (decresc ? "de" : "") + "cresc\n"; + a.str_ = ps; + + + a.dim_.x () = Interval (0, width); + a.dim_.y () = Interval (-2*height, 2*height); + a.font_ = font_; + return a; +} + +Atom +Ps_lookup::plet (Real dy , Real dx, Direction dir) const +{ + String ps; + + ps += String_convert::double_str (dx) + " " + + String_convert::double_str (dy) + " " + + String_convert::int_str ( (int)dir) + + " draw_plet"; + + Atom s; + s.str_ = ps; + return s; +} + +Atom +Ps_lookup::ps_beam (Real slope, Real width, Real thick) const +{ + String ps; + ps += to_str (width) + " "+ to_str (slope) + " " + to_str (thick) + + " draw_beam"; + + Atom s; + s.str_ = ps; + return s; +} + +Atom +Ps_lookup::slur (Array controls) const +{ + assert (controls.size () == 8); + + String ps; + + 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.str_ = ps; + + s.dim_[X_AXIS] = Interval (0, dx); + s.dim_[Y_AXIS] = Interval (0 ? dy); + s.font_ = font_; + return s; +} + +Atom +Ps_lookup::stem (Real y1, Real y2) const +{ + // return Lookup::stem (y1, y2, "\\kern %\\vrule width % height % depth %"); + return Lookup::stem (y1, y2, "% % moveto % % lineto"); +} + +Atom +Ps_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.str_ = to_str (y) + " draw_bracket"; + psbracket.dim_[Y_AXIS] = Interval (-y/2,y/2); + psbracket.dim_[X_AXIS] = Interval (0,4 PT); + return psbracket; +} + + + diff --git a/lily/ps-outputter.cc b/lily/ps-outputter.cc new file mode 100644 index 0000000000..768270a8a2 --- /dev/null +++ b/lily/ps-outputter.cc @@ -0,0 +1,81 @@ +/* + ps-outputter.cc -- implement Ps_outputter + + source file of the GNU LilyPond music typesetter + + (c) 1997--1998 Han-Wen Nienhuys + Jan Nieuwenhuizen +*/ + +#include "ps-outputter.hh" +#include "ps-stream.hh" +#include "molecule.hh" +#include "atom.hh" +#include "array.hh" +#include "dimension.hh" +#include "tex.hh" +#include "string-convert.hh" +#include "debug.hh" + +Ps_outputter::Ps_outputter (Paper_stream *s) + :Paper_outputter (s) +{ +} + +Ps_outputter::~Ps_outputter () +{ +} + +/* + 26 fonts ought to be enough for anyone. +*/ +static String +ps_font_command(int i) +{ + return "\\font" +String_convert::form_str ("%c", 'A' + i) ; +} + +void +Ps_outputter::switch_to_font (String fontname) +{ + if (!fontname.length_i () || fontname == current_font_) + return; + + current_font_ = fontname; + int i=0; + for (; i< font_arr_.size (); i++) + if (font_arr_[i] == fontname) + { + *outstream_l_ < -*/ - -#include -#include "main.hh" -#include "misc.hh" -#include "lookup.hh" -#include "molecule.hh" -#include "dimension.hh" -#include "debug.hh" -#include "paper-def.hh" -#include "string-convert.hh" - -Atom -Lookup::plet (Real dy , Real dx, Direction dir) const -{ - String ps = "\\embeddedps{\n"; - - ps += String_convert::double_str (dx) + " " - + String_convert::double_str (dy) + " " - + String_convert::int_str ((int)dir) + - " draw_plet}"; - - Atom s; - s.tex_ = ps; - return s; -} diff --git a/lily/ps-stream.cc b/lily/ps-stream.cc new file mode 100644 index 0000000000..970b75f695 --- /dev/null +++ b/lily/ps-stream.cc @@ -0,0 +1,54 @@ +/* + tex-stream.cc -- implement Ps_stream + + source file of the GNU LilyPond music typesetter + + (c) 1997--1998 Han-Wen Nienhuys + Jan Nieuwenhuizen +*/ + +#include +#include + +#include "main.hh" +#include "ps-stream.hh" +#include "debug.hh" + +Ps_stream::Ps_stream (String filename) + : Paper_stream (filename) +{ + header (); +} + +void +Ps_stream::header () +{ + *os << _ ("%%!PS Adobe\n"); + // urg, merge with Tex + *os << _ ("% Creator: "); + if (no_timestamps_global_b) + *os << "GNU LilyPond\n"; + else + *os << get_version_str () << '\n'; + *os << _ ("% Automatically generated"); + if (no_timestamps_global_b) + *os << ".\n"; + else + { + *os << _ (", at "); + time_t t (time (0)); + *os << ctime (&t) << "%\n"; + } +} + +Ps_stream::~Ps_stream () +{ +} + +// print string. don't forget indent. +Paper_stream& +Ps_stream::operator << (Scalar s) +{ + return Paper_stream::operator << (s); +} + diff --git a/lily/symtable.cc b/lily/symtable.cc index a31477b551..d09dbb0b44 100644 --- a/lily/symtable.cc +++ b/lily/symtable.cc @@ -23,6 +23,8 @@ Symtables::Symtables() Symtables::Symtables (Symtables const &s) : Dictionary (s) { + font_ = s.font_; + font_path_ = s.font_path_; for (Assoc_iter i (s); i.ok(); i++) { add (i.key(), new Symtable (*i.val ())); diff --git a/lily/tex-beam.cc b/lily/tex-beam.cc index 002154acc4..e69de29bb2 100644 --- a/lily/tex-beam.cc +++ b/lily/tex-beam.cc @@ -1,65 +0,0 @@ -/* - tex-beam.cc -- implement Lookup::beam - - source file of the GNU LilyPond music typesetter - - (c) 1996, 1997--1998 Han-Wen Nienhuys -*/ - -/* - Code to generate beams for TeX - */ - -#include -#include "atom.hh" -#include "molecule.hh" -#include "tex.hh" -#include "symtable.hh" -#include "dimension.hh" -#include "debug.hh" -#include "lookup.hh" -#include "misc.hh" -#include "paper-def.hh" -#include "string-convert.hh" -#include "main.hh" - - -Atom -Lookup::rule_symbol (Real height, Real width) const -{ - Atom bs=(*symtables_p_)("param")->lookup ("rule"); - Array args; - args.push (print_dimen (height)); - args.push (print_dimen (width)); - bs.tex_ = substitute_args (bs.tex_,args); - bs.dim_.x() = Interval (0,width); - bs.dim_.y() = Interval (0,height); - return bs; -} - -Atom -Lookup::beam(Real slope, Real width, Real thick) const -{ - - 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::ps_beam (Real slope, Real width, Real thick) const -{ - String ps = "\\embeddedps{\n"; - ps += to_str (width) + " "+ to_str (slope) + " " + to_str (thick) - + " draw_beam}"; - - Atom s; - s.tex_ = ps; - return s; -} - diff --git a/lily/tex-lookup.cc b/lily/tex-lookup.cc new file mode 100644 index 0000000000..480ff14468 --- /dev/null +++ b/lily/tex-lookup.cc @@ -0,0 +1,93 @@ +/* + tex-lookup.cc -- implement Tex_lookup + + source file of the GNU LilyPond music typesetter + + (c) 1997--1998 Jan Nieuwenhuizen + Jan Nieuwenhuizen +*/ + +#include "tex-lookup.hh" +#include "debug.hh" +#include "symtable.hh" +#include "dimension.hh" +#include "tex.hh" +#include "scalar.hh" +#include "paper-def.hh" +#include "string-convert.hh" +#include "main.hh" + +Tex_lookup::Tex_lookup () + : Ps_lookup () +{ +} + +Tex_lookup::Tex_lookup (Lookup const& s) + : Ps_lookup (s) +{ +} + +Tex_lookup::Tex_lookup (Symtables const& s) + : Ps_lookup (s) +{ +} + +Tex_lookup::~Tex_lookup() +{ +} + +Atom +Tex_lookup::afm_find (String s) const +{ + return Lookup::afm_find (s, String ("\\char%d")); +} + +Atom +Tex_lookup::dashed_slur (Array controls, Real thick, Real dash) const +{ + return embed (Ps_lookup::dashed_slur (controls, thick, dash)); +} + +Atom +Tex_lookup::embed (Atom a) const +{ + a.str_ = "\\embeddedps{\n" + a.str_ + "}"; + return a; +} + +Atom +Tex_lookup::hairpin (Real width, bool decresc, bool continued) const +{ + return embed (Ps_lookup::hairpin (width, decresc, continued)); +} + +Atom +Tex_lookup::plet (Real dy , Real dx, Direction dir) const +{ + return embed (Ps_lookup::plet (dy, dx, dir)); +} + +Atom +Tex_lookup::ps_beam (Real slope, Real width, Real thick) const +{ + return embed (Ps_lookup::ps_beam (slope, width, thick)); +} + +Atom +Tex_lookup::slur (Array controls) const +{ + return embed (Ps_lookup::slur (controls)); +} + +Atom +Tex_lookup::stem (Real y1, Real y2) const +{ + return Lookup::stem (y1, y2, "\\kern %\\vrule width % height % depth %"); +} + +Atom +Tex_lookup::vbracket (Real &y) const +{ + return embed (Ps_lookup::vbracket (y)); +} + diff --git a/lily/tex-outputter.cc b/lily/tex-outputter.cc index 67ea1fe0ab..30aff3b9d0 100644 --- a/lily/tex-outputter.cc +++ b/lily/tex-outputter.cc @@ -4,6 +4,7 @@ source file of the GNU LilyPond music typesetter (c) 1997--1998 Han-Wen Nienhuys + Jan Nieuwenhuizen */ #include "tex-outputter.hh" @@ -16,9 +17,13 @@ #include "string-convert.hh" #include "debug.hh" -Tex_outputter::Tex_outputter (Tex_stream *s) +Tex_outputter::Tex_outputter (Paper_stream *s) + :Paper_outputter (s) +{ +} + +Tex_outputter::~Tex_outputter () { - outstream_l_ = s; } /* @@ -57,27 +62,9 @@ Tex_outputter::output_molecule (Molecule const*m, Offset o, char const *nm) if (check_debug) *outstream_l_ << String ("\n%start: ") << nm << "\n"; - for (PCursor i (m->atoms_); i.ok (); i++) - { - Offset a_off = i->offset (); - a_off += o; - - switch_to_font (i->font_); - - Array a; - String r; - - - String s ("\\placebox{%}{%}{%}"); - a.push (print_dimen (a_off.y())); - a.push (print_dimen (a_off.x())); - a.push (i->tex_); - r += substitute_args (s, a); - *outstream_l_ << r; - } + Paper_outputter::output_molecule (m, o, nm, "\\placebox{%}{%}{%}"); } - void Tex_outputter::start_line () { diff --git a/lily/tex-stream.cc b/lily/tex-stream.cc index 9866c231ad..90764d289a 100644 --- a/lily/tex-stream.cc +++ b/lily/tex-stream.cc @@ -15,30 +15,21 @@ #include "tex-stream.hh" #include "debug.hh" -const int MAXLINELEN = 200; - Tex_stream::Tex_stream (String filename) + : Paper_stream (filename) { - if (filename.length_i () && (filename != "-")) - os = new ofstream (filename.ch_C ()); - else -// os = new ostream (cout.ostreambuf ()); - os = new ostream (cout._strbuf); - if (!*os) - error (_f ("can't open file: `%s\'", filename)); - nest_level = 0; - line_len_i_ = 0; - outputting_comment=false; - header(); + header (); } + void -Tex_stream::header() +Tex_stream::header () { + // urg, merge with Ps *os << _ ("% Creator: "); if (no_timestamps_global_b) *os << "GNU LilyPond\n"; else - *os << get_version_str() << '\n'; + *os << get_version_str () << '\n'; *os << _ ("% Automatically generated"); if (no_timestamps_global_b) *os << ".\n"; @@ -50,78 +41,14 @@ Tex_stream::header() } } -Tex_stream::~Tex_stream() +Tex_stream::~Tex_stream () { - *os << flush; - if (!*os) - { - warning(_ ("error syncing file (disk full?)")); - exit_status_i_ = 1; - } - delete os; - assert (nest_level == 0); } // print string. don't forget indent. -Tex_stream& +Paper_stream& Tex_stream::operator << (Scalar s) { - for (char const *cp = s.ch_C (); *cp; cp++) - { - if (outputting_comment) - { - *os << *cp; - if (*cp == '\n') - { - outputting_comment=false; - - } - continue; - } - line_len_i_ ++; - switch (*cp) - { - case '%': - outputting_comment = true; - *os << *cp; - break; - case '{': - nest_level++; - *os << *cp; - break; - case '}': - nest_level--; - *os << *cp; - - if (nest_level < 0) - { - delete os; // we want to see the remains. - assert (nest_level>=0); - } - /* FALLTHROUGH */ - - case '\n': - break_line(); - break; - case ' ': - *os << ' '; - if (line_len_i_ > MAXLINELEN) - break_line(); - - break; - default: - *os << *cp; - break; - } - } - return *this; -} - -void -Tex_stream::break_line() -{ - *os << "%\n"; - *os << to_str (' ', nest_level); - line_len_i_ = 0; + return Paper_stream::operator << (s); } diff --git a/lily/time-signature.cc b/lily/time-signature.cc index 931766ccc8..50878c4679 100644 --- a/lily/time-signature.cc +++ b/lily/time-signature.cc @@ -19,7 +19,7 @@ Time_signature::Time_signature () } Molecule* -Time_signature::brew_molecule_p() const +Time_signature::brew_molecule_p () const { Atom s; if (time_sig_type_str_.length_i ()) @@ -28,7 +28,7 @@ Time_signature::brew_molecule_p() const } else s = lookup_l ()->time_signature (args_); - s.translate_axis (-s.extent()[Y_AXIS].center (), Y_AXIS); + s.translate_axis (-s.extent ()[Y_AXIS].center (), Y_AXIS); return new Molecule (Atom (s)); } diff --git a/make/STATE-VECTOR b/make/STATE-VECTOR index 9cf5c4b8cf..5cc82d5699 100644 --- a/make/STATE-VECTOR +++ b/make/STATE-VECTOR @@ -93,3 +93,5 @@ 1.0.12.am1 1.0.12.hwn1 1.0.12.hwn2 +1.0.12.jcn1 +1.0.12.jcn2 -- 2.39.2