From 9c21843d08490535b953eb47666d8bc0dac1f0bf Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Thu, 14 Mar 2019 22:49:45 -0700 Subject: [PATCH] from blown speakers --- fontland/fontland/cff-glyph.rkt | 18 ++++++++----- fontland/fontland/subset.rkt | 2 +- fontland/fontland/table/cff/cff-font.rkt | 10 +++---- fontland/fontland/table/cff/cff-index.rkt | 26 ++++++++++++------- .../table/cff/cff-standard-strings.rkt | 2 +- 5 files changed, 34 insertions(+), 24 deletions(-) diff --git a/fontland/fontland/cff-glyph.rkt b/fontland/fontland/cff-glyph.rkt index f6cc3107..78bc5ee0 100644 --- a/fontland/fontland/cff-glyph.rkt +++ b/fontland/fontland/cff-glyph.rkt @@ -15,8 +15,8 @@ https://github.com/mbutterick/fontkit/blob/master/src/glyph/CFFGlyph.js (define (bias this s) (cond - [(< (length s) 1240) 107] - [(< (length s) 33900) 1131] + [(< (vector-length s) 1240) 107] + [(< (vector-length s) 33900) 1131] [else 32768])) (define-syntax-rule (case= ID [(NUMS ...) . BODY] ... [else . ELSEBODY]) @@ -29,7 +29,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/glyph/CFFGlyph.js ;;;(define pos (pos stream)) (define cff (get-table (glyph-font this) 'CFF_)) - (define str (list-ref (hash-ref (hash-ref cff 'topDict) 'CharStrings) (glyph-id this))) + (define str (vector-ref (hash-ref (hash-ref cff 'topDict) 'CharStrings) (glyph-id this))) (define end (+ (hash-ref str 'offset) (hash-ref str 'length))) (pos stream (hash-ref str 'offset)) @@ -73,11 +73,15 @@ https://github.com/mbutterick/fontkit/blob/master/src/glyph/CFFGlyph.js (define usedSubrs (make-hash)) (define open #false) - (define gsubrs (hash-ref cff 'globalSubrIndex null)) + (define gsubrs (match (hash-ref cff 'globalSubrIndex (vector)) + [(? list? vals) (list->vector vals)] + [vec vec])) (define gsubrsBias (bias this gsubrs)) (define privateDict (or (privateDictForGlyph cff (glyph-id this)) (make-hash))) - (define subrs (hash-ref privateDict 'Subrs null)) + (define subrs (match (hash-ref privateDict 'Subrs (vector)) + [(? list? vals) (list->vector vals)] + [vec vec])) (define subrsBias (bias this subrs)) ;; skip variations shit @@ -147,7 +151,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/glyph/CFFGlyph.js [(10) ;; callsubr (define index (+ (pop stack) subrsBias)) - (define subr (list-ref subrs index)) + (define subr (vector-ref subrs index)) (when subr (hash-set! usedSubrs index #true) (define p (pos stream)) @@ -264,7 +268,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/glyph/CFFGlyph.js [(29) ;; callgsubr (define index (+ (pop stack) gsubrsBias)) - (define subr (list-ref gsubrs index)) + (define subr (vector-ref gsubrs index)) (when subr (hash-set! usedGsubrs index #true) (define p (pos stream)) diff --git a/fontland/fontland/subset.rkt b/fontland/fontland/subset.rkt index 6115a58c..97468021 100644 --- a/fontland/fontland/subset.rkt +++ b/fontland/fontland/subset.rkt @@ -144,7 +144,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/subset/CFFSubset.js (set-cff-subset-strings! this (append (cff-subset-strings this) (list string))) - (+ (length standardStrings) (sub1 (length (cff-subset-strings this))))])) + (+ (vector-length standardStrings) (sub1 (length (cff-subset-strings this))))])) (define (cff-subset-encode this stream) diff --git a/fontland/fontland/table/cff/cff-font.rkt b/fontland/fontland/table/cff/cff-font.rkt index 83689f55..d22e0ad0 100644 --- a/fontland/fontland/table/cff/cff-font.rkt +++ b/fontland/fontland/table/cff/cff-font.rkt @@ -28,7 +28,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFFont.js (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)] + [(vector 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)) @@ -38,16 +38,16 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFFont.js (cond [(not sid) #false] [(>= (hash-ref this 'version) 2) #false] - [(< sid (length standardStrings)) (list-ref standardStrings sid)] - [else (list-ref (hash-ref this 'stringIndex) (- sid (length standardStrings)))])) + [(< sid (vector-length standardStrings)) (vector-ref standardStrings sid)] + [else (vector-ref (hash-ref this 'stringIndex) (- sid (vector-length standardStrings)))])) (define (CFFFont-postscriptName this) - (and (< (hash-ref this 'version) 2) (car (hash-ref this 'nameIndex)))) + (and (< (hash-ref this 'version) 2) (vector-ref (hash-ref this 'nameIndex) 0))) (define CFFFont (make-object CFFFont%)) (define (getCharString cff-font glyph-id) - (define glyph-record (list-ref (hash-ref (hash-ref cff-font 'topDict) 'CharStrings) glyph-id)) + (define glyph-record (vector-ref (hash-ref (hash-ref cff-font 'topDict) 'CharStrings) glyph-id)) (pos (hash-ref cff-font 'stream) (hash-ref glyph-record 'offset)) (read-bytes (hash-ref glyph-record 'length) (hash-ref cff-font 'stream))) diff --git a/fontland/fontland/table/cff/cff-index.rkt b/fontland/fontland/table/cff/cff-index.rkt index 56eead33..3f77b3c8 100644 --- a/fontland/fontland/table/cff/cff-index.rkt +++ b/fontland/fontland/table/cff/cff-index.rkt @@ -33,7 +33,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFIndex.js (define startPos (+ (pos stream) (* (add1 count) offSize) -1)) (for/fold ([vals null] [start (send offsetType x:decode stream)] - #:result (begin0 (reverse vals) (pos stream (+ startPos start)))) + #:result (begin0 (list->vector (reverse vals)) (pos stream (+ startPos start)))) ([i (in-range count)]) (define end (send offsetType x:decode stream)) (define val @@ -50,15 +50,18 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFIndex.js 'length (- end start))])) (values (cons val vals) end))])) - (define/augride (x:size arr parent) + (define/augride (x:size arr-arg parent) + (define arr (match arr-arg + [(? list? xs) (list->vector xs)] + [vec vec])) (+ 2 (cond - [(zero? (length arr)) 0] + [(zero? (vector-length arr)) 0] [else (define type (or @type (x:buffer))) ;; find maximum offset to determinine offset type (define offset - (add1 (for/sum ([item (in-list arr)]) + (add1 (for/sum ([item (in-vector arr)]) (send type x:size item parent)))) (define offset-type @@ -69,12 +72,15 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFIndex.js [(<= offset #xffffffff) uint32be] [else (error 'CFFIndex-size (format "bad offset: ~a" offset))])) - (+ (* (send offset-type x:size) (add1 (length arr))) offset)]))) + (+ (* (send offset-type x:size) (add1 (vector-length arr))) offset)]))) - (define/augride (x:encode arr stream parent) - (send uint16be x:encode (length arr) stream) + (define/augride (x:encode arr-arg stream parent) + (define arr (match arr-arg + [(? list? xs) (list->vector xs)] + [vec vec])) + (send uint16be x:encode (vector-length arr) stream) (cond - [(zero? (length arr))] + [(zero? (vector-length arr))] [else (define type (or @type (x:buffer))) @@ -83,7 +89,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFIndex.js (for/fold ([sizes null] [offset 1] #:result (values (reverse sizes) offset)) - ([item (in-list arr)]) + ([item (in-vector arr)]) (define s (send type x:size item parent)) (values (cons s sizes) (+ offset s)))) @@ -105,7 +111,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFIndex.js (send offsetType x:encode next-offset stream) next-offset) - (for ([item (in-list arr)]) + (for ([item (in-vector arr)]) (send type x:encode item stream parent))])))) (define (CFFIndex [type #f]) diff --git a/fontland/fontland/table/cff/cff-standard-strings.rkt b/fontland/fontland/table/cff/cff-standard-strings.rkt index 5559c6b1..df32dddc 100644 --- a/fontland/fontland/table/cff/cff-standard-strings.rkt +++ b/fontland/fontland/table/cff/cff-standard-strings.rkt @@ -7,7 +7,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFStandardStrings.js |# (define standardStrings - '(".notdef" "space" "exclam" "quotedbl" "numbersign" "dollar" + '#(".notdef" "space" "exclam" "quotedbl" "numbersign" "dollar" "percent" "ampersand" "quoteright" "parenleft" "parenright" "asterisk" "plus" "comma" "hyphen" "period" "slash" "zero" "one" "two" "three" "four" "five" "six" "seven" "eight" "nine" "colon"