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
32 ;;; * Install gnome/gtk development stuff
34 ;;; * Install g-wrap and guile-gnome, see buildscripts/guile-gnome.sh
36 ;;; * Setup environment
38 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
39 export LD_LIBRARY_PATH=$HOME/usr/pkg/g-wrap/lib:$HOME/usr/pkg/guile-gnome/lib
40 export XEDITOR='/usr/bin/emacsclient --no-wait +%l:%c %f'
42 ;;; * Also for GNOME point-and-click, you need to set XEDITOR and add
44 #(ly:set-point-and-click 'line-column)
46 ;;; to your .ly; then click an object on the canvas.
50 lilypond-bin -fgnome input/simple-song.ly
54 (debug-enable 'backtrace)
56 (define-module (scm output-gnome))
57 (define this-module (current-module))
66 ;; The name of the module will change to `canvas' rsn
67 (if (resolve-module '(gnome gw canvas))
68 (use-modules (gnome gw canvas))
69 (use-modules (gnome gw libgnomecanvas)))
72 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
76 (define system-origin '(0 . 0))
78 ;;; set by framework-gnome.scm
79 (define canvas-root #f)
80 (define output-scale #f)
83 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
86 (define (stderr string . rest)
90 (apply format (cons (current-error-port) (cons string rest)))
91 (force-output (current-error-port)))))
95 ((< i #x80) (make-string 1 (integer->char i)))
96 ((< i #x800) (list->string
98 (list (+ #xc0 (quotient i #x40))
99 (+ #x80 (modulo i #x40))))))
101 (let ((x (quotient i #x1000))
102 (y (modulo i #x1000)))
106 (+ #x80 (quotient y #x40))
107 (+ #x80 (modulo y #x40)))))))
110 (define (custom-utf8 i)
113 (utf8 (+ #xee00 i))))
115 (define (draw-rectangle x1 y1 x2 y2 color width-units)
116 (make <gnome-canvas-rect>
117 #:parent (canvas-root) #:x1 x1 #:y1 y1 #:x2 x2 #:y2 y2
118 #:fill-color color #:width-units width-units))
121 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
122 ;;; stencil outputters
125 ;;; catch-all for missing stuff
126 ;;; comment this out to see find out what functions you miss :-)
127 (define (dummy . foo) #f)
128 (map (lambda (x) (module-define! this-module x dummy))
130 (ly:all-stencil-expressions)
131 (ly:all-output-backend-commands)))
135 (define (char font i)
136 (text font (utf8 i)))
138 (define (placebox x y expr)
139 (stderr "item: ~S\n" expr)
142 ;; FIXME ugly hack to skip #unspecified ...
143 (if (and item (not (eq? item (if #f #f))))
146 (* output-scale (+ (car system-origin) x))
147 (* output-scale (- (car system-origin) y)))
148 (affine-relative item output-scale 0 0 output-scale 0 0)
152 (define (round-filled-box breapth width depth height blot-diameter)
153 ;; FIXME: no rounded corners on rectangle...
155 (draw-rectangle (- breapth) depth width (- height) "black" blot-diameter))
157 (define (pango-font-name font)
159 ((equal? (ly:font-name font) "GNU-LilyPond-feta-20")
160 "lilypond-feta, regular 32")
164 ;;(ly:font-name font))))
165 ;;(ly:font-filename font))))
167 (define (pango-font-size font)
168 (let* ((designsize (ly:font-design-size font))
169 (magnification (* (ly:font-magnification font)))
171 ;; experimental sizing:
172 ;; where does factor come from?
174 ;; 0.435 * (12 / 20) = 0.261
175 ;; 2.8346456692913/ 0.261 = 10.86071137659501915708
176 ;;(ops (* 0.435 (/ 12 20) (* output-scale pixels-per-unit)))
180 (scaling (* ops magnification designsize)))
181 (stderr "OPS:~S\n" ops)
182 (stderr "scaling:~S\n" scaling)
183 (stderr "magnification:~S\n" magnification)
184 (stderr "design:~S\n" designsize)
188 ;;font-name: "GNU-LilyPond-feta-20"
189 ;;font-filename: "feta20"
190 ;;pango-font-name: "lilypond-feta, regular 32"
192 ;;scaling:29.7046771653543
193 ;;magnification:0.569055118110236
196 (define (text font string)
197 (stderr "font-name: ~S\n" (ly:font-name font))
198 ;; TODO s/filename/file-name/
199 (stderr "font-filename: ~S\n" (ly:font-filename font))
201 (stderr "pango-font-name: ~S\n" (pango-font-name font))
202 (stderr "pango-font-size: ~S\n" (pango-font-size font))
204 (make <gnome-canvas-text>
205 #:parent (canvas-root)
207 ;; experimental text placement corrections.
208 ;; UGHR? What happened to tex offsets? south-west?
209 ;; is pango doing something 'smart' wrt baseline ?
214 ;;#:x 0.015 #:y -3.71
216 #:font (pango-font-name font)
218 #:size-points (pango-font-size font)
222 ;;apparently no effect :-(
229 (define (filledbox a b c d)
230 (round-filled-box a b c d 0.001))
232 ;; WTF is this in every backend?
233 (define (horizontal-line x1 x2 thickness)
234 (filledbox (- x1) (- x2 x1) (* .5 thickness) (* .5 thickness)))
236 ;;(define (define-origin file line col)
237 ;; (if (procedure? point-and-click)
238 ;; (list 'location line col file)))
240 (define (grob-cause grob)