]> git.donarmstrong.com Git - lilypond.git/blob - scm/sodipodi.scm
268fc48ccb52171fe36990b81f8d27b6ad6893a9
[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 (define output-scale 1)
82
83 (define scale-to-unit
84   (cond
85    ((equal? (ly:unit) "mm") (/ 72.0  25.4))
86    ((equal? (ly:unit) "pt") (/ 72.0  72.27))
87    (else (error "unknown unit" (ly:unit)))))
88
89 ;; alist containing fontname -> fontcommand assoc (both strings)
90 ;;(define font-name-alist '())
91
92 ;; Helper functions
93
94
95 (define (tagify tag string . attribute-alist)
96   (string-append
97    "<" tag
98    (apply string-append (map (lambda (x) (string-append
99                                           " "
100                                           (symbol->string (car x))
101                                           "='"
102                                           (cdr x)
103                                           "'"))
104                              attribute-alist))
105    ">\n"
106    string "\n</" tag ">\n"))
107
108
109 ;; Interface functions
110
111 (define (char i)
112   (tagify "tspan" (make-string 1 (integer->char i))))
113
114 (define (end-output)
115   "</g></svg>")
116
117
118 (define (filledbox breapth width depth height)
119   (tagify "rect" ""
120
121           '(style . "fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-opacity:1;stroke-width:1pt;stroke-linejoin:miter;stroke-linecap:butt;")
122           `(x . ,(number->string (* output-scale (- 0 breapth))))
123           `(y . ,(number->string (* output-scale (- 0 height))))
124           `(width . ,(number->string (* output-scale (+ breapth width))))
125           `(height . ,(number->string (* output-scale (+ depth height))))))
126
127
128 (define (fontify name-mag-pair expr)
129
130   ;; for simple sodipodi with feta20.pfb:
131 ;;  (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;"))
132
133   ;; Sketch' svg input filter groks this:
134   (tagify "text" (dispatch expr) '(style . "fill:black;stroke:none;font-family:LilyPond-Feta-20;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;"))
135
136   )
137
138
139 (define (header creator generate)
140 "<?xml version='1.0' standalone='no'?>
141 <!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 20010904//EN'
142 'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'
143 [
144  <!ATTLIST svg
145  xmlns:xlink CDATA #FIXED 'http://www.w3.org/1999/xlink'>
146 ]>
147 <!-- Created with Sodipodi ('http://www.sodipodi.com/') -->
148 <svg
149    id='svg1'
150    sodipodi:version='0.26'
151    xmlns='http://www.w3.org/2000/svg'
152    xmlns:sodipodi='http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd'
153    xmlns:xlink='http://www.w3.org/1999/xlink'
154    width='210mm'
155    height='297mm'
156    sodipodi:docbase='/tmp/'
157    sodipodi:docname='/tmp/x'>
158   <defs
159      id='defs3' />
160   <sodipodi:namedview
161      id='base' />
162   <g tranform='translate(50,-250)'>
163   ")
164
165
166 (define (placebox x y expr)
167   (tagify "g" (dispatch expr) `(transform .
168                                           ,(string-append
169                                             "translate(" (number->string
170                                                           (* output-scale x))
171                                             ","
172                                             (number->string (- 0 (* output-scale y)))
173                                             ")"))))
174                                  
175 (define (lily-def key val)
176   (if (equal? key "lilypondpaperoutputscale")
177       ;; ugr
178       (set! output-scale (* scale-to-unit (string->number val))))
179   "")
180
181