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 ;;; * font selection: name, size, design size
11 ;;; * .cff MUST NOT be in fc's fontpath?
13 ;;; * check: blot+scaling
14 ;;; * Figure out and fix font scaling and character placement
15 ;;; * EC font package: add missing X font directories and AFMs
16 ;;; * User-interface, keybindings
17 ;;; * Implement missing stencil functions
18 ;;; * Implement missing commands
19 ;;; * More information in stencils, e.g., location and grob tag.
21 ;;; - allow GnomeCanvas or `toplevel' GtkWindow to be created
22 ;;; outside of LilyPond
24 ;;; * Release schedule and packaging of dependencies.
25 ;;; - g-wrap-1.9.3 is already in incoming.
26 ;;; - guile-gnome-platform-2.8.0 will probably be packaged early 2005.
30 ;;; * Rotty's g-wrap >= 1.9.3
31 ;;; * guile-gnome-platform >= 2.7.97
34 ;;; See also: guile-gtk-general@gnu.org
38 ;;; * Install gnome/gtk and libffi development stuff
40 ;;; * Install [pango, g-wrap and] guile-gnome from source,
41 ;;; see buildscripts/guile-gnome.sh
43 ;;; * Build LilyPond with gui support: configure --enable-gui
45 ;;; * Supposing that LilyPond was built in ~/cvs/savannah/lilypond,
46 ;;; tell fontconfig about the feta fonts dir and run fc-cache
48 cat > ~/.fonts.conf << EOF
50 <dir>~/cvs/savannah/lilypond/mf/out</dir>
51 <dir>/usr/share/texmf/fonts/type1/public/ec-fonts-mftraced</dir>
56 ;;; or copy all your .pfa/.pfb's to ~/.fonts if your fontconfig
57 ;;; already looks there for fonts. Check if it works by doing:
59 fc-list | grep -i lily
62 ;;; * Setup environment
64 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
65 export LD_LIBRARY_PATH=$HOME/usr/pkg/pango/lib:$HOME/usr/pkg/g-wrap/lib:$HOME/usr/pkg/guile-gnome/lib:$LD_LIBRARY_PATH
66 export XEDITOR='/usr/bin/emacsclient --no-wait +%l:%c %f'
68 ;;; * Also for GNOME point-and-click, you need to set XEDITOR and add
70 #(ly:set-point-and-click 'line-column)
76 lilypond -fgnome input/simple-song.ly
78 ;;; point-and-click: (mouse-1) click on a graphical object;
79 ;;; grob-property-list: (mouse-3) click on a graphical object.
81 (debug-enable 'backtrace)
83 (define-module (scm output-gnome))
84 (define this-module (current-module))
94 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
97 ;;; set by framework-gnome.scm
98 (define canvas-root #f)
99 (define output-scale #f)
101 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
104 (define (stderr string . rest)
105 (apply format (cons (current-error-port) (cons string rest)))
106 (force-output (current-error-port)))
108 (define (debugf string . rest)
110 (apply stderr (cons string rest))))
114 ((< i #x80) (list (integer->char i)))
115 ((< i #x800) (map integer->char
116 (list (+ #xc0 (quotient i #x40))
117 (+ #x80 (modulo i #x40)))))
119 (let ((x (quotient i #x1000))
120 (y (modulo i #x1000)))
123 (+ #x80 (quotient y #x40))
124 (+ #x80 (modulo y #x40))))))
125 (else (begin (stderr "programming-error: utf8 too big:~x\n" i)
126 (list (integer->char 32))))))
128 (define (integer->utf8-string integer)
129 (list->string (utf8 integer)))
131 (define (char->utf8-string char)
132 (list->string (utf8 (char->integer char))))
134 (define (string->utf8-string string)
137 (map (lambda (x) (char->utf8-string x)) (string->list string))))
139 (define (music-font? font)
140 (let ((family (font-family font)))
141 (string=? (substring family 0 (min (string-length family) 10))
144 (define (pango-font-name font)
145 (debugf "FONT-NAME:~S:~S\n" (ly:font-name font) (ly:font-design-size font))
146 ;;(debugf "FONT-FAMILY:~S:~S\n" (font-family font) (otf-name-mangling font (font-family font)))
149 (define (pango-font-size font)
150 (let* ((designsize (ly:font-design-size font))
151 (magnification (* (ly:font-magnification font)))
153 ;;(scaling (* output-scale magnification designsize)))
154 (scaling (* 1.4 output-scale magnification designsize)))
155 ;;(debugf "OPS:~S\n" ops)
156 (debugf "scaling:~S\n" scaling)
157 (debugf "magnification:~S\n" magnification)
158 (debugf "design:~S\n" designsize)
162 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
163 ;;; Wrappers from guile-gnome TLA
164 ;;; guile-gnome-devel@gnu.org--2004
165 ;;; http://arch.gna.org/guile-gnome/archive-2004
167 ;;; janneke@gnu.org--2004-gnome
168 ;;; http://lilypond.org/~janneke/{arch}/2004-gnome
170 (if (not (defined? '<gnome-canvas-path-def>))
172 (define-class <gnome-canvas-path-def> (<gobject>)
173 (closure #:init-value (gnome-canvas-path-def-new)
174 #:init-keyword #:path-def
175 #:getter get-def #:setter set-def))
177 (define-method (moveto (this <gnome-canvas-path-def>) x y)
178 (gnome-canvas-path-def-moveto (get-def this) x y))
179 (define-method (curveto (this <gnome-canvas-path-def>) x1 y1 x2 y2 x3 y3)
180 (gnome-canvas-path-def-curveto (get-def this) x1 y1 x2 y2 x3 y3))
181 (define-method (lineto (this <gnome-canvas-path-def>) x y)
182 (gnome-canvas-path-def-lineto (get-def this) x y))
183 (define-method (closepath (this <gnome-canvas-path-def>))
184 (gnome-canvas-path-def-closepath (get-def this)))
185 (define-method (reset (this <gnome-canvas-path-def>))
186 (gnome-canvas-path-def-reset (get-def this)))
188 (define -set-path-def set-path-def)
189 (define -get-path-def get-path-def)
191 (define-method (set-path-def (this <gnome-canvas-shape>)
192 (def <gnome-canvas-path-def>))
193 (-set-path-def this (get-def def)))
195 (define-method (get-path-def (this <gnome-canvas-shape>))
196 (make <gnome-canvas-path-def> #:path-def (-get-path-def this)))))
198 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
199 ;;; stencil outputters
202 ;;; catch-all for missing stuff
203 ;;; comment this out to see find out what functions you miss :-)
204 (define (dummy . foo) #f)
205 (map (lambda (x) (module-define! this-module x dummy))
207 (ly:all-stencil-expressions)
208 (ly:all-output-backend-commands)))
210 (define (beam width slope thick blot)
211 (define cursor '(0 . 0))
212 (define (rmoveto def x y)
213 (set! cursor (cons (+ x (car cursor)) (+ y (cdr cursor))))
214 (moveto def (car cursor) (cdr cursor)))
215 (define (rlineto def x y)
216 (set! cursor (cons (+ x (car cursor)) (+ y (cdr cursor))))
217 (lineto def (car cursor) (cdr cursor)))
218 (let* ((def (make <gnome-canvas-path-def>))
219 (bezier (make <gnome-canvas-bpath>
220 #:parent (canvas-root)
222 #:outline-color "black"
224 #:join-style 'round))
230 (rmoveto def (/ blot 2) (/ t 2))
231 (rlineto def w (- h))
232 (rlineto def 0 (- t))
233 (rlineto def (- w) h)
236 (set-path-def bezier def)
239 (define (square-beam width slope thick blot)
240 (let* ((def (make <gnome-canvas-path-def>))
241 (y (* (- width) slope))
242 (props (make <gnome-canvas-bpath>
243 #:parent (canvas-root)
245 #:outline-color "black"
251 (lineto def width (- y thick))
252 (lineto def 0 (- thick))
255 (set-path-def props def)
259 (define (bezier-sandwich lst thick)
260 (let* ((def (make <gnome-canvas-path-def>))
261 (bezier (make <gnome-canvas-bpath>
262 #:parent (canvas-root)
264 #:outline-color "black"
266 #:join-style 'round)))
270 ;; FIXME: LST is pre-mangled for direct ps stack usage
274 (moveto def (car (list-ref lst 3)) (- (cdr (list-ref lst 3))))
275 (curveto def (car (list-ref lst 0)) (- (cdr (list-ref lst 0)))
276 (car (list-ref lst 1)) (- (cdr (list-ref lst 1)))
277 (car (list-ref lst 2)) (- (cdr (list-ref lst 2))))
279 (lineto def (car (list-ref lst 7)) (- (cdr (list-ref lst 7))))
280 (curveto def (car (list-ref lst 4)) (- (cdr (list-ref lst 4)))
281 (car (list-ref lst 5)) (- (cdr (list-ref lst 5)))
282 (car (list-ref lst 6)) (- (cdr (list-ref lst 6))))
283 (lineto def (car (list-ref lst 3)) (- (cdr (list-ref lst 3))))
286 (set-path-def bezier def)
289 (define (char font i)
290 (text font (ly:font-index-to-charcode font i)))
292 (define (dashed-line thick on off dx dy)
293 (draw-line thick 0 0 dx dy))
295 (define (draw-line thick x1 y1 x2 y2)
296 (let* ((def (make <gnome-canvas-path-def>))
297 (props (make <gnome-canvas-bpath>
298 #:parent (canvas-root)
300 #:outline-color "black"
301 #:width-units thick)))
303 (moveto def x1 (- y1))
304 (lineto def x2 (- y2))
305 (set-path-def props def)
309 (define (filledbox breapth width depth height)
310 (make <gnome-canvas-rect>
311 #:parent (canvas-root)
312 #:x1 (- breapth) #:y1 depth #:x2 width #:y2 (- height)
314 #:join-style 'miter))
316 ;; FIXME: the framework-gnome backend needs to see every item that
317 ;; gets created. All items created here must should be put in a group
318 ;; that gets returned.
319 (define (glyph-string font postscript-font-name x-y-named-glyphs)
323 ;; UGR, glyph names not found
324 (stderr "GLYPH:~S\n" (caddr x))
325 (stderr "ID:~S\n" (ly:font-glyph-name-to-charcode font (caddr x)))
326 (placebox (car x) (cadr x)
327 (make <gnome-canvas-text>
328 #:parent (canvas-root)
331 ;;#:font postscript-font-name
332 #:font (pango-font-name font)
336 (integer->utf8-string
337 (ly:font-glyph-name-to-charcode font (caddr x))))))
340 (define (grob-cause grob)
343 ;; WTF is this in every backend?
344 (define (horizontal-line x1 x2 thickness)
345 (filledbox (- x1) (- x2 x1) (* .5 thickness) (* .5 thickness)))
347 (define (named-glyph font name)
348 (text font (ly:font-glyph-name-to-charcode font name)))
350 (define (placebox x y expr)
353 ;; FIXME ugly hack to skip #unspecified ...
354 (if (and item (not (eq? item (if #f #f))))
356 (move item (* output-scale x) (* output-scale (- y)))
357 (affine-relative item output-scale 0 0 output-scale 0 0)
361 (define (polygon coords blot-diameter)
362 (let* ((def (make <gnome-canvas-path-def>))
363 (props (make <gnome-canvas-bpath>
364 #:parent (canvas-root)
366 #:outline-color "black"
368 #:width-units blot-diameter)
369 (points (ly:list->offsets '() coords))
370 (last-point (car (last-pair points))))
373 (moveto def (car last-point) (cdr last-point))
374 (for-each (lambda (x) (lineto def (car x) (cdr x))) points)
376 (set-path-def props def)
379 (define (round-filled-box breapth width depth height blot-diameter)
380 (let ((r (/ blot-diameter 2)))
381 (make <gnome-canvas-rect>
382 #:parent (canvas-root)
383 #:x1 (- r breapth) #:y1 (- depth r) #:x2 (- width r) #:y2 (- r height)
385 #:outline-color "black"
386 #:width-units blot-diameter
387 #:join-style 'round)))
389 (define (text font s)
390 (stderr "FONT:~S\n" font)
391 (stderr "FONT:~S\n" (pango-font-name font))
393 (make <gnome-canvas-text>
394 #:parent (canvas-root)
395 ;; ugh, experimental placement corections
397 #:x 0.0 #:y (if (music-font? font) 0.15 0.69)
398 #:anchor (if (music-font? font) 'west 'south-west)
399 #:font (pango-font-name font)
401 #:size-points (pango-font-size font)
403 ;; #:size (inexact->exact (round (pango-font-size font)))
405 #:text (if (integer? s)
406 (integer->utf8-string s)
407 (string->utf8-string s))))
409 (define (utf8-string pango-font-description string)
410 (make <gnome-canvas-text>
411 #:parent (canvas-root)
414 #:font pango-font-description