From da4f8a83c1dbfcff1b03fa9b54c3ae9dc1e2a835 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Thu, 14 Mar 2019 22:19:27 -0700 Subject: [PATCH] try --- fontland/fontland/cff-glyph.rkt | 18 +++++++++++------- fontland/fontland/table/cff/cff-font.rkt | 8 ++++---- fontland/fontland/table/cff/cff-index.rkt | 5 +++-- .../table/cff/cff-standard-strings.rkt | 2 +- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/fontland/fontland/cff-glyph.rkt b/fontland/fontland/cff-glyph.rkt index f6cc3107..523a8cf2 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,13 +73,16 @@ 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 (hash-ref cff 'globalSubrIndex (vector))) (define gsubrsBias (bias this gsubrs)) (define privateDict (or (privateDictForGlyph cff (glyph-id this)) (make-hash))) - (define subrs (hash-ref privateDict 'Subrs null)) + (define subrs (hash-ref privateDict 'Subrs (vector))) (define subrsBias (bias this subrs)) + #R (vector? gsubrs) + #R (vector? subrs) + ;; skip variations shit #;(define vstore (and (hash-ref* cff 'topDict 'vstore) (hash-ref* cff 'topDict 'vstore))) @@ -105,6 +108,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/glyph/CFFGlyph.js (let loop () (when (< (pos stream) end) (define op (read-byte stream)) + #R (list op x y) (cond [(< op 32) (case= op @@ -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/table/cff/cff-font.rkt b/fontland/fontland/table/cff/cff-font.rkt index 83689f55..ea3d0ac4 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,8 +38,8 @@ 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)))) @@ -47,7 +47,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFFont.js (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..5eccefe3 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 vals) (pos stream (+ startPos start)))) ([i (in-range count)]) (define end (send offsetType x:decode stream)) (define val @@ -50,7 +50,8 @@ 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 (if (vector? arr-arg) (vector->list arr-arg) arr-arg)) (+ 2 (cond [(zero? (length arr)) 0] 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"