main
Matthew Butterick 7 years ago
parent 3847daa32a
commit 1303acbb06

@ -43,7 +43,6 @@ https://github.com/mbutterick/fontkit/blob/master/src/subset/TTFSubset.js
|#
(define-subclass Subset (TTFSubset)
(report 'in-ttf-subset)
(field [glyphEncoder (make-object TTFGlyphEncoder)])
(field [glyf #f]
[offset #f]
@ -52,15 +51,11 @@ https://github.com/mbutterick/fontkit/blob/master/src/subset/TTFSubset.js
(as-methods
_addGlyph
encode)
(report 'in-ttf-subset-end)
)
encode))
(define/contract (_addGlyph this gid)
(index? . ->m . index?)
(report 'in-ttf-subset-addglyph)
(define glyph (send (· this font) getGlyph gid))
(define glyf (send glyph _decode))
@ -83,12 +78,9 @@ https://github.com/mbutterick/fontkit/blob/master/src/subset/TTFSubset.js
;; skip variation shit
(push-end-field! glyf this buffer)
(report 'updating-loca)
(hash-update! (get-field loca this) 'offsets (λ (os) (report* os (list (get-field offset this)))
(hash-update! (get-field loca this) 'offsets (λ (os)
(append os (list (get-field offset this)))))
(report 'updating-hmtx)
(hash-update! (get-field hmtx this) 'metrics (λ (ms) (append ms
(list (mhash 'advance (· glyph advanceWidth)
'bearing (· (send glyph _getMetrics) leftBearing))))))
@ -103,7 +95,6 @@ https://github.com/mbutterick/fontkit/blob/master/src/subset/TTFSubset.js
(define/contract (encode this stream)
(EncodeStream? . ->m . void?)
(report 'in-subset-encode)
(set-field! glyf this empty)
(set-field! offset this 0)
(set-field! loca this (mhash 'offsets empty))
@ -111,17 +102,12 @@ https://github.com/mbutterick/fontkit/blob/master/src/subset/TTFSubset.js
;; include all the glyphs used in the document
(for ([gid (in-list (· this glyphs))])
(report gid 'adding-gid)
(send this _addGlyph gid))
(report 'all-glyphs-added)
(report (· this glyphs) 'glyphs-added)
(define maxp (cloneDeep (send (· this font) _getTable 'maxp)))
(hash-set! maxp 'numGlyphs (length (· this glyf)))
;; populate the new loca table
(report 'doing-loca)
(hash-update! (· this loca) 'offsets (λ (vals) (append vals (list (· this offset)))))
(loca-preEncode (· this loca))
@ -129,10 +115,8 @@ https://github.com/mbutterick/fontkit/blob/master/src/subset/TTFSubset.js
(hash-set! head 'indexToLocFormat (· this loca version))
(define hhea (cloneDeep (send (· this font) _getTable 'hhea)))
(report (· this hmtx metrics))
(hash-set! hhea 'numberOfMetrics (length (· this hmtx metrics)))
(report 'encoding-directory)
(send Directory encode stream
(mhash 'tables
(mhash
@ -147,7 +131,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/subset/TTFSubset.js
'fpgm (send (· this font) _getTable 'fpgm)
)))
(report* (bytes-length (send stream dump)))
#;(report* (bytes-length (send stream dump)))
(void)
)

@ -76,8 +76,6 @@ https://github.com/mbutterick/fontkit/blob/master/src/glyph/TTFGlyph.js
(define glyfPos (list-ref offsets id))
(define nextPos (list-ref offsets (add1 id)))
(report* glyfPos nextPos)
;; Nothing to do if there is no data for this glyph
(cond
[(= glyfPos nextPos) #f]
@ -108,12 +106,11 @@ https://github.com/mbutterick/fontkit/blob/master/src/glyph/TTFGlyph.js
(hash-set! glyph 'points empty)
(define endPtsOfContours (send (+Array uint16be (· glyph numberOfContours)) decode stream))
(report* (· glyph numberOfContours) endPtsOfContours)
(hash-set! glyph 'instructions (send (+Array uint8be uint16be) decode stream))
(define numCoords (add1 (list-ref endPtsOfContours (sub1 (length endPtsOfContours)))))
(report numCoords)
(define flags
(reverse
(for/fold ([flags empty])
@ -131,9 +128,6 @@ https://github.com/mbutterick/fontkit/blob/master/src/glyph/TTFGlyph.js
(append repeated-flags (cons flag flags)))))
(report flags 'my-flags-homey)
(report endPtsOfContours)
(define glyph-points (mhash))
(for ([(flag i) (in-indexed flags)])
(define point (+Point (zero? (bitwise-and flag ON_CURVE)) (and (index-of endPtsOfContours i) #t) 0 0))

@ -8,7 +8,6 @@ https://github.com/mbutterick/pdfkit/blob/master/lib/font/embedded.coffee
|#
(define-subclass PDFFont (EmbeddedFont document font id)
(report 'embedded-font)
(field [subset (· this font createSubset)]
;; we make `unicode` and `width` fields integer-keyed hashes not lists
;; because they offer better random access and growability
@ -46,7 +45,6 @@ For now, we'll just measure width of the characters.
(define/contract (encode this text [features #f])
((string?) ((or/c list? #f)) . ->*m .
(list/c (listof string?) (listof (is-a?/c GlyphPosition))))
(report 'in-embedded-encode)
(define glyphRun (send (· this font) layout text features))
(define glyphs (· glyphRun glyphs))
(define positions (· glyphRun positions))

@ -15,10 +15,10 @@
;; test against non-subsetted font version
(define-runtime-path this "test12rkt.pdf")
(make-doc this #f proc #:test #f #:pdfkit #f)
(make-doc this #f proc #:pdfkit #f)
#;(define-runtime-path that "test12crkt.pdf")
#;(make-doc that #t proc #:pdfkit #f)
(define-runtime-path that "test12crkt.pdf")
(make-doc that #t proc #:pdfkit #f)
#;(module+ test
(define doc (make-object PDFDocument))

Loading…
Cancel
Save