- (string-append
- "1 setlinecap 1 setlinejoin "
- (ly:number->string thick) " setlinewidth "
- (ly:number->string x1) " "
- (ly:number->string y1) " moveto "
- (ly:number->string x2) " "
- (ly:number->string y2) " lineto stroke"))
-
-(define (end-output)
- "\nend-lilypond-output\n")
-
-(define (ez-ball ch letter-col ball-col)
- (string-append
- " (" ch ") "
- (ly:numbers->string (list letter-col ball-col))
- " /Helvetica-Bold " ;; ugh
- " draw_ez_ball"))
-
-(define (filledbox breapth width depth height)
- (string-append (ly:numbers->string (list breapth width depth height))
- " draw_box"))
-
-(define (header creator time-stamp page-count-)
- (set! page-count page-count-)
- (set! page-number 0)
- (string-append
- "%!PS-Adobe-3.0\n"
- "%%Creator: " creator " " time-stamp "\n"
- "%%Pages: " (number->string page-count) "\n"
- "%%PageOrder: Ascend\n"
- ;; FIXME: TODO get from paper
- ;; "%%DocumentPaperSizes: a6\n"
- ;;(string-append "GNU LilyPond (" (lilypond-version) "), ")
- ;; (strftime "%c" (localtime (current-time))))
- ;; FIXME: duplicated in every backend
- (ps-string-def
- "lilypond" 'tagline
- (string-append "Engraved by LilyPond (version " (lilypond-version) ")"))))
-
-(define (header-end)
- (string-append
- (ly:gulp-file "lilyponddefs.ps")
- (ly:gulp-file "music-drawing-routines.ps")))
-
-(define (horizontal-line x1 x2 th)
- (draw-line th x1 0 x2 0))
-
-(define (lily-def key val)
- (let ((prefix "lilypondpaper"))
- (if (string=?
- (substring key 0 (min (string-length prefix) (string-length key)))
- prefix)
- (string-append "/" key " {" val "} bind def\n")
- (string-append "/" key " (" val ") def\n"))))
-
-(define (no-origin) "")
-
-;; FIXME: duplictates output-scopes, duplicated in other backends
-;; FIXME: silly interface name
-(define (output-paper-def pd)
- (let ((prefix "lilypondpaper"))
-
- (define (scope-entry->string key var)
- (if (variable-bound? var)
- (let ((val (variable-ref var)))
- (cond
- ((string? val) (ps-string-def prefix key val))
- ((number? val) (ps-number-def prefix key val))
- (else "")))
- ""))
-
- (apply
- string-append
- (module-map scope-entry->string (ly:output-def-scope pd)))))
-
-;; FIXME: duplicated in other output backends
-;; FIXME: silly interface name
-(define (output-scopes paper scopes fields basename)
- (let ((prefix "lilypond"))
-
- ;; FIXME: duplicates output-paper's scope-entry->string, mostly
- (define (scope-entry->string key var)
- (if (variable-bound? var)
- (let ((val (variable-ref var)))
- (if (and (memq key fields) (string? val))
- (header-to-file basename key val))
- (cond
- ((string? val) (ps-string-def prefix key val))
- ((number? val) (ps-number-def prefix key val))
- (else "")))
- ""))
-
- (define (output-scope scope)
- (apply string-append (module-map scope-entry->string scope)))
-
- (string-append (apply string-append (map output-scope scopes)))))
-
-;; hmm, looks like recursing call is always last statement, does guile
-;; think so too?
-(define (output-stencil port expr offset)
- (if (pair? expr)
- (let ((head (car expr)))
- (cond
- ((ly:input-location? head)
- (display (apply define-origin (ly:input-location head)) port)
- (output-stencil port (cadr expr) offset))
- ((eq? head 'no-origin)
- (display (expression->string head) port)
- (output-stencil port (cadr expr) offset))
- ((eq? head 'translate-stencil)
- (output-stencil port (caddr expr) (offset-add offset (cadr expr))))
- ((eq? head 'combine-stencil)
- (output-stencil port (cadr expr) offset)
- (output-stencil port (caddr expr) offset))
- (else
- (display (placebox (car offset) (cdr offset)
- (expression->string expr)) port))))))
+ (ly:format "~4f ~4f ~4f ~4f ~4f draw_line"
+ (- x2 x1) (- y2 y1)
+ x1 y1 thick))
+
+(define (ellipse x-radius y-radius thick fill)
+ (ly:format
+ "~a ~4f ~4f ~4f draw_ellipse"
+ (if fill
+ "true"
+ "false")
+ x-radius y-radius thick))
+
+(define (embedded-ps string)
+ string)
+
+(define (glyph-string postscript-font-name
+ size
+ cid?
+ w-x-y-named-glyphs)
+
+ (define (glyph-spec w x y g)
+ (let ((prefix (if (string? g) "/" "")))
+ (ly:format "~4f ~4f ~a~a"
+ (+ w x) y
+ prefix g)))
+
+ (ly:format
+ (if cid?
+"/~a /CIDFont findresource ~a output-scale div scalefont setfont
+~a
+~a print_glyphs"
+
+"/~a ~a output-scale div selectfont
+~a
+~a print_glyphs")
+ postscript-font-name
+ size
+ (string-join (map (lambda (x) (apply glyph-spec x))
+ (reverse w-x-y-named-glyphs)) "\n")
+ (length w-x-y-named-glyphs)))
+
+
+(define (grob-cause offset grob)
+ (if (ly:get-option 'point-and-click)
+ (let* ((cause (ly:grob-property grob 'cause))
+ (music-origin (if (ly:stream-event? cause)
+ (ly:event-property cause 'origin))))
+ (if (ly:input-location? music-origin)
+ (let* ((location (ly:input-file-line-char-column music-origin))
+ (raw-file (car location))
+ (file (if (is-absolute? raw-file)
+ raw-file
+ (string-append (ly-getcwd) "/" raw-file)))
+ (x-ext (ly:grob-extent grob grob X))
+ (y-ext (ly:grob-extent grob grob Y)))
+
+ (if (and (< 0 (interval-length x-ext))
+ (< 0 (interval-length y-ext)))
+ (ly:format "~4f ~4f ~4f ~4f (textedit://~a:~a:~a:~a) mark_URI\n"
+ (+ (car offset) (car x-ext))
+ (+ (cdr offset) (car y-ext))
+ (+ (car offset) (cdr x-ext))
+ (+ (cdr offset) (cdr y-ext))
+
+ ;; TODO
+ ;;full escaping.
+
+ ;; backslash is interpreted by GS.
+ (ly:string-substitute "\\" "/"
+ (ly:string-substitute " " "%20" file))
+ (cadr location)
+ (caddr location)
+ (cadddr location))
+ ""))
+ ""))
+ ""))
+
+(define (named-glyph font glyph)
+ (ly:format "~a /~a glyphshow " ;;Why is there a space at the end?
+ (ps-font-command font)
+ glyph))
+
+(define (no-origin)
+ "")
+
+(define (oval x-radius y-radius thick fill)
+ (ly:format
+ "~a ~4f ~4f ~4f draw_oval"
+ (if fill
+ "true"
+ "false")
+ x-radius y-radius thick))