main
Matthew Butterick 6 years ago
parent c2fc31616b
commit ca43aa9b71

@ -42,7 +42,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/glyph/CFFGlyph.js
(define gsubrs (hash-ref cff 'globalSubrIndex null))
(define gsubrsBias (bias this gsubrs))
(define privateDict (privateDictForGlyph cff (glyph-id this)))
(define privateDict (or (privateDictForGlyph cff (glyph-id this)) (make-hash)))
(define subrs (hash-ref privateDict 'Subrs null))
(define subrsBias (bias this subrs))

@ -84,8 +84,6 @@ https://github.com/mbutterick/fontkit/blob/master/src/subset/CFFSubset.js
(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)
@ -191,6 +189,12 @@ https://github.com/mbutterick/fontkit/blob/master/src/subset/CFFSubset.js
'stringIndex (cff-subset-strings this)
'globalSubrIndex (cff-subset-gsubrs this)))
(for ([k (sort (dict-keys topDict) symbol<?)])
(define val (dict-ref topDict k))
(unless (or (list? val) (dict? val))
k
val))
(encode CFFTop top stream))
#;(module+ test

@ -88,8 +88,6 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFDict.js
(augment [@size size])
(define (@size dict parent [includePointers #true])
#RRR @name
#RRR includePointers
(define ctx
(mhasheq x:parent-key parent
@ -104,8 +102,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFDict.js
[val (in-value (dict-ref dict (list-ref field 1) #false))]
#:unless (let ([ res (or (not val) (equal? val (list-ref field 3)))])
res))
#R k
#R len
(define operands (encodeOperands (list-ref field 2) #f ctx val))
(set! len (+ len
(for/sum ([op (in-list operands)])
@ -114,16 +111,18 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFDict.js
(define key (if (list? (list-ref field 0))
(list-ref field 0)
(list (list-ref field 0))))
(set! len (+ len #R (length key))))
(set! len (+ len (length key))))
(when #R includePointers
(set! len (+ len #R (hash-ref ctx x:pointer-size-key))))
(when includePointers
(set! len (+ len (hash-ref ctx x:pointer-size-key))))
(define final-len len)
#R final-len)
len)
(augment [@encode encode])
(define (@encode dict stream parent)
#RRR 'entering-cff-dict-encode
#R @name
#R @fields
(define ctx (mhasheq
x:pointers-key null
x:start-offset-key (pos stream)
@ -150,10 +149,13 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFDict.js
(define i 0)
(let loop ()
(when (< i (length (hash-ref ctx x:pointers-key)))
(when (< i #R (length (hash-ref ctx x:pointers-key)))
(define ptr (list-ref (hash-ref ctx x:pointers-key) i))
#R ptr
(set! i (add1 i))
(send (hash-ref ptr 'type) encode (hash-ref ptr 'val) stream (hash-ref ptr 'parent))
(loop))))))
(loop)))
#R 'returning-from-cff-dict-encode)))
(define (CFFDict [name 'unknown] [ops null]) (make-object CFFDict% name ops))

@ -1,6 +1,6 @@
#lang debug racket/base
(require racket/class racket/list xenomorph/pointer xenomorph/base "cff-struct.rkt")
(provide CFFPointer)
(provide CFFPointer CFFPointer%)
#|
approximates
@ -32,6 +32,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFPointer.js
(override [@encode encode])
(define (@encode value stream ctx)
#R 'entering=cff-pointer-encode
(cond
[(not stream)
;; compute the size (so ctx.pointerSize is correct)
@ -42,7 +43,6 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFPointer.js
(send this size value ctx)
(list (Ptr 0))]
[else
#RRR 'rees
(define ptr #false)
(set! offset-type (make-object
(class x:base%

@ -132,19 +132,22 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFTop.js
(augment [@decode decode])
(define (@decode stream parent operands)
(hash-set! parent 'length (first operands))
(send ptr decode stream parent (list (second operands))))
(hash-set! parent 'length #R (list-ref operands 0))
(send ptr decode stream parent (list (list-ref operands 1))))
(define/augment (size dict ctx)
(list (send CFFPrivateDict size dict ctx #false)
(car (send ptr size dict ctx))))
(define/augment (encode dict stream ctx)
#R 'encoding-privateop
(begin0
(list (send CFFPrivateDict size dict ctx #false)
(car (send ptr encode dict stream ctx))))))
#R (car (send ptr encode dict stream ctx)))
#R 'returning-from-privateop))))
(define (CFFPrivateOp . args)
(apply make-object CFFPrivateOp% args))
(define (CFFPrivateOp)
(make-object CFFPrivateOp%))
(define FontDict
(CFFDict

Loading…
Cancel
Save