David, Thank you very much. I try to do two punctuation to the left, but I cannot make it work. Any help is appreciated. Please refer to "a" and "c" from the .png
Thank again, Ming. >________________________________ > From: David Nalesnik <[email protected]> >To: Jun Wang <[email protected]> >Cc: MING TSANG <[email protected]>; "[email protected]" ><[email protected]> >Sent: Friday, May 3, 2013 9:00:52 PM >Subject: Re: Lyrics and Punctuations Alignment Issue? > > > >Hi Ming and Jun, > > >This should work for the special period character. If there are any other >punctuation marks you need at the ends of words, add them as strings to the >variable called "punct-right." Note: punctuation which goes to the left is >handled differently. If you need additional characters, add them to the >variable "punct-L" as characters--i.e. preceded by #\ > > >If you need any multi-byte characters for punctuation which goes to the left, >the function will need to be adapted. Easy enough to do--just let me know. > > >HTH, >David > > >%%%%%%%%%%%%%%%%%%%%%%%%% >\version "2.16" > > >#(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 (align grob) > (let* ((stil (ly:grob-property grob 'stencil)) > (stil-X (ly:stencil-extent stil X)) > (text (ly:grob-property grob 'text)) > (punct-L (char-set #\" #\`)) > ; 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 (string-trim text punct-L)) > (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 >} > > >\relative c' { > \time 3/4 e4 e4. e8 > d4 e d c2. >} > > >\addlyrics { > \override LyricText #'X-offset = #align > "\"I" am so lone -- "ly,\"" said she >} >\addlyrics { > \override LyricText #'X-offset = #align > 樂無 極! 寶 名, 貝 名。 啊? >} >\addlyrics { > \override LyricText #'X-offset = #align > a b c d e f g >} > >
\version "2.16"
#(define (drop-punctuation-right str)
(let ((punct-right '("ï¼" "ï¼" "ï¼" "ï¼" "ï¼½" "ï¼" "ï¼" "ã"))) % I updated this line
(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) %line 19 I added line 19 - 32 and change all -right to -left
(let ((punct-left '("ï¼»" "ï¼" ))) % I modify
(let loop ((elt punct-left))
(if (null? elt)
#f
(if (string-suffix? (car elt) str)
(string-drop-left 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))) %line 32
#(define (align grob)
(let* ((stil (ly:grob-property grob 'stencil))
(stil-X (ly:stencil-extent stil X))
(text (ly:grob-property grob 'text))
(punct-L (char-set #\" #\`))
; 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 (string-trim text punct-L))
(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
}
\relative c' {
\time 3/4 e4 e4. e8
d4 e d c2.
}
\addlyrics {
\override LyricText #'X-offset = #align
"\"I" am so lone -- "ly,\"" said she
}
\addlyrics {
\override LyricText #'X-offset = #align
ï¼»æ¨ æ¥µï¼½ ï¼å¯¶ åï¼ è²ï¼ åã å?
}
\addlyrics {
\override LyricText #'X-offset = #align
a b c d e f g
}<<attachment: 2013-05-03_215757.png>>
_______________________________________________ lilypond-user mailing list [email protected] https://lists.gnu.org/mailman/listinfo/lilypond-user
