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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
97 (define system-origin '(0 . 0))
99 ;;; set by framework-gnome.scm
100 (define canvas-root #f)
101 (define output-scale #f)
104 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
107 (define (stderr string . rest)
111 (apply format (cons (current-error-port) (cons string rest)))
112 (force-output (current-error-port)))))
116 ((< i #x80) (list (integer->char i)))
117 ((< i #x800) (map integer->char
118 (list (+ #xc0 (quotient i #x40))
119 (+ #x80 (modulo i #x40)))))
121 (let ((x (quotient i #x1000))
122 (y (modulo i #x1000)))
125 (+ #x80 (quotient y #x40))
126 (+ #x80 (modulo y #x40))))))
129 (define (custom-utf8 i)
132 (utf8 (+ #xee00 i))))
134 (define (string->utf8-string string)
136 (apply append (map utf8 (map char->integer (string->list string))))))
138 (define (char->utf8-string char)
139 (list->string (utf8 (char->integer char))))
141 (define (draw-rectangle x1 y1 x2 y2 color width-units)
142 (make <gnome-canvas-rect>
143 #:parent (canvas-root) #:x1 x1 #:y1 y1 #:x2 x2 #:y2 y2
144 #:fill-color color #:width-units width-units))
147 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
148 ;;; stencil outputters
151 ;;; catch-all for missing stuff
152 ;;; comment this out to see find out what functions you miss :-)
153 (define (dummy . foo) #f)
154 (map (lambda (x) (module-define! this-module x dummy))
156 (ly:all-stencil-expressions)
157 (ly:all-output-backend-commands)))
161 (define (char font i)
162 (text font (utf8 i)))
164 (define (placebox x y expr)
165 (stderr "item: ~S\n" expr)
168 ;; FIXME ugly hack to skip #unspecified ...
169 (if (and item (not (eq? item (if #f #f))))
172 (* output-scale (+ (car system-origin) x))
173 (* output-scale (- (car system-origin) y)))
174 (affine-relative item output-scale 0 0 output-scale 0 0)
178 (define (round-filled-box breapth width depth height blot-diameter)
179 ;; FIXME: no rounded corners on rectangle...
181 (draw-rectangle (- breapth) depth width (- height) "black" blot-diameter))
183 (define (pango-font-name font)
185 ((equal? (ly:font-name font) "GNU-LilyPond-feta-20")
186 "lilypond-feta, regular 32")
190 ;;(ly:font-name font))))
191 ;;(ly:font-filename font))))
193 (define (pango-font-size font)
194 (let* ((designsize (ly:font-design-size font))
195 (magnification (* (ly:font-magnification font)))
197 ;; experimental sizing:
198 ;; where does factor come from?
200 ;; 0.435 * (12 / 20) = 0.261
201 ;; 2.8346456692913/ 0.261 = 10.86071137659501915708
202 ;;(ops (* 0.435 (/ 12 20) (* output-scale pixels-per-unit)))
206 (scaling (* ops magnification designsize)))
207 (stderr "OPS:~S\n" ops)
208 (stderr "scaling:~S\n" scaling)
209 (stderr "magnification:~S\n" magnification)
210 (stderr "design:~S\n" designsize)
214 ;;font-name: "GNU-LilyPond-feta-20"
215 ;;font-filename: "feta20"
216 ;;pango-font-name: "lilypond-feta, regular 32"
218 ;;scaling:29.7046771653543
219 ;;magnification:0.569055118110236
222 (define (text font string)
223 (stderr "font-name: ~S\n" (ly:font-name font))
224 ;; TODO s/filename/file-name/
225 (stderr "font-filename: ~S\n" (ly:font-filename font))
227 (stderr "pango-font-name: ~S\n" (pango-font-name font))
228 (stderr "pango-font-size: ~S\n" (pango-font-size font))
230 (make <gnome-canvas-text>
231 #:parent (canvas-root)
236 #:font (pango-font-name font)
238 #:size-points (pango-font-size font)
242 ;;apparently no effect :-(
247 #:text (if (string? string)
248 (string->utf8-string string)
249 (char->utf8-string (car string)))))
251 (define (filledbox a b c d)
252 (round-filled-box a b c d 0.001))
254 ;; WTF is this in every backend?
255 (define (horizontal-line x1 x2 thickness)
256 (filledbox (- x1) (- x2 x1) (* .5 thickness) (* .5 thickness)))
258 ;;(define (define-origin file line col)
259 ;; (if (procedure? point-and-click)
260 ;; (list 'location line col file)))
262 (define (grob-cause grob)