racket/draw win32: work around a Pango bug

Pango crashes (with an assertion failure) on characters U+1D173
through U+1D17A. Trying to fix (or even just compile) Pango for
Windows is hard, so skip the characters at the `draw-text' and
`text-extent' level.

The bug is unlikely to be specific to just those characters in the
long run, but only those characters appear to be problematic on my
Windows 7 installation. So, the workaround may be enough for many
installations, and hopefully the Pango bug wil be fixed one day.

Relevant to PR 13513
This commit is contained in:
Matthew Flatt 2013-02-19 08:08:30 -07:00
parent ca951294d4
commit 8f9606007f

View File

@ -44,6 +44,11 @@
black)
(color->immutable-color c)))
;; The Windows version of Pango crashes on characters
;; #\U1D173 through #\U1D17A (which are unusual characters
;; replated to music notation), so work around it:
(define broken-music-pango? (eq? (system-type) 'windows))
;; dc-backend : interface
;;
;; This is the interface that the backend specific code must implement
@ -1279,11 +1284,19 @@
[blank? (string=? s "")]
[s (if (and (not draw-mode) blank?) " " s)]
[s (if (for/or ([c (in-string s)])
(or (eqv? c #\uFFFE) (eqv? c #\uFFFF)))
(or (eqv? c #\uFFFE)
(eqv? c #\uFFFF)
(and broken-music-pango?
(let ([n (char->integer c)])
(<= #x1D173 n #x1D17A)))))
;; Since \uFFFE and \uFFFF are not supposed to be in any
;; interchange, we must replace them away before passing a
;; string to Pango:
(regexp-replace* #rx"[\uFFFE\uFFFF]" s "\uFFFD")
(regexp-replace* (if broken-music-pango?
#rx"[\uFFFE\uFFFF\U1D173-\U1D17A]"
#rx"[\uFFFE\uFFFF]")
s
"\uFFFD")
s)]
[rotate? (and draw-mode (not (zero? angle)))]
[smoothing-index (get-smoothing-index font)]