diff --git a/pitfall/fontkit/glyph-iterator.rkt b/pitfall/fontkit/glyph-iterator.rkt index 05763069..f1e1c058 100644 --- a/pitfall/fontkit/glyph-iterator.rkt +++ b/pitfall/fontkit/glyph-iterator.rkt @@ -26,6 +26,8 @@ https://github.com/mbutterick/fontkit/blob/master/src/opentype/GlyphIterator.js (and (· flags ignoreLigatures) (· glyph isLigature)))) (define/public (move dir) + (unless (= (abs dir) 1) + (raise-argument-error 'GlyphIterator:move "1 or -1" dir)) (increment-field! index this dir) (while (and (<= 0 (· this index)) (< (· this index) (length (· this glyphs))) @@ -55,7 +57,22 @@ https://github.com/mbutterick/fontkit/blob/master/src/opentype/GlyphIterator.js res) (define/public (increment [count 1]) - (for ([i (in-range (abs count))]) - (send this move (if (negative? count) -1 1))) - (list-ref (· this glyphs) (· this index)))) - + (for/last ([i (in-range (abs count))]) + (send this move (if (negative? count) -1 1))))) + +(test-module + (define gi (+GlyphIterator '(a b c))) + (check-equal? (· gi index) 0) + (check-equal? (send gi cur) 'a) + (check-equal? (send gi move 1) 'b) + (check-equal? (send gi move 1) 'c) + (check-false (send gi move 1)) + (check-equal? (send gi increment -3) 'a) + (check-equal? (send gi cur) 'a) + (check-equal? (send gi peek 1) 'b) + (check-equal? (send gi peek 2) 'c) + (check-equal? (send gi peek 3) #f) + (check-equal? (send gi cur) 'a) + + + ) diff --git a/pitfall/fontkit/gpos-processor.rkt b/pitfall/fontkit/gpos-processor.rkt index 70d630d8..0b7f5e00 100644 --- a/pitfall/fontkit/gpos-processor.rkt +++ b/pitfall/fontkit/gpos-processor.rkt @@ -8,8 +8,18 @@ https://github.com/mbutterick/fontkit/blob/master/src/opentype/GPOSProcessor.js (define-subclass OTProcessor (GPOSProcessor) + (define/public (applyPositionValue sequenceIndex value) + (define position (list-ref (· this positions) (send (· this glyphIterator) peekIndex sequenceIndex))) + (when (· value xAdvance) + (increment-field! xAdvance position (or (· value xAdvance) 0))) + (when (· value yAdvance) + (increment-field! yAdvance position (· value yAdvance))) + (when (· value xPlacement) + (increment-field! xOffset position (· value xPlacement))) + (when (· value yPlacement) + (increment-field! yOffset position (· value yPlacement)))) + (define/override (applyLookup lookupType table) - (report/file 'starting-applyLookup) (case lookupType [(1) ;; Single positioning value (report/file 'single-positioning-value) @@ -17,25 +27,26 @@ https://github.com/mbutterick/fontkit/blob/master/src/opentype/GPOSProcessor.js (report/file index) (cond [(= index -1) #f] - [else (case (· table version) + [else (case (report (· table version)) [(1) (send this applyPositionValue 0 (· table value))] [(2) (send this applyPositionValue 0 (send (· table values) get index))]) #t])] [(2) ;; Pair Adjustment Positioning - (report/file 'pair-adjustment) + (report/file 'applyLookup:pair-adjustment) (define nextGlyph (· this glyphIterator peek)) - (report/file nextGlyph) (cond [(not nextGlyph) #f] [else + (report 'getting-pair-coverage-for) + (report* (· this glyphIterator cur id) (· this glyphIterator peek id) (· table coverage)) (define index (send this coverageIndex (· table coverage))) - (report/file index) + (report index) (cond [(= index -1) #f] [else - (case (· table version) + (case (report (· table version)) [(1) ;; Adjustments for glyph pairs - (report/file 'glyph-pair) + (report 'glyph-pair) (define set (send (· table pairSets) get index)) (for/first ([pair (in-list set)] #:when (= (· pair secondGlyph) (· nextGlyph id))) @@ -43,8 +54,8 @@ https://github.com/mbutterick/fontkit/blob/master/src/opentype/GPOSProcessor.js (send this applyPositionValue 0 (· pair value2)))] [(2) ;; Class pair adjustment (report/file 'class-pair) - (define class1 (send this getClassId (· this glyphIterator cur id) (· table classDef1))) - (define class2 (send this getClassId (· nextGlyph id) (· table classDef2))) + (define class1 (send this getClassID (· this glyphIterator cur id) (· table classDef1))) + (define class2 (send this getClassID (· nextGlyph id) (· table classDef2))) (cond [(or (= class1 -1) (= class2 -1)) #f] [else (define pair (send (send (· table classRecords) get class1) get class2)) @@ -52,26 +63,26 @@ https://github.com/mbutterick/fontkit/blob/master/src/opentype/GPOSProcessor.js (send this applyPositionValue 0 (· pair value2)) #t])])])])] [(3) ;; Cursive Attachment Positioning - (report/file 'cursive-attachment-positioning-unimplemented) - (error)] + #;(report/file 'cursive-attachment-positioning-unimplemented) + (void)] [(4) ;; Mark to base positioning - (report/file 'mark-to-base-positioning-unimplemented) - (error)] + #;(report/file 'mark-to-base-positioning-unimplemented) + (void)] [(5) ;; Mark to ligature positioning - (report/file 'mark-to-ligature-positioning-unimplemented) - (error)] + #;(report/file 'mark-to-ligature-positioning-unimplemented) + (void)] [(6) ;; Mark to mark positioning - (report/file 'mark-to-mark-positioning-unimplemented) - (error)] + #;(report/file 'mark-to-mark-positioning-unimplemented) + (void)] [(7) ;; Contextual positioning - (report/file 'contextual-positioning-unimplemented) - (error)] + #;(report/file 'contextual-positioning-unimplemented) + (void)] [(8) ;; Chaining contextual positioning - (report/file 'chaining-contextual-positioning-unimplemented) - (error)] + #;(report/file 'chaining-contextual-positioning-unimplemented) + (void)] [(9) ;; Extension positioning - (report/file 'extension-contextual-positioning-unimplemented) - (error)] + #;(report/file 'extension-contextual-positioning-unimplemented) + (void)] [else (raise-argument-error 'GPOSProcessor:applyLookup "supported GPOS table" lookupType)])) @@ -80,9 +91,11 @@ https://github.com/mbutterick/fontkit/blob/master/src/opentype/GPOSProcessor.js (define/override (applyFeatures userFeatures glyphs advances) (super applyFeatures userFeatures glyphs advances) - (for ([i (in-range (length (· this glyphs)))]) - (send this fixCursiveAttachment i)) - (send this fixMarkAttachment)) + (report/file 'fixCursiveAttachment-unimplemented) + #;(for ([i (in-range (length (· this glyphs)))]) + (send this fixCursiveAttachment i)) + (report/file 'fixMarkAttachment-unimplemented) + #;(send this fixMarkAttachment)) ) \ No newline at end of file diff --git a/pitfall/fontkit/ot-processor.rkt b/pitfall/fontkit/ot-processor.rkt index 96761795..6c9849bb 100644 --- a/pitfall/fontkit/ot-processor.rkt +++ b/pitfall/fontkit/ot-processor.rkt @@ -105,7 +105,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/opentype/OTProcessor.js (send (· this glyphIterator) reset (· lookup flags)) (while (< (· this glyphIterator index) (length glyphs)) (when (dict-has-key? (· this glyphIterator cur features) feature) - (for/first ([table (in-list (· lookup subTables))]) + (for/or ([table (in-list (· lookup subTables))]) (send this applyLookup (· lookup lookupType) table))) (send (· this glyphIterator) next)))) @@ -118,13 +118,25 @@ https://github.com/mbutterick/fontkit/blob/master/src/opentype/OTProcessor.js (define/public (coverageIndex coverage [glyph #f]) (unless glyph (set! glyph (· this glyphIterator cur id))) - - (or (case (· coverage version) + (or (case (report (· coverage version)) [(1) (index-of (· coverage glyphs) glyph)] [(2) (for/first ([range (in-list (· coverage rangeRecords))] #:when (<= (· range start) glyph (· range end))) (+ (· range startCoverageIndex) glyph (- (· range start))))] [else #f]) -1)) - - ) \ No newline at end of file + (define/public (getClassID glyph classDef) + (or + (case (· classDef version) + [(1) ;; Class array + (define i (- glyph (· classDef startGlyph))) + (and (>= i 0) + (< i (length (· classDef classValueArray))) + (list-ref (· classDef classValueArray) i))] + [(2) + (for/first ([range (in-list (· classDef classRangeRecord))] + #:when (<= (· range start) glyph (· range end))) + (· range class))]) + 0))) + + \ No newline at end of file diff --git a/pitfall/pdfkit/node_modules/fontkit/index.js b/pitfall/pdfkit/node_modules/fontkit/index.js index 33c6e740..623240f4 100644 --- a/pitfall/pdfkit/node_modules/fontkit/index.js +++ b/pitfall/pdfkit/node_modules/fontkit/index.js @@ -2523,7 +2523,7 @@ var ValueRecord = function () { var fields = {}; fields.rel = function () { - console.log("struct._startOffset="+ struct._startOffset); + //console.log("struct._startOffset="+ struct._startOffset); return struct._startOffset; }; @@ -12417,9 +12417,9 @@ var TTFFont = (_class = function () { * @return {GlyphRun} */ TTFFont.prototype.layout = function layout(string, userFeatures, script, language) { - console.log("userFeatures="+userFeatures); - console.log("script="+script); - console.log("language="+language); + //console.log("userFeatures="+userFeatures); + //console.log("script="+script); + //console.log("language="+language); return this._layoutEngine.layout(string, userFeatures, script, language); }; diff --git a/pitfall/pitfall/alltest.rkt b/pitfall/pitfall/alltest.rkt index 870873e6..c5535978 100644 --- a/pitfall/pitfall/alltest.rkt +++ b/pitfall/pitfall/alltest.rkt @@ -15,6 +15,6 @@ pitfall/test/test12 ; ttf subset pitfall/test/test13 ; subset with composites pitfall/test/test14 ; Fira ttf with GPOS (no kerning) - ;pitfall/test/test15 ; Fira ttf with GPOS kerning + pitfall/test/test15 ; Fira ttf with GPOS kerning pitfall/page-test (submod pitfall/zlib test))) \ No newline at end of file diff --git a/pitfall/pitfall/embedded.rkt b/pitfall/pitfall/embedded.rkt index 1e62c480..c5928c37 100644 --- a/pitfall/pitfall/embedded.rkt +++ b/pitfall/pitfall/embedded.rkt @@ -49,7 +49,8 @@ https://github.com/mbutterick/pdfkit/blob/master/lib/font/embedded.coffee (for ([g (in-list glyphs)]) (· g id)) (define positions (· glyphRun positions)) - (report positions) + (report/file (for/list ([p (in-list positions)]) + (list (· p xAdvance) (· p xOffset)))) (define-values (subset-idxs new-positions) (for/lists (idxs posns) ([(glyph i) (in-indexed glyphs)] diff --git a/pitfall/pitfall/test/out.bin b/pitfall/pitfall/test/out.bin index 9a630365..82c6a1c3 100644 Binary files a/pitfall/pitfall/test/out.bin and b/pitfall/pitfall/test/out.bin differ diff --git a/pitfall/pitfall/test/test14rkt.pdf b/pitfall/pitfall/test/test14rkt.pdf index e69de29b..a2e57e9f 100644 Binary files a/pitfall/pitfall/test/test14rkt.pdf and b/pitfall/pitfall/test/test14rkt.pdf differ diff --git a/pitfall/pitfall/test/test15.coffee b/pitfall/pitfall/test/test15.coffee index 204591b8..53cbb1f9 100644 --- a/pitfall/pitfall/test/test15.coffee +++ b/pitfall/pitfall/test/test15.coffee @@ -9,7 +9,7 @@ make = (doc) -> # Set the font, draw some text doc.font('the-font') .fontSize(25) - .text('ATAVATA', 100, 100, {width: false}) + .text('HTAVATH', 100, 100, {width: false}) doc.end() diff --git a/pitfall/pitfall/test/test15.pdf b/pitfall/pitfall/test/test15.pdf index d91e9f3c..5ba4007e 100644 Binary files a/pitfall/pitfall/test/test15.pdf and b/pitfall/pitfall/test/test15.pdf differ diff --git a/pitfall/pitfall/test/test15.rkt b/pitfall/pitfall/test/test15.rkt index 2a3f8818..5452bd17 100644 --- a/pitfall/pitfall/test/test15.rkt +++ b/pitfall/pitfall/test/test15.rkt @@ -12,11 +12,11 @@ (send* doc [font "the-font"] [fontSize 25] - [text "ATAVATA" 100 100 (hash 'width #f)])) + [text "HTAVATH" 100 100 (hash 'width #f)])) (define-runtime-path this "test15rkt.pdf") -(make-doc this #f proc #:test #f) +(make-doc this #f proc) -#;(define-runtime-path that "test15crkt.pdf") -#;(make-doc that #t proc #:pdfkit #f) \ No newline at end of file +(define-runtime-path that "test15crkt.pdf") +(make-doc that #t proc #:pdfkit #f) \ No newline at end of file diff --git a/pitfall/pitfall/test/test15crkt copy.pdf b/pitfall/pitfall/test/test15crkt copy.pdf new file mode 100644 index 00000000..325efa8b Binary files /dev/null and b/pitfall/pitfall/test/test15crkt copy.pdf differ diff --git a/pitfall/pitfall/test/test15crkt.pdf b/pitfall/pitfall/test/test15crkt.pdf new file mode 100644 index 00000000..325efa8b Binary files /dev/null and b/pitfall/pitfall/test/test15crkt.pdf differ diff --git a/pitfall/pitfall/test/test15rkt copy.pdf b/pitfall/pitfall/test/test15rkt copy.pdf new file mode 100644 index 00000000..3158c592 Binary files /dev/null and b/pitfall/pitfall/test/test15rkt copy.pdf differ diff --git a/pitfall/pitfall/test/test15rkt.pdf b/pitfall/pitfall/test/test15rkt.pdf index 74b79659..3158c592 100644 Binary files a/pitfall/pitfall/test/test15rkt.pdf and b/pitfall/pitfall/test/test15rkt.pdf differ