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 ;;; * Figure out and fix font scaling and character placement
10 ;;; * EC font package: add missing X font directories and AFMs
11 ;;; * User-interface, keybindings
12 ;;; * Implement missing stencil functions
13 ;;; * Implement missing commands
14 ;;; * More information in stencils, e.g., location and grob tag.
16 ;;; - allow GnomeCanvas or `toplevel' GtkWindow to be created
17 ;;; outside of LilyPond
19 ;;; * Release schedule and packaging of dependencies.
20 ;;; - g-wrap-1.9.3 is already in incoming.
21 ;;; - guile-gnome-platform-2.8.0 will probably be packaged early 2005.
25 ;;; * Rotty's g-wrap >= 1.9.3
26 ;;; * guile-gnome-platform >= 2.7.97
29 ;;; See also: guile-gtk-general@gnu.org
33 ;;; * Install gnome/gtk and libffi development stuff
35 ;;; * Install [pango, g-wrap and] guile-gnome from source,
36 ;;; see buildscripts/guile-gnome.sh
38 ;;; * Build LilyPond with gui support: configure --enable-gui
40 ;;; * Supposing that LilyPond was built in ~/cvs/savannah/lilypond,
41 ;;; tell fontconfig about the feta fonts dir and run fc-cache
43 cat > ~/.fonts.conf << EOF
45 <dir>~/cvs/savannah/lilypond/mf/out</dir>
46 <dir>/usr/share/texmf/fonts/type1/public/ec-fonts-mftraced</dir>
51 ;;; or copy all your .pfa/.pfb's to ~/.fonts if your fontconfig
52 ;;; already looks there for fonts. Check if it works by doing:
54 fc-list | grep -i lily
57 ;;; * Setup environment
59 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
60 export LD_LIBRARY_PATH=$HOME/usr/pkg/pango/lib:$HOME/usr/pkg/g-wrap/lib:$HOME/usr/pkg/guile-gnome/lib:$LD_LIBRARY_PATH
61 export XEDITOR='/usr/bin/emacsclient --no-wait +%l:%c %f'
63 ;;; * Also for GNOME point-and-click, you need to set XEDITOR and add
65 #(ly:set-point-and-click 'line-column)
71 lilypond -fgnome input/simple-song.ly
73 ;;; point-and-click: (mouse-1) click on a graphical object;
74 ;;; grob-property-list: (mouse-3) click on a graphical object.
76 (debug-enable 'backtrace)
78 (define-module (scm output-gnome))
79 (define this-module (current-module))
89 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
92 ;;; set by framework-gnome.scm
93 (define canvas-root #f)
94 (define output-scale #f)
96 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
99 (define (stderr string . rest)
100 (apply format (cons (current-error-port) (cons string rest)))
101 (force-output (current-error-port)))
103 (define (debugf string . rest)
105 (apply stderr (cons string rest))))
107 (define (list->offsets accum coords)
110 (cons (cons (car coords) (cadr coords))
111 (list->offsets accum (cddr coords)))))
115 ((< i #x80) (list (integer->char i)))
116 ((< i #x800) (map integer->char
117 (list (+ #xc0 (quotient i #x40))
118 (+ #x80 (modulo i #x40)))))
120 (let ((x (quotient i #x1000))
121 (y (modulo i #x1000)))
124 (+ #x80 (quotient y #x40))
125 (+ #x80 (modulo y #x40))))))
126 (else (begin (stderr "programming-error: utf-8 too big:~x\n" i)
127 (list (integer->char 32))))))
129 (define (integer->utf8-string integer)
130 (list->string (utf8 integer)))
132 (define (char->utf8-string char)
133 (list->string (utf8 (char->integer char))))
135 (define (string->utf8-string string)
138 (map (lambda (x) (char->utf8-string x)) (string->list string))))
140 (define (music-font? font)
141 (let ((encoding (ly:font-encoding font))
142 (family (font-family font)))
143 (or (memq encoding '(fetaMusic fetaBraces))
144 (string=? (substring family 0 (min (string-length family) 9))
148 (define-public (otf-name-mangling font family)
149 ;; Hmm, family is bigcheese20/26?
150 (if (string=? (substring family 0 (min (string-length family) 9))
152 (string-append "LilyPond " (substring family 9))
153 (if (string=? family "aybabtu")
157 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
158 ;;; Wrappers from guile-gnome TLA
159 ;;; guile-gnome-devel@gnu.org--2004
160 ;;; http://arch.gna.org/guile-gnome/archive-2004
162 ;;; janneke@gnu.org--2004-gnome
163 ;;; http://lilypond.org/~janneke/{arch}/2004-gnome
165 (if (not (defined? '<gnome-canvas-path-def>))
167 (define-class <gnome-canvas-path-def> (<gobject>)
168 (closure #:init-value (gnome-canvas-path-def-new)
169 #:init-keyword #:path-def
170 #:getter get-def #:setter set-def))
172 (define-method (moveto (this <gnome-canvas-path-def>) x y)
173 (gnome-canvas-path-def-moveto (get-def this) x y))
174 (define-method (curveto (this <gnome-canvas-path-def>) x1 y1 x2 y2 x3 y3)
175 (gnome-canvas-path-def-curveto (get-def this) x1 y1 x2 y2 x3 y3))
176 (define-method (lineto (this <gnome-canvas-path-def>) x y)
177 (gnome-canvas-path-def-lineto (get-def this) x y))
178 (define-method (closepath (this <gnome-canvas-path-def>))
179 (gnome-canvas-path-def-closepath (get-def this)))
180 (define-method (reset (this <gnome-canvas-path-def>))
181 (gnome-canvas-path-def-reset (get-def this)))
183 (define -set-path-def set-path-def)
184 (define -get-path-def get-path-def)
186 (define-method (set-path-def (this <gnome-canvas-shape>)
187 (def <gnome-canvas-path-def>))
188 (-set-path-def this (get-def def)))
190 (define-method (get-path-def (this <gnome-canvas-shape>))
191 (make <gnome-canvas-path-def> #:path-def (-get-path-def this)))))
193 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
194 ;;; stencil outputters
197 ;;; catch-all for missing stuff
198 ;;; comment this out to see find out what functions you miss :-)
199 (define (dummy . foo) #f)
200 (map (lambda (x) (module-define! this-module x dummy))
202 (ly:all-stencil-expressions)
203 (ly:all-output-backend-commands)))
205 (define (beam width slope thick blot)
206 (define cursor '(0 . 0))
207 (define (rmoveto def x y)
208 (set! cursor (cons (+ x (car cursor)) (+ y (cdr cursor))))
209 (moveto def (car cursor) (cdr cursor)))
210 (define (rlineto def x y)
211 (set! cursor (cons (+ x (car cursor)) (+ y (cdr cursor))))
212 (lineto def (car cursor) (cdr cursor)))
213 (let* ((def (make <gnome-canvas-path-def>))
214 (bezier (make <gnome-canvas-bpath>
215 #:parent (canvas-root)
217 #:outline-color "black"
219 #:join-style 'round))
225 (rmoveto def (/ blot 2) (/ t 2))
226 (rlineto def w (- h))
227 (rlineto def 0 (- t))
228 (rlineto def (- w) h)
231 (set-path-def bezier def)
234 (define (square-beam width slope thick blot)
236 ((def (make <gnome-canvas-path-def>))
237 (y (* (- width) slope))
238 (props (make <gnome-canvas-bpath>
239 #:parent (canvas-root)
241 #:outline-color "black"
247 (lineto def width (- y thick))
248 (lineto def 0 (- thick))
251 (set-path-def props def)
255 (define (bezier-sandwich lst thick)
256 (let* ((def (make <gnome-canvas-path-def>))
257 (bezier (make <gnome-canvas-bpath>
258 #:parent (canvas-root)
260 #:outline-color "black"
262 #:join-style 'round)))
266 ;; FIXME: LST is pre-mangled for direct ps stack usage
270 (moveto def (car (list-ref lst 3)) (- (cdr (list-ref lst 3))))
271 (curveto def (car (list-ref lst 0)) (- (cdr (list-ref lst 0)))
272 (car (list-ref lst 1)) (- (cdr (list-ref lst 1)))
273 (car (list-ref lst 2)) (- (cdr (list-ref lst 2))))
275 (lineto def (car (list-ref lst 7)) (- (cdr (list-ref lst 7))))
276 (curveto def (car (list-ref lst 4)) (- (cdr (list-ref lst 4)))
277 (car (list-ref lst 5)) (- (cdr (list-ref lst 5)))
278 (car (list-ref lst 6)) (- (cdr (list-ref lst 6))))
279 (lineto def (car (list-ref lst 3)) (- (cdr (list-ref lst 3))))
282 (set-path-def bezier def)
285 (define (char font i)
286 (text font (ly:font-index-to-charcode font i)))
289 (define (filledbox breapth width depth height)
290 (make <gnome-canvas-rect>
291 #:parent (canvas-root)
292 #:x1 (- breapth) #:y1 depth #:x2 width #:y2 (- height)
294 #:join-style 'miter))
296 (define (grob-cause grob)
299 ;; WTF is this in every backend?
300 (define (horizontal-line x1 x2 thickness)
301 (filledbox (- x1) (- x2 x1) (* .5 thickness) (* .5 thickness)))
303 (define (placebox x y expr)
306 ;; FIXME ugly hack to skip #unspecified ...
307 (if (and item (not (eq? item (if #f #f))))
309 (move item (* output-scale x) (* output-scale (- y)))
310 (affine-relative item output-scale 0 0 output-scale 0 0)
314 (define (dashed-line thick on off dx dy)
315 (draw-line thick 0 0 dx dy))
317 (define (draw-line thick fx fy tx ty)
319 ((def (make <gnome-canvas-path-def>))
320 (props (make <gnome-canvas-bpath>
321 #:parent (canvas-root)
323 #:outline-color "black"
324 #:width-units thick)))
327 (moveto def fx (- fy))
328 (lineto def tx (- ty))
329 (set-path-def props def)
332 (define (named-glyph font name)
333 (text font (ly:font-glyph-name-to-charcode font name)))
335 (define (polygon coords blotdiameter)
337 ((def (make <gnome-canvas-path-def>))
338 (props (make <gnome-canvas-bpath>
339 #:parent (canvas-root)
341 #:outline-color "black"
342 #:width-units blotdiameter))
343 (points (list->offsets '() coords))
344 (last-point (car (last-pair points))))
347 (moveto def (car last-point) (cdr last-point))
348 (for-each (lambda (x)
349 (lineto def (car x) (cdr x))
352 (set-path-def props def)
356 (define (round-filled-box breapth width depth height blot-diameter)
357 (let ((r (/ blot-diameter 2)))
358 (make <gnome-canvas-rect>
359 #:parent (canvas-root)
360 #:x1 (- r breapth) #:y1 (- depth r) #:x2 (- width r) #:y2 (- r height)
362 #:outline-color "black"
363 #:width-units blot-diameter
364 #:join-style 'round)))
366 (define (text font s)
368 (define (pango-font-name font)
369 (debugf "FONT-NAME:~S:~S\n" (ly:font-name font) (ly:font-design-size font))
370 (debugf "FONT-FAMILY:~S:~S\n" (font-family font) (otf-name-mangling font (font-family font)))
371 (otf-name-mangling font (font-family font)))
373 (define (pango-font-size font)
374 (let* ((designsize (ly:font-design-size font))
375 (magnification (* (ly:font-magnification font)))
377 ;;font-name: "GNU-LilyPond-feta-20"
378 ;;font-file-name: "feta20"
379 ;;pango-font-name: "lilypond-feta, regular 32"
381 ;;scaling:29.7046771653543
382 ;;magnification:0.569055118110236
385 ;; ugh, experimental sizing
386 ;; where does factor ops come from?
387 ;; Hmm, design size: 26/20
390 (scaling (* ops magnification designsize)))
391 (debugf "OPS:~S\n" ops)
392 (debugf "scaling:~S\n" scaling)
393 (debugf "magnification:~S\n" magnification)
394 (debugf "design:~S\n" designsize)
398 (make <gnome-canvas-text>
399 #:parent (canvas-root)
400 ;; ugh, experimental placement corections
402 #:x 0.0 #:y (if (music-font? font) 0.15 0.69)
403 #:anchor (if (music-font? font) 'west 'south-west)
404 #:font (pango-font-name font)
405 #:size-points (pango-font-size font)
407 #:text (if (integer? s)
408 (integer->utf8-string s)
409 (string->utf8-string s))))