]> git.donarmstrong.com Git - lilypond.git/blob - scm/output-gnome.scm
* scm/output-gnome.scm (placebox): Shield affine-relative.
[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--tng TLA, possibly Janneke's if you have libffi-3.4.
25 ;;;   * guile-gnome TLA
26 ;;;   * pango CVS (ie, > 2004-06-12)
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           ;; UGH latest guile-gnome is broken
163           (if (defined? 'affine-relative)
164               (affine-relative item output-scale 0 0 output-scale 0 0))
165           item)
166         #f)))
167
168 (define (round-filled-box breapth width depth height blot-diameter)
169   ;; FIXME: no rounded corners on rectangle...
170   ;; FIXME: blot?
171   (draw-rectangle (- breapth) depth width (- height) "black" blot-diameter))
172
173 (define (pango-font-name font)
174   (cond
175    ((equal? (ly:font-name font) "GNU-LilyPond-feta-20")
176     "lilypond-feta, regular 32")
177    (else
178     ;; FIXME
179     "ecrm12")))
180     ;;(ly:font-name font))))
181     ;;(ly:font-filename font))))
182
183 (define (pango-font-size font)
184   (let* ((designsize (ly:font-design-size font))
185          (magnification (* (ly:font-magnification font)))
186          
187          ;; experimental sizing:
188          ;; where does factor come from?
189          ;;
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)))
193          ;; for size-points
194          (ops 2.61)
195          
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)
201     
202     scaling))
203
204 ;;font-name: "GNU-LilyPond-feta-20"
205 ;;font-filename: "feta20"
206 ;;pango-font-name: "lilypond-feta, regular 32"
207 ;;OPS:2.61
208 ;;scaling:29.7046771653543
209 ;;magnification:0.569055118110236
210 ;;design:20.0
211
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))
216   
217   (stderr "pango-font-name: ~S\n" (pango-font-name font))
218   (stderr "pango-font-size: ~S\n" (pango-font-size font))
219   
220   (make <gnome-canvas-text>
221     #:parent (canvas-root)
222     
223     ;; experimental text placement corrections.
224     ;; UGHR?  What happened to tex offsets?  south-west?
225     ;; is pango doing something 'smart' wrt baseline ?
226     #:anchor 'south-west
227     #:x 0.003 #:y 0.123
228     
229     ;;#:anchor 'west
230     ;;#:x 0.015 #:y -3.71
231     
232     #:font (pango-font-name font)
233     
234     #:size-points (pango-font-size font)
235     ;;#:size ...
236     #:size-set #t
237     
238     ;;apparently no effect :-(
239     ;;#:scale 1.0
240     ;;#:scale-set #t
241     
242     #:fill-color "black"
243     #:text string))
244
245 (define (filledbox a b c d)
246   (round-filled-box a b c d 0.001))
247
248 ;; WTF is this in every backend?
249 (define (horizontal-line x1 x2 thickness)
250   (filledbox (- x1) (- x2 x1) (* .5 thickness) (* .5 thickness)))
251
252 ;;(define (define-origin file line col)
253 ;;  (if (procedure? point-and-click)
254 ;;      (list 'location line col file)))
255
256 (define (grob-cause grob)
257   grob)