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 ;;; * guile-1.6.4 (NOT CVS -- we are working on this)
25 ;;; * Rotty's g-wrap--tng TLA, possibly Janneke's if you have libffi-3.4.
27 ;;; * pango CVS (ie, > 2004-06-12)
29 ;;; See also: guile-gtk-general@gnu.org
33 ;;; * If you are using GUILE CVS, recompile LilyPond with GUILE 1.6.
35 ;;; [If for some unknown or funny reason you do not want to
36 ;;; overwrite your lilypond-bin with GUILE CVS, you can
37 ;;; reconfigure a new configuration, say g16:
39 PATH=/usr/bin/:$PATH ./configure --enable-config=g16 && make conf=g16
43 ;;; * Install gnome/gtk development stuff
45 ;;; * Install g-wrap and guile-gnome, see buildscripts/guile-gnome.sh
47 ;;; * Setup environment
49 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
50 export LD_LIBRARY_PATH=$HOME/usr/pkg/g-wrap/lib:$HOME/usr/pkg/guile-gnome/lib
51 export XEDITOR='/usr/bin/emacsclient --no-wait +%l:%c %f'
53 ;;; * Also for GNOME point-and-click, you need to set XEDITOR and add
55 #(ly:set-point-and-click 'line-column)
57 ;;; to your .ly; then click an object on the canvas.
61 lilypond-bin -fgnome input/simple-song.ly
65 (debug-enable 'backtrace)
67 (define-module (scm output-gnome))
68 (define this-module (current-module))
77 ;; The name of the module will change to `canvas' rsn
78 (if (resolve-module '(gnome gw canvas))
79 (use-modules (gnome gw canvas))
80 (use-modules (gnome gw libgnomecanvas)))
83 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
87 (define system-origin '(0 . 0))
89 ;;; set by framework-gnome.scm
90 (define canvas-root #f)
91 (define output-scale #f)
94 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
97 (define (stderr string . rest)
101 (apply format (cons (current-error-port) (cons string rest)))
102 (force-output (current-error-port)))))
106 ((< i #x80) (make-string 1 (integer->char i)))
107 ((< i #x800) (list->string
109 (list (+ #xc0 (quotient i #x40))
110 (+ #x80 (modulo i #x40))))))
112 (let ((x (quotient i #x1000))
113 (y (modulo i #x1000)))
117 (+ #x80 (quotient y #x40))
118 (+ #x80 (modulo y #x40)))))))
121 (define (custom-utf8 i)
124 (utf8 (+ #xee00 i))))
126 (define (draw-rectangle x1 y1 x2 y2 color width-units)
127 (make <gnome-canvas-rect>
128 #:parent (canvas-root) #:x1 x1 #:y1 y1 #:x2 x2 #:y2 y2
129 #:fill-color color #:width-units width-units))
132 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
133 ;;; stencil outputters
136 ;;; catch-all for missing stuff
137 ;;; comment this out to see find out what functions you miss :-)
138 (define (dummy . foo) #f)
139 (map (lambda (x) (module-define! this-module x dummy))
141 (ly:all-stencil-expressions)
142 (ly:all-output-backend-commands)))
146 (define (char font i)
147 (text font (utf8 i)))
149 (define (placebox x y expr)
150 (stderr "item: ~S\n" expr)
153 ;; FIXME ugly hack to skip #unspecified ...
154 (if (and item (not (eq? item (if #f #f))))
157 (* output-scale (+ (car system-origin) x))
158 (* output-scale (- (car system-origin) y)))
159 (affine-relative item output-scale 0 0 output-scale 0 0)
163 (define (round-filled-box breapth width depth height blot-diameter)
164 ;; FIXME: no rounded corners on rectangle...
166 (draw-rectangle (- breapth) depth width (- height) "black" blot-diameter))
168 (define (pango-font-name font)
170 ((equal? (ly:font-name font) "GNU-LilyPond-feta-20")
171 "lilypond-feta, regular 32")
175 ;;(ly:font-name font))))
176 ;;(ly:font-filename font))))
178 (define (pango-font-size font)
179 (let* ((designsize (ly:font-design-size font))
180 (magnification (* (ly:font-magnification font)))
182 ;; experimental sizing:
183 ;; where does factor come from?
185 ;; 0.435 * (12 / 20) = 0.261
186 ;; 2.8346456692913/ 0.261 = 10.86071137659501915708
187 ;;(ops (* 0.435 (/ 12 20) (* output-scale pixels-per-unit)))
191 (scaling (* ops magnification designsize)))
192 (stderr "OPS:~S\n" ops)
193 (stderr "scaling:~S\n" scaling)
194 (stderr "magnification:~S\n" magnification)
195 (stderr "design:~S\n" designsize)
199 ;;font-name: "GNU-LilyPond-feta-20"
200 ;;font-filename: "feta20"
201 ;;pango-font-name: "lilypond-feta, regular 32"
203 ;;scaling:29.7046771653543
204 ;;magnification:0.569055118110236
207 (define (text font string)
208 (stderr "font-name: ~S\n" (ly:font-name font))
209 ;; TODO s/filename/file-name/
210 (stderr "font-filename: ~S\n" (ly:font-filename font))
212 (stderr "pango-font-name: ~S\n" (pango-font-name font))
213 (stderr "pango-font-size: ~S\n" (pango-font-size font))
215 (make <gnome-canvas-text>
216 #:parent (canvas-root)
218 ;; experimental text placement corrections.
219 ;; UGHR? What happened to tex offsets? south-west?
220 ;; is pango doing something 'smart' wrt baseline ?
225 ;;#:x 0.015 #:y -3.71
227 #:font (pango-font-name font)
229 #:size-points (pango-font-size font)
233 ;;apparently no effect :-(
240 (define (filledbox a b c d)
241 (round-filled-box a b c d 0.001))
243 ;; WTF is this in every backend?
244 (define (horizontal-line x1 x2 thickness)
245 (filledbox (- x1) (- x2 x1) (* .5 thickness) (* .5 thickness)))
247 (define (define-origin file line col)
248 (if (procedure? point-and-click)
249 (list 'location line col file)))