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.
24 ;;; * Rotty's g-wrap >= 1.9.1 (or TLA)
25 ;;; * guile-gnome-platform >= 2.5.992 (or TLA)
26 ;;; * pango >= 1.5.2 (or CVS)
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 ;; The name of the module will change to `canvas' rsn
91 (if (resolve-module '(gnome gw canvas))
92 (use-modules (gnome gw canvas))
93 (use-modules (gnome gw libgnomecanvas)))
96 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
97 ;;; Wrappers from guile-gnome TLA
98 ;;; guile-gnome-devel@gnu.org--2004
99 ;;; http://arch.gna.org/guile-gnome/archive-2004
101 ;;; janneke@gnu.org--2004-gnome
102 ;;; http://lilypond.org/~janneke/{arch}/2004-gnome
104 (if (not (defined? '<gnome-canvas-path-def>))
106 (define-class <gnome-canvas-path-def> (<gobject>)
107 (closure #:init-value (gnome-canvas-path-def-new)
108 #:init-keyword #:path-def
109 #:getter get-def #:setter set-def))
111 (define-method (moveto (this <gnome-canvas-path-def>) x y)
112 (gnome-canvas-path-def-moveto (get-def this) x y))
113 (define-method (curveto (this <gnome-canvas-path-def>) x1 y1 x2 y2 x3 y3)
114 (gnome-canvas-path-def-curveto (get-def this) x1 y1 x2 y2 x3 y3))
115 (define-method (lineto (this <gnome-canvas-path-def>) x y)
116 (gnome-canvas-path-def-lineto (get-def this) x y))
117 (define-method (closepath (this <gnome-canvas-path-def>))
118 (gnome-canvas-path-def-closepath (get-def this)))
119 (define-method (reset (this <gnome-canvas-path-def>))
120 (gnome-canvas-path-def-reset (get-def this)))
122 (define -set-path-def set-path-def)
123 (define -get-path-def get-path-def)
125 (define-method (set-path-def (this <gnome-canvas-shape>)
126 (def <gnome-canvas-path-def>))
127 (-set-path-def this (get-def def)))
129 (define-method (get-path-def (this <gnome-canvas-shape>))
130 (make <gnome-canvas-path-def> #:path-def (-get-path-def this)))))
132 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
136 (define system-origin '(0 . 0))
138 ;;; set by framework-gnome.scm
139 (define canvas-root #f)
140 (define output-scale #f)
143 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
146 (define (stderr string . rest)
147 (apply format (cons (current-error-port) (cons string rest)))
148 (force-output (current-error-port)))
150 (define (debugf string . rest)
152 (apply stderr (cons string rest))))
156 ((< i #x80) (list (integer->char i)))
157 ((< i #x800) (map integer->char
158 (list (+ #xc0 (quotient i #x40))
159 (+ #x80 (modulo i #x40)))))
161 (let ((x (quotient i #x1000))
162 (y (modulo i #x1000)))
165 (+ #x80 (quotient y #x40))
166 (+ #x80 (modulo y #x40))))))
169 (define (custom-utf8 i)
172 (utf8 (+ #xee00 i))))
174 (define (string->utf8-string string)
176 (apply append (map utf8 (map char->integer (string->list string))))))
178 (define (char->utf8-string char)
179 (list->string (utf8 (char->integer char))))
181 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
182 ;;; stencil outputters
185 ;;; catch-all for missing stuff
186 ;;; comment this out to see find out what functions you miss :-)
187 (define (dummy . foo) #f)
188 (map (lambda (x) (module-define! this-module x dummy))
190 (ly:all-stencil-expressions)
191 (ly:all-output-backend-commands)))
193 (define (beam width slope thick blot)
194 (define cursor '(0 . 0))
195 (define (rmoveto def x y)
196 (set! cursor (cons (+ x (car cursor)) (+ y (cdr cursor))))
197 (moveto def (car cursor) (cdr cursor)))
198 (define (rlineto def x y)
199 (set! cursor (cons (+ x (car cursor)) (+ y (cdr cursor))))
200 (lineto def (car cursor) (cdr cursor)))
201 (let* ((def (make <gnome-canvas-path-def>))
202 (bezier (make <gnome-canvas-bpath>
203 #:parent (canvas-root)
205 #:outline-color "black"
207 #:join-style 'round))
213 (rmoveto def (/ blot 2) (/ t 2))
214 (rlineto def w (- h))
215 (rlineto def 0 (- t))
216 (rlineto def (- w) h)
219 (set-path-def bezier def)
222 (define (square-beam width slope thick blot)
224 ((def (make <gnome-canvas-path-def>))
225 (y (* (- width) slope))
226 (props (make <gnome-canvas-bpath>
227 #:parent (canvas-root)
229 #:outline-color "black"
235 (lineto def width (- y thick))
236 (lineto def 0 (- thick))
239 (set-path-def props def)
244 (define (bezier-sandwich lst thick)
245 (let* ((def (make <gnome-canvas-path-def>))
246 (bezier (make <gnome-canvas-bpath>
247 #:parent (canvas-root)
249 #:outline-color "black"
251 #:join-style 'round)))
255 ;; FIXME: LST is pre-mangled for direct ps stack usage
259 (moveto def (car (list-ref lst 3)) (- (cdr (list-ref lst 3))))
260 (curveto def (car (list-ref lst 0)) (- (cdr (list-ref lst 0)))
261 (car (list-ref lst 1)) (- (cdr (list-ref lst 1)))
262 (car (list-ref lst 2)) (- (cdr (list-ref lst 2))))
264 (lineto def (car (list-ref lst 7)) (- (cdr (list-ref lst 7))))
265 (curveto def (car (list-ref lst 4)) (- (cdr (list-ref lst 4)))
266 (car (list-ref lst 5)) (- (cdr (list-ref lst 5)))
267 (car (list-ref lst 6)) (- (cdr (list-ref lst 6))))
268 (lineto def (car (list-ref lst 3)) (- (cdr (list-ref lst 3))))
271 (set-path-def bezier def)
274 (define (char font i)
275 (text font (utf8 i)))
278 (define (filledbox breapth width depth height)
279 (make <gnome-canvas-rect>
280 #:parent (canvas-root)
281 #:x1 (- breapth) #:y1 depth #:x2 width #:y2 (- height)
283 #:join-style 'miter))
285 (define (grob-cause grob)
288 ;; WTF is this in every backend?
289 (define (horizontal-line x1 x2 thickness)
290 (filledbox (- x1) (- x2 x1) (* .5 thickness) (* .5 thickness)))
292 (define (placebox x y expr)
293 (debugf "item: ~S\n" expr)
296 ;; FIXME ugly hack to skip #unspecified ...
297 (if (and item (not (eq? item (if #f #f))))
300 (* output-scale (+ (car system-origin) x))
301 (* output-scale (- (car system-origin) y)))
302 (affine-relative item output-scale 0 0 output-scale 0 0)
306 (define (dashed-line thick on off dx dy)
307 (draw-line thick 0 0 dx dy))
309 (define (draw-line thick fx fy tx ty)
311 ((def (make <gnome-canvas-path-def>))
312 (props (make <gnome-canvas-bpath>
313 #:parent (canvas-root)
315 #:outline-color "black"
316 #:width-units thick)))
319 (moveto def fx (- fy))
320 (lineto def tx (- ty))
321 (set-path-def props def)
325 (define (list->offsets accum coords)
328 (cons (cons (car coords) (cadr coords))
329 (list->offsets accum (cddr coords))
332 (define (polygon coords blotdiameter)
334 ((def (make <gnome-canvas-path-def>))
335 (props (make <gnome-canvas-bpath>
336 #:parent (canvas-root)
338 #:outline-color "black"
339 #:width-units blotdiameter))
340 (points (list->offsets '() coords))
341 (last-point (car (last-pair points))))
344 (moveto def (car last-point) (cdr last-point))
345 (for-each (lambda (x)
346 (lineto def (car x) (cdr x))
349 (set-path-def props def)
353 (define (round-filled-box breapth width depth height blot-diameter)
354 (let ((r (/ blot-diameter 2)))
355 (make <gnome-canvas-rect>
356 #:parent (canvas-root)
357 #:x1 (- r breapth) #:y1 (- depth r) #:x2 (- width r) #:y2 (- r height)
359 #:outline-color "black"
360 #:width-units blot-diameter
361 #:join-style 'round)))
363 (define (text font string)
364 (define (pango-font-name font)
365 (let ((name (ly:font-name font)))
367 (regexp-substitute/global #f "^GNU-(.*)-[.0-9]*$" name 'pre 1 'post)
369 (stderr "font-name: ~S\n" (ly:font-name font))
370 ;; TODO s/filename/file-name/
371 (stderr "font-filename: ~S\n" (ly:font-filename font))
372 (stderr "pango-font-size: ~S\n" (pango-font-size font))
374 (ly:font-filename font)))))
376 (define (pango-font-size font)
377 (let* ((designsize (ly:font-design-size font))
378 (magnification (* (ly:font-magnification font)))
381 ;;font-name: "GNU-LilyPond-feta-20"
382 ;;font-filename: "feta20"
383 ;;pango-font-name: "lilypond-feta, regular 32"
385 ;;scaling:29.7046771653543
386 ;;magnification:0.569055118110236
389 ;; experimental sizing:
390 ;; where does factor ops come from?
391 ;; Hmm, design size: 26/20
394 (scaling (* ops magnification designsize)))
395 (debugf "OPS:~S\n" ops)
396 (debugf "scaling:~S\n" scaling)
397 (debugf "magnification:~S\n" magnification)
398 (debugf "design:~S\n" designsize)
402 (make <gnome-canvas-text>
403 #:parent (canvas-root)
408 #:font (pango-font-name font)
410 #:size-points (pango-font-size font)
414 ;;apparently no effect :-(
419 #:text (if (string? string)
420 (string->utf8-string string)
421 (char->utf8-string (car string)))))