]> git.donarmstrong.com Git - lilypond.git/blob - scm/output-gnome.scm
Small fixes.
[lilypond.git] / scm / output-gnome.scm
1 ;;;; output-gnome.scm -- implement GNOME canvas output
2 ;;;;
3 ;;;;  source file of the GNU LilyPond music typesetter
4 ;;;; 
5 ;;;; (c)  2004 Jan Nieuwenhuizen <janneke@gnu.org>
6
7 ;;; TODO:
8 ;;;
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.
15 ;;;  * Embedded Lily:
16 ;;;    - allow GnomeCanvas or `toplevel' GtkWindow to be created
17 ;;;      outside of LilyPond
18 ;;;    - lilylib.
19 ;;;  * Release schedule and packaging of dependencies.  This hack
20 ;;;    depends on several CVS and TLA development sources.
21
22 ;;; You need:
23 ;;;
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)
27 ;;;
28 ;;; See also: guile-gtk-general@gnu.org
29
30 ;;; Try it
31 ;;;
32 ;;;   [* Get cvs and tla]
33 ;;;
34 ;;;   * Install gnome/gtk and libffi development stuff
35 ;;;
36 ;;;   * Install pango, g-wrap and guile-gnome from CVS or arch: 
37 ;;;     see buildscripts/guile-gnome.sh
38 ;;;  
39 ;;;   * Build LilyPond with gui support: configure --enable-gui
40 ;;;
41 ;;;   * Supposing that LilyPond was built in ~/cvs/lilypond, tell X about
42 ;;;     feta fonts:
43 "
44 ln -s ~/cvs/lilypond/mf/out ~/.fonts
45 mkfontdir ~/.fonts
46 xset +fp ~/.fonts
47 "
48 ;;;
49 ;;;   * Setup environment
50 "
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'
54 "
55 ;;;  * Also for GNOME point-and-click, you need to set XEDITOR and add
56 "
57 #(ly:set-point-and-click 'line-column)
58 "
59 ;;;    to your .ly.
60 ;;;
61 ;;;  * Run lily:
62 "
63 lilypond-bin -fgnome input/simple-song.ly
64 "
65 ;;; point-and-click: (mouse-1) click on a graphical object;
66 ;;; grob-property-list: (mouse-3) click on a graphical object.
67
68 (debug-enable 'backtrace)
69
70 (define-module (scm output-gnome))
71 (define this-module (current-module))
72
73 (use-modules
74  (guile)
75  (srfi srfi-13)
76  (lily)
77  (gnome gtk))
78
79
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)))
84
85
86 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
87 ;;; globals
88
89 ;; junkme
90 (define system-origin '(0 . 0))
91
92 ;;; set by framework-gnome.scm
93 (define canvas-root #f)
94 (define output-scale #f)
95
96
97 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
98 ;; helper functions
99
100 (define (stderr string . rest)
101   ;; debugging
102   (if #f
103       (begin
104         (apply format (cons (current-error-port) (cons string rest)))
105         (force-output (current-error-port)))))
106
107 (define (utf8 i)
108   (cond
109    ((< i #x80) (make-string 1 (integer->char i)))
110    ((< i #x800) (list->string
111                  (map integer->char
112                       (list (+ #xc0 (quotient i #x40))
113                             (+ #x80 (modulo i #x40))))))
114    ((< i #x10000)
115     (let ((x (quotient i #x1000))
116           (y (modulo i #x1000)))
117       (list->string
118        (map integer->char
119             (list (+ #xe0 x)
120                   (+ #x80 (quotient y #x40))
121                   (+ #x80 (modulo y #x40)))))))
122    (else FIXME)))
123   
124 (define (custom-utf8 i)
125   (if (< i 80)
126       (utf8 i)
127       (utf8 (+ #xee00 i))))
128
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))
133
134
135 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
136 ;;; stencil outputters
137 ;;;
138
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))
143      (append
144       (ly:all-stencil-expressions)
145       (ly:all-output-backend-commands)))
146
147
148
149 (define (char font i)
150   (text font (utf8 i)))
151
152 (define (placebox x y expr)
153   (stderr "item: ~S\n" expr)
154   (let ((item expr))
155     ;;(if item
156     ;; FIXME ugly hack to skip #unspecified ...
157     (if (and item (not (eq? item (if #f #f))))
158         (begin
159           (move item
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)
163           item)
164         #f)))
165
166 (define (round-filled-box breapth width depth height blot-diameter)
167   ;; FIXME: no rounded corners on rectangle...
168   ;; FIXME: blot?
169   (draw-rectangle (- breapth) depth width (- height) "black" blot-diameter))
170
171 (define (pango-font-name font)
172   (cond
173    ((equal? (ly:font-name font) "GNU-LilyPond-feta-20")
174     "lilypond-feta, regular 32")
175    (else
176     ;; FIXME
177     "ecrm12")))
178     ;;(ly:font-name font))))
179     ;;(ly:font-filename font))))
180
181 (define (pango-font-size font)
182   (let* ((designsize (ly:font-design-size font))
183          (magnification (* (ly:font-magnification font)))
184          
185          ;; experimental sizing:
186          ;; where does factor come from?
187          ;;
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)))
191          ;; for size-points
192          (ops 2.61)
193          
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)
199     
200     scaling))
201
202 ;;font-name: "GNU-LilyPond-feta-20"
203 ;;font-filename: "feta20"
204 ;;pango-font-name: "lilypond-feta, regular 32"
205 ;;OPS:2.61
206 ;;scaling:29.7046771653543
207 ;;magnification:0.569055118110236
208 ;;design:20.0
209
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))
214   
215   (stderr "pango-font-name: ~S\n" (pango-font-name font))
216   (stderr "pango-font-size: ~S\n" (pango-font-size font))
217   
218   (make <gnome-canvas-text>
219     #:parent (canvas-root)
220
221     #:anchor 'west
222     #:x 0.0 #:y 0.0
223     
224     #:font (pango-font-name font)
225     
226     #:size-points (pango-font-size font)
227     ;;#:size ...
228     #:size-set #t
229     
230     ;;apparently no effect :-(
231     ;;#:scale 1.0
232     ;;#:scale-set #t
233     
234     #:fill-color "black"
235     #:text string))
236
237 (define (filledbox a b c d)
238   (round-filled-box a b c d 0.001))
239
240 ;; WTF is this in every backend?
241 (define (horizontal-line x1 x2 thickness)
242   (filledbox (- x1) (- x2 x1) (* .5 thickness) (* .5 thickness)))
243
244 ;;(define (define-origin file line col)
245 ;;  (if (procedure? point-and-click)
246 ;;      (list 'location line col file)))
247
248 (define (grob-cause grob)
249   grob)