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.
21 ;;; * Maybe we need to have a unicode mapping somehow, we could
22 ;;; - use OpenType instead of Type1
23 ;;; http://lists.gnu.org/archive/html/lilypond-devel/2004-05/msg00098.html
24 ;;; - or fix the pangofc-afm-decoder and add it to Pango (no chance?)
25 ;;; or have fontconfig read AFM files
26 ;;; http://lists.gnu.org/archive/html/lilypond-devel/2004-05/msg00103.html
30 ;;; * Rotty's g-wrap >= 1.9.3 (or TLA)
31 ;;; * guile-gnome-platform >= 2.7.95 (or TLA)
34 ;;; See also: guile-gtk-general@gnu.org
38 ;;; [* Get cvs and tla]
40 ;;; * Install gnome/gtk and libffi development stuff
42 ;;; * Install pango, g-wrap and guile-gnome from CVS or arch:
43 ;;; see buildscripts/guile-gnome.sh
45 ;;; * Build LilyPond with gui support: configure --enable-gui
47 ;;; * Supposing that LilyPond was built in ~/cvs/savannah/lilypond,
48 ;;; tell fontconfig about the feta fonts dir and run fc-cache
50 cat > ~/.fonts.conf << EOF
52 <dir>~/cvs/savannah/lilypond/mf/out</dir>
53 <dir>/usr/share/texmf/fonts/type1/public/ec-fonts-mftraced</dir>
58 ;;; or copy all your .pfa/.pfb's to ~/.fonts if your fontconfig
59 ;;; already looks there for fonts. Check if it works by doing:
61 fc-list | grep -i lily
64 ;;; * Setup environment
66 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
67 export LD_LIBRARY_PATH=$HOME/usr/pkg/pango/lib:$HOME/usr/pkg/g-wrap/lib:$HOME/usr/pkg/guile-gnome/lib:$LD_LIBRARY_PATH
68 export XEDITOR='/usr/bin/emacsclient --no-wait +%l:%c %f'
70 ;;; * Also for GNOME point-and-click, you need to set XEDITOR and add
72 #(ly:set-point-and-click 'line-column)
78 lilypond -fgnome input/simple-song.ly
80 ;;; point-and-click: (mouse-1) click on a graphical object;
81 ;;; grob-property-list: (mouse-3) click on a graphical object.
83 (debug-enable 'backtrace)
85 (define-module (scm output-gnome))
86 (define this-module (current-module))
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 (char->utf8-string font char)
170 (list->string (utf8 (char->unicode-index font char))))
172 (define (string->utf8-string font string)
175 (map (lambda (x) (char->utf8-string font x)) (string->list string))))
177 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
178 ;;; stencil outputters
181 ;;; catch-all for missing stuff
182 ;;; comment this out to see find out what functions you miss :-)
183 (define (dummy . foo) #f)
184 (map (lambda (x) (module-define! this-module x dummy))
186 (ly:all-stencil-expressions)
187 (ly:all-output-backend-commands)))
189 (define (beam width slope thick blot)
190 (define cursor '(0 . 0))
191 (define (rmoveto def x y)
192 (set! cursor (cons (+ x (car cursor)) (+ y (cdr cursor))))
193 (moveto def (car cursor) (cdr cursor)))
194 (define (rlineto def x y)
195 (set! cursor (cons (+ x (car cursor)) (+ y (cdr cursor))))
196 (lineto def (car cursor) (cdr cursor)))
197 (let* ((def (make <gnome-canvas-path-def>))
198 (bezier (make <gnome-canvas-bpath>
199 #:parent (canvas-root)
201 #:outline-color "black"
203 #:join-style 'round))
209 (rmoveto def (/ blot 2) (/ t 2))
210 (rlineto def w (- h))
211 (rlineto def 0 (- t))
212 (rlineto def (- w) h)
215 (set-path-def bezier def)
218 (define (square-beam width slope thick blot)
220 ((def (make <gnome-canvas-path-def>))
221 (y (* (- width) slope))
222 (props (make <gnome-canvas-bpath>
223 #:parent (canvas-root)
225 #:outline-color "black"
231 (lineto def width (- y thick))
232 (lineto def 0 (- thick))
235 (set-path-def props def)
239 (define (bezier-sandwich lst thick)
240 (let* ((def (make <gnome-canvas-path-def>))
241 (bezier (make <gnome-canvas-bpath>
242 #:parent (canvas-root)
244 #:outline-color "black"
246 #:join-style 'round)))
250 ;; FIXME: LST is pre-mangled for direct ps stack usage
254 (moveto def (car (list-ref lst 3)) (- (cdr (list-ref lst 3))))
255 (curveto def (car (list-ref lst 0)) (- (cdr (list-ref lst 0)))
256 (car (list-ref lst 1)) (- (cdr (list-ref lst 1)))
257 (car (list-ref lst 2)) (- (cdr (list-ref lst 2))))
259 (lineto def (car (list-ref lst 7)) (- (cdr (list-ref lst 7))))
260 (curveto def (car (list-ref lst 4)) (- (cdr (list-ref lst 4)))
261 (car (list-ref lst 5)) (- (cdr (list-ref lst 5)))
262 (car (list-ref lst 6)) (- (cdr (list-ref lst 6))))
263 (lineto def (car (list-ref lst 3)) (- (cdr (list-ref lst 3))))
266 (set-path-def bezier def)
269 (define (char font i)
270 (text font (integer->char i)))
273 (define (filledbox breapth width depth height)
274 (make <gnome-canvas-rect>
275 #:parent (canvas-root)
276 #:x1 (- breapth) #:y1 depth #:x2 width #:y2 (- height)
278 #:join-style 'miter))
280 (define (grob-cause grob)
283 ;; WTF is this in every backend?
284 (define (horizontal-line x1 x2 thickness)
285 (filledbox (- x1) (- x2 x1) (* .5 thickness) (* .5 thickness)))
287 (define (placebox x y expr)
288 (debugf "item: ~S\n" expr)
291 ;; FIXME ugly hack to skip #unspecified ...
292 (if (and item (not (eq? item (if #f #f))))
295 (* output-scale (+ (car system-origin) x))
296 (* output-scale (- (car system-origin) y)))
297 (affine-relative item output-scale 0 0 output-scale 0 0)
301 (define (dashed-line thick on off dx dy)
302 (draw-line thick 0 0 dx dy))
304 (define (draw-line thick fx fy tx ty)
306 ((def (make <gnome-canvas-path-def>))
307 (props (make <gnome-canvas-bpath>
308 #:parent (canvas-root)
310 #:outline-color "black"
311 #:width-units thick)))
314 (moveto def fx (- fy))
315 (lineto def tx (- ty))
316 (set-path-def props def)
319 (define (list->offsets accum coords)
322 (cons (cons (car coords) (cadr coords))
323 (list->offsets accum (cddr coords)))))
325 (define (named-glyph font name)
326 (text font (integer->char (ly:font-get-glyph-index font name))))
328 (define (polygon coords blotdiameter)
330 ((def (make <gnome-canvas-path-def>))
331 (props (make <gnome-canvas-bpath>
332 #:parent (canvas-root)
334 #:outline-color "black"
335 #:width-units blotdiameter))
336 (points (list->offsets '() coords))
337 (last-point (car (last-pair points))))
340 (moveto def (car last-point) (cdr last-point))
341 (for-each (lambda (x)
342 (lineto def (car x) (cdr x))
345 (set-path-def props def)
349 (define (round-filled-box breapth width depth height blot-diameter)
350 (let ((r (/ blot-diameter 2)))
351 (make <gnome-canvas-rect>
352 #:parent (canvas-root)
353 #:x1 (- r breapth) #:y1 (- depth r) #:x2 (- width r) #:y2 (- r height)
355 #:outline-color "black"
356 #:width-units blot-diameter
357 #:join-style 'round)))
359 (define (text font s)
360 (define (pango-font-name font)
363 (define (pango-font-size font)
364 (let* ((designsize (ly:font-design-size font))
365 (magnification (* (ly:font-magnification font)))
367 ;;font-name: "GNU-LilyPond-feta-20"
368 ;;font-file-name: "feta20"
369 ;;pango-font-name: "lilypond-feta, regular 32"
371 ;;scaling:29.7046771653543
372 ;;magnification:0.569055118110236
375 ;; ugh, experimental sizing
376 ;; where does factor ops come from?
377 ;; Hmm, design size: 26/20
380 (scaling (* ops magnification designsize)))
381 (debugf "OPS:~S\n" ops)
382 (debugf "scaling:~S\n" scaling)
383 (debugf "magnification:~S\n" magnification)
384 (debugf "design:~S\n" designsize)
388 (let ((encoding (ly:font-encoding font)))
389 (make <gnome-canvas-text>
390 #:parent (canvas-root)
391 ;; ugh, experimental placement corections
393 #:x 0.0 #:y (if (memq encoding '(fetaMusic fetaBraces)) 0.15 0.69)
395 #:anchor (if (memq encoding '(fetaMusic fetaBraces)) 'west 'south-west)
396 #:font (pango-font-name font)
397 #:size-points (pango-font-size font)
400 (char->utf8-string font s)
401 (string->utf8-string font s)))))