1 Font structures and contracts
(require sfont) | package: sfont |
struct
(struct font ( fontinfo groups kerning features glyphs layers lib data images)) fontinfo : fontinfo/c groups : groups/c kerning : kerning/c features : features/c
glyphs :
(or/c (listof glyph?) (hash/c name/c glyph? #:immutable #t))
layers :
(or/c (listof layer-info?) (listof (cons/c name/c layer-info?))) lib : lib/c data : data/c images : images/c
Glyphs are stored internally in an hash table so they can be easily accessed by name, however the guard of font accept a list of glyphs and transform it in hash table. Font layers informations are stored in an association list (to preserve the order) and, like glyphs, the guard accepts a list of layer-info and transform it in an hash table.
Fonts, like all the structures defined below (with the exception of advance) implement the gen:geometric interface.
parameter
(display-size size) → void? size : natural-number/c
parameter
(display-text) → (listof (listof symbol?))
(display-text text) → void? text : (listof (listof symbol?))
parameter
(show-kerning? show) → void? show : boolean?
value
value
value
value
value
value
value
value
value
procedure
(string->color s) → color/c
s : string?
procedure
(color->string c) → string?
c : color/c
If a layer is added to a glyph, the respective layer-info has to be added to the font layers.
struct
(struct glyph (name advance unicodes note image layers lib))
name : name/c advance : advance? unicodes : (listof natural-number/c) note : (or/c string? #f) image : (or/c image? #f) layers : (or/c (listof layer?) (hash/c name/c layer? #:immutable #t)) lib : lib/c
Transformations can be applied to glyphs, however only scale will affect the advance width and height of the glyph.
struct
filename : string? matrix : trans-mat? color : (or/c color/c #f)
struct
(struct layer (name guidelines anchors contours components))
name : name/c guidelines : (listof guideline?) anchors : (listof anchor?) contours : (listof contour?) components : (listof component?)
Transformations applied to a layer are applied to its content.
value
foreground : 'public.default
value
background : 'public.background
struct
pos : vec? angle : real? name : (or/c string? #f) color : (or/c color/c #f) identifier : (or/c symbol? #f)
struct
pos : vec? name : string? color : (or/c color/c #f) identifier : (or/c symbol? #f)
struct
base : name/c matrix : trans-mat? identifier : (or/c symbol? #f)
struct
identifier : (or/c symbol? #f) points : (listof point?)
struct
pos : vec? type : (one-of/c 'move 'line 'offcurve 'curve 'qcurve) smooth : boolean? name : (or/c string? #f) identifier : (or/c symbol? #f)
1.1 Functions
1.1.1 Reading and writing UFOs
procedure
file : path-string?
procedure
(write-ufo f file [ #:overwrite overwrite #:format format]) → void? f : font? file : path-string? overwrite : boolean? = #t format : (list/c 2 3) = 2
1.1.2 Inspecting glyphs and layers
procedure
(remove-glyph f g) → font?
f : font? g : name/c
procedure
(insert-glyph f g) → font?
f : font? g : glyph?
procedure
(map-glyphs proc f [#:sorted sorted]) → (listof any/c)
proc : (-> glyph? any/c) f : font? sorted : boolean? = #f
procedure
(for-each-glyphs proc f [#:sorted sorted]) → void?
proc : (-> glyph? any/c) f : font? sorted : boolean? = #f
procedure
(font-glyphs-list f) → (listof glyph?)
f : font?
procedure
(sort-glyph-list gl [#:key key #:pred pred]) → (listof glyph?)
gl : (listof glyph?)
key : (-> glyph? any/c) = (lambda (g) (symbol->string (glyph-name g))) pred : (-> any/c any/c boolean?) = string<?
procedure
g : glyph? l : name/c = foreground
procedure
(map-layers proc g [#:sorted sorted]) → (listof any/c)
proc : (-> layer? any/c) g : glyph? sorted : boolean? = #f
procedure
(for-each-layers proc g [#:sorted sorted]) → void?
proc : (-> layer? any/c) g : glyph? sorted : boolean? = #f
procedure
(decompose-glyph f g) → glyph?
f : font? g : glyph?
procedure
(decompose-font f) → font?
f : font?
procedure
(glyph-bounding-box g f) → bounding-box/c
g : glyph? f : font? (glyph-bounding-box g) → bounding-box/c g : glyph?
procedure
(font-bounding-box f [components]) → bounding-box/c
f : font? components : boolean? = #t
1.1.3 Sidebearings and spacing properties
procedure
(get-sidebearings g f) → (or/c (cons/c real? real?) #f)
g : glyph? f : font? (get-sidebearings g) → (or/c (cons/c real? real?) #f) g : glyph?
procedure
(intersections-at g f h) → (listof vec?)
g : glyph? f : font? h : real? (intersections-at g h) → (listof vec?) g : glyph? h : real?
procedure
(get-sidebearings-at g f h) → (or/c (cons/c real? real?) #f)
g : glyph? f : font? h : real? (get-sidebearings-at g h) → (or/c (cons/c real? real?) #f) g : glyph? h : real?
procedure
(set-sidebearings g f left right) → glyph?
g : glyph? f : font? left : real? right : real? (set-sidebearings g left right) → glyph? g : glyph? left : real? right : real?
procedure
(set-sidebearings-at g f left right h) → glyph?
g : glyph? f : font? left : real? right : real? h : real? (set-sidebearings-at g left right h) → glyph? g : glyph? left : real? right : real? h : real?
procedure
(adjust-sidebearings g f left right) → glyph?
g : glyph? f : font? left : real? right : real? (adjust-sidebearings g left right) → glyph? g : glyph? left : real? right : real?
1.1.4 Rounding coordinates
procedure
(font-round f) → font?
f : font?
procedure
(layer-round l) → layer?
l : layer?
procedure
(kerning-round k) → kerning/c
k : kerning/c
procedure
(glyph-round g) → glyph?
g : glyph?
procedure
(advance-round a) → advance?
a : advance?
procedure
(image-round i) → image?
i : image?
procedure
(anchor-round a) → anchor?
a : anchor?
procedure
(contour-round c) → contour?
c : contour?
procedure
(component-round c) → component?
c : component?
procedure
(guideline-round g) → guideline?
g : guideline?
procedure
(point-round p) → point?
p : point?
1.1.5 Contours, components, anchors and guidelines
procedure
(map-components proc o) → (listof any/c)
proc : (-> component? any/c) o : (or/c layer? glyph?)
procedure
(for-each-components proc o) → void?
proc : (-> component? any) o : (or/c layer? glyph?)
procedure
(map-guidelines proc o) → (listof any/c)
proc : (-> guideline? any/c) o : (or/c layer? glyph?)
procedure
(for-each-guidelines proc o) → void?
proc : (-> guideline? any) o : (or/c layer? glyph?)
procedure
(contour->bezier c) → bezier/c
c : contour?
procedure
(bezier->contour b) → contour?
b : bezier/c
procedure
(component->outlines c g) → (listof contour?)
c : component? g : glyph?
procedure
(contour-open? c) → boolean?
c : contour?
procedure
(reverse-contour c) → contour?
c : contour?
procedure
g : glyph?
procedure
g : glyph?
1.1.6 kerning
procedure
(kern-groups2->3 f) → font?
f : font?
procedure
(valid-kerning-group-name? g side) → boolean?
g : name/c side : (or/c 'left 'right)
procedure
(left-kerning-group? g) → boolean?
g : name/c
procedure
(right-kerning-group? g) → boolean?
g : name/c
procedure
(kerning-group? g) → boolean?
g : name/c
procedure
(update-kerning-group-name g side) → name/c
g : name/c side : (or/c 'left 'right)
procedure
(kerning-value f left right) → real?
f : font? left : name/c right : name/c
1.1.7 More
procedure
(glyph-signed-area g f sides) → real?
g : glyph? f : font? sides : natural-number/c (glyph-signed-area g sides) → real? g : glyph? sides : natural-number/c
procedure
(lowercase-stems f) → real?
f : font?
procedure
(uppercase-stems f) → real?
f : font?
procedure
(correct-directions f) → font?
f : font?
procedure
(print-glyph f gn) → pict?
f : font? gn : name/c