From 27b5b5a23e97816a7e08796bd3d35bdc958bb563 Mon Sep 17 00:00:00 2001 From: Reinhold Kainhofer Date: Sun, 23 Sep 2007 10:39:49 +0200 Subject: [PATCH] MusicXML: Correctly convert instrument names with line breaks Convert line breaks in instrument names to \markup \columns {\line {..} \line {..}} Also add regression test file. Signed-off-by: Reinhold Kainhofer --- python/musicexp.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/python/musicexp.py b/python/musicexp.py index 9c6e2341f3..504cdf139a 100644 --- a/python/musicexp.py +++ b/python/musicexp.py @@ -6,8 +6,17 @@ import re from rational import Rational -def escape_output_string (input_string): - return "\"" + string.replace (input_string, "\"", "\\\"") + "\"" +def escape_instrument_string (input_string): + retstring = string.replace (input_string, "\"", "\\\"") + if re.match ('.*\n.*', retstring): + strings = retstring.split ('\r\n') + retstring = "\\markup { \\column { " + for s in strings: + retstring += "\\line {\"" + s + "\"} " + retstring += "} }" + else: + retstring = "\"" + retstring + "\"" + return retstring class Output_stack_element: def __init__ (self): @@ -949,11 +958,11 @@ class StaffGroup: printer.newline () if self.stafftype and self.instrument_name: printer.dump ("\\set %s.instrumentName = %s" % (self.stafftype, - escape_output_string (self.instrument_name))) + escape_instrument_string (self.instrument_name))) printer.newline () if self.stafftype and self.short_instrument_name: printer.dump ("\\set %s.shortInstrumentName = %s\n" % (self.stafftype, - escape_output_string (self.short_instrument_name))) + escape_instrument_string (self.short_instrument_name))) printer.newline () self.print_ly_contents (printer) printer.newline () -- 2.39.5