1 ;;;; output-gnome.scm -- implement GNOME canvas output
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 2004 Jan Nieuwenhuizen <janneke@gnu.org>
9 ;;; * check: blot+scaling
10 ;;; * Figure out and fix font scaling and character placement
11 ;;; * EC font package: add missing X font directories and AFMs
12 ;;; * User-interface, keybindings
13 ;;; * Implement missing stencil functions
14 ;;; * Implement missing commands
15 ;;; * More information in stencils, e.g., location and grob tag.
17 ;;; - allow GnomeCanvas or `toplevel' GtkWindow to be created
18 ;;; outside of LilyPond
20 ;;; * Release schedule and packaging of dependencies.
21 ;;; - g-wrap-1.9.3 is already in incoming.
22 ;;; - guile-gnome-platform-2.8.0 will probably be packaged early 2005.
26 ;;; * Rotty's g-wrap >= 1.9.3
27 ;;; * guile-gnome-platform >= 2.7.97
30 ;;; See also: guile-gtk-general@gnu.org
34 ;;; * Install gnome/gtk and libffi development stuff
36 ;;; * Install [pango, g-wrap and] guile-gnome from source,
37 ;;; see buildscripts/guile-gnome.sh
39 ;;; * Build LilyPond with gui support: configure --enable-gui
41 ;;; * Supposing that LilyPond was built in ~/cvs/savannah/lilypond,
42 ;;; tell fontconfig about the feta fonts dir and run fc-cache
44 cat > ~/.fonts.conf << EOF
46 <dir>~/cvs/savannah/lilypond/mf/out</dir>
47 <dir>/usr/share/texmf/fonts/type1/public/ec-fonts-mftraced</dir>
52 ;;; or copy all your .pfa/.pfb's to ~/.fonts if your fontconfig
53 ;;; already looks there for fonts. Check if it works by doing:
55 fc-list | grep -i lily
58 ;;; * Setup environment
60 export GUILE_LOAD_PATH=$HOME/usr/pkg/g-wrap/share/guile/site:$HOME/usr/pkg/g-wrap/share/guile/site/g-wrap:$HOME/usr/pkg/guile-gnome/share/guile:$GUILE_LOAD_PATH
61 export LD_LIBRARY_PATH=$HOME/usr/pkg/pango/lib:$HOME/usr/pkg/g-wrap/lib:$HOME/usr/pkg/guile-gnome/lib:$LD_LIBRARY_PATH
62 export XEDITOR='/usr/bin/emacsclient --no-wait +%l:%c %f'
64 ;;; * Also for GNOME point-and-click, you need to set XEDITOR and add
66 #(ly:set-point-and-click 'line-column)
72 lilypond -fgnome input/simple-song.ly
74 ;;; point-and-click: (mouse-1) click on a graphical object;
75 ;;; grob-property-list: (mouse-3) click on a graphical object.
77 (debug-enable 'backtrace)
79 (define-module (scm output-gnome))
80 (define this-module (current-module))
90 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
93 ;;; set by framework-gnome.scm
94 (define canvas-root #f)
95 (define output-scale #f)
97 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
100 (define (stderr string . rest)
101 (apply format (cons (current-error-port) (cons string rest)))
102 (force-output (current-error-port)))
104 (define (debugf string . rest)
106 (apply stderr (cons string rest))))
110 ((< i #x80) (list (integer->char i)))
111 ((< i #x800) (map integer->char
112 (list (+ #xc0 (quotient i #x40))
113 (+ #x80 (modulo i #x40)))))
115 (let ((x (quotient i #x1000))
116 (y (modulo i #x1000)))
119 (+ #x80 (quotient y #x40))
120 (+ #x80 (modulo y #x40))))))
121 (else (begin (stderr "programming-error: utf-8 too big:~x\n" i)
122 (list (integer->char 32))))))
124 (define (integer->utf8-string integer)
125 (list->string (utf8 integer)))
127 (define (char->utf8-string char)
128 (list->string (utf8 (char->integer char))))
130 (define (string->utf8-string string)
133 (map (lambda (x) (char->utf8-string x)) (string->list string))))
135 (define (music-font? font)
136 (let ((encoding (ly:font-encoding font))
137 (family (font-family font)))
138 (or (memq encoding '(fetaMusic fetaBraces))
139 (string=? (substring family 0 (min (string-length family) 9))
143 (define-public (otf-name-mangling font family)
144 ;; Hmm, family is bigcheese20/26?
145 (if (string=? (substring family 0 (min (string-length family) 9))
147 (string-append "LilyPond " (substring family 9))
148 (if (string=? family "aybabtu")
152 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
153 ;;; Wrappers from guile-gnome TLA
154 ;;; guile-gnome-devel@gnu.org--2004
155 ;;; http://arch.gna.org/guile-gnome/archive-2004
157 ;;; janneke@gnu.org--2004-gnome
158 ;;; http://lilypond.org/~janneke/{arch}/2004-gnome
160 (if (not (defined? '<gnome-canvas-path-def>))
162 (define-class <gnome-canvas-path-def> (<gobject>)
163 (closure #:init-value (gnome-canvas-path-def-new)
164 #:init-keyword #:path-def
165 #:getter get-def #:setter set-def))
167 (define-method (moveto (this <gnome-canvas-path-def>) x y)
168 (gnome-canvas-path-def-moveto (get-def this) x y))
169 (define-method (curveto (this <gnome-canvas-path-def>) x1 y1 x2 y2 x3 y3)
170 (gnome-canvas-path-def-curveto (get-def this) x1 y1 x2 y2 x3 y3))
171 (define-method (lineto (this <gnome-canvas-path-def>) x y)
172 (gnome-canvas-path-def-lineto (get-def this) x y))
173 (define-method (closepath (this <gnome-canvas-path-def>))
174 (gnome-canvas-path-def-closepath (get-def this)))
175 (define-method (reset (this <gnome-canvas-path-def>))
176 (gnome-canvas-path-def-reset (get-def this)))
178 (define -set-path-def set-path-def)
179 (define -get-path-def get-path-def)
181 (define-method (set-path-def (this <gnome-canvas-shape>)
182 (def <gnome-canvas-path-def>))
183 (-set-path-def this (get-def def)))
185 (define-method (get-path-def (this <gnome-canvas-shape>))
186 (make <gnome-canvas-path-def> #:path-def (-get-path-def this)))))
188 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
189 ;;; stencil outputters
192 ;;; catch-all for missing stuff
193 ;;; comment this out to see find out what functions you miss :-)
194 (define (dummy . foo) #f)
195 (map (lambda (x) (module-define! this-module x dummy))
197 (ly:all-stencil-expressions)
198 (ly:all-output-backend-commands)))
200 (define (beam width slope thick blot)
201 (define cursor '(0 . 0))
202 (define (rmoveto def x y)
203 (set! cursor (cons (+ x (car cursor)) (+ y (cdr cursor))))
204 (moveto def (car cursor) (cdr cursor)))
205 (define (rlineto def x y)
206 (set! cursor (cons (+ x (car cursor)) (+ y (cdr cursor))))
207 (lineto def (car cursor) (cdr cursor)))
208 (let* ((def (make <gnome-canvas-path-def>))
209 (bezier (make <gnome-canvas-bpath>
210 #:parent (canvas-root)
212 #:outline-color "black"
214 #:join-style 'round))
220 (rmoveto def (/ blot 2) (/ t 2))
221 (rlineto def w (- h))
222 (rlineto def 0 (- t))
223 (rlineto def (- w) h)
226 (set-path-def bezier def)
229 (define (square-beam width slope thick blot)
230 (let* ((def (make <gnome-canvas-path-def>))
231 (y (* (- width) slope))
232 (props (make <gnome-canvas-bpath>
233 #:parent (canvas-root)
235 #:outline-color "black"
241 (lineto def width (- y thick))
242 (lineto def 0 (- thick))
245 (set-path-def props def)
249 (define (bezier-sandwich lst thick)
250 (let* ((def (make <gnome-canvas-path-def>))
251 (bezier (make <gnome-canvas-bpath>
252 #:parent (canvas-root)
254 #:outline-color "black"
256 #:join-style 'round)))
260 ;; FIXME: LST is pre-mangled for direct ps stack usage
264 (moveto def (car (list-ref lst 3)) (- (cdr (list-ref lst 3))))
265 (curveto def (car (list-ref lst 0)) (- (cdr (list-ref lst 0)))
266 (car (list-ref lst 1)) (- (cdr (list-ref lst 1)))
267 (car (list-ref lst 2)) (- (cdr (list-ref lst 2))))
269 (lineto def (car (list-ref lst 7)) (- (cdr (list-ref lst 7))))
270 (curveto def (car (list-ref lst 4)) (- (cdr (list-ref lst 4)))
271 (car (list-ref lst 5)) (- (cdr (list-ref lst 5)))
272 (car (list-ref lst 6)) (- (cdr (list-ref lst 6))))
273 (lineto def (car (list-ref lst 3)) (- (cdr (list-ref lst 3))))
276 (set-path-def bezier def)
279 (define (char font i)
280 (text font (ly:font-index-to-charcode font i)))
282 (define (dashed-line thick on off dx dy)
283 (draw-line thick 0 0 dx dy))
285 (define (draw-line thick x1 y1 x2 y2)
286 (let* ((def (make <gnome-canvas-path-def>))
287 (props (make <gnome-canvas-bpath>
288 #:parent (canvas-root)
290 #:outline-color "black"
291 #:width-units thick)))
293 (moveto def x1 (- y1))
294 (lineto def x2 (- y2))
295 (set-path-def props def)
299 (define (filledbox breapth width depth height)
300 (make <gnome-canvas-rect>
301 #:parent (canvas-root)
302 #:x1 (- breapth) #:y1 depth #:x2 width #:y2 (- height)
304 #:join-style 'miter))
306 (define (grob-cause grob)
309 ;; WTF is this in every backend?
310 (define (horizontal-line x1 x2 thickness)
311 (filledbox (- x1) (- x2 x1) (* .5 thickness) (* .5 thickness)))
313 (define (placebox x y expr)
316 ;; FIXME ugly hack to skip #unspecified ...
317 (if (and item (not (eq? item (if #f #f))))
319 (move item (* output-scale x) (* output-scale (- y)))
320 (affine-relative item output-scale 0 0 output-scale 0 0)
324 (define (named-glyph font name)
325 (text font (ly:font-glyph-name-to-charcode font name)))
327 (define (polygon coords blot-diameter)
328 (let* ((def (make <gnome-canvas-path-def>))
329 (props (make <gnome-canvas-bpath>
330 #:parent (canvas-root)
332 #:outline-color "black"
334 #:width-units blot-diameter)
335 (points (ly:list->offsets '() coords))
336 (last-point (car (last-pair points))))
339 (moveto def (car last-point) (cdr last-point))
340 (for-each (lambda (x) (lineto def (car x) (cdr x))) points)
342 (set-path-def props def)
345 (define (round-filled-box breapth width depth height blot-diameter)
346 (let ((r (/ blot-diameter 2)))
347 (make <gnome-canvas-rect>
348 #:parent (canvas-root)
349 #:x1 (- r breapth) #:y1 (- depth r) #:x2 (- width r) #:y2 (- r height)
351 #:outline-color "black"
352 #:width-units blot-diameter
353 #:join-style 'round)))
355 (define (text font s)
357 (define (pango-font-name font)
358 (debugf "FONT-NAME:~S:~S\n" (ly:font-name font) (ly:font-design-size font))
359 (debugf "FONT-FAMILY:~S:~S\n" (font-family font) (otf-name-mangling font (font-family font)))
360 (otf-name-mangling font (font-family font)))
362 (define (pango-font-size font)
363 (let* ((designsize (ly:font-design-size font))
364 (magnification (* (ly:font-magnification font)))
366 ;;font-name: "GNU-LilyPond-feta-20"
367 ;;font-file-name: "feta20"
368 ;;pango-font-name: "lilypond-feta, regular 32"
370 ;;scaling:29.7046771653543
371 ;;magnification:0.569055118110236
374 ;; ugh, experimental sizing
375 ;; where does factor ops come from?
376 ;; Hmm, design size: 26/20
379 (scaling (* ops magnification designsize)))
380 (debugf "OPS:~S\n" ops)
381 (debugf "scaling:~S\n" scaling)
382 (debugf "magnification:~S\n" magnification)
383 (debugf "design:~S\n" designsize)
387 (make <gnome-canvas-text>
388 #:parent (canvas-root)
389 ;; ugh, experimental placement corections
391 #:x 0.0 #:y (if (music-font? font) 0.15 0.69)
392 #:anchor (if (music-font? font) 'west 'south-west)
393 #:font (pango-font-name font)
394 #:size-points (pango-font-size font)
396 #:text (if (integer? s)
397 (integer->utf8-string s)
398 (string->utf8-string s))))