On this page:
space
space-glyph
kern
lowercase-tracy
uppercase-tracy
define-spacing-rule

2 Spacing fonts🔗ℹ

 (require sfont/space) package: sfont

This module define functions and macros for spacing fonts.

syntax

(space font-expr maybe-groups spacing-form ...)

 
maybe-groups = 
  | [groups (group-name group) ...]
     
spacing-form = glyph-name : side side
  | @ group-name : side side
  | (glyph-name ...) : side side
     
side = --
  | (/--/ advance-width)
  | (<-> adjustment)
  | (^ sidebearing height)
  | sidebearing
This syntax form is designed to define the spacing of a font. The result is a new font with the spacing applied. One example should clarify how it works:
(space font-to-be-spaced
       [groups (group1 '(h i l m n))
               (group2 '(o e c d))]
       v        : 10 10
       f        : 80 (^ 200 100)
       a        : -- (/--/ 400)
       k        : (/--/ 400) --
       (s z)    : (<-> 20) (<-> 20)
       @ group1 : (^ 80 200) (^ 80 100)
       @ group2 : 40 --)

Two groups are defined (group1 and group2) and they are added to the font groups field.

v : 10 10: means set both sidebearings of v to 10

f : 80 (200 100): means set the left sidebearings of f to 80 while the right sidebearing is set to 200 at height 100

a : -- (/--/ 400): means leave the left sidebearings of a untouched and set its advance width to 400

k : (/--/ 400) --: means leave the right sidebearings of k untouched and set its advance width to 400

(s z) : (<-> 20) (<-> 20): defines an inline group (s and z) that won’t be added to the font groups. and adjust the left and right sidebearings of both glyphs by 20 units.

@ group1 : (80 200) (80 100): applies the spacing rules to every glyph in group1, The left sidebearing is set to 80 at height 200, while the right sidebearing is set to 80 at height 100

@ group2 : 40 --: sets the left sidebearing of every glyph in group2 to 40.

The various forms can be combined freely.

syntax

(space-glyph glyph-expr side side)

(space-glyph (glyph-expr font-expr) side side)
Produce a new glyph with the spacing applied, the syntax of side is the same used in space. The second form, that specify a font, takes into account components.

syntax

(kern font expr maybe-groups kern-form ...)

 
maybe-groups = 
  | 
[groups (side1 [group-name group] ...)
        (side2 [group-name group] ...)]
     
kern-form = glyph1 glyph2 : kern
  | @ group-name glyph2 : kern
  | glyph1 @ group-name : kern
  | @ group-name @ group-name : kern
This syntax can be used to define the kerning table of a font:
(kern font-to-be-kerned
      [groups
       (side1 [curved '(d e c o)])
       (side2 [diag   '(v w y)])]
      @ roundR @ diagL : -20
      k o : -16)

procedure

(lowercase-tracy f xh n o min [c-adj] l-adj)  font?

  f : font?
  xh : real?
  n : real?
  o : real?
  min : real?
  c-adj : real? = 0.8
  l-adj : 1.05
Produce a new font applying the rule described in W.Tracy’s book "Letters of Credit" for the lowercase latin alphabet. In this rule the designer should set the left sidebearing of n, the sidebearings of o and the minimum space to be applied to diagonal letters. Moreover, Tracy says that some space should be ’slightly less or ’slightly more, this is captured by the two optional arguments. The first argument (xh) is the x-height of the the font.

procedure

(uppercase-tracy f caps h o min)  font?

  f : font?
  caps : real?
  h : real?
  o : real?
  min : real?
Produces a new font applyng W.Tracy’s rule for uppercase latin alphabet. The designer have to set the spacing for H, O and a minimum for uppercase diagonal letters. The first argument is the height of uppercase letters.

syntax

(define-spacing-rule name (arg ...)
  (locals ...)
  maybe-groups
  spacing-form ...)
Define a new procedure name with the arguments defined in arg ... locals are a list of bindings. The rest is like the space macro. The procedure applies the spacing to the font. To make an example, this is a part of the definition of lowercase-tracy:

(define-spacing-rule
lowercase-tracy
[xh n o min [c-adj 0.8] [l-adj 1.05]]
([mid (/ xh 2)]
 [a n]
 [b (floor (* 0.9 n))]
 [c (floor (* l-adj n))]
 [d min]
 [e o]
 [f (floor (* c-adj o))])
a : -- (b mid)
b : (a mid) e
c : e f
d : e (a mid)
e : e f
f : -- --
g : -- --
h : (c mid) (b mid)
...)