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:
44 cat > ~/.fonts.conf << EOF
46 <dir>~/cvs/savannah/lilypond/mf/out</dir>
50 ;;; or copy all your .pfa/.pfb's to ~/.fonts if your fontconfig
51 ;;; already looks there for fonts. Check if it works by doing:
53 fc-list | grep -i lily
56 ;;; * Setup environment
58 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
59 export LD_LIBRARY_PATH=$HOME/usr/pkg/pango/lib:$HOME/usr/pkg/g-wrap/lib:$HOME/usr/pkg/guile-gnome/lib:$LD_LIBRARY_PATH
60 export XEDITOR='/usr/bin/emacsclient --no-wait +%l:%c %f'
62 ;;; * Also for GNOME point-and-click, you need to set XEDITOR and add
64 #(ly:set-point-and-click 'line-column)
70 lilypond -fgnome input/simple-song.ly
72 ;;; point-and-click: (mouse-1) click on a graphical object;
73 ;;; grob-property-list: (mouse-3) click on a graphical object.
75 (debug-enable 'backtrace)
77 (define-module (scm output-gnome))
78 (define this-module (current-module))
87 ;; The name of the module will change to `canvas' rsn
88 (if (resolve-module '(gnome gw canvas))
89 (use-modules (gnome gw canvas))
90 (use-modules (gnome gw libgnomecanvas)))
93 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
94 ;;; Wrappers from guile-gnome TLA
95 ;;; guile-gnome-devel@gnu.org--2004
96 ;;; http://arch.gna.org/guile-gnome/archive-2004
98 ;;; janneke@gnu.org--2004-gnome
99 ;;; http://lilypond.org/~janneke/{arch}/2004-gnome
101 (if (not (defined? '<gnome-canvas-path-def>))
103 (define-class <gnome-canvas-path-def> (<gobject>)
104 (closure #:init-value (gnome-canvas-path-def-new)
105 #:init-keyword #:path-def
106 #:getter get-def #:setter set-def))
108 (define-method (moveto (this <gnome-canvas-path-def>) x y)
109 (gnome-canvas-path-def-moveto (get-def this) x y))
110 (define-method (curveto (this <gnome-canvas-path-def>) x1 y1 x2 y2 x3 y3)
111 (gnome-canvas-path-def-curveto (get-def this) x1 y1 x2 y2 x3 y3))
112 (define-method (lineto (this <gnome-canvas-path-def>) x y)
113 (gnome-canvas-path-def-lineto (get-def this) x y))
114 (define-method (closepath (this <gnome-canvas-path-def>))
115 (gnome-canvas-path-def-closepath (get-def this)))
117 (define -set-path-def set-path-def)
118 (define -get-path-def get-path-def)
120 (define-method (set-path-def (this <gnome-canvas-shape>)
121 (def <gnome-canvas-path-def>))
122 (-set-path-def this (get-def def)))
124 (define-method (get-path-def (this <gnome-canvas-shape>))
125 (make <gnome-canvas-path-def> #:path-def (-get-path-def this)))))
127 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
131 (define system-origin '(0 . 0))
133 ;;; set by framework-gnome.scm
134 (define canvas-root #f)
135 (define output-scale #f)
138 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
141 (define (stderr string . rest)
142 (apply format (cons (current-error-port) (cons string rest)))
143 (force-output (current-error-port)))
145 (define (debugf string . rest)
147 (apply stderr (cons string rest))))
151 ((< i #x80) (list (integer->char i)))
152 ((< i #x800) (map integer->char
153 (list (+ #xc0 (quotient i #x40))
154 (+ #x80 (modulo i #x40)))))
156 (let ((x (quotient i #x1000))
157 (y (modulo i #x1000)))
160 (+ #x80 (quotient y #x40))
161 (+ #x80 (modulo y #x40))))))
164 (define (custom-utf8 i)
167 (utf8 (+ #xee00 i))))
169 (define (string->utf8-string string)
171 (apply append (map utf8 (map char->integer (string->list string))))))
173 (define (char->utf8-string char)
174 (list->string (utf8 (char->integer char))))
176 (define (draw-rectangle x1 y1 x2 y2 color width-units)
177 (make <gnome-canvas-rect>
178 #:parent (canvas-root) #:x1 x1 #:y1 y1 #:x2 x2 #:y2 y2
179 #:fill-color color #:width-units width-units))
182 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
183 ;;; stencil outputters
186 ;;; catch-all for missing stuff
187 ;;; comment this out to see find out what functions you miss :-)
188 (define (dummy . foo) #f)
189 (map (lambda (x) (module-define! this-module x dummy))
191 (ly:all-stencil-expressions)
192 (ly:all-output-backend-commands)))
195 (define (bezier-sandwich lst thick)
196 (let* ((def (make <gnome-canvas-path-def>))
197 (bezier (make <gnome-canvas-bpath>
198 #:parent (canvas-root)
200 #:outline-color "black"
201 #:width-units thick)))
206 (moveto def (car (list-ref lst 3)) (- (cdr (list-ref lst 3))))
207 (curveto def (car (list-ref lst 0)) (- (cdr (list-ref lst 0)))
208 (car (list-ref lst 1)) (- (cdr (list-ref lst 1)))
209 (car (list-ref lst 2)) (- (cdr (list-ref lst 2))))
211 (lineto def (car (list-ref lst 7)) (- (cdr (list-ref lst 7))))
212 (curveto def (car (list-ref lst 4)) (- (cdr (list-ref lst 4)))
213 (car (list-ref lst 5)) (- (cdr (list-ref lst 5)))
214 (car (list-ref lst 6)) (- (cdr (list-ref lst 6))))
215 (lineto def (car (list-ref lst 3)) (- (cdr (list-ref lst 3))))
218 (set-path-def bezier def)
221 (define (char font i)
222 (text font (utf8 i)))
224 (define (placebox x y expr)
225 (debugf "item: ~S\n" expr)
228 ;; FIXME ugly hack to skip #unspecified ...
229 (if (and item (not (eq? item (if #f #f))))
232 (* output-scale (+ (car system-origin) x))
233 (* output-scale (- (car system-origin) y)))
234 (affine-relative item output-scale 0 0 output-scale 0 0)
238 (define (round-filled-box breapth width depth height blot-diameter)
239 ;; FIXME: no rounded corners on rectangle...
241 (draw-rectangle (- breapth) depth width (- height) "black" blot-diameter))
243 (define (pango-font-name font)
245 ((equal? (ly:font-name font) "GNU-LilyPond-feta-20")
246 "lilypond-feta, regular 32")
250 ;;(ly:font-name font))))
251 ;;(ly:font-filename font))))
253 (define (pango-font-size font)
254 (let* ((designsize (ly:font-design-size font))
255 (magnification (* (ly:font-magnification font)))
257 ;; experimental sizing:
258 ;; where does factor come from?
260 ;; 0.435 * (12 / 20) = 0.261
261 ;; 2.8346456692913/ 0.261 = 10.86071137659501915708
262 ;;(ops (* 0.435 (/ 12 20) (* output-scale pixels-per-unit)))
266 (scaling (* ops magnification designsize)))
267 (debugf "OPS:~S\n" ops)
268 (debugf "scaling:~S\n" scaling)
269 (debugf "magnification:~S\n" magnification)
270 (debugf "design:~S\n" designsize)
274 ;;font-name: "GNU-LilyPond-feta-20"
275 ;;font-filename: "feta20"
276 ;;pango-font-name: "lilypond-feta, regular 32"
278 ;;scaling:29.7046771653543
279 ;;magnification:0.569055118110236
282 (define (text font string)
283 (stderr "font-name: ~S\n" (ly:font-name font))
284 ;; TODO s/filename/file-name/
285 (stderr "font-filename: ~S\n" (ly:font-filename font))
287 (stderr "pango-font-name: ~S\n" (pango-font-name font))
288 (stderr "pango-font-size: ~S\n" (pango-font-size font))
290 (make <gnome-canvas-text>
291 #:parent (canvas-root)
296 #:font (pango-font-name font)
298 #:size-points (pango-font-size font)
302 ;;apparently no effect :-(
307 #:text (if (string? string)
308 (string->utf8-string string)
309 (char->utf8-string (car string)))))
311 (define (filledbox a b c d)
312 (round-filled-box a b c d 0.001))
314 ;; WTF is this in every backend?
315 (define (horizontal-line x1 x2 thickness)
316 (filledbox (- x1) (- x2 x1) (* .5 thickness) (* .5 thickness)))
318 ;;(define (define-origin file line col)
319 ;; (if (procedure? point-and-click)
320 ;; (list 'location line col file)))
322 (define (grob-cause grob)