]> git.donarmstrong.com Git - lilypond.git/blob - scm/sodipodi.scm
* scm/lily.scm: Register sodipodi output module.
[lilypond.git] / scm / sodipodi.scm
1 ;;;; sodipodi.scm -- implement Scheme output routines for PostScript
2 ;;;;
3 ;;;;  source file of the GNU LilyPond music typesetter
4 ;;;; 
5 ;;;; (c) 1998--2002 Jan Nieuwenhuizen <janneke@gnu.org>
6
7 ;;;; NOTE that Sodipodi
8 ;;;;
9 ;;;;  * dumps core on displaying feta characters
10 ;;;;  * needs PFBs (ie, not PFAs like sketch)
11 ;;;;  * must have (LilyPond/feta) fonts registered through GNOME's
12 ;;;;    gnome-font-install (ie, not through X11, like sketch and xfontsel),
13 ;;;;    which in turn is very picky about afm files
14 ;;;;  * has it's own svg-like language: possibly this file should be
15 ;;;;    moved to svg.scm
16
17
18 (debug-enable 'backtrace)
19
20
21 (define-module (scm sodipodi))
22 (define this-module (current-module))
23
24 (use-modules
25  (guile)
26  (lily))
27
28
29
30
31 ;;; Lily output interface --- cleanup and docme
32
33 ;;; Bare minimum interface for \score { \notes c } }
34 ;;; should implement:
35 ;;;
36 ;;;    xx-output-expression
37 ;;;    char
38 ;;;    filledbox
39 ;;;    placebox
40
41 ;;; and should intercept: 
42 ;;;
43 ;;;    fontify
44 ;;;    lily-def
45 ;;;    header-end
46 ;;;    define-fonts
47 ;;;    no-origin
48 ;;;    start-system
49 ;;;    end-output
50 ;;;    header
51 ;;;    comment
52 ;;;    stop-last-system
53
54
55
56 ;; Module entry
57 ;;(define-public (sodipodi-output-expression expr port)
58 ;;  (display (eval expr this-module) port))
59
60 (define-public (sodipodi-output-expression expr port)
61   (display (dispatch expr) port))
62
63
64 (define (dispatch expr)
65   (let ((keyword (car expr)))
66     (cond
67      ((eq? keyword 'some-func) "")
68      ;;((eq? keyword 'placebox) (dispatch (cadddr expr)))
69      ;;((eq? keyword 'fontify) (dispatch (caddr expr)))
70      (else
71       (if (module-defined? this-module keyword)
72           (apply (eval keyword this-module) (cdr expr))
73           (begin
74             (display
75              (string-append "undefined: " (symbol->string keyword) "\n"))
76             ""))))))
77   
78
79 ;; Global vars
80
81 ;; alist containing fontname -> fontcommand assoc (both strings)
82 ;;(define font-name-alist '())
83
84 ;; Helper functions
85 (define (tagify tag string . attribute-alist)
86   (string-append
87    "<" tag
88    (apply string-append (map (lambda (x) (string-append
89                                           " "
90                                           (symbol->string (car x))
91                                           "='"
92                                           (cdr x)
93                                           "'"))
94                              attribute-alist))
95    ">\n"
96    string "\n</" tag ">\n"))
97
98
99 ;; Interface functions
100
101 (define (char i)
102   (tagify "tspan" (make-string 1 (integer->char i))))
103
104 (define (end-output)
105   "</svg>")
106
107
108 (define (filledbox breapth width depth height)
109   (tagify "rect" ""
110
111           '(style . "fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-opacity:1;stroke-width:1pt;stroke-linejoin:miter;stroke-linecap:butt;")
112 ;;        `(x . "50.0")
113 ;;        `(y . "400.0")
114           `(x . ,(number->string (* 5.5 breapth)))
115           `(y . ,(number->string (* 5.5 (- 0 depth))))
116           `(width . ,(number->string (* 5.5 (+ breapth width))))
117           `(height . ,(number->string (* 5.5 (+ depth height))))))
118
119
120 (define (fontify name-mag-pair expr)
121 ;;  (dispatch expr))
122 ;;  (tagify "text" (dispatch expr) '(style . "font-family:LilyPond;font-style:feta20;font-size:200;")))
123 ;;  (tagify "text" (dispatch expr) '(style . "fill:black;stroke:none;font-family:feta20;font-style:normal;font-weight:normal;font-size:200;fill-opacity:1;stroke-opacity:1;stroke-width:1pt;stroke-linejoin:miter;stroke-linecap:butt;text-anchor:start;writing-mode:lr;"))
124   (tagify "text" (dispatch expr) '(style . "fill:black;stroke:none;font-family:futa20;font-style:normal;font-weight:normal;font-size:20;fill-opacity:1;stroke-opacity:1;stroke-width:1pt;stroke-linejoin:miter;stroke-linecap:butt;text-anchor:start;writing-mode:lr;"))
125
126   )
127
128
129 (define (header creator generate)
130 "<?xml version='1.0' standalone='no'?>
131 <!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 20010904//EN'
132 'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'
133 [
134  <!ATTLIST svg
135  xmlns:xlink CDATA #FIXED 'http://www.w3.org/1999/xlink'>
136 ]>
137 <!-- Created with Sodipodi ('http://www.sodipodi.com/') -->
138 <svg
139    id='svg1'
140    sodipodi:version='0.26'
141    xmlns='http://www.w3.org/2000/svg'
142    xmlns:sodipodi='http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd'
143    xmlns:xlink='http://www.w3.org/1999/xlink'
144    width='210mm'
145    height='297mm'
146    sodipodi:docbase='/tmp/'
147    sodipodi:docname='/tmp/x'>
148   <defs
149      id='defs3' />
150   <sodipodi:namedview
151      id='base' />")
152
153
154 (define (placebox x y expr)
155 ;;  (dispatch expr))
156   (tagify "g" (dispatch expr) `(transform .
157                                           ,(string-append
158                                             "translate(" (number->string
159                                                           (* 5.5 x))
160                                             ","
161                                             (number->string (- 700 (* 5.5 y)))
162                                             ")"))))
163