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)))
116 (define-method (reset (this <gnome-canvas-path-def>))
117 (gnome-canvas-path-def-reset (get-def this)))
119 (define -set-path-def set-path-def)
120 (define -get-path-def get-path-def)
122 (define-method (set-path-def (this <gnome-canvas-shape>)
123 (def <gnome-canvas-path-def>))
124 (-set-path-def this (get-def def)))
126 (define-method (get-path-def (this <gnome-canvas-shape>))
127 (make <gnome-canvas-path-def> #:path-def (-get-path-def this)))))
129 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
133 (define system-origin '(0 . 0))
135 ;;; set by framework-gnome.scm
136 (define canvas-root #f)
137 (define output-scale #f)
140 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
143 (define (stderr string . rest)
144 (apply format (cons (current-error-port) (cons string rest)))
145 (force-output (current-error-port)))
147 (define (debugf string . rest)
149 (apply stderr (cons string rest))))
153 ((< i #x80) (list (integer->char i)))
154 ((< i #x800) (map integer->char
155 (list (+ #xc0 (quotient i #x40))
156 (+ #x80 (modulo i #x40)))))
158 (let ((x (quotient i #x1000))
159 (y (modulo i #x1000)))
162 (+ #x80 (quotient y #x40))
163 (+ #x80 (modulo y #x40))))))
166 (define (custom-utf8 i)
169 (utf8 (+ #xee00 i))))
171 (define (string->utf8-string string)
173 (apply append (map utf8 (map char->integer (string->list string))))))
175 (define (char->utf8-string char)
176 (list->string (utf8 (char->integer char))))
178 (define (draw-rectangle x1 y1 x2 y2 color width-units)
179 (make <gnome-canvas-rect>
180 #:parent (canvas-root) #:x1 x1 #:y1 y1 #:x2 x2 #:y2 y2
181 #:fill-color color #:width-units width-units))
184 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
185 ;;; stencil outputters
188 ;;; catch-all for missing stuff
189 ;;; comment this out to see find out what functions you miss :-)
190 (define (dummy . foo) #f)
191 (map (lambda (x) (module-define! this-module x dummy))
193 (ly:all-stencil-expressions)
194 (ly:all-output-backend-commands)))
197 (define (bezier-sandwich lst thick)
198 (let* ((def (make <gnome-canvas-path-def>))
199 (bezier (make <gnome-canvas-bpath>
200 #:parent (canvas-root)
202 #:outline-color "black"
203 #:width-units thick)))
210 (moveto def (car (list-ref lst 3)) (- (cdr (list-ref lst 3))))
211 (curveto def (car (list-ref lst 0)) (- (cdr (list-ref lst 0)))
212 (car (list-ref lst 1)) (- (cdr (list-ref lst 1)))
213 (car (list-ref lst 2)) (- (cdr (list-ref lst 2))))
215 (lineto def (car (list-ref lst 7)) (- (cdr (list-ref lst 7))))
216 (curveto def (car (list-ref lst 4)) (- (cdr (list-ref lst 4)))
217 (car (list-ref lst 5)) (- (cdr (list-ref lst 5)))
218 (car (list-ref lst 6)) (- (cdr (list-ref lst 6))))
219 (lineto def (car (list-ref lst 3)) (- (cdr (list-ref lst 3))))
222 (set-path-def bezier def)
225 (define (char font i)
226 ;;(text font (utf8 i)))
227 (text font (list->string (list (integer->char i))))); (utf8 i)))
229 (define (placebox x y expr)
230 (debugf "item: ~S\n" expr)
233 ;; FIXME ugly hack to skip #unspecified ...
234 (if (and item (not (eq? item (if #f #f))))
237 (* output-scale (+ (car system-origin) x))
238 (* output-scale (- (car system-origin) y)))
239 (affine-relative item output-scale 0 0 output-scale 0 0)
243 (define (round-filled-box breapth width depth height blot-diameter)
244 ;; FIXME: no rounded corners on rectangle...
246 (draw-rectangle (- breapth) depth width (- height) "black" blot-diameter))
248 (define pango-font-name-alist
249 '(("GNU-LilyPond-feta-20" . "lilypond-feta, regular 32")
250 ("GNU-LilyPond-feta-nummer-5.5" . "lilypond-feta-nummer, regular 32")
251 ("GNU-LilyPond-feta-din-14" . "lilypond-feta-din, 25")
252 ("GNU-LilyPond-feta-14.14" . "lilypond-feta, regular 25")
253 ("GNU-LilyPond-feta-12.6" . "lilypond-feta, regular 22")
254 ("GNU-LilyPond-feta-braces-f-90" . "LilyPond-feta-braces-f, 32")
257 (define (pango-font-name font)
258 (let ((pango-font (assoc-get (ly:font-name font) pango-font-name-alist #f)))
262 (stderr "font-name: ~S\n" (ly:font-name font))
263 ;; TODO s/filename/file-name/
264 (stderr "font-filename: ~S\n" (ly:font-filename font))
265 (stderr "pango-font-size: ~S\n" (pango-font-size font))
268 (define (pango-font-size font)
269 (let* ((designsize (ly:font-design-size font))
270 (magnification (* (ly:font-magnification font)))
272 ;; experimental sizing:
273 ;; where does factor come from?
275 ;; 0.435 * (12 / 20) = 0.261
276 ;; 2.8346456692913/ 0.261 = 10.86071137659501915708
277 ;;(ops (* 0.435 (/ 12 20) (* output-scale pixels-per-unit)))
281 (scaling (* ops magnification designsize)))
282 (debugf "OPS:~S\n" ops)
283 (debugf "scaling:~S\n" scaling)
284 (debugf "magnification:~S\n" magnification)
285 (debugf "design:~S\n" designsize)
289 ;;font-name: "GNU-LilyPond-feta-20"
290 ;;font-filename: "feta20"
291 ;;pango-font-name: "lilypond-feta, regular 32"
293 ;;scaling:29.7046771653543
294 ;;magnification:0.569055118110236
297 (define (text font string)
298 (make <gnome-canvas-text>
299 #:parent (canvas-root)
304 #:font (pango-font-name font)
306 #:size-points (pango-font-size font)
310 ;;apparently no effect :-(
315 #:text (if (string? string)
316 (string->utf8-string string)
317 (char->utf8-string (car string)))))
319 (define (filledbox a b c d)
320 (round-filled-box a b c d 0.001))
322 ;; WTF is this in every backend?
323 (define (horizontal-line x1 x2 thickness)
324 (filledbox (- x1) (- x2 x1) (* .5 thickness) (* .5 thickness)))
326 ;;(define (define-origin file line col)
327 ;; (if (procedure? point-and-click)
328 ;; (list 'location line col file)))
330 (define (grob-cause grob)