lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Character encoding / poor man's letterspacing


From: David Kastrup
Subject: Re: Character encoding / poor man's letterspacing
Date: Mon, 11 Mar 2019 19:30:35 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Urs Liska <address@hidden> writes:

> Hi,
>
> I've written a poor-man's implementation of a simple \letterspaced
> markup command:
>
> #(define-markup-command
>   (letterspaced layout props text)(markup?)
>   (let*
>    ((chars (string->list text))
>     (dummy (ly:message "Chars: ~a" chars))
>     (spaced-text
>      (string-join
>       (map string chars) " ")))
>    (interpret-markup layout props
>      (markup spaced-text))))
>
> However, this scrambles umlauts and presumably other UTF-8 characters
> as you can see with
>
> {
>   s1 ^\markup \letterspaced "Täst"
> }
>
> =>Chars: (T � � s t)
>
> Obviously the characters are wrongly en/decoded along the way, which
> makes me think whether I have simply forgotten an encoding setting
> somewhere (although I have no idea where and how I should include
> that) or whether that whole routine is totally clumsy.
>
> Any pointer would be appreciated.

Guile-1.8 has only byte strings, not Unicode character strings.
However, the regexp procedures are locale aware, so you can use
something like

#(use-modules (ice-9 regex))

#(define-markup-command
  (letterspaced layout props text)(string?)
  (let*
   ((chars (map match:substring (list-matches "." text)))
    (spaced-text (string-join chars " ")))
   (interpret-markup layout props
     (markup spaced-text))))

{
  s1 ^\markup \letterspaced "Täst"
}


-- 
David Kastrup

reply via email to

[Prev in Thread] Current Thread [Next in Thread]