Closed muraiki closed 11 years ago
Fixed:
; remove-last-two : string -> string
; Strips off the last two characters of a string. Used for cleaning up hyphenated text before rendering
; Example: "text__" -> "text"
(define (remove-last-two a-text)
(substring a-text 0 (- (string-length a-text) 2)))
; hyphenate : string integer string -> image
; receives text, an int that is the image width of the neumes above it, and the string to hyphenate with
(define (hyphenate a-text neumes-width hyphenate-string)
(let* ([text-image (render-text (remove-last-two a-text))]
[num-hyp-strings (sub1 (floor (/ (- neumes-width (image-width text-image))
(image-width (render-text hyphenate-string)))))])
(beside text-image
(render-text (repeat-string hyphenate-string num-hyp-strings)))))
; repeat-string : string integer -> string
(define (repeat-string a-string an-integer)
(if (= 1 an-integer) a-string
(string-append a-string (repeat-string a-string (sub1 an-integer)))))
Fix the hyphenator to use a more efficient technique than recursive image combination.
Currently the hyphenator simply calls itself over and over recursively until it generates an image with underscores or hyphens of an appropriate length. Needless to say, this is a bit processor intensive. It'd be better if the hyphenator could calculate how many hyphens it needs and then append them all at once, or perhaps use (string-append) to modify the string send to the text rendering function.