bug in encoding empty glyf table
parent
ec675b61fa
commit
677a4291f1
@ -0,0 +1,23 @@
|
||||
#lang fontkit/racket
|
||||
(require restructure)
|
||||
(provide (all-defined-out))
|
||||
#|
|
||||
approximates
|
||||
https://github.com/mbutterick/fontkit/blob/master/src/tables/glyf.js
|
||||
|#
|
||||
|
||||
(define-subclass Struct (Rglyf))
|
||||
|
||||
(define glyf (+Array (+Buffer)))
|
||||
|
||||
(test-module
|
||||
(define ip (open-input-file charter-path))
|
||||
(define dir (deserialize (read (open-input-file charter-directory-path))))
|
||||
(define offset (· dir tables glyf offset))
|
||||
(define len (· dir tables glyf length))
|
||||
(check-equal? offset 4620)
|
||||
(check-equal? len 34072)
|
||||
(set-port-position! ip 0)
|
||||
(define table-bytes (peek-bytes len offset ip))
|
||||
(define ds (+DecodeStream table-bytes))
|
||||
)
|
@ -0,0 +1,36 @@
|
||||
#lang restructure/racket
|
||||
(require "number.rkt" "utils.rkt")
|
||||
(provide (all-defined-out))
|
||||
|
||||
#|
|
||||
approximates
|
||||
https://github.com/mbutterick/restructure/blob/master/src/Buffer.coffee
|
||||
|#
|
||||
|
||||
(define-subclass RestructureBase (Buffer [_length #f])
|
||||
(define/override (decode stream [parent #f])
|
||||
(define len (resolveLength _length stream parent))
|
||||
(send stream readBuffer len))
|
||||
|
||||
(define/override (size [val #f] [parent #f])
|
||||
(when val (unless (bytes? val)
|
||||
(raise-argument-error 'Buffer:size "bytes" val)))
|
||||
(if val
|
||||
(bytes-length val)
|
||||
(resolveLength _length val parent)))
|
||||
|
||||
(define/override (encode stream buf parent)
|
||||
(when (Number? _length)
|
||||
(send _length encode stream (bytes-length buf)))
|
||||
(send stream writeBuffer buf)))
|
||||
|
||||
|
||||
#;(test-module
|
||||
(require "stream.rkt")
|
||||
(define stream (+DecodeStream #"\2BCDEF"))
|
||||
(define S (+String uint8 'utf8))
|
||||
(check-equal? (send S decode stream) "BC")
|
||||
(define os (+EncodeStream))
|
||||
(send S encode os "Mike")
|
||||
(check-equal? (send os dump) #"\4Mike")
|
||||
(check-equal? (send (+String) size "foobar") 6))
|
Loading…
Reference in New Issue