From 8f9606007fee4caece23214b0b20dc36a3a7c010 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Tue, 19 Feb 2013 08:08:30 -0700 Subject: [PATCH] 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 --- collects/racket/draw/private/dc.rkt | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/collects/racket/draw/private/dc.rkt b/collects/racket/draw/private/dc.rkt index 0be6628e6a..3d26a54d48 100644 --- a/collects/racket/draw/private/dc.rkt +++ b/collects/racket/draw/private/dc.rkt @@ -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)]