fontlab.flZone
flZone
A single alignment zone — a band near a metric line used to snap stroke endings consistently.
Common Patterns for flZone
Reading all zones
font = fl.CurrentFont()
print("Top zones:")
for z in font.ps_zonesT:
print(f" '{z.name}' pos={z.position} overshoot={z.width}")
print("Bottom zones:")
for z in font.ps_zonesB:
print(f" '{z.name}' pos={z.position} overshoot={z.width}")
Adding zones for all standard metric positions
from fontlab import flZone
font = fl.CurrentFont()
# Baseline zone: position = 0, negative width (extends below)
baseline = flZone()
baseline.name = "Baseline"
baseline.position = 0
baseline.width = -16 # extends 16 units below baseline
font.ps_zonesB.append(baseline)
# X-height zone: position = x-height value, positive width (extends above)
xh = flZone()
xh.name = "XHeight"
xh.position = int(font.xHeight_value)
xh.width = 16 # 16 units of overshoot above x-height
font.ps_zonesT.append(xh)
# Cap height zone:
cap = flZone()
cap.name = "CapHeight"
cap.position = int(font.capsHeight_value)
cap.width = 20
font.ps_zonesT.append(cap)
Tutorial — Stems and Zones Together
import fontlab as fl
from fontlab import flStem, flZone
font = fl.CurrentFont()
master_name = font.masters[0] # e.g. "Regular"
# ============================================================
# 1. Inspect the existing stems
# ============================================================
# Vertical stems are the main uprights — the stroke you see in
# the leg of "H" or the body of "I". These control the weight
# of the predominant strokes in your font.
print("Vertical (PS) stems:")
for s in font.ps_stemsV:
print(f" '{s.name}' = {s.value} units")
# Horizontal stems are the thin strokes — crossbars, serifs,
# or the thin parts of a high-contrast design.
print("Horizontal (PS) stems:")
for s in font.ps_stemsH:
print(f" '{s.name}' = {s.value} units")
# ============================================================
# 2. Create new stems
# ============================================================
# Measure a vertical stem from your "H" glyph and add it.
# The value should be the width of the upright stroke in font
# units — something like 80–100 for a regular-weight text font
# at 1000 UPM.
v_stem = flStem()
v_stem.name = "Stem" # short, descriptive name
v_stem.value = 85.0 # adjust to match your design
v_stem.guaranteeName() # ensures name is unique
font.ps_stemsV.append(v_stem)
# For a high-contrast font you'd also add a horizontal stem:
h_stem = flStem()
h_stem.name = "HStem"
h_stem.value = 40.0
h_stem.guaranteeName()
font.ps_stemsH.append(h_stem)
# ============================================================
# 3. Inspect the existing zones
# ============================================================
# Top zones snap the tops of uppercase and lowercase letters
# to consistent pixel rows.
print("\nTop alignment zones:")
for z in font.ps_zonesT:
print(f" '{z.name}' position={z.position} "
f"overshoot={z.width}")
# Bottom zones snap the bottoms of letters and descenders.
print("Bottom alignment zones:")
for z in font.ps_zonesB:
print(f" '{z.name}' position={z.position} "
f"overshoot={z.width}")
# ============================================================
# 4. Set up all standard alignment zones
# ============================================================
# A typical Roman font needs these zones:
# Bottom: baseline (0), descender
# Top: x-height, cap height, ascender
# --- Baseline (bottom zone, extends downward) ---
baseline = flZone()
baseline.name = "Baseline"
baseline.position = 0
# A negative width means the zone extends BELOW position 0.
# This covers the baseline overshoot of rounded letters like
# "o" and "c" that dip slightly below.
baseline.width = -16
baseline.guaranteeName(False) # False = it's a bottom zone
font.ps_zonesB.append(baseline)
# --- Descender (bottom zone) ---
desc = flZone()
desc.name = "Descender"
desc.position = int(font.descender_value) # e.g. -200
desc.width = -16
desc.guaranteeName(False)
font.ps_zonesB.append(desc)
# --- X-height (top zone, extends upward) ---
xh = flZone()
xh.name = "XHeight"
xh.position = int(font.xHeight_value) # e.g. 500
# A positive width means the zone extends ABOVE the position.
# This covers the overshoot of rounded lowercase letters.
xh.width = 16
xh.guaranteeName(True) # True = it's a top zone
font.ps_zonesT.append(xh)
# --- Cap height (top zone) ---
cap = flZone()
cap.name = "CapHeight"
cap.position = int(font.capsHeight_value) # e.g. 700
cap.width = 20
cap.guaranteeName(True)
font.ps_zonesT.append(cap)
# --- Ascender (top zone) ---
asc = flZone()
asc.name = "Ascender"
asc.position = int(font.ascender_value) # e.g. 800
asc.width = 20
asc.guaranteeName(True)
font.ps_zonesT.append(asc)
# ============================================================
# 5. Run auto-hinting with the new stems and zones in place
# ============================================================
# Auto-hint every glyph in the font.
# make_hints=True means actually write the hints (not just analyse).
font.autohintGlyphs(list(font.glyphs), True)
# ============================================================
# 6. Convert zones to guidelines for visual reference
# ============================================================
# This creates font-level guidelines at each zone boundary,
# which you can see while drawing. Useful to check that your
# zones match your actual letterforms.
font.convertZonesToGuidelines(font.ps_zonesT, font.ps_zonesB)
fl.Update()
Common Scripting Patterns
Add standard zones to a font
import fontlab as fl
from fontlab import flZone
font = fl.CurrentFont()
# Access metrics:
cap_h = font.masterInfo[0].capHeight if font.masterInfo else 700
x_h = font.masterInfo[0].xHeight if font.masterInfo else 500
asc = font.masterInfo[0].ascender if font.masterInfo else 750
desc = font.masterInfo[0].descender if font.masterInfo else -200
zone_specs = [
("baseline", 0, 14),
("xheight", x_h, 14),
("capheight", cap_h, 14),
("ascender", asc, 14),
("descender", desc, -14),
]
font.ps_zones.clear()
for name, position, width in zone_specs:
z = flZone()
z.name = name
z.position = position
z.width = width
font.ps_zones.append(z)
print(f"Added {len(zone_specs)} zones.")
Copy zones from one master to another
import fontlab as fl
from fontlab import flZone
font = fl.CurrentFont()
source = list(font.ps_zones) # snapshot of current zones
print(f"Zones to copy: {[(z.name, z.position, z.width) for z in source]}")
# Apply to another font:
# for z in source:
# new_z = flZone(); new_z.name = z.name
# new_z.position = z.position; new_z.width = z.width
# other_font.ps_zones.append(new_z)
Constructors: flZone() flZone(double p, double w[, QString _n = ]) flZone(flZone)
Native bases: object
Captured native MRO: flZone, object
Native new allocation evidence (not an init overload): (args, *kwargs) Create and return a new object. See help(type) for accurate signature.
Supplemental documentation:
An alignment zone described by position and width (both double), with name, tags, program and programText attributes. The captured declaration also exposes guaranteeName, tagsSet and toZone. Consult the retained constructor documentation for the supported creation forms.
Source: FontLab Proteus API documentation
Source: generated/fontlab.py: flZone captured declaration
Complete member index
Every captured member retains its own identity. Identical captured declaration text is linked once; this does not establish native inheritance or interchangeable objects.
| Member | Kind | Signature | Summary |
|---|---|---|---|
__init__ |
function | (self, /, *args: Any, **kwargs: Any) -> None |
Initialize self. (shared captured text) |
guaranteeName |
function | (self, top: bool) -> Any |
If the zone has no name, automatically assign a unique default name based on its position and whether it is a top or bottom zone. |
name |
attribute | Any |
(shared captured text) |
position |
attribute | Any |
The Y-coordinate of the zone's reference edge, in font units. |
program |
attribute | Any |
QSet<int, int> (shared captured text) |
programText |
attribute | Any |
(shared captured text) |
tags |
attribute | Any |
(shared captured text) |
tagsSet |
function | (self) -> Any |
QSet<QString>/Nothing tagsSet() (shared captured text) |
toZone |
function | (self, arg0: fgZone, top: bool) -> Any |
Export this zone into a low-level fontgate zone object. |
width |
attribute | Any |
How far the zone extends from its reference edge. |