X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=python%2Fbook_snippets.py;h=cbf09a7a28f59bcf47cb8103883c2d511bedc510;hb=ff4a77f00d352158e487637b0a537281fd63db1a;hp=5d6600691312bcb72e9d1fc5da328679a81e7352;hpb=bff1751d9aaf9fc2f39b878aa86807d3537c7e5a;p=lilypond.git diff --git a/python/book_snippets.py b/python/book_snippets.py index 5d66006913..cbf09a7a28 100644 --- a/python/book_snippets.py +++ b/python/book_snippets.py @@ -38,14 +38,11 @@ EXAMPLEINDENT = 'exampleindent' FILENAME = 'filename' FILTER = 'filter' FRAGMENT = 'fragment' -LANG = 'lang' ## TODO: This is handled nowhere! LAYOUT = 'layout' -LILYQUOTE = 'lilyquote' LINE_WIDTH = 'line-width' NOFRAGMENT = 'nofragment' NOGETTEXT = 'nogettext' NOINDENT = 'noindent' -NOQUOTE = 'noquote' INDENT = 'indent' NORAGGED_RIGHT = 'noragged-right' NOTES = 'body' @@ -68,7 +65,6 @@ VERSION = 'lilypondversion' # NOTIME and NOGETTEXT have no opposite so they aren't part of this # dictionary. -# NOQUOTE is used internally only. no_options = { NOFRAGMENT: FRAGMENT, NOINDENT: INDENT, @@ -92,7 +88,6 @@ simple_options = [ PRINTFILENAME, DOCTITLE, TEXIDOC, - LANG, VERBATIM, FILENAME, ALT, @@ -117,7 +112,6 @@ snippet_options = { INDENT: r'''indent = %(indent)s''', LINE_WIDTH: r'''line-width = %(line-width)s''', QUOTE: r'''line-width = %(line-width)s - 2.0 * %(exampleindent)s''', - LILYQUOTE: r'''line-width = %(line-width)s - 2.0 * %(exampleindent)s''', RAGGED_RIGHT: r'''ragged-right = ##t''', NORAGGED_RIGHT: r'''ragged-right = ##f''', }, @@ -145,24 +139,9 @@ snippet_options = { -FRAGMENT_LY = r''' -%(notes_string)s -{ - - -%% **************************************************************** -%% ly snippet contents follows: -%% **************************************************************** -%(code)s - - -%% **************************************************************** -%% end ly snippet -%% **************************************************************** -} -''' - def classic_lilypond_book_compatibility (key, value): + if key == 'lilyquote': + return (QUOTE, value) if key == 'singleline' and value == None: return (RAGGED_RIGHT, None) @@ -183,6 +162,8 @@ def classic_lilypond_book_compatibility (key, value): return (None, None) +# TODO: Remove the 1mm additional padding in the line-width, once lilypond +# creates tighter cropped images! PREAMBLE_LY = '''%%%% Generated by %(program_name)s %%%% Options: [%(option_string)s] \\include "lilypond-book-preamble.ly" @@ -196,8 +177,9 @@ PREAMBLE_LY = '''%%%% Generated by %(program_name)s \paper { %(paper_string)s - force-assignment = #"" - line-width = #(- line-width (* mm %(padding_mm)f)) + %% offset the left padding, also add 1mm as lilypond creates cropped + %% images with a little space on the right + line-width = #(- line-width (* mm %(padding_mm)f) (* mm 1)) } \layout { @@ -222,10 +204,23 @@ FULL_LY = ''' %% **************************************************************** ''' +FRAGMENT_LY = r''' +%(notes_string)s +{ +%% **************************************************************** +%% ly snippet contents follows: +%% **************************************************************** +%(code)s +%% **************************************************************** +%% end ly snippet +%% **************************************************************** +} +''' + @@ -400,13 +395,13 @@ class LilypondSnippet (Snippet): self.option_dict[option] = None - # If LINE_WIDTH is used without parameter, set it to default. + # Store if we have an explicit line-width given has_line_width = self.option_dict.has_key (LINE_WIDTH) if has_line_width and self.option_dict[LINE_WIDTH] == None: has_line_width = False del self.option_dict[LINE_WIDTH] - # TODO: Can't we do that more efficiently (built-in python func?) + # Use default options (i.e. auto-detected line-width, etc) for k in self.formatter.default_snippet_options: if k not in self.option_dict: self.option_dict[k] = self.formatter.default_snippet_options[k] @@ -417,22 +412,6 @@ class LilypondSnippet (Snippet): if has_relative and not self.option_dict.has_key (FRAGMENT): self.option_dict[FRAGMENT] = None - if not has_line_width: - if type == 'lilypond' or FRAGMENT in self.option_dict: - self.option_dict[RAGGED_RIGHT] = None - - if type == 'lilypond': - if LINE_WIDTH in self.option_dict: - del self.option_dict[LINE_WIDTH] - else: - if RAGGED_RIGHT in self.option_dict: - if LINE_WIDTH in self.option_dict: - del self.option_dict[LINE_WIDTH] - - if QUOTE in self.option_dict or type == 'lilypond': - if LINE_WIDTH in self.option_dict: - del self.option_dict[LINE_WIDTH] - if not INDENT in self.option_dict: self.option_dict[INDENT] = '0\\mm' @@ -443,8 +422,7 @@ class LilypondSnippet (Snippet): # all settings before writing them in the \paper block. if not LINE_WIDTH in self.option_dict: if not QUOTE in self.option_dict: - if not LILYQUOTE in self.option_dict: - self.option_dict[LINE_WIDTH] = "#(- paper-width \ + self.option_dict[LINE_WIDTH] = "#(- paper-width \ left-margin-default right-margin-default)" def get_option_list (self): @@ -460,10 +438,6 @@ left-margin-default right-margin-default)" return self.option_list def compose_ly (self, code): - if FRAGMENT in self.option_dict: - body = FRAGMENT_LY - else: - body = FULL_LY # Defaults. relative = 1 @@ -574,6 +548,10 @@ left-margin-default right-margin-default)" d = globals().copy() d.update (locals()) d.update (self.global_options.information) + if FRAGMENT in self.option_dict: + body = FRAGMENT_LY + else: + body = FULL_LY return (PREAMBLE_LY + body) % d def get_checksum (self): @@ -868,19 +846,19 @@ class MusicXMLFileSnippet (LilypondFileSnippet): def convert_from_musicxml (self): name = self.filename - option_list = [] + xml2ly_option_list = [] for (key, value) in self.option_dict.items (): cmd_key = self.musicxml_options_dict.get (key, None) if cmd_key == None: continue if value == None: - option_list.append (cmd_key) + xml2ly_option_list.append (cmd_key) else: - option_list.append (cmd_key + '=' + value) - if ('.mxl' in name) and ('--compressed' not in option_list): - option_list.append ('--compressed') + xml2ly_option_list.append (cmd_key + '=' + value) + if ('.mxl' in name) and ('--compressed' not in xml2ly_option_list): + xml2ly_option_list.append ('--compressed') self.compressed = True - opts = " ".join (option_list) + opts = " ".join (xml2ly_option_list) progress (_ ("Converting MusicXML file `%s'...\n") % self.filename) ly_code = self.filter_pipe (self.contents, 'musicxml2ly %s --out=- - ' % opts)