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--tng TLA, possibly Janneke's if you have libffi-3.4.
26 ;;; * pango CVS (ie, > 2004-06-12)
28 ;;; See also: guile-gtk-general@gnu.org
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/lilypond, tell X about
44 ln -s ~/cvs/lilypond/mf/out ~/.fonts
49 ;;; * Setup environment
51 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
52 export LD_LIBRARY_PATH=$HOME/usr/pkg/pango/lib:$HOME/usr/pkg/g-wrap/lib:$HOME/usr/pkg/guile-gnome/lib:$LD_LIBRARY_PATH
53 export XEDITOR='/usr/bin/emacsclient --no-wait +%l:%c %f'
55 ;;; * Also for GNOME point-and-click, you need to set XEDITOR and add
57 #(ly:set-point-and-click 'line-column)
63 lilypond-bin -fgnome input/simple-song.ly
65 ;;; point-and-click: (mouse-1) click on a graphical object;
66 ;;; grob-property-list: (mouse-3) click on a graphical object.
68 (debug-enable 'backtrace)
70 (define-module (scm output-gnome))
71 (define this-module (current-module))
80 ;; The name of the module will change to `canvas' rsn
81 (if (resolve-module '(gnome gw canvas))
82 (use-modules (gnome gw canvas))
83 (use-modules (gnome gw libgnomecanvas)))
86 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
90 (define system-origin '(0 . 0))
92 ;;; set by framework-gnome.scm
93 (define canvas-root #f)
94 (define output-scale #f)
97 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
100 (define (stderr string . rest)
104 (apply format (cons (current-error-port) (cons string rest)))
105 (force-output (current-error-port)))))
109 ((< i #x80) (make-string 1 (integer->char i)))
110 ((< i #x800) (list->string
112 (list (+ #xc0 (quotient i #x40))
113 (+ #x80 (modulo i #x40))))))
115 (let ((x (quotient i #x1000))
116 (y (modulo i #x1000)))
120 (+ #x80 (quotient y #x40))
121 (+ #x80 (modulo y #x40)))))))
124 (define (custom-utf8 i)
127 (utf8 (+ #xee00 i))))
129 (define (draw-rectangle x1 y1 x2 y2 color width-units)
130 (make <gnome-canvas-rect>
131 #:parent (canvas-root) #:x1 x1 #:y1 y1 #:x2 x2 #:y2 y2
132 #:fill-color color #:width-units width-units))
135 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
136 ;;; stencil outputters
139 ;;; catch-all for missing stuff
140 ;;; comment this out to see find out what functions you miss :-)
141 (define (dummy . foo) #f)
142 (map (lambda (x) (module-define! this-module x dummy))
144 (ly:all-stencil-expressions)
145 (ly:all-output-backend-commands)))
149 (define (char font i)
150 (text font (utf8 i)))
152 (define (placebox x y expr)
153 (stderr "item: ~S\n" expr)
156 ;; FIXME ugly hack to skip #unspecified ...
157 (if (and item (not (eq? item (if #f #f))))
160 (* output-scale (+ (car system-origin) x))
161 (* output-scale (- (car system-origin) y)))
162 (affine-relative item output-scale 0 0 output-scale 0 0)
166 (define (round-filled-box breapth width depth height blot-diameter)
167 ;; FIXME: no rounded corners on rectangle...
169 (draw-rectangle (- breapth) depth width (- height) "black" blot-diameter))
171 (define (pango-font-name font)
173 ((equal? (ly:font-name font) "GNU-LilyPond-feta-20")
174 "lilypond-feta, regular 32")
178 ;;(ly:font-name font))))
179 ;;(ly:font-filename font))))
181 (define (pango-font-size font)
182 (let* ((designsize (ly:font-design-size font))
183 (magnification (* (ly:font-magnification font)))
185 ;; experimental sizing:
186 ;; where does factor come from?
188 ;; 0.435 * (12 / 20) = 0.261
189 ;; 2.8346456692913/ 0.261 = 10.86071137659501915708
190 ;;(ops (* 0.435 (/ 12 20) (* output-scale pixels-per-unit)))
194 (scaling (* ops magnification designsize)))
195 (stderr "OPS:~S\n" ops)
196 (stderr "scaling:~S\n" scaling)
197 (stderr "magnification:~S\n" magnification)
198 (stderr "design:~S\n" designsize)
202 ;;font-name: "GNU-LilyPond-feta-20"
203 ;;font-filename: "feta20"
204 ;;pango-font-name: "lilypond-feta, regular 32"
206 ;;scaling:29.7046771653543
207 ;;magnification:0.569055118110236
210 (define (text font string)
211 (stderr "font-name: ~S\n" (ly:font-name font))
212 ;; TODO s/filename/file-name/
213 (stderr "font-filename: ~S\n" (ly:font-filename font))
215 (stderr "pango-font-name: ~S\n" (pango-font-name font))
216 (stderr "pango-font-size: ~S\n" (pango-font-size font))
218 (make <gnome-canvas-text>
219 #:parent (canvas-root)
221 ;; experimental text placement corrections.
222 ;; UGHR? What happened to tex offsets? south-west?
223 ;; is pango doing something 'smart' wrt baseline ?
228 ;;#:x 0.015 #:y -3.71
230 #:font (pango-font-name font)
232 #:size-points (pango-font-size font)
236 ;;apparently no effect :-(
243 (define (filledbox a b c d)
244 (round-filled-box a b c d 0.001))
246 ;; WTF is this in every backend?
247 (define (horizontal-line x1 x2 thickness)
248 (filledbox (- x1) (- x2 x1) (* .5 thickness) (* .5 thickness)))
250 ;;(define (define-origin file line col)
251 ;; (if (procedure? point-and-click)
252 ;; (list 'location line col file)))
254 (define (grob-cause grob)