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:
45 <dir>~/cvs/savannah/lilypond/mf/out</dir>
48 ;;; or copy all your .pfa/.pfb's to ~/.fonts if your fontconfig
49 ;;; already looks there for fonts
51 ;;; * Setup environment
53 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
54 export LD_LIBRARY_PATH=$HOME/usr/pkg/pango/lib:$HOME/usr/pkg/g-wrap/lib:$HOME/usr/pkg/guile-gnome/lib:$LD_LIBRARY_PATH
55 export XEDITOR='/usr/bin/emacsclient --no-wait +%l:%c %f'
57 ;;; * Also for GNOME point-and-click, you need to set XEDITOR and add
59 #(ly:set-point-and-click 'line-column)
65 lilypond -fgnome input/simple-song.ly
67 ;;; point-and-click: (mouse-1) click on a graphical object;
68 ;;; grob-property-list: (mouse-3) click on a graphical object.
70 (debug-enable 'backtrace)
72 (define-module (scm output-gnome))
73 (define this-module (current-module))
82 ;; The name of the module will change to `canvas' rsn
83 (if (resolve-module '(gnome gw canvas))
84 (use-modules (gnome gw canvas))
85 (use-modules (gnome gw libgnomecanvas)))
88 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
92 (define system-origin '(0 . 0))
94 ;;; set by framework-gnome.scm
95 (define canvas-root #f)
96 (define output-scale #f)
99 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
102 (define (stderr string . rest)
106 (apply format (cons (current-error-port) (cons string rest)))
107 (force-output (current-error-port)))))
111 ((< i #x80) (make-string 1 (integer->char i)))
112 ((< i #x800) (list->string
114 (list (+ #xc0 (quotient i #x40))
115 (+ #x80 (modulo i #x40))))))
117 (let ((x (quotient i #x1000))
118 (y (modulo i #x1000)))
122 (+ #x80 (quotient y #x40))
123 (+ #x80 (modulo y #x40)))))))
126 (define (custom-utf8 i)
129 (utf8 (+ #xee00 i))))
131 (define (draw-rectangle x1 y1 x2 y2 color width-units)
132 (make <gnome-canvas-rect>
133 #:parent (canvas-root) #:x1 x1 #:y1 y1 #:x2 x2 #:y2 y2
134 #:fill-color color #:width-units width-units))
137 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
138 ;;; stencil outputters
141 ;;; catch-all for missing stuff
142 ;;; comment this out to see find out what functions you miss :-)
143 (define (dummy . foo) #f)
144 (map (lambda (x) (module-define! this-module x dummy))
146 (ly:all-stencil-expressions)
147 (ly:all-output-backend-commands)))
151 (define (char font i)
152 (text font (utf8 i)))
154 (define (placebox x y expr)
155 (stderr "item: ~S\n" expr)
158 ;; FIXME ugly hack to skip #unspecified ...
159 (if (and item (not (eq? item (if #f #f))))
162 (* output-scale (+ (car system-origin) x))
163 (* output-scale (- (car system-origin) y)))
164 (affine-relative item output-scale 0 0 output-scale 0 0)
168 (define (round-filled-box breapth width depth height blot-diameter)
169 ;; FIXME: no rounded corners on rectangle...
171 (draw-rectangle (- breapth) depth width (- height) "black" blot-diameter))
173 (define (pango-font-name font)
175 ((equal? (ly:font-name font) "GNU-LilyPond-feta-20")
176 "lilypond-feta, regular 32")
180 ;;(ly:font-name font))))
181 ;;(ly:font-filename font))))
183 (define (pango-font-size font)
184 (let* ((designsize (ly:font-design-size font))
185 (magnification (* (ly:font-magnification font)))
187 ;; experimental sizing:
188 ;; where does factor come from?
190 ;; 0.435 * (12 / 20) = 0.261
191 ;; 2.8346456692913/ 0.261 = 10.86071137659501915708
192 ;;(ops (* 0.435 (/ 12 20) (* output-scale pixels-per-unit)))
196 (scaling (* ops magnification designsize)))
197 (stderr "OPS:~S\n" ops)
198 (stderr "scaling:~S\n" scaling)
199 (stderr "magnification:~S\n" magnification)
200 (stderr "design:~S\n" designsize)
204 ;;font-name: "GNU-LilyPond-feta-20"
205 ;;font-filename: "feta20"
206 ;;pango-font-name: "lilypond-feta, regular 32"
208 ;;scaling:29.7046771653543
209 ;;magnification:0.569055118110236
212 (define (text font string)
213 (stderr "font-name: ~S\n" (ly:font-name font))
214 ;; TODO s/filename/file-name/
215 (stderr "font-filename: ~S\n" (ly:font-filename font))
217 (stderr "pango-font-name: ~S\n" (pango-font-name font))
218 (stderr "pango-font-size: ~S\n" (pango-font-size font))
220 (make <gnome-canvas-text>
221 #:parent (canvas-root)
226 #:font (pango-font-name font)
228 #:size-points (pango-font-size font)
232 ;;apparently no effect :-(
239 (define (filledbox a b c d)
240 (round-filled-box a b c d 0.001))
242 ;; WTF is this in every backend?
243 (define (horizontal-line x1 x2 thickness)
244 (filledbox (- x1) (- x2 x1) (* .5 thickness) (* .5 thickness)))
246 ;;(define (define-origin file line col)
247 ;; (if (procedure? point-and-click)
248 ;; (list 'location line col file)))
250 (define (grob-cause grob)