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. This hack
20 ;;; depends on several CVS and TLA development sources. In the works.
24 ;;; * Rotty's g-wrap >= 1.9.3 (or TLA)
25 ;;; * guile-gnome-platform >= 2.7.95 (or TLA)
28 ;;; See also: guile-gtk-general@gnu.org
32 ;;; [* Get cvs and tla]
34 ;;; * Install gnome/gtk and libffi development stuff
36 ;;; * Install pango, g-wrap and guile-gnome from CVS or arch:
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
91 ;;; Wrappers from guile-gnome TLA
92 ;;; guile-gnome-devel@gnu.org--2004
93 ;;; http://arch.gna.org/guile-gnome/archive-2004
95 ;;; janneke@gnu.org--2004-gnome
96 ;;; http://lilypond.org/~janneke/{arch}/2004-gnome
98 (if (not (defined? '<gnome-canvas-path-def>))
100 (define-class <gnome-canvas-path-def> (<gobject>)
101 (closure #:init-value (gnome-canvas-path-def-new)
102 #:init-keyword #:path-def
103 #:getter get-def #:setter set-def))
105 (define-method (moveto (this <gnome-canvas-path-def>) x y)
106 (gnome-canvas-path-def-moveto (get-def this) x y))
107 (define-method (curveto (this <gnome-canvas-path-def>) x1 y1 x2 y2 x3 y3)
108 (gnome-canvas-path-def-curveto (get-def this) x1 y1 x2 y2 x3 y3))
109 (define-method (lineto (this <gnome-canvas-path-def>) x y)
110 (gnome-canvas-path-def-lineto (get-def this) x y))
111 (define-method (closepath (this <gnome-canvas-path-def>))
112 (gnome-canvas-path-def-closepath (get-def this)))
113 (define-method (reset (this <gnome-canvas-path-def>))
114 (gnome-canvas-path-def-reset (get-def this)))
116 (define -set-path-def set-path-def)
117 (define -get-path-def get-path-def)
119 (define-method (set-path-def (this <gnome-canvas-shape>)
120 (def <gnome-canvas-path-def>))
121 (-set-path-def this (get-def def)))
123 (define-method (get-path-def (this <gnome-canvas-shape>))
124 (make <gnome-canvas-path-def> #:path-def (-get-path-def this)))))
126 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
129 ;;; set by framework-gnome.scm
130 (define canvas-root #f)
131 (define output-scale #f)
133 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
136 (define (stderr string . rest)
137 (apply format (cons (current-error-port) (cons string rest)))
138 (force-output (current-error-port)))
140 (define (debugf string . rest)
142 (apply stderr (cons string rest))))
144 (define (list->offsets accum coords)
147 (cons (cons (car coords) (cadr coords))
148 (list->offsets accum (cddr coords)))))
152 ((< i #x80) (list (integer->char i)))
153 ((< i #x800) (map integer->char
154 (list (+ #xc0 (quotient i #x40))
155 (+ #x80 (modulo i #x40)))))
157 (let ((x (quotient i #x1000))
158 (y (modulo i #x1000)))
161 (+ #x80 (quotient y #x40))
162 (+ #x80 (modulo y #x40))))))
165 (define (integer->utf8-string font integer)
166 (list->string (utf8 integer)))
168 (define (char->utf8-string font char)
169 (list->string (utf8 (char->unicode-index font char))))
171 (define (string->utf8-string font string)
174 (map (lambda (x) (char->utf8-string font x)) (string->list string))))
176 (define (music-font? font)
177 (let ((encoding (ly:font-encoding font))
178 (family (font-family font)))
179 (or (memq encoding '(fetaMusic fetaBraces))
180 (string=? (substring family 0 (min (string-length family) 9))
183 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
184 ;;; stencil outputters
187 ;;; catch-all for missing stuff
188 ;;; comment this out to see find out what functions you miss :-)
189 (define (dummy . foo) #f)
190 (map (lambda (x) (module-define! this-module x dummy))
192 (ly:all-stencil-expressions)
193 (ly:all-output-backend-commands)))
195 (define (beam width slope thick blot)
196 (define cursor '(0 . 0))
197 (define (rmoveto def x y)
198 (set! cursor (cons (+ x (car cursor)) (+ y (cdr cursor))))
199 (moveto def (car cursor) (cdr cursor)))
200 (define (rlineto def x y)
201 (set! cursor (cons (+ x (car cursor)) (+ y (cdr cursor))))
202 (lineto def (car cursor) (cdr cursor)))
203 (let* ((def (make <gnome-canvas-path-def>))
204 (bezier (make <gnome-canvas-bpath>
205 #:parent (canvas-root)
207 #:outline-color "black"
209 #:join-style 'round))
215 (rmoveto def (/ blot 2) (/ t 2))
216 (rlineto def w (- h))
217 (rlineto def 0 (- t))
218 (rlineto def (- w) h)
221 (set-path-def bezier def)
224 (define (square-beam width slope thick blot)
226 ((def (make <gnome-canvas-path-def>))
227 (y (* (- width) slope))
228 (props (make <gnome-canvas-bpath>
229 #:parent (canvas-root)
231 #:outline-color "black"
237 (lineto def width (- y thick))
238 (lineto def 0 (- thick))
241 (set-path-def props def)
245 (define (bezier-sandwich lst thick)
246 (let* ((def (make <gnome-canvas-path-def>))
247 (bezier (make <gnome-canvas-bpath>
248 #:parent (canvas-root)
250 #:outline-color "black"
252 #:join-style 'round)))
256 ;; FIXME: LST is pre-mangled for direct ps stack usage
260 (moveto def (car (list-ref lst 3)) (- (cdr (list-ref lst 3))))
261 (curveto def (car (list-ref lst 0)) (- (cdr (list-ref lst 0)))
262 (car (list-ref lst 1)) (- (cdr (list-ref lst 1)))
263 (car (list-ref lst 2)) (- (cdr (list-ref lst 2))))
265 (lineto def (car (list-ref lst 7)) (- (cdr (list-ref lst 7))))
266 (curveto def (car (list-ref lst 4)) (- (cdr (list-ref lst 4)))
267 (car (list-ref lst 5)) (- (cdr (list-ref lst 5)))
268 (car (list-ref lst 6)) (- (cdr (list-ref lst 6))))
269 (lineto def (car (list-ref lst 3)) (- (cdr (list-ref lst 3))))
272 (set-path-def bezier def)
275 (define (char font i)
276 (text font (ly:font-index-to-charcode font i)))
279 (define (filledbox breapth width depth height)
280 (make <gnome-canvas-rect>
281 #:parent (canvas-root)
282 #:x1 (- breapth) #:y1 depth #:x2 width #:y2 (- height)
284 #:join-style 'miter))
286 (define (grob-cause grob)
289 ;; WTF is this in every backend?
290 (define (horizontal-line x1 x2 thickness)
291 (filledbox (- x1) (- x2 x1) (* .5 thickness) (* .5 thickness)))
293 (define (placebox x y expr)
296 ;; FIXME ugly hack to skip #unspecified ...
297 (if (and item (not (eq? item (if #f #f))))
299 (move item (* output-scale x) (* output-scale (- y)))
300 (affine-relative item output-scale 0 0 output-scale 0 0)
304 (define (dashed-line thick on off dx dy)
305 (draw-line thick 0 0 dx dy))
307 (define (draw-line thick fx fy tx ty)
309 ((def (make <gnome-canvas-path-def>))
310 (props (make <gnome-canvas-bpath>
311 #:parent (canvas-root)
313 #:outline-color "black"
314 #:width-units thick)))
317 (moveto def fx (- fy))
318 (lineto def tx (- ty))
319 (set-path-def props def)
322 (define (named-glyph font name)
323 (text font (ly:font-glyph-name-to-charcode font name)))
325 (define (polygon coords blotdiameter)
327 ((def (make <gnome-canvas-path-def>))
328 (props (make <gnome-canvas-bpath>
329 #:parent (canvas-root)
331 #:outline-color "black"
332 #:width-units blotdiameter))
333 (points (list->offsets '() coords))
334 (last-point (car (last-pair points))))
337 (moveto def (car last-point) (cdr last-point))
338 (for-each (lambda (x)
339 (lineto def (car x) (cdr x))
342 (set-path-def props def)
346 (define (round-filled-box breapth width depth height blot-diameter)
347 (let ((r (/ blot-diameter 2)))
348 (make <gnome-canvas-rect>
349 #:parent (canvas-root)
350 #:x1 (- r breapth) #:y1 (- depth r) #:x2 (- width r) #:y2 (- r height)
352 #:outline-color "black"
353 #:width-units blot-diameter
354 #:join-style 'round)))
356 (define (text font s)
358 (define (pango-font-name font)
359 (stderr "FONT-NAME:~S:~S\n" (ly:font-name font) (ly:font-design-size 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 font s)
398 (string->utf8-string font s))))