diff --git a/fontland/fontland/font.rkt b/fontland/fontland/font.rkt index ff042888..d5d55cc6 100644 --- a/fontland/fontland/font.rkt +++ b/fontland/fontland/font.rkt @@ -5,7 +5,7 @@ "subset.rkt" "glyph.rkt" "bbox.rkt" - "glyphrun.rkt" + (except-in "glyphrun.rkt" advanceWidth) "directory.rkt" "db.rkt" xenomorph @@ -275,7 +275,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/TTFFont.js (define positions (for/list ([pos (in-list posns)]) (match pos [(list xad yad xoff yoff _) (+GlyphPosition xad yad xoff yoff)]))) - (+GlyphRun glyphs positions)])) + (glyphrun glyphs positions)])) (define (harfbuzz-layout this codepoints userFeatures script language) diff --git a/fontland/fontland/glyphrun.rkt b/fontland/fontland/glyphrun.rkt index 1131a5f6..877b8907 100644 --- a/fontland/fontland/glyphrun.rkt +++ b/fontland/fontland/glyphrun.rkt @@ -12,20 +12,26 @@ https://github.com/mbutterick/fontkit/blob/master/src/layout/GlyphRun.js ;; Represents a run of Glyph and GlyphPosition objects. ;; Returned by the font layout method. -(define-subclass object% (GlyphRun - glyphs ; An array of Glyph objects in the run - positions) ; An array of GlyphPosition objects for each glyph in the run +#;(define-subclass object% (GlyphRun + glyphs ; An array of Glyph objects in the run + positions) ; An array of GlyphPosition objects for each glyph in the run - (define/public (advanceWidth) - (for/sum ([pos (in-list positions)]) - (· pos xAdvance)))) + (define/public (advanceWidth) + (for/sum ([pos (in-list positions)]) + (· pos xAdvance)))) +(struct glyphrun (glyphs positions) #:transparent) + +(define (advanceWidth gr) + (for/sum ([pos (in-list (glyphrun-positions gr))]) + (· pos xAdvance))) + (define (append-glyphruns . grs) (for/fold ([glyphss null] [positionss null] - #:result (make-object GlyphRun + #:result (make-object glyphrun (apply append (reverse glyphss)) (apply append (reverse positionss)))) ([gr (in-list grs)]) diff --git a/fontland/fontland/main.rkt b/fontland/fontland/main.rkt index 72b77ba9..e27a4adb 100644 --- a/fontland/fontland/main.rkt +++ b/fontland/fontland/main.rkt @@ -7,4 +7,5 @@ "glyph-position.rkt" "subset.rkt" "bbox.rkt" - "tables.rkt") \ No newline at end of file + "tables.rkt" + "glyphrun.rkt") \ No newline at end of file