progress
parent
8ae32ee305
commit
6af07a581a
@ -0,0 +1,61 @@
|
|||||||
|
#lang fontkit/racket
|
||||||
|
(require br/cond)
|
||||||
|
(provide (all-defined-out))
|
||||||
|
|
||||||
|
#|
|
||||||
|
approximates
|
||||||
|
https://github.com/mbutterick/fontkit/blob/master/src/opentype/GlyphIterator.js
|
||||||
|
|#
|
||||||
|
|
||||||
|
(define-subclass object%
|
||||||
|
(GlyphIterator glyphs [flags (mhasheq)])
|
||||||
|
(field [index #f])
|
||||||
|
(reset flags)
|
||||||
|
|
||||||
|
(define/public (reset flags)
|
||||||
|
(set-field! flags this flags)
|
||||||
|
(set-field! index this 0))
|
||||||
|
|
||||||
|
(define/public (cur)
|
||||||
|
(and (< (· this index) (length (· this glyphs)))
|
||||||
|
(list-ref (· this glyphs) (· this index))))
|
||||||
|
|
||||||
|
(define/public (shouldIgnore glyph flags)
|
||||||
|
(or (and (· flags ignoreMarks) (· glyph isMark))
|
||||||
|
(and (· flags ignoreBaseGlyphs) (not (· glyph isMark)))
|
||||||
|
(and (· flags ignoreLigatures) (· glyph isLigature))))
|
||||||
|
|
||||||
|
(define/public (move dir)
|
||||||
|
(increment-field! index this dir)
|
||||||
|
(while (and (<= 0 (· this index))
|
||||||
|
(< (· this index) (length (· this glyphs)))
|
||||||
|
(send this shouldIgnore (list-ref (· this glyphs) (· this index)) (· this flags)))
|
||||||
|
(increment-field! index this dir))
|
||||||
|
|
||||||
|
(if (or (> 0 (· this index))
|
||||||
|
(>= (· this index) (length (· this glyphs))))
|
||||||
|
#f
|
||||||
|
(list-ref (· this glyphs) (· this index))))
|
||||||
|
|
||||||
|
(define/public (next) (move 1))
|
||||||
|
|
||||||
|
(define/public (prev) (move -1))
|
||||||
|
|
||||||
|
(define/public (peek [count 1])
|
||||||
|
(define idx (· this index))
|
||||||
|
(define res (send this increment count))
|
||||||
|
(set-field! index this idx)
|
||||||
|
res)
|
||||||
|
|
||||||
|
(define/public (peekIndex [count 1])
|
||||||
|
(define idx (· this index))
|
||||||
|
(send this increment count)
|
||||||
|
(define res (· this index))
|
||||||
|
(set-field! index this idx)
|
||||||
|
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))))
|
||||||
|
|
Loading…
Reference in New Issue