From 6b969d46cb286e491a1bef7ced3793379d0f1721 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Wed, 24 Sep 2014 06:56:20 -0600 Subject: [PATCH] racket/draw: constrain font-map repair to Windows Adjust changes in 6bfad43429 to avoid creating more font maps than necessary, especially on platforms other than Windows. --- .../draw-lib/racket/draw/private/dc.rkt | 64 ++++++++++++------- 1 file changed, 40 insertions(+), 24 deletions(-) diff --git a/pkgs/draw-pkgs/draw-lib/racket/draw/private/dc.rkt b/pkgs/draw-pkgs/draw-lib/racket/draw/private/dc.rkt index 50f2670fd6..1cb5fb42a3 100644 --- a/pkgs/draw-pkgs/draw-lib/racket/draw/private/dc.rkt +++ b/pkgs/draw-pkgs/draw-lib/racket/draw/private/dc.rkt @@ -240,14 +240,20 @@ ;; at least for the Quartz and Win32 back-ends. ;; (But we create the font maps on demand.) ;; We fold hinting in, too, as an extra factor of 2. -;; In the case of aligned hinting, at least, the font map -;; might further depend on the transformation, at least -;; for Windows, so each element of `font-maps` is +;; In the case of aligned hinting on Windows, the font map +;; might further depend on the transformation, so for that +;; platform and ramge each element of `font-maps` is ;; (vector font-map xform (hash xform -> font-map)) ;; where the first two elements of the vector act as ;; a cache for the hash-table lookup. (define font-maps (make-vector 8 #f)) +(define UNALIGNED-INDEX 4) +(define multi-font-map-boundary + (case (system-type) + [(windows) UNALIGNED-INDEX] + [else 0])) + (define (dc-mixin backend%) (defclass* dc% backend% (dc<%>) (super-new) @@ -1310,7 +1316,7 @@ [(smoothed) 3]) (case (send font get-hinting) [(aligned) 0] - [(unaligned) 4]))) + [(unaligned) UNALIGNED-INDEX]))) (define/private (get-context cr smoothing-index font xform) (or (let ([c (vector-ref contexts smoothing-index)]) @@ -1330,26 +1336,36 @@ c))) (define/private (get-font-map smoothing-index xform) - (define old-fmv (vector-ref font-maps smoothing-index)) - (define fmv (or old-fmv (vector #f #f #hash()))) - (unless old-fmv - (vector-set! font-maps smoothing-index fmv)) - (or (and (equal? xform (vector-ref fmv 1)) - (vector-ref fmv 0)) - (let* ([fm (hash-ref (vector-ref fmv 2) xform #f)] - [new-fm (or fm - (pango_cairo_font_map_new))]) - (vector-set! fmv 0 new-fm) - (vector-set! fmv 1 xform) - (unless fm - (define ht (vector-ref fmv 2)) - (define new-ht - ;; Limit the number of font maps that we cache: - (if ((hash-count ht) . < . 8) - ht - #hash())) - (vector-set! fmv 2 (hash-set new-ht xform new-fm))) - new-fm))) + (cond + [(smoothing-index . < . multi-font-map-boundary) + (define old-fmv (vector-ref font-maps smoothing-index)) + (define fmv (or old-fmv (vector #f #f #hash()))) + (unless old-fmv + (vector-set! font-maps smoothing-index fmv)) + (or (and (equal? xform (vector-ref fmv 1)) + (vector-ref fmv 0)) + (let* ([fm (hash-ref (vector-ref fmv 2) xform #f)] + [new-fm (or fm + (pango_cairo_font_map_new))]) + (vector-set! fmv 0 new-fm) + (vector-set! fmv 1 xform) + (unless fm + (define ht (vector-ref fmv 2)) + (define new-ht + ;; Limit the number of font maps that we cache: + (if ((hash-count ht) . < . 8) + ht + #hash())) + (vector-set! fmv 2 (hash-set new-ht xform new-fm))) + new-fm))] + [else + (define fm (vector-ref font-maps smoothing-index)) + (cond + [fm fm] + [else + (define fm (pango_cairo_font_map_new)) + (vector-set! font-maps smoothing-index fm) + fm])])) (define/private (do-text cr draw-mode s x y font combine? offset angle) (let* ([s (if (zero? offset)