lilypond-user
[Top][All Lists]
Advanced

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

Re: SVG export - how might you add classes for all graphical objects?


From: Carl Sorensen
Subject: Re: SVG export - how might you add classes for all graphical objects?
Date: Tue, 29 Jun 2021 16:35:33 +0000
User-agent: Microsoft-MacOutlook/10.10.1b.201012


On 6/29/21, 2:43 AM, "lilypond-user on behalf of Matt Hood" 
<lilypond-user-bounces+carl.d.sorensen=gmail.com@gnu.org on behalf of 
matthood0@gmail.com> wrote:

    Hi everyone,
    
    I'm working with lilypond output in the browser, using its SVG export
    function. Lilypond permits attaching attributes to particular kinds of
    grobs, e.g.:
    
    {
      \override NoteHead.output-attributes =
      #'((class . "NoteHead"))
      c
    }
    
    The above will cause all NoteHead objects to have the following SVG:
    
    <g class="NoteHead">
      ...NoteHead grob SVG elements...
    </g>
    
    My question is: how can I make it so that all graphical objects have
    their name in the class attribute?
    
    I've tried using the following scheme function:
    
    #(define (add-class grob grob-origin context)
             (let (name (cdr (assoc 'name
                                    (ly:grob-property grob 'meta))))
                (set! (ly:grob-property grob 'output-attributes) '((class
    . name)))))
    
    This successfully (I believe) extracts the correct name, and assigns
    it to the output-attributes field. As per the instructions in the
    lilypond documentation, I then attempted to use \applyOutput Score
    #add-class to apply this function to all graphical objects, but it
    didn't supply all of the required objects. My attempted code is below:
    
    \applyOutput Score #add-class
    \score {
        \new RhythmicStaff {
          c'2 c'16 c' c' c' \tuplet 5/4 { c'16 c' c' c' c' }
        }
    }
    
    If I add a print call to the add-class function, I can see that it was
    called for the objects with the following names from which crucial
    objects such as NoteHead are missing:
    
    NonMusicalPaperColumn
    PaperColumn
    Clef
    TimeSignature
    LedgerLineSpanner
    StaffSymbol
    VerticalAxisGroup
    SystemStartBar
    SpacingSpanner
    VerticalAlignment
    StaffSpacing
    BreakAlignment
    LeftEdge
    BreakAlignGroup
    BreakAlignGroup
    BreakAlignGroup
    
Matt, I'm not an expert on \applyOutput, but it appears to me these are all 
grobs created by engravers that live in the Score context by default.  

You may wish to try \applyOutput to Staff and Voice as well.

Haven't tried it, and don't know if it will work, but it's an idea.

HTH,

Carl
    


reply via email to

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