From 04632ba102819fba60da34dabf7cef673eb19923 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Thu, 14 Mar 2019 23:33:28 -0700 Subject: [PATCH] closer --- fontland/fontland/cff-glyph.rkt | 4 +- fontland/fontland/table/cff/cff-dict.rkt | 40 +++++++++---------- .../fontland/table/cff/cff-private-dict.rkt | 3 +- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/fontland/fontland/cff-glyph.rkt b/fontland/fontland/cff-glyph.rkt index 78bc5ee0..b41eba12 100644 --- a/fontland/fontland/cff-glyph.rkt +++ b/fontland/fontland/cff-glyph.rkt @@ -74,13 +74,13 @@ https://github.com/mbutterick/fontkit/blob/master/src/glyph/CFFGlyph.js (define open #false) (define gsubrs (match (hash-ref cff 'globalSubrIndex (vector)) - [(? list? vals) (list->vector vals)] + [(list) (vector)] [vec vec])) (define gsubrsBias (bias this gsubrs)) (define privateDict (or (privateDictForGlyph cff (glyph-id this)) (make-hash))) (define subrs (match (hash-ref privateDict 'Subrs (vector)) - [(? list? vals) (list->vector vals)] + [(list) (vector)] [vec vec])) (define subrsBias (bias this subrs)) diff --git a/fontland/fontland/table/cff/cff-dict.rkt b/fontland/fontland/table/cff/cff-dict.rkt index 1eb2ba7e..a103d962 100644 --- a/fontland/fontland/table/cff/cff-dict.rkt +++ b/fontland/fontland/table/cff/cff-dict.rkt @@ -1,4 +1,4 @@ -#lang racket/base +#lang debug racket/base (require racket/class racket/match racket/list @@ -25,13 +25,13 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFDict.js (field [(@fields fields) (for/hash ([field (in-list @ops)]) - (values (op->key field) field))]) + (values (op->key field) field))]) (define (decode-operands type stream ret operands) (match type [(? list?) (for/list ([op (in-list operands)] [subtype (in-list type)]) - (decode-operands subtype stream ret (list op)))] + (decode-operands subtype stream ret (list op)))] [(? xenomorphic?) (send type x:decode stream ret operands)] [(or 'number 'offset 'sid) (car operands)] ['boolean (if (car operands) #t #f)] @@ -42,7 +42,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFDict.js [(? list?) (for/list ([op (in-list operands)] [subtype (in-list type)]) - (car (encode-operands subtype stream ctx op)))] + (car (encode-operands subtype stream ctx op)))] [(? xenomorphic?) type (send type x:encode operands stream ctx)] [_ (match operands [(? number?) (list operands)] @@ -63,7 +63,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFDict.js ;; fill in defaults (for ([(key field) (in-hash @fields)]) - (hash-set! ret (second field) (fourth field))) + (hash-set! ret (second field) (fourth field))) (let loop ([operands null]) (when (< (pos stream) end) @@ -98,11 +98,11 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFDict.js [field (in-value (dict-ref @fields k))] [val (in-value (dict-ref dict (list-ref field 1) #false))] #:unless (or (not val) (equal? val (list-ref field 3)))) - (define operands (encode-operands (list-ref field 2) #false ctx val)) - (define operand-size (for/sum ([op (in-list operands)]) - (size CFFOperand op))) - (define key (if (list? (car field)) (car field) (list (car field)))) - (+ operand-size (length key))) + (define operands (encode-operands (list-ref field 2) #false ctx val)) + (define operand-size (for/sum ([op (in-list operands)]) + (size CFFOperand op))) + (define key (if (list? (car field)) (car field) (list (car field)))) + (+ operand-size (length key))) (if include-pointers (hash-ref ctx x:pointer-size-key) 0))) (define/augment (x:encode dict stream parent) @@ -116,16 +116,16 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFDict.js (hash-set! ctx x:pointer-offset-key (+ (pos stream) (x:size dict ctx #false))) (for ([field (in-list @ops)]) - (define val (dict-ref dict (list-ref field 1) #false)) - (cond - [(or (not val) (equal? val (list-ref field 3)))] - [else - (define operands (encode-operands (list-ref field 2) stream ctx val)) - (for ([op (in-list operands)]) - (send CFFOperand x:encode op stream)) - (define key (if (list? (car field)) (car field) (list (car field)))) - (for ([op (in-list key)]) - (encode uint8 op stream))])) + (match-define (list f0 f1 f2 f3) field) + (match (dict-ref dict f1 #false) + [(or #false (== f3)) (void)] + [val + (define operands (encode-operands f2 stream ctx val)) + (for ([op (in-list operands)]) + (send CFFOperand x:encode op stream)) + (define key (if (list? f0) f0 (list f0))) + (for ([op (in-list key)]) + (encode uint8 op stream))])) (let loop ([i 0]) (when (< i (length (hash-ref ctx x:pointers-key))) diff --git a/fontland/fontland/table/cff/cff-private-dict.rkt b/fontland/fontland/table/cff/cff-private-dict.rkt index e6495563..134b4a92 100644 --- a/fontland/fontland/table/cff/cff-private-dict.rkt +++ b/fontland/fontland/table/cff/cff-private-dict.rkt @@ -44,4 +44,5 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFPrivateDict.js (21 nominalWidthX number 0) (22 vsindex number 0) (23 blend ,CFFBlendOp #false) - (19 Subrs ,(CFFPointer (CFFIndex) #:relative-to 'local) ,null)))) \ No newline at end of file + (19 Subrs ,(CFFPointer (CFFIndex) #:relative-to 'local) ,null)))) +;; todo: why can't the subrs default value be `(vector)`? \ No newline at end of file