fontlab.flStem
flStem
Hinting Stem Definition.
What is flStem?
A stem is a measured stroke width — the core data that PostScript hinting uses to keep your letters looking consistent at small sizes on screen. When you measure the width of the vertical uprights in your 'H' and record it as a stem, the hinting engine ensures that every glyph's vertical strokes render at the same pixel width, keeping your type even and readable.
Stems come in two flavours: vertical stems (stemsV) describe the main upright strokes (the legs of 'H', the body of 'I'), and horizontal stems (stemsH) describe the thin strokes and serifs. Both are flStem objects; only the list they live in differs.
Each flStem has a value (the width in font units) and a name (so you can tell your stems apart). Most fonts have one vertical stem and one horizontal stem. High-contrast designs may have several of each.
Tutorial
Stems are the foundation of PostScript hinting. Here is how to inspect, measure, and add stems in a real font.
import fontlab as fl
from fontlab import flStem
# ============================================================
# Read all stems defined for the current font.
# ============================================================
font = fl.CurrentFont()
print(f"Font: {font.fontName}")
print("\nVertical stems (stroke widths):")
for s in font.ps_stemsV:
print(f" '{s.name}': value={s.value:.0f} fu")
s.guaranteeName() # auto-name if empty
print("\nHorizontal stems (thin strokes / serifs):")
for s in font.ps_stemsH:
print(f" '{s.name}': value={s.value:.0f} fu")
# ============================================================
# Measure the actual stroke widths in a reference glyph ('H')
# to suggest stem values.
# ============================================================
glyph = font['H']
if glyph:
layer = glyph.layers[0]
# A simple approach: find the narrowest and widest distances
# between extremal x-coordinates of vertical stems.
xs = []
for shape in layer.shapes:
for contour in shape.contours:
for node in contour.nodes():
xs.append(node.x)
if len(xs) >= 2:
measured = min(xs), max(xs)
print(f"\n'H' x range: {measured[0]:.0f} – {measured[1]:.0f}")
print("(Measure the actual vertical strokes for the real stem value.)")
# ============================================================
# Add a new vertical stem.
# ============================================================
new_stem = flStem()
new_stem.name = "MainStem"
new_stem.value = 85.0 # replace with your measured value
font.ps_stemsV.append(new_stem)
print(f"\nAdded V-stem '{new_stem.name}' = {new_stem.value:.0f}")
# Remove it again (demo only):
font.ps_stemsV.remove(new_stem)
Common Scripting Patterns
Copy stems from one font to another
import fontlab as fl
from fontlab import flStem
src = fl.CurrentFont()
# Collect stem data:
v_stems = [(s.name, s.value) for s in src.ps_stemsV]
h_stems = [(s.name, s.value) for s in src.ps_stemsH]
print("V-stems:", v_stems)
print("H-stems:", h_stems)
# To apply to another font:
# for name, value in v_stems:
# s = flStem(); s.name = name; s.value = value
# dst.ps_stemsV.append(s)
Check if a font has any stems defined
import fontlab as fl
font = fl.CurrentFont()
if not font.ps_stemsV and not font.ps_stemsH:
print("No stems defined — PostScript hinting will use defaults.")
else:
print(f"{len(font.ps_stemsV)} V-stem(s), {len(font.ps_stemsH)} H-stem(s)")
Constructors: flStem() flStem(double _v[, QString _n = ]) flStem(fgStem)
Native bases: object
Captured native MRO: flStem, 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:
A stem described by value (double), with name, tags, program and programText attributes. The captured declaration also exposes guaranteeName, linear, ppm, tagsSet and toStem. Consult the retained constructor documentation for the supported creation forms.
Source: FontLab Proteus API documentation
Source: generated/fontlab.py: flStem 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) -> Any |
If the stem has no name yet, automatically assign a unique default name (e.g. |
linear |
function | (self, upm: float, k: int) -> int |
Calculate the linear rasterisation value for this stem at the given ppem. |
name |
attribute | Any |
|
ppm |
function | (self, upm: float, k: int) -> int |
Calculate the pixels-per-em value at which this stem width snaps to the next pixel, given the font's units-per-em and a target ppem k. |
program |
attribute | Any |
QSet<int, int> |
programText |
attribute | Any |
|
tags |
attribute | Any |
|
tagsSet |
function | (self) -> Any |
QSet<QString>/Nothing tagsSet() |
toStem |
function | (self, arg0: fgStem) -> Any |
Export this stem's data into a low-level fontgate stem object. |
value |
attribute | Any |
The stem width in font units. |