Re: Output file extension

2019-12-23 Thread Paolo Prete
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"))
 "
"
   (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  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.
>
>


Re: Output file extension

2019-12-23 Thread Malte Meyn




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.




Re: Output file extension

2019-12-23 Thread Malte Meyn




Am 23.12.19 um 03:31 schrieb Paolo Prete:
is it possible, in some way (without an external script) to override the 
extension for the output file?


I need that output.svg is renamed as output.html


Yes, that’s possible. The extension .svg as well as .preview.svg, 
.cropped.svg and -[number].svg are hardcoded in the file 
scm/framework-svg.scm. You can change them directly in that file if you 
want to have this change for everything you do with LilyPond.


If you want the change only for one project, you’d have to redefine 
output-framework & Co. in your LilyPond input file. I tried that (inside 
\book and on toplevel) but without success, it seems like it’s “too 
late” for redefinition. But maybe there is a possibility to make it work 
that I don’t know of (might have something to do with Scheme modules or 
including init files after the redefinition?).




Output file extension

2019-12-22 Thread Paolo Prete
Hello,

is it possible, in some way (without an external script) to override the
extension for the output file?

I need that output.svg is renamed as output.html

Thanks