main
Matthew Butterick 7 years ago
parent 12147506cb
commit b758ec2723

@ -1,12 +1,13 @@
#lang fontkit/racket
(provide (all-defined-out))
(require (for-syntax racket/string))
(define-macro (define-table-codecs ID TABLE-ID ...)
(with-pattern ([(TABLE-ID-STRING ...) (pattern-case-filter #'(TABLE-ID ...)
[STX (datum->syntax caller-stx (format "~a.rkt" (syntax->datum #'STX)))])])
[STX (datum->syntax caller-stx (string-replace (format "~a.rkt" (syntax->datum #'STX)) "/" ""))])])
#'(begin
(r+p TABLE-ID-STRING ...)
(test-module (require (submod TABLE-ID-STRING test) ...))
(define ID (make-hasheq (map cons (list 'TABLE-ID ...) (list TABLE-ID ...)))))))
(define-table-codecs table-codecs maxp hhea head loca prep fpgm hmtx cvt_ glyf)
(define-table-codecs table-codecs maxp hhea head loca prep fpgm hmtx cvt_ glyf OS/2 post)

@ -77,12 +77,17 @@ For now, we'll just measure width of the characters.
#;(send (send (· this subset) encodeStream) pipe fontFile)
(send fontFile end (send (send (· this subset) encodeStream) dump))
;; todo
;; (define familyClass (send (· this font) has-table? #"OS/2"))
(define familyClass 0)
;; todo: flags
(define flags 0)
(define familyClass (let ([val (if (send (· this font) has-table? 'OS/2)
(· (send (· this font) _getTable 'OS/2) sFamilyClass)
0)])
(floor (/ val 256)))) ; equivalent to >> 8
(define flags (+
(if (not (zero? (· (send (· this font) _getTable 'post) isFixedPitch))) (expt 2 0) 0)
(if (<= 1 familyClass 7) (expt 2 1) 0)
(expt 2 2) ; assume the font uses non-latin characters
(if (= familyClass 10) (expt 2 3) 0)
(if (· (send (· this font) _getTable 'head) macStyle italic) (expt 2 6) 0)))
;; generate a random tag (6 uppercase letters. 65 is the char code for 'A')
(when (test-mode) (random-seed 0))

@ -18,11 +18,4 @@
(make-doc this #f proc)
(define-runtime-path that "test12crkt.pdf")
(make-doc that #t proc #:pdfkit #f)
#;(module+ test
(define doc (make-object PDFDocument))
(send doc registerFont "Charter" (path->string charter-path))
(send* doc [font "Charter"])
(send doc pipe (open-output-string))
(send doc end))
(make-doc that #t proc #:pdfkit #f)
Loading…
Cancel
Save