You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
typesetting/pitfall/fontkit/gpos-processor.rkt

103 lines
4.3 KiB
Racket

#lang fontkit/racket
(require "ot-processor.rkt")
(provide (all-defined-out))
#|
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))))
7 years ago
(define/override (applyLookup lookupType table)
(case lookupType
[(1) ;; Single positioning value
#;(report/file 'single-positioning-value)
7 years ago
(define index (send this coverageIndex (· table coverage)))
#;(report/file index)
7 years ago
(cond
[(= index -1) #f]
[else #;(report (· table version))
(case (· table version)
7 years ago
[(1) (send this applyPositionValue 0 (· table value))]
[(2) (send this applyPositionValue 0 (send (· table values) get index))])
#t])]
[(2) ;; Pair Adjustment Positioning
#;(report/file 'applyLookup:pair-adjustment)
7 years ago
(define nextGlyph (· this glyphIterator peek))
(cond
[(not nextGlyph) #f]
[else
#;(report 'getting-pair-coverage-for)
#;(report* (· this glyphIterator cur id) (· this glyphIterator peek id) (· table coverage))
7 years ago
(define index (send this coverageIndex (· table coverage)))
#;(report index)
7 years ago
(cond
[(= index -1) #f]
[else
#;(report (· table version))
(case (· table version)
7 years ago
[(1) ;; Adjustments for glyph pairs
#;(report 'glyph-pair)
7 years ago
(define set (send (· table pairSets) get index))
(for/first ([pair (in-list set)]
#:when (= (· pair secondGlyph) (· nextGlyph id)))
(send this applyPositionValue 0 (· pair value1))
(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)))
7 years ago
(cond
[(or (= class1 -1) (= class2 -1)) #f]
[else (define pair (send (send (· table classRecords) get class1) get class2))
(send this applyPositionValue 0 (· pair value1))
(send this applyPositionValue 0 (· pair value2))
#t])])])])]
[(3) ;; Cursive Attachment Positioning
#;(report/file 'cursive-attachment-positioning-unimplemented)
(void)]
7 years ago
[(4) ;; Mark to base positioning
#;(report/file 'mark-to-base-positioning-unimplemented)
(void)]
7 years ago
[(5) ;; Mark to ligature positioning
#;(report/file 'mark-to-ligature-positioning-unimplemented)
(void)]
7 years ago
[(6) ;; Mark to mark positioning
#;(report/file 'mark-to-mark-positioning-unimplemented)
(void)]
7 years ago
[(7) ;; Contextual positioning
#;(report/file 'contextual-positioning-unimplemented)
(void)]
7 years ago
[(8) ;; Chaining contextual positioning
#;(report/file 'chaining-contextual-positioning-unimplemented)
(void)]
7 years ago
[(9) ;; Extension positioning
#;(report/file 'extension-contextual-positioning-unimplemented)
(void)]
7 years ago
[else
(raise-argument-error 'GPOSProcessor:applyLookup "supported GPOS table" lookupType)]))
(define/override (applyFeatures userFeatures glyphs advances)
7 years ago
(super applyFeatures userFeatures glyphs advances)
#;(report/file 'fixCursiveAttachment-unimplemented)
#;(for ([i (in-range (length (· this glyphs)))])
(send this fixCursiveAttachment i))
#;(report/file 'fixMarkAttachment-unimplemented)
#;(send this fixMarkAttachment))
7 years ago
)