From 6d813b80ee9cd2ecc15bf614d29ff40b0783c00b Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Sat, 9 Mar 2019 09:08:40 -0800 Subject: [PATCH] trudge --- fontland/fontland/table/cff/cff-dict.rkt | 16 +++++----- fontland/fontland/table/cff/cff-index.rkt | 4 +-- fontland/fontland/table/cff/cff-operand.rkt | 1 - fontland/fontland/table/cff/cff-top.rkt | 35 ++++++++++++--------- 4 files changed, 30 insertions(+), 26 deletions(-) diff --git a/fontland/fontland/table/cff/cff-dict.rkt b/fontland/fontland/table/cff/cff-dict.rkt index f83edc91..def532e6 100644 --- a/fontland/fontland/table/cff/cff-dict.rkt +++ b/fontland/fontland/table/cff/cff-dict.rkt @@ -33,13 +33,11 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFDict.js [_ operands])) (define (encodeOperands type stream ctx operands) - #R 'in-encode-operands - #R stream (cond [(list? type) (for/list ([(op i) (in-indexed operands)]) (car (encodeOperands (list-ref type i) stream ctx op)))] - [(xenomorphic? type) #RRR type (send type encode operands #RRR stream ctx)] + [(xenomorphic? type) type (send type encode operands stream ctx)] [(number? operands) (list operands)] [(boolean? operands) (list (if operands 1 0))] [(list? operands) operands] @@ -87,7 +85,8 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFDict.js (augment [@size size]) (define (@size dict parent [includePointers #true]) - #R 'in-cff-dict-size + #RRR 'in-cff-dict-size + #RR includePointers (define ctx (mhasheq x:parent-key parent @@ -109,17 +108,20 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFDict.js #RR operands (set! len (+ len (for/sum ([op (in-list operands)]) - #R (size CFFOperand op)))) + (size CFFOperand op)))) (define key (if (list? (list-ref field 0)) (list-ref field 0) (list (list-ref field 0)))) (set! len (+ len #R (length key)))) - (when includePointers + #RRR 'intermediate-len + #RR len + + (when #RRR includePointers (set! len (+ len (hash-ref ctx x:pointer-size-key)))) - #R 'final-len + #RRR 'final-len #R len) (augment [@encode encode]) diff --git a/fontland/fontland/table/cff/cff-index.rkt b/fontland/fontland/table/cff/cff-index.rkt index 44a5a3c8..a51babe3 100644 --- a/fontland/fontland/table/cff/cff-index.rkt +++ b/fontland/fontland/table/cff/cff-index.rkt @@ -48,13 +48,11 @@ (augride [@size size]) (define (@size arr parent) - #RRR 'in-cfff-index-size (define size 2) (cond [(zero? (length arr)) size] [else - (define type (or #RR @type (x:buffer))) - #RR type + (define type (or @type (x:buffer))) ;; find maximum offset to determinine offset type (define offset 1) diff --git a/fontland/fontland/table/cff/cff-operand.rkt b/fontland/fontland/table/cff/cff-operand.rkt index b4ac9e97..20876ba9 100644 --- a/fontland/fontland/table/cff/cff-operand.rkt +++ b/fontland/fontland/table/cff/cff-operand.rkt @@ -53,7 +53,6 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFOperand.js (define/augment (size value-arg _) ;; if the value needs to be forced to the largest size (32 bit) ;; e.g. for unknown pointers, set to 32768 - #RRR value-arg (define value (cond [(or (and (hash? value-arg) (hash-ref value-arg 'forceLarge #f)) (and (Ptr? value-arg) (Ptr-forceLarge value-arg))) diff --git a/fontland/fontland/table/cff/cff-top.rkt b/fontland/fontland/table/cff/cff-top.rkt index aaf9dcb0..bcb74ab0 100644 --- a/fontland/fontland/table/cff/cff-top.rkt +++ b/fontland/fontland/table/cff/cff-top.rkt @@ -20,7 +20,6 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFTop.js [(@type type) #f]) (define/override (pre-encode val) - #R 'in-PredefinedOp%-pre-encode ;; because fontkit depends on overloading 'version key, and we don't (let ([val (make-hasheq val)]) (hash-set! val 'x:version (hash-ref val 'version)) @@ -38,10 +37,8 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFTop.js (augment [@encode encode]) (define (@encode value stream ctx) - #RRR 'encode-pdop - #RR '--------------------- (or (index-of @predefinedOps value) - #RRR (send #RR @type encode #RR value #RR stream ctx))))) + (send @type encode value stream ctx))))) (define (PredefinedOp predefinedOps type) (make-object PredefinedOp% predefinedOps type)) @@ -79,9 +76,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFTop.js (class x:array% (super-new) (inherit-field [@len len] [@type type]) - #RRR @type (define/override (decode stream parent) - #RRR 'in-RangeArray%-decode (define length (resolve-length @len stream parent)) (for/fold ([res null] [count 0] @@ -130,15 +125,26 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFTop.js 'sentinel uint32be)))) (define ptr (CFFPointer CFFPrivateDict)) + +(define CFFPrivateOp% + (class x:base% + (super-new) + + (augment [@decode decode]) + (define (@decode stream parent operands) + (hash-set! parent 'length (first operands)) + (send ptr decode stream parent (list (second operands)))) + + (define/augment (size dict ctx) + (list (send CFFPrivateDict size dict ctx #false) + (car (send ptr size dict ctx)))) + + (define/augment (encode dict stream ctx) + (list (send CFFPrivateDict size dict ctx #false) + (car (send ptr encode dict stream ctx)))))) + (define (CFFPrivateOp . args) - (apply make-object - (class x:base% - (super-new) - (augment [@decode decode]) - (define (@decode stream parent operands) - (hash-set! parent 'length (first operands)) - (decode ptr stream #:parent parent (list (second operands))))) - args)) + (apply make-object CFFPrivateOp% args)) (define FontDict (CFFDict @@ -190,7 +196,6 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFTop.js (x:versioned-struct #:pre-encode (λ (val) - #R 'in-cfftop-pre-encode ;; because fontkit depends on overloading 'version key, and we don't (hash-set! val 'x:version (hash-ref val 'version)) val)