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

@ -76,8 +76,6 @@ https://github.com/mbutterick/fontkit/blob/master/src/glyph/TTFGlyph.js
(define glyfPos (list-ref offsets id)) (define glyfPos (list-ref offsets id))
(define nextPos (list-ref offsets (add1 id))) (define nextPos (list-ref offsets (add1 id)))
(report* glyfPos nextPos)
;; Nothing to do if there is no data for this glyph ;; Nothing to do if there is no data for this glyph
(cond (cond
[(= glyfPos nextPos) #f] [(= glyfPos nextPos) #f]
@ -108,12 +106,11 @@ https://github.com/mbutterick/fontkit/blob/master/src/glyph/TTFGlyph.js
(hash-set! glyph 'points empty) (hash-set! glyph 'points empty)
(define endPtsOfContours (send (+Array uint16be (· glyph numberOfContours)) decode stream)) (define endPtsOfContours (send (+Array uint16be (· glyph numberOfContours)) decode stream))
(report* (· glyph numberOfContours) endPtsOfContours)
(hash-set! glyph 'instructions (send (+Array uint8be uint16be) decode stream)) (hash-set! glyph 'instructions (send (+Array uint8be uint16be) decode stream))
(define numCoords (add1 (list-ref endPtsOfContours (sub1 (length endPtsOfContours))))) (define numCoords (add1 (list-ref endPtsOfContours (sub1 (length endPtsOfContours)))))
(report numCoords)
(define flags (define flags
(reverse (reverse
(for/fold ([flags empty]) (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))))) (append repeated-flags (cons flag flags)))))
(report flags 'my-flags-homey)
(report endPtsOfContours)
(define glyph-points (mhash)) (define glyph-points (mhash))
(for ([(flag i) (in-indexed flags)]) (for ([(flag i) (in-indexed flags)])
(define point (+Point (zero? (bitwise-and flag ON_CURVE)) (and (index-of endPtsOfContours i) #t) 0 0)) (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) (define-subclass PDFFont (EmbeddedFont document font id)
(report 'embedded-font)
(field [subset (· this font createSubset)] (field [subset (· this font createSubset)]
;; we make `unicode` and `width` fields integer-keyed hashes not lists ;; we make `unicode` and `width` fields integer-keyed hashes not lists
;; because they offer better random access and growability ;; 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]) (define/contract (encode this text [features #f])
((string?) ((or/c list? #f)) . ->*m . ((string?) ((or/c list? #f)) . ->*m .
(list/c (listof string?) (listof (is-a?/c GlyphPosition)))) (list/c (listof string?) (listof (is-a?/c GlyphPosition))))
(report 'in-embedded-encode)
(define glyphRun (send (· this font) layout text features)) (define glyphRun (send (· this font) layout text features))
(define glyphs (· glyphRun glyphs)) (define glyphs (· glyphRun glyphs))
(define positions (· glyphRun positions)) (define positions (· glyphRun positions))

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

Loading…
Cancel
Save