- f = float (m.group (1))
- return 'linewidth=%f\\%s' % (f, m.group (2))
- return None
-
-def compose_ly (code, options):
- options += default_ly_options.keys ()
- vars ().update (default_ly_options)
-
- m = re.search (r'''\\score''', code)
- if not m and (not options \
- or not 'nofragment' in options \
- or 'fragment' in options):
- if 'raggedright' not in options:
- options.append ('raggedright')
+ return ('staffsize', m.group (1))
+
+ if key == 'indent' or key == 'linewidth':
+ m = re.match ('([-.0-9]+)(cm|in|mm|pt|staffspace)', value)
+ if m:
+ f = float (m.group (1))
+ return (key, '%f\\%s' % (f, m.group (2)))
+
+ return (None, None)
+
+def compose_ly (code, options, type):
+ option_dict = {}
+
+ for i in options:
+ if string.find (i, '=') > 0:
+ (key, value) = re.split ('\s*=\s*', i)
+ option_dict[key] = value
+ else:
+ if i in no_options.keys ():
+ if no_options[i] in option_dict.keys ():
+ del option_dict[no_options[i]]
+ else:
+ option_dict[i] = None
+
+ has_linewidth = option_dict.has_key (LINEWIDTH)
+ no_linewidth_value = 0
+
+ # If LINEWIDTH is used without parameter, set it to default.
+ if has_linewidth and option_dict[LINEWIDTH] == None:
+ no_linewidth_value = 1
+ del option_dict[LINEWIDTH]
+
+ for i in default_ly_options.keys ():
+ if i not in option_dict.keys ():
+ option_dict[i] = default_ly_options[i]
+
+ if not has_linewidth:
+ if type == 'lilypond' or FRAGMENT in option_dict.keys ():
+ option_dict[RAGGEDRIGHT] = None
+
+ if type == 'lilypond':
+ if LINEWIDTH in option_dict.keys ():
+ del option_dict[LINEWIDTH]
+ else:
+ if RAGGEDRIGHT in option_dict.keys ():
+ if LINEWIDTH in option_dict.keys ():
+ del option_dict[LINEWIDTH]
+
+ if QUOTE in option_dict.keys () or type == 'lilypond':
+ if LINEWIDTH in option_dict.keys ():
+ del option_dict[LINEWIDTH]
+
+ if not INDENT in option_dict.keys ():
+ option_dict[INDENT] = '0\\mm'
+
+ # The QUOTE pattern from ly_options only emits the `linewidth'
+ # keyword.
+ if has_linewidth and QUOTE in option_dict.keys ():
+ if no_linewidth_value:
+ del option_dict[LINEWIDTH]
+ else:
+ del option_dict[QUOTE]
+
+ if FRAGMENT in option_dict.keys ():