pass test15 (gpos kerning)

main
Matthew Butterick 7 years ago
parent 6af07a581a
commit cc6f1fb148

@ -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)
)

@ -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))
)

@ -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))
)
(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)))

@ -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);
};

@ -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)))

@ -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)]

Binary file not shown.

@ -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()

Binary file not shown.

@ -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)
(define-runtime-path that "test15crkt.pdf")
(make-doc that #t proc #:pdfkit #f)
Loading…
Cancel
Save