resume in embedded:encode
parent
fa4eef1325
commit
f5b128dcb7
@ -0,0 +1,5 @@
|
||||
#lang pitfall/racket
|
||||
(provide CmapProcessor)
|
||||
|
||||
(define-subclass object% (CmapProcessor cmapTable)
|
||||
(super-new))
|
@ -0,0 +1,16 @@
|
||||
#lang pitfall/racket
|
||||
(provide GlyphPosition)
|
||||
|
||||
;; Represents positioning information for a glyph in a GlyphRun.
|
||||
(define-subclass object% (GlyphPosition
|
||||
;; The amount to move the virtual pen in the X direction after rendering this glyph.
|
||||
[xAdvance 0]
|
||||
;; The amount to move the virtual pen in the Y direction after rendering this glyph.
|
||||
[yAdvance 0]
|
||||
;; The offset from the pen position in the X direction at which to render this glyph.
|
||||
|
||||
[xOffset 0]
|
||||
;; The offset from the pen position in the Y direction at which to render this glyph.
|
||||
[yOffset 0])
|
||||
(super-new)
|
||||
)
|
@ -0,0 +1,37 @@
|
||||
#lang pitfall/racket
|
||||
(require "bbox.rkt" "script.rkt")
|
||||
(provide GlyphRun)
|
||||
|
||||
;; 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
|
||||
features-in
|
||||
script ; The script that was requested for shaping. This was either passed in or detected automatically.
|
||||
language) ; The language requested for shaping, as passed in. If `null`, the default language for the script was used.
|
||||
|
||||
(super-new)
|
||||
|
||||
;; An array of GlyphPosition objects for each glyph in the run
|
||||
(field [positions #f])
|
||||
|
||||
;; The directionality of the requested script (either ltr or rtl).
|
||||
(field [direction (script-direction script)])
|
||||
|
||||
;; The features requested during shaping. This is a combination of user
|
||||
;; specified features and features chosen by the shaper.
|
||||
(field [features (cond
|
||||
[(hash? features-in) features-in]
|
||||
;; Convert features to an object
|
||||
[(list? features-in)
|
||||
(define f (mhash))
|
||||
(for ([tag (in-list features)])
|
||||
(hash-set! f tag #t))
|
||||
f]
|
||||
[(not features-in) (mhash)]
|
||||
[else (error 'glyphrun:unknown-features-type)])])
|
||||
|
||||
|
||||
|
||||
|
||||
)
|
@ -0,0 +1,108 @@
|
||||
#lang pitfall/racket
|
||||
(require "script.rkt" "glyph.rkt" "glyphrun.rkt" "glyph-position.rkt")
|
||||
(provide LayoutEngine)
|
||||
|
||||
(define-subclass object% (LayoutEngine font)
|
||||
(super-new)
|
||||
(field [unicodeLayoutEngine #f]
|
||||
[kernProcessor #f]
|
||||
[engine
|
||||
;; Choose an advanced layout engine.
|
||||
;; We try the AAT morx table first since more
|
||||
;; scripts are currently supported because
|
||||
;; the shaping logic is built into the font.
|
||||
(cond
|
||||
[(· this font has-morx-table?) (error 'morx-layout-unimplemented)]
|
||||
[(or (· this font has-gsub-table?) (· this font has-gpos-table?))
|
||||
(error 'ot-layout-unimplemented)]
|
||||
[else #f])])
|
||||
|
||||
(as-methods
|
||||
layout
|
||||
substitute
|
||||
position
|
||||
hideDefaultIgnorables
|
||||
isDefaultIgnorable))
|
||||
|
||||
(define/contract (layout this str-or-glyphs [features #f]
|
||||
;; Attempt to detect the script if not provided.
|
||||
[script (if (string? str-or-glyphs)
|
||||
(script-for-string str-or-glyphs)
|
||||
(script-for-codepoints (append-map (λ (g) (· g codePoints)) str-or-glyphs)))]
|
||||
[language #f])
|
||||
(((or/c string? (listof (is-a?/c Glyph)))) ((or/c list? #f) (or/c symbol? #f) (or/c symbol? #f)) . ->*m . (is-a?/c GlyphRun))
|
||||
|
||||
(define glyphs
|
||||
(if (string? str-or-glyphs)
|
||||
(send (· this font) glyphsForString str-or-glyphs)
|
||||
str-or-glyphs))
|
||||
|
||||
(define glyphRun (make-object GlyphRun glyphs features script language))
|
||||
|
||||
(if (empty? glyphs)
|
||||
(set-field! positions glyphRun empty)
|
||||
(begin
|
||||
;; Setup the advanced layout engine ; todo
|
||||
|
||||
;; Substitute and position the glyphs
|
||||
(send this substitute glyphRun)
|
||||
(send this position glyphRun)
|
||||
(send this hideDefaultIgnorables glyphRun)
|
||||
|
||||
;; Let the layout engine clean up any state it might have
|
||||
(and (· this engine) (· this engine cleanup))))
|
||||
|
||||
glyphRun)
|
||||
|
||||
|
||||
(define/contract (substitute this glyphRun)
|
||||
((is-a?/c GlyphRun) . ->m . void?)
|
||||
;; Call the advanced layout engine to make substitutions
|
||||
(when (and (· this engine) (· this engine substitute))
|
||||
(send (· this engine) substitute glyphRun)))
|
||||
|
||||
|
||||
(define/contract (position this glyphRun)
|
||||
((is-a?/c GlyphRun) . ->m . void?)
|
||||
|
||||
(define positions (for/list ([g (in-list (· glyphRun glyphs))])
|
||||
(make-object GlyphPosition (· g advanceWidth))))
|
||||
(set-field! positions glyphRun positions)
|
||||
|
||||
;; Call the advanced layout engine. Returns the features applied.
|
||||
(define positioned
|
||||
(and (· this engine) (· this engine position)
|
||||
(send (· this engine) position glyphRun)))
|
||||
|
||||
;; if there is no GPOS table, use unicode properties to position marks.
|
||||
;; todo: implement unicodelayoutengine
|
||||
|
||||
|
||||
;; if kerning is not supported by GPOS, do kerning with the TrueType/AAT kern table
|
||||
;; todo: implement kerning
|
||||
(void)
|
||||
)
|
||||
|
||||
|
||||
(define/contract (hideDefaultIgnorables this glyphRun)
|
||||
((is-a?/c GlyphRun) . ->m . void?)
|
||||
(define space (send (· this font) glyphForCodePoint #x20))
|
||||
(define-values (new-glyphs new-positions)
|
||||
(for/lists (ngs nps)
|
||||
([glyph (in-list (· glyphRun glyphs))]
|
||||
[pos (in-list (· glyphRun positions))])
|
||||
(cond
|
||||
[(send this isDefaultIgnorable (car (· glyph codePoints)))
|
||||
(define new-pos pos)
|
||||
(set-field! xAdvance new-pos 0)
|
||||
(set-field! yAdvance new-pos 0)
|
||||
(values space new-pos)]
|
||||
[else (values glyph pos)])))
|
||||
(set-field! glyphs glyphRun new-glyphs)
|
||||
(set-field! positions glyphRun new-positions))
|
||||
|
||||
|
||||
(define/contract (isDefaultIgnorable this codepoint)
|
||||
(index? . ->m . boolean?)
|
||||
#f ; todo: everything
|
||||
)
|
@ -0,0 +1,23 @@
|
||||
#lang pitfall/racket
|
||||
(provide (all-defined-out))
|
||||
|
||||
;; approximates
|
||||
;; https://github.com/devongovett/fontkit/blob/master/src/layout/Script.js
|
||||
|
||||
(define/contract (script-for-string str)
|
||||
(string? . -> . symbol?)
|
||||
;; infers unicode script from string.
|
||||
;; todo: everything
|
||||
'latn)
|
||||
|
||||
|
||||
(define/contract (script-for-codepoints codepoints)
|
||||
((listof integer?) . -> . symbol?)
|
||||
;; infers unicode script from string.
|
||||
;; todo: everything
|
||||
(error 'script-for-codepoints-unimplemented))
|
||||
|
||||
|
||||
(define/contract (script-direction script)
|
||||
((or/c symbol? #f) . -> . symbol?)
|
||||
'ltr) ; todo everything
|
Binary file not shown.
Loading…
Reference in New Issue