diff --git a/pitfall/pitfall/embedded.rkt b/pitfall/pitfall/embedded.rkt index baaed63d..db1f353f 100644 --- a/pitfall/pitfall/embedded.rkt +++ b/pitfall/pitfall/embedded.rkt @@ -54,15 +54,15 @@ https://github.com/mbutterick/pdfkit/blob/master/lib/font/embedded.coffee (list string size (and features (sort features symbol*m . - (list/c (listof string?) (listof GlyphPosition?))) +(define (encode this text [features #f]) + #;((string?) ((option/c list?)) . ->*m . + (list/c (listof string?) (listof glyphposition?))) #;(report*/file 'starting-layout-in-embedded (description (· this font))) (define glyphRun (send (· this font) layout text features)) (define glyphs (glyphrun-glyphs glyphRun)) @@ -77,12 +77,12 @@ https://github.com/mbutterick/pdfkit/blob/master/lib/font/embedded.coffee [posn (in-list positions)]) (define gid (send (· this subset) includeGlyph (· glyph id))) (define subset-idx (toHex gid)) - (set-field! advanceWidth posn (· glyph advanceWidth)) + (set-glyph-position-advance-width! posn (· glyph advanceWidth)) - (hash-ref! (· this widths) gid (λ () (· posn advanceWidth))) + (hash-ref! (· this widths) gid (λ () (glyph-position-advance-width posn))) (hash-ref! (· this unicode) gid (λ () (· glyph codePoints))) - (send posn scale (· this scale)) + (scale-glyph-position! posn (· this scale)) (values subset-idx posn))) (list subset-idxs new-positions)) diff --git a/pitfall/pitfall/standard-font.rkt b/pitfall/pitfall/standard-font.rkt index f3704ae3..04ec05b3 100644 --- a/pitfall/pitfall/standard-font.rkt +++ b/pitfall/pitfall/standard-font.rkt @@ -36,8 +36,8 @@ (· this dictionary end)) -(define/contract (encode this text [options #f]) - ((string?) ((or/c hash? #f)) . ->*m . (list/c (listof string?) (listof (is-a?/c GlyphPosition)))) +(define (encode this text [options #f]) + #;((string?) ((or/c hash? #f)) . ->*m . (list/c (listof string?) (listof glyph-position?))) (define this-font (· this font)) (define encoded (send this-font encodeText text)) (define glyphs (send this-font glyphsForString text)) @@ -45,7 +45,7 @@ (define positions (for/list ([glyph (in-list glyphs)] [advance (in-list advances)]) - (make-object GlyphPosition advance 0 0 0 (send this-font widthOfGlyph glyph)))) + (+glyph-position advance 0 0 0 (send this-font widthOfGlyph glyph)))) (list encoded positions)) diff --git a/pitfall/pitfall/text.rkt b/pitfall/pitfall/text.rkt index dbd39757..e94cb440 100644 --- a/pitfall/pitfall/text.rkt +++ b/pitfall/pitfall/text.rkt @@ -10,7 +10,8 @@ sugar/unstable/js sugar/unstable/dict sugar/list - racket/promise) + racket/promise + fontland/glyph-position) (provide text-mixin) #| @@ -221,7 +222,7 @@ https://github.com/mbutterick/pdfkit/blob/master/lib/mixins/text.coffee (when (< last cur) (let* ([hex (string-append* (sublist encoded-char-strs last cur))] [posn (list-ref positions (sub1 cur))] - [advance (- (· posn xAdvance) (· posn advanceWidth))]) + [advance (- (glyph-position-x-advance posn) (glyph-position-advance-width posn))]) (push-end! commands (format "<~a> ~a" hex (number (- advance)))))) (set! last cur)) @@ -240,13 +241,13 @@ https://github.com/mbutterick/pdfkit/blob/master/lib/mixins/text.coffee (cond ;; If we have an x or y offset, we have to break out of the current TJ command ;; so we can move the text position. - [(or (not (zero? (· posn xOffset))) (not (zero? (· posn yOffset)))) + [(or (not (zero? (glyph-position-x-offset posn))) (not (zero? (glyph-position-y-offset posn)))) ;; Flush the current buffer (flush i) ;; Move the text position and flush just the current character (send this addContent (format "1 0 0 1 ~a ~a Tm" - (number (+ x (* (· posn xOffset) scale))) - (number (+ y (* (· posn yOffset) scale))))) + (number (+ x (* (glyph-position-x-offset posn) scale))) + (number (+ y (* (glyph-position-y-offset posn) scale))))) (flush (add1 i)) #t] [else @@ -255,12 +256,12 @@ https://github.com/mbutterick/pdfkit/blob/master/lib/mixins/text.coffee (send this addContent (format "1 0 0 1 ~a ~a Tm" (number x) (number y)))) ;; Group segments that don't have any advance adjustments - (unless (zero? (- (· posn xAdvance) (· posn advanceWidth))) + (unless (zero? (- (glyph-position-x-advance posn) (glyph-position-advance-width posn))) (addSegment (add1 i))) #f])) - (values havingOffset (+ x (* (· posn xAdvance) scale)))) + (values havingOffset (+ x (* (glyph-position-x-advance posn) scale)))) ;; Flush any remaining commands