diff options
author | Han-Wen Nienhuys <hanwen@xs4all.nl> | 2005-04-12 23:38:49 +0000 |
---|---|---|
committer | Han-Wen Nienhuys <hanwen@xs4all.nl> | 2005-04-12 23:38:49 +0000 |
commit | 933ea175663dc544f1357dc087a653d8a4e4a7bd (patch) | |
tree | deb2c316af0649dc83f4ee6f879d7a6042aac02a /lily | |
parent | 57be7394ffa2e7d7ba6d60548dba563f3409d472 (diff) |
* ly/performer-init.ly: add CueVoice to MIDI too.
* ps/music-drawing-routines.ps: new routine BeginEPSF /
EndEPSF.
* input/regression/markup-eps.ly: new file.
* scm/framework-ps.scm (write-preamble): change order: vars should
be inited before procedures.
* scm/output-ps.scm (glyph-string): break lines. 255 chars is max
for EPS files.
* scm/define-markup-commands.scm (epsfile): add epsfile command.
Diffstat (limited to 'lily')
-rw-r--r-- | lily/hairpin.cc | 34 | ||||
-rw-r--r-- | lily/include/hairpin.hh | 1 | ||||
-rw-r--r-- | lily/include/source-file.hh | 2 | ||||
-rw-r--r-- | lily/source-file.cc | 62 |
4 files changed, 81 insertions, 18 deletions
diff --git a/lily/hairpin.cc b/lily/hairpin.cc index 2c7368fa57..d4f7e8a6fb 100644 --- a/lily/hairpin.cc +++ b/lily/hairpin.cc @@ -19,13 +19,39 @@ #include "lookup.hh" #include "text-item.hh" + +MAKE_SCHEME_CALLBACK(Hairpin,after_line_breaking,1); +SCM +Hairpin::after_line_breaking (SCM smob) +{ + Spanner *me = dynamic_cast<Spanner *> (unsmob_grob (smob)); + + Drul_array<bool> broken; + Drul_array<Item *> bounds; + Direction d = LEFT; + do + { + bounds[d] = me->get_bound (d); + broken[d] = bounds[d]->break_status_dir () != CENTER; + } + while (flip (&d) != LEFT); + + if (broken[LEFT] + && ly_c_equal_p (bounds[RIGHT]->get_column ()->get_property ("when"), + bounds[LEFT]->get_property ("when"))) + { + me->suicide (); + } + return SCM_UNSPECIFIED; +} + + MAKE_SCHEME_CALLBACK (Hairpin, print, 1); SCM Hairpin::print (SCM smob) { - Grob *me = unsmob_grob (smob); - Spanner *spanner = dynamic_cast<Spanner *> (me); + Spanner *me = dynamic_cast<Spanner *> (unsmob_grob (smob)); SCM s = me->get_property ("grow-direction"); if (!is_direction (s)) @@ -42,14 +68,14 @@ Hairpin::print (SCM smob) Direction d = LEFT; do { - bounds[d] = spanner->get_bound (d); + bounds[d] = me->get_bound (d); broken[d] = bounds[d]->break_status_dir () != CENTER; } while (flip (&d) != LEFT); Grob *common = bounds[LEFT]->common_refpoint (bounds[RIGHT], X_AXIS); Drul_array<Real> x_points; - + do { Item *b = bounds[d]; diff --git a/lily/include/hairpin.hh b/lily/include/hairpin.hh index 66c41193e3..31e40f7629 100644 --- a/lily/include/hairpin.hh +++ b/lily/include/hairpin.hh @@ -18,6 +18,7 @@ struct Hairpin { public: DECLARE_SCHEME_CALLBACK (print, (SCM)); + DECLARE_SCHEME_CALLBACK (after_line_breaking, (SCM)); static bool has_interface (Grob *); }; diff --git a/lily/include/source-file.hh b/lily/include/source-file.hh index faf8e5c66b..90ec4dd710 100644 --- a/lily/include/source-file.hh +++ b/lily/include/source-file.hh @@ -53,7 +53,7 @@ public: Slice line_slice (char const *pos_str0) const; String line_string (char const *pos_str0) const; int get_column (char const *pos_str0) const; - int get_char (char const *pos_str0) const; + int get_char_of_line (char const *pos_str0) const; /* JUNKME. diff --git a/lily/source-file.cc b/lily/source-file.cc index ba61d770bd..c904838124 100644 --- a/lily/source-file.cc +++ b/lily/source-file.cc @@ -11,7 +11,14 @@ #include "config.hh" +#if HAVE_UTF8_WCHAR_H +#include <utf8/wchar.h> /* wcrtomb */ +#else +#include <wchar.h> /* wcrtomb */ +#endif + #include <cstdio> + #if HAVE_SSTREAM #include <sstream> #else @@ -110,7 +117,7 @@ Source_file::init_port () int Source_file::tell () const { - return pos_str0_ - contents_str0_; + return pos_str0_ - contents_str0_; } std::istream* @@ -137,7 +144,7 @@ Source_file::file_line_column_string (char const *context_str0) const return " (" + _ ("position unknown") + ")"; else return name_string () + ":" + to_string (get_line (context_str0)) - + ":" + to_string (get_char (context_str0)); + + ":" + to_string (get_column (context_str0)); } String @@ -195,7 +202,7 @@ Source_file::line_string (char const* pos_str0) const } int -Source_file::get_char (char const *pos_str0) const +Source_file::get_char_of_line (char const *pos_str0) const { if (!contains (pos_str0)) return 0; @@ -210,17 +217,46 @@ Source_file::get_column (char const *pos_str0) const if (!contains (pos_str0)) return 0; - int ch_i = get_char (pos_str0); - String line = line_string (pos_str0); + Slice line = line_slice (pos_str0); + char const *data = to_str0 (); + Byte const *line_start = (Byte const *)data + line[LEFT]; + + int left = (Byte const*) pos_str0 - line_start; + String line_begin (line_start, left); + char const *line_chars = line_begin.to_str0(); + + int column = 0; + mbstate_t state; + + /* Initialize the state. */ + memset (&state, '\0', sizeof (state)); - int col_i = 0; - for (int i = 0; i < ch_i; i++) - if (line[i] == '\t') - col_i = (col_i / 8 + 1) * 8; - else - col_i++; + while (left > 0) + { + wchar_t multibyte[2]; + size_t thislen = mbrtowc (multibyte, line_chars, left, &state); + + /* Stop converting at invalid character; + this can mean we have read just the first part + of a valid character. */ + if (thislen == (size_t) -1) + break; + /* We want to handle embedded NUL bytes + but the return value is 0. Correct this. */ + if (thislen == 0) + thislen = 1; + + if (thislen == 1 && line_chars[0] == '\t') + column = (column / 8 + 1) * 8; + else + column ++; + + /* Advance past this character. */ + line_chars += thislen; + left -= thislen; + } - return col_i; + return column; } String @@ -229,7 +265,7 @@ Source_file::error_string (char const* pos_str0) const if (!contains (pos_str0)) return " (" + _ ("position unknown") + ")"; - int ch_i = get_char (pos_str0); + int ch_i = get_char_of_line (pos_str0); String line = line_string (pos_str0); String context = line.left_string (ch_i) + to_string ('\n') |