From 0c2e44a2098c9699cfbd113ab399204b151768c3 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Tue, 16 May 2017 14:18:40 -0700 Subject: [PATCH] refac --- pitfall/pitfall/font.rkt | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/pitfall/pitfall/font.rkt b/pitfall/pitfall/font.rkt index ffc54868..329fcf5d 100644 --- a/pitfall/pitfall/font.rkt +++ b/pitfall/pitfall/font.rkt @@ -37,8 +37,8 @@ (class PDFFont (super-new) (init-field document name id) - (field [font (make-object AFMFont ((hash-ref STANDARD_FONTS name)))]) - (field [ascender (· font ascender)] + (field [font (make-object AFMFont ((hash-ref STANDARD_FONTS name)))] + [ascender (· font ascender)] [descender (· font descender)] [bbox (· font bbox)] [lineGap (· font lineGap)]) @@ -58,20 +58,20 @@ (define/contract (encode this text [options #f]) ((string?) ((or/c hash? #f)) . ->*m . (list/c (listof string?) (listof hash?))) - (define encoded (send (· this font) encodeText text)) - (define glyphs (send (· this font) glyphsForString (~a text))) - (define advances (send (· this font) advancesForGlyphs glyphs)) + (define this-font (· this font)) + (define encoded (send this-font encodeText text)) + (define glyphs (send this-font glyphsForString text)) + (define advances (send this-font advancesForGlyphs glyphs)) (define positions - (for/list ([(glyph i) (in-indexed glyphs)]) - (mhash 'xAdvance (list-ref advances i) - 'yAdvance 0 - 'xOffset 0 - 'yOffset 0 - 'advanceWidth (send (· this font) widthOfGlyph glyph)))) - + (for/list ([(glyph i) (in-indexed glyphs)] + [advance (in-list advances)]) + (hasheq 'xAdvance advance + 'yAdvance 0 + 'xOffset 0 + 'yOffset 0 + 'advanceWidth (send this-font widthOfGlyph glyph)))) (list encoded positions)) (module+ test - (define stdfont (make-object StandardFont #f "Helvetica" #f)) - stdfont) \ No newline at end of file + (define stdfont (make-object StandardFont #f "Helvetica" #f))) \ No newline at end of file