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>
47 <dir>/usr/share/texmf/fonts/type1/public/ec-fonts-mftraced</dir>
51 ;;; or copy all your .pfa/.pfb's to ~/.fonts if your fontconfig
52 ;;; already looks there for fonts. Check if it works by doing:
54 fc-list | grep -i lily
57 ;;; * Setup environment
59 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
60 export LD_LIBRARY_PATH=$HOME/usr/pkg/pango/lib:$HOME/usr/pkg/g-wrap/lib:$HOME/usr/pkg/guile-gnome/lib:$LD_LIBRARY_PATH
61 export XEDITOR='/usr/bin/emacsclient --no-wait +%l:%c %f'
63 ;;; * Also for GNOME point-and-click, you need to set XEDITOR and add
65 #(ly:set-point-and-click 'line-column)
71 lilypond -fgnome input/simple-song.ly
73 ;;; point-and-click: (mouse-1) click on a graphical object;
74 ;;; grob-property-list: (mouse-3) click on a graphical object.
76 (debug-enable 'backtrace)
78 (define-module (scm output-gnome))
79 (define this-module (current-module))
89 ;; The name of the module will change to `canvas' rsn
90 (if (resolve-module '(gnome gw canvas))
91 (use-modules (gnome gw canvas))
92 (use-modules (gnome gw libgnomecanvas)))
95 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
96 ;;; Wrappers from guile-gnome TLA
97 ;;; guile-gnome-devel@gnu.org--2004
98 ;;; http://arch.gna.org/guile-gnome/archive-2004
100 ;;; janneke@gnu.org--2004-gnome
101 ;;; http://lilypond.org/~janneke/{arch}/2004-gnome
103 (if (not (defined? '<gnome-canvas-path-def>))
105 (define-class <gnome-canvas-path-def> (<gobject>)
106 (closure #:init-value (gnome-canvas-path-def-new)
107 #:init-keyword #:path-def
108 #:getter get-def #:setter set-def))
110 (define-method (moveto (this <gnome-canvas-path-def>) x y)
111 (gnome-canvas-path-def-moveto (get-def this) x y))
112 (define-method (curveto (this <gnome-canvas-path-def>) x1 y1 x2 y2 x3 y3)
113 (gnome-canvas-path-def-curveto (get-def this) x1 y1 x2 y2 x3 y3))
114 (define-method (lineto (this <gnome-canvas-path-def>) x y)
115 (gnome-canvas-path-def-lineto (get-def this) x y))
116 (define-method (closepath (this <gnome-canvas-path-def>))
117 (gnome-canvas-path-def-closepath (get-def this)))
118 (define-method (reset (this <gnome-canvas-path-def>))
119 (gnome-canvas-path-def-reset (get-def this)))
121 (define -set-path-def set-path-def)
122 (define -get-path-def get-path-def)
124 (define-method (set-path-def (this <gnome-canvas-shape>)
125 (def <gnome-canvas-path-def>))
126 (-set-path-def this (get-def def)))
128 (define-method (get-path-def (this <gnome-canvas-shape>))
129 (make <gnome-canvas-path-def> #:path-def (-get-path-def this)))))
131 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
135 (define system-origin '(0 . 0))
137 ;;; set by framework-gnome.scm
138 (define canvas-root #f)
139 (define output-scale #f)
142 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
145 (define (stderr string . rest)
146 (apply format (cons (current-error-port) (cons string rest)))
147 (force-output (current-error-port)))
149 (define (debugf string . rest)
151 (apply stderr (cons string rest))))
155 ((< i #x80) (list (integer->char i)))
156 ((< i #x800) (map integer->char
157 (list (+ #xc0 (quotient i #x40))
158 (+ #x80 (modulo i #x40)))))
160 (let ((x (quotient i #x1000))
161 (y (modulo i #x1000)))
164 (+ #x80 (quotient y #x40))
165 (+ #x80 (modulo y #x40))))))
168 (define (custom-utf8 i)
171 (utf8 (+ #xee00 i))))
173 (define (string->utf8-string string)
175 (apply append (map utf8 (map char->integer (string->list string))))))
177 (define (char->utf8-string char)
178 (list->string (utf8 (char->integer char))))
180 (define (draw-rectangle x1 y1 x2 y2 color width-units)
181 (make <gnome-canvas-rect>
182 #:parent (canvas-root) #:x1 x1 #:y1 y1 #:x2 x2 #:y2 y2
183 #:fill-color color #:width-units width-units))
186 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
187 ;;; stencil outputters
190 ;;; catch-all for missing stuff
191 ;;; comment this out to see find out what functions you miss :-)
192 (define (dummy . foo) #f)
193 (map (lambda (x) (module-define! this-module x dummy))
195 (ly:all-stencil-expressions)
196 (ly:all-output-backend-commands)))
199 (define (bezier-sandwich lst thick)
200 (let* ((def (make <gnome-canvas-path-def>))
201 (bezier (make <gnome-canvas-bpath>
202 #:parent (canvas-root)
204 #:outline-color "black"
205 #:width-units thick)))
212 (moveto def (car (list-ref lst 3)) (- (cdr (list-ref lst 3))))
213 (curveto def (car (list-ref lst 0)) (- (cdr (list-ref lst 0)))
214 (car (list-ref lst 1)) (- (cdr (list-ref lst 1)))
215 (car (list-ref lst 2)) (- (cdr (list-ref lst 2))))
217 (lineto def (car (list-ref lst 7)) (- (cdr (list-ref lst 7))))
218 (curveto def (car (list-ref lst 4)) (- (cdr (list-ref lst 4)))
219 (car (list-ref lst 5)) (- (cdr (list-ref lst 5)))
220 (car (list-ref lst 6)) (- (cdr (list-ref lst 6))))
221 (lineto def (car (list-ref lst 3)) (- (cdr (list-ref lst 3))))
224 (set-path-def bezier def)
227 (define (char font i)
228 (text font (utf8 i)))
230 (define (placebox x y expr)
231 (debugf "item: ~S\n" expr)
234 ;; FIXME ugly hack to skip #unspecified ...
235 (if (and item (not (eq? item (if #f #f))))
238 (* output-scale (+ (car system-origin) x))
239 (* output-scale (- (car system-origin) y)))
240 (affine-relative item output-scale 0 0 output-scale 0 0)
244 (define (round-filled-box breapth width depth height blot-diameter)
245 ;; FIXME: no rounded corners on rectangle...
247 (draw-rectangle (- breapth) depth width (- height) "black" blot-diameter))
249 (define (pango-font-name font)
250 (let ((name (ly:font-name font)))
252 (regexp-substitute/global #f "^GNU-(.*)-[.0-9]*$" name 'pre 1 'post)
254 (stderr "font-name: ~S\n" (ly:font-name font))
255 ;; TODO s/filename/file-name/
256 (stderr "font-filename: ~S\n" (ly:font-filename font))
257 (stderr "pango-font-size: ~S\n" (pango-font-size font))
260 (define (pango-font-size font)
261 (let* ((designsize (ly:font-design-size font))
262 (magnification (* (ly:font-magnification font)))
264 ;; experimental sizing:
265 ;; where does factor come from?
267 ;; 0.435 * (12 / 20) = 0.261
268 ;; 2.8346456692913/ 0.261 = 10.86071137659501915708
269 ;;(ops (* 0.435 (/ 12 20) (* output-scale pixels-per-unit)))
273 (scaling (* ops magnification designsize)))
274 (debugf "OPS:~S\n" ops)
275 (debugf "scaling:~S\n" scaling)
276 (debugf "magnification:~S\n" magnification)
277 (debugf "design:~S\n" designsize)
281 ;;font-name: "GNU-LilyPond-feta-20"
282 ;;font-filename: "feta20"
283 ;;pango-font-name: "lilypond-feta, regular 32"
285 ;;scaling:29.7046771653543
286 ;;magnification:0.569055118110236
289 (define (text font string)
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)