lilypond-user
[Top][All Lists]
Advanced

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

Re: Output file extension


From: Paolo Prete
Subject: Re: Output file extension
Date: Mon, 23 Dec 2019 13:07:54 +0100

Hi Melt:  I just solved in this way  ( I looked at https://stackoverflow.com/questions/21816306/guile-scheme-redefine-another-modules-internal-function for understanding how a redefinition of a module's function works):
Lot of dependencies to fix as a consequence, but it works:

*****************************************************************************************************

#(use-modules
 (guile)
 (lily)
 (scm page)
 (scm paper-system)
 (scm output-svg)
 (scm clip-region)
 (srfi srfi-1)
 (srfi srfi-2)
 (srfi srfi-13)
 (ice-9 regex))

#(define (svg-begin . rest)
  (string-append
    (eo 'svg #t
        '(xmlns . "http://www.w3.org/2000/svg")
        '(xmlns:xlink . "http://www.w3.org/1999/xlink")
        '(version . "1.2")
        `(width . ,(ly:format "~2fmm" (first rest)))
        `(height . ,(ly:format "~2fmm" (second rest)))
        `(viewBox . ,(ly:format "~4f ~4f ~4f ~4f"
                                (third rest) (fourth rest)
                                (fifth rest) (sixth rest))))
    (eo 'style #t '(text . "style/css"))
     "<![CDATA[
tspan { white-space: pre; }
"))

#(define (svg-end)
  (ec 'svg))

#(define (style-defs-end)
  (string-append
   "]]>
"
   (ec 'style)))

#(define (woff-header paper dir)
  "TODO:
      * add (ly:version) to font name
      * copy woff font with version alongside svg output
"
  (set! output-dir dir)
  (define-fonts paper svg-define-font svg-define-font))

#(define (dump-page paper filename page page-number page-count)
  (let* ((outputter (ly:make-paper-outputter (open-file filename "wb") 'svg))
         (dump (lambda (str) (display str (ly:outputter-port outputter))))
         (lookup (lambda (x) (ly:output-def-lookup paper x)))
         (unit-length (lookup 'output-scale))
         (output-scale (* lily-unit->mm-factor unit-length))
         (device-width (lookup 'paper-width))
         (device-height (lookup 'paper-height))
         (page-width (* output-scale device-width))
         (page-height (* output-scale device-height)))

    (if (ly:get-option 'svg-woff)
        (module-define! (ly:outputter-module outputter) 'paper paper))
    (dump (svg-begin page-width page-height
                     0 0 device-width device-height))
    (if (ly:get-option 'svg-woff)
        (module-remove! (ly:outputter-module outputter) 'paper))
    (if (ly:get-option 'svg-woff)
        (dump (woff-header paper (dirname filename))))
    (dump (style-defs-end))
    (dump (comment (format #f "Page: ~S/~S" page-number page-count)))
    (ly:outputter-output-scheme outputter
                                `(begin (set! lily-unit-length ,unit-length)
                                        ""))
    (ly:outputter-dump-stencil outputter page)
    (dump (svg-end))
    (ly:outputter-close outputter)))

%
%
% HERE IS THE OVERRIDE
%
%
#(module-define! (resolve-module '(scm framework-svg)) 'output-framework
  (lambda (basename book scopes fields)  (let* ((paper (ly:paper-book-paper book))
         (page-stencils (map page-stencil (ly:paper-book-pages book)))
         (page-number (1- (ly:output-def-lookup paper 'first-page-number)))
         (page-count (length page-stencils))
         (filename "")
         (file-suffix (lambda (num)
                        (if (= page-count 1) "" (format #f "-~a" num)))))
    (if (ly:get-option 'clip-systems) (clip-system-SVG basename book))
    (for-each
     (lambda (page)
       (set! page-number (1+ page-number))
       (set! filename (format #f "~a~a.html"
                              basename
                              (file-suffix page-number)))
       (dump-page paper filename page page-number page-count))
     page-stencils))))

*****************************************************************************************************

Best,
Paolo



On Mon, Dec 23, 2019 at 10:30 AM Malte Meyn <address@hidden> wrote:


Am 23.12.19 um 10:19 schrieb Malte Meyn:
> might have something to do with Scheme modules

The reason for this guess: I copied and changed the definition for
output-preview-framework and it didn’t work as expected. So I looked
where this function is called and found the file lily/paper-book.cc. The
function output-preview-framework isn’t just called directly but the
name 'output-preview-framework is looked up in a module resolved from
some string probably containing "svg". I have no idea what LilyPond and
I are doing here but maybe it’s a hint for someone else searching for a
solution.


reply via email to

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