From 6583b96498f89927747af0494cdb2ca50627abee Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Tue, 5 Mar 2019 15:30:03 -0800 Subject: [PATCH] green --- fontland/fontland/table/cff/cff-font.rkt | 27 ++++++++++++----------- fontland/fontland/table/cff/cff-index.rkt | 12 +++++----- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/fontland/fontland/table/cff/cff-font.rkt b/fontland/fontland/table/cff/cff-font.rkt index 9f3707c5..7e15d67a 100644 --- a/fontland/fontland/table/cff/cff-font.rkt +++ b/fontland/fontland/table/cff/cff-font.rkt @@ -1,5 +1,5 @@ #lang debug racket/base -(require racket/class racket/list xenomorph "cff-top.rkt") +(require racket/class racket/match racket/list xenomorph "cff-top.rkt") (provide (rename-out (CFFFont CFF_))) #| @@ -14,21 +14,22 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFFont.js (class x:base% (super-new) - (define/augride (decode stream parent) + (augride [@decode decode]) + (define (@decode stream parent) (define cff-font (make-hasheq)) (hash-set! cff-font 'stream stream) - (for ([(k v) (in-hash (send CFFTop decode stream))]) + (for ([(k v) (in-hash (decode CFFTop stream))]) (hash-set! cff-font k v)) ;; because fontkit depends on overloading 'version key, and we don't - #;(hash-set! cff-font 'version (hash-ref cff-font 'x:version)) + (hash-set! cff-font 'version (hash-ref cff-font 'x:version)) #;(when (and (hash-has-key? cff-font 'version) (< (hash-ref cff-font 'version) 2)) - (match (hash-ref cff-font 'topDictIndex) - [(list dict) (hash-set! cff-font 'topDict dict)] - [_ (error 'only-single-font-allowed-in-cff)])) + (match (hash-ref cff-font 'topDictIndex) + [(list dict) (hash-set! cff-font 'topDict dict)] + [_ (error 'only-single-font-allowed-in-cff)])) #;(hash-set! cff-font 'isCIDFont (hash-ref (hash-ref cff-font 'topDict) 'ROS)) cff-font))) @@ -47,10 +48,10 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFFont.js (define ip (open-input-file fira-otf-path)) (define cff-bytes (peek-bytes cff-length cff-offset ip)) (define cff-font (decode CFFFont cff-bytes)) - #;(check-equal? (hash-ref cff-font 'length) 13) - #;(check-equal? (hash-ref cff-font 'hdrSize) 4) - #;(check-equal? (hash-ref cff-font 'offSize) 3) - #;(check-equal? (hash-ref cff-font 'nameIndex) '("FiraSans-Book")) - #;(check-equal? (hash-ref cff-font 'length) (string-length (car (hash-ref cff-font 'nameIndex)))) - #;cff-font + (check-equal? (hash-ref cff-font 'length) 13) + (check-equal? (hash-ref cff-font 'hdrSize) 4) + (check-equal? (hash-ref cff-font 'offSize) 3) + (check-equal? (hash-ref cff-font 'nameIndex) '("FiraSans-Book")) + (check-equal? (hash-ref cff-font 'length) (string-length (car (hash-ref cff-font 'nameIndex)))) + cff-font ) \ No newline at end of file diff --git a/fontland/fontland/table/cff/cff-index.rkt b/fontland/fontland/table/cff/cff-index.rkt index cff15dc0..c7a5c71e 100644 --- a/fontland/fontland/table/cff/cff-index.rkt +++ b/fontland/fontland/table/cff/cff-index.rkt @@ -21,12 +21,12 @@ (match (decode (if (>= (getCFFVersion parent) 2) uint32be uint16be) stream) [0 null] [count (define offSize (decode uint8 stream)) - (define offsetType (case offSize - [(1) uint8] - [(2) uint16be] - [(3) uint24be] - [(4) uint32be] - [else (error 'bad-offset-size-in-CFFIndex)])) + (define offsetType (match offSize + [1 uint8] + [2 uint16be] + [3 uint24be] + [4 uint32be] + [_ (error 'bad-offset-size-in-CFFIndex)])) (define startPos (+ (pos stream) (* (add1 count) offSize) -1)) (for/fold ([vals null] [start (decode offsetType stream)]