From f25c3a2aeebda7209ec0f167153f456164203090 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Fri, 8 Mar 2019 13:18:08 -0800 Subject: [PATCH] why isn't ptr-offset set --- fontland/fontland/subset.rkt | 10 ++++++++-- fontland/fontland/table/cff/cff-dict.rkt | 18 ++++++++++++++---- fontland/fontland/table/cff/cff-operand.rkt | 6 ++++-- fontland/fontland/table/cff/cff-top.rkt | 11 +++++++---- 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/fontland/fontland/subset.rkt b/fontland/fontland/subset.rkt index 3fe29116..f2bcf7ff 100644 --- a/fontland/fontland/subset.rkt +++ b/fontland/fontland/subset.rkt @@ -78,16 +78,23 @@ https://github.com/mbutterick/fontkit/blob/master/src/subset/CFFSubset.js (subset-add-glyph! ss 0) ss) +(require racket/format racket/string) +(define (bytes->hexes bs) + (string-join + (for/list ([b (in-bytes bs)]) + (~r #:base 16 b #:min-width 2 #:pad-string "0"))  " ")) + (define (subsetCharstrings this) (set-cff-subset-charstrings! this null) (define gsubrs (make-hash)) (for ([gid (in-list (subset-glyphs this))]) + #R gid + (set-cff-subset-charstrings! this (append (cff-subset-charstrings this) (list (getCharString (cff-subset-cff this) gid)))) - #R gid (define glyph (get-glyph (subset-font this) gid)) ;; apparently path parsing is not necessary? #;(define path (hash-ref glyph 'path)) ;; this causes the glyph to be parsed @@ -190,7 +197,6 @@ https://github.com/mbutterick/fontkit/blob/master/src/subset/CFFSubset.js 'stringIndex (cff-subset-strings this) 'globalSubrIndex (cff-subset-gsubrs this))) - #R top (encode CFFTop top stream) (error 'boom)) diff --git a/fontland/fontland/table/cff/cff-dict.rkt b/fontland/fontland/table/cff/cff-dict.rkt index ac1ee837..9f5720f9 100644 --- a/fontland/fontland/table/cff/cff-dict.rkt +++ b/fontland/fontland/table/cff/cff-dict.rkt @@ -30,7 +30,15 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFDict.js [_ operands])) (define (encodeOperands type stream ctx operands) - (error 'cff-dict-encodeOperands-undefined)) + (cond + [(list? type) + (for/list ([(op i) (in-indexed operands)]) + (car (encodeOperands (list-ref type i) stream ctx op)))] + [(xenomorphic? type) (encode type operands stream #:parent ctx)] + [(number? operands) (list operands)] + [(boolean? operands) (list (if operands 1 0))] + [(list? operands) operands] + [else (list operands)])) (define/override (post-decode val) (dict->mutable-hash val)) @@ -72,7 +80,8 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFDict.js ret) - (define/augment (size dict parent [includePointers #true]) + (augment [@size size]) + (define (@size dict parent [includePointers #true]) (define ctx (mhasheq x:parent-key parent x:val-key dict @@ -99,7 +108,8 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFDict.js len) - (define/augment (encode stream dict parent) - (error 'cff-dict-encode-undefined)))) + (augment [@encode encode]) + (define (@encode stream dict parent) + (error 'cff-dict-encode-undefined)))) (define (CFFDict [ops null]) (make-object CFFDict% ops)) \ No newline at end of file diff --git a/fontland/fontland/table/cff/cff-operand.rkt b/fontland/fontland/table/cff/cff-operand.rkt index be7e7e00..0932e320 100644 --- a/fontland/fontland/table/cff/cff-operand.rkt +++ b/fontland/fontland/table/cff/cff-operand.rkt @@ -50,10 +50,12 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFOperand.js (let ([strs (cons (vector-ref FLOAT_LOOKUP n2) strs)]) (values strs #false))]))]))])) - (define/augment (size value-arg) + (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 - (define value (if (hash-ref value-arg 'forceLarge #f) 32768 value-arg)) + (define value (if (and (hash? value-arg) (hash-ref value-arg 'forceLarge #f)) + 32768 + value-arg)) (cond [(not (integer? value)) ; floating point diff --git a/fontland/fontland/table/cff/cff-top.rkt b/fontland/fontland/table/cff/cff-top.rkt index f09ad260..a0a1a7e6 100644 --- a/fontland/fontland/table/cff/cff-top.rkt +++ b/fontland/fontland/table/cff/cff-top.rkt @@ -29,8 +29,11 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFTop.js (define/augment (size value ctx) (error 'predefined-op-size-not-finished)) - (define/augment (encode stream value ctx) - (error 'predefined-op-encode-not-finished)))) + (augment [@encode encode]) + (define (@encode stream value ctx) + #R (get-field pointer-relative-to @type) + (or (index-of @predefinedOps value) + (encode @type value stream #:parent ctx))))) (define (PredefinedOp predefinedOps type) (make-object PredefinedOp% predefinedOps type)) @@ -176,8 +179,8 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFTop.js (x:versioned-struct #:pre-encode (λ (val) - ;; because fontkit depends on overloading 'version key, and we don't - (hash-set! val 'x:version (hash-ref val 'version)) + ;; because fontkit depends on overloading 'version key, and we don't + (hash-set! val 'x:version (hash-ref val 'version)) val) fixed16be (dictify