|
From: | Jun Wang |
Subject: | RE: Lyrics and Punctuations Alignment Issue? |
Date: | Sun, 5 May 2013 21:50:41 -0400 |
Since this issue is so common, I wonder if we could add this feature to the lilypond code base? I thought the requirement is following: 1. The feature should be turned on by default with list of ascii punctuations, like ",.?{}()! : 2. The list of punctuation can be override/customized with any unicode character list. 3. The feature can be turned off by override/set the punctuation list to empty. Is it feasible? If it is ok, I would like to help, but with my limited lilypond and Scheme knowledge, I wonder If I could make it. Thanks Jun Date: Sun, 5 May 2013 06:24:26 -0700 From: address@hidden Subject: Re: Lyrics and Punctuations Alignment Issue? To: address@hidden CC: address@hidden; address@hidden David & Jun: I complete the punctuation and parenthesis to the "align grob". The following is the .ly UTF-8 file with test. I also attacha png file for your reference. Thank you for your help, Ming \version "2.17"
#(define (drop-punctuation-right str)
(let ((punct-right '("." "," ";" ":" "?" "!" ")" "\"" "'" "。" "," ";" ":" "?" "!" ")" "]")))
(let loop ((elt punct-right))
(if (null? elt)
#f
(if (string-suffix? (car elt) str)
(string-drop-right str (string-length (car elt)))
(loop (cdr elt)))))))
#(define (drop-all-punctuation-right str)
(let ((core (drop-punctuation-right str)))
(if core
(drop-all-punctuation-right core)
str)))
#(define (drop-punctuation-left str)
(let ((punct-left '("(" "\"" "'" "[" "(")))
(let loop ((elt punct-left))
(if (null? elt)
#f
(if (string-prefix? (car elt) str)
(string-drop str (string-length (car elt)))
(loop (cdr elt)))))))
#(define (drop-all-punctuation-left str)
(let ((core (drop-punctuation-left str)))
(if core
(drop-all-punctuation-left core)
str)))
#(define (align grob)
(let* ((stil (ly:grob-property grob 'stencil))
(stil-X (ly:stencil-extent stil X))
(text (ly:grob-property grob 'text))
; determine X-extent of text stencil without punctuation at end
(text-L (drop-all-punctuation-right text))
(text-L-stil (grob-interpret-markup grob text-L))
(text-L-stil-X (ly:stencil-extent text-L-stil X))
(displacement (/ (- (cdr text-L-stil-X) (cdr stil-X)) 2))
; determine X-extent of text stencil without punctuation at start
(text-R (drop-all-punctuation-left text))
(text-R-stil (grob-interpret-markup grob text-R))
(text-R-stil-X (ly:stencil-extent text-R-stil X))
(displacement (+ displacement
(/ (- (cdr stil-X) (cdr text-R-stil-X)) 2))))
(- (ly:self-alignment-interface::aligned-on-x-parent grob)
displacement)))
\paper {
ragged-right = ##f
}
\markup {" The following is lyric with override LyricText ................"}
\relative c' {
\time 3/4 e4 e4. e8
d4 e d c d e
}
\addlyrics { \set stanza = "1. "
\override LyricText #'X-offset = #align
a "\"bb" ccc -- "dddd\"" eeeee f 'g h i'
}
%{
\addlyrics { \set stanza = "2. "
\override LyricText #'X-offset = #align
"\"I" am so lone -- "ly,\"" said she
}
%}
\addlyrics { \set stanza = "3. "
\override LyricText #'X-offset = #align
[�� �O] (�� 名) ��; 名。 啊: 明? 天!
}
\addlyrics { \set stanza = "4. "
\override LyricText #'X-offset = #align
"\"��" "�O\"" (�� 名) ��; 名. 啊: 明? 天!
}
\markup { " " }
\markup { " " }
\markup { " " }
\markup {"The following is normal lyric ie. no override LyricText .............."}
\relative c' {
\time 3/4 e4 e4. e8
d4 e d c d e
}
\addlyrics { \set stanza = "1. "
a bb ccc dddd eeeee f 'g h' i
}
\addlyrics { \set stanza = "5. "
[�� �O] (�� 名) ��; 名。 啊: 明? 天!
}
\addlyrics { \set stanza = "6. "
"\"��" "�O\"" (�� 名) ��; 名. 啊: 明? 天!
}
|
[Prev in Thread] | Current Thread | [Next in Thread] |