fontlab.LocationValue
LocationValue
What is a LocationValue?
A LocationValue is the value stored for a single axis in an flLocation. For the vast majority of uses, a LocationValue is just a number — you set it to 400 and read it back as 400. But it can also be anisotropic, which means it carries two slightly different numbers.
Isotropic vs anisotropic
Isotropic (the normal case): a single number. Both sides of the default on the axis use the same value. When you write loc["wght"] = 700, you're creating an isotropic LocationValue with x == y == 700.
Anisotropic: two numbers, x and y. These represent the value on the approach side (coming from the default toward the minimum) and the departure side (going from the default toward the maximum). This is used for rare cases like optical-size axes where the interpolation behavior at the default point is asymmetric — the letter shapes transition differently when you go up vs. down from the default.
In practice, you'll almost always use isotropic values. Anisotropic values are a niche feature.
# Isotropic (normal):
v = LocationValue(400)
print(float(v)) # 400.0
# Anisotropic (rare, advanced):
v2 = LocationValue(400, 450)
# x=400 on one side of the default, y=450 on the other
When x == y, a LocationValue displays and accepts as a plain number. When x != y, it appears as a (x, y) tuple.
Tutorial
import fontlab as fl
from fontlab import flLocation, LocationValue
font = fl.CurrentFont()
# ============================================================
# 1. Creating a location from scratch
# ============================================================
# The simplest approach: start with an empty location, then
# add axis values one by one, just like filling a dictionary.
loc = flLocation()
loc["wght"] = 400 # Weight axis at Regular (400)
loc["wdth"] = 100 # Width axis at Normal (100)
print("My location:", dict(loc)) # {'wght': 400.0, 'wdth': 100.0}
# ============================================================
# 2. Creating a location from a dict (most convenient)
# ============================================================
# You can pass a plain Python dict directly to the constructor.
# This is the cleanest way to build a location in one line.
bold_loc = flLocation({"wght": 700, "wdth": 100})
condensed_loc = flLocation({"wght": 400, "wdth": 75})
bold_condensed = flLocation({"wght": 700, "wdth": 75})
print("Bold location:", dict(bold_loc))
# ============================================================
# 3. Reading values from a location
# ============================================================
# Use the axis tag as the key, just like a dictionary.
# The value comes back as a LocationValue, but it acts like a number.
wght_val = bold_loc["wght"]
print(f"Weight: {wght_val}") # prints: 700 (or similar)
print(f"As float: {float(wght_val)}") # explicitly convert to float
# ============================================================
# 4. Updating values in a location
# ============================================================
loc["wght"] = 600 # change weight to Semibold
print("Updated weight:", float(loc["wght"])) # 600.0
# ============================================================
# 5. Checking what axes are in a location
# ============================================================
print("Axes in location:", list(loc.keys()))
print("Has wght?", "wght" in loc)
print("Has opsz?", "opsz" in loc) # False if optical size not set
print("Number of axes:", len(loc))
# ============================================================
# 6. Iterating over a location
# ============================================================
# Iterate just like a dict — you get the axis tags, and then
# look up each value.
print("All axis values:")
for tag in loc:
print(f" {tag} = {float(loc[tag]):.0f}")
# Or iterate over .items() for tag+value pairs:
for tag, val in loc.items():
print(f" {tag} → {float(val):.1f}")
# ============================================================
# 7. Removing an axis from a location
# ============================================================
# If you want a location that only specifies some axes,
# you can remove others with del.
loc2 = flLocation({"wght": 300, "wdth": 75, "ital": 0})
del loc2["ital"] # remove the italic axis
print("After removing ital:", list(loc2.keys())) # ["wght", "wdth"]
# ============================================================
# 8. LocationValue — isotropic vs anisotropic
# ============================================================
# Normally you'll just use plain numbers. But here's how
# LocationValue works if you need to inspect it directly.
# Isotropic (the everyday case):
v_iso = LocationValue(400)
print("Isotropic value:", float(v_iso)) # 400.0
# Anisotropic (rare — for axes with asymmetric interpolation):
v_aniso = LocationValue(400, 450)
# Use this in a location:
loc["opsz"] = v_aniso
# ============================================================
# 9. Reading the current design-space location
# ============================================================
# font.currentLocation() tells you which location the font
# editor is currently showing. This is useful if you want to
# run a script that operates on "wherever the designer is right now."
cur_loc = font.currentLocation()
print("\nCurrently viewing:")
for tag in cur_loc:
print(f" {tag} = {float(cur_loc[tag]):.0f}")
# ============================================================
# 10. Reading instance locations
# ============================================================
# Each named instance has a location that defines exactly where
# it lives in design space. You can read and compare these.
print("\nAll named instances:")
for inst in font.instances:
loc_parts = [
f"{tag}={float(inst.location[tag]):.0f}"
for tag in inst.location
]
print(f" '{inst.name}': {', '.join(loc_parts)}")
# ============================================================
# 11. Building a location to navigate to a specific master
# ============================================================
# Use setCurrentLocation to move the editor view to a specific
# point in design space. This is equivalent to dragging the
# axis sliders in the Variations panel.
# Navigate to Bold:
# font.setCurrentLocation(bold_loc)
# Navigate to Condensed:
# font.setCurrentLocation(condensed_loc)
# ============================================================
# 12. Converting a location to a plain Python dict
# ============================================================
# Sometimes you need a plain dict — for JSON export, for printing,
# or to pass to code that doesn't know about flLocation.
plain_dict = {tag: float(loc[tag]) for tag in loc}
print("As plain dict:", plain_dict)
fl.Update()
Common Scripting Patterns
Find the instance closest to the current location
# Useful when you want to know which named preset the user
# is currently looking at, even if they've dragged a slider away.
import fontlab as fl
font = fl.CurrentFont()
cur = font.currentLocation()
def location_distance(loc_a, loc_b):
"""Simple Euclidean distance between two locations in design space."""
total = 0.0
for tag in loc_a:
if tag in loc_b:
diff = float(loc_a[tag]) - float(loc_b[tag])
total += diff * diff
return total ** 0.5
closest = min(font.instances,
key=lambda inst: location_distance(cur, inst.location))
print(f"Closest instance to current view: '{closest.name}'")
Build a location from a dict of axis names (not tags)
# If you have axis names ("Weight") rather than tags ("wght"),
# this helper converts them for you.
import fontlab as fl
from fontlab import flLocation
font = fl.CurrentFont()
axes_by_name = {a.name: a for a in font.axes}
def location_from_names(name_dict):
"""Build an flLocation from a dict keyed by axis name."""
loc = flLocation()
for axis_name, value in name_dict.items():
if axis_name in axes_by_name:
loc[axes_by_name[axis_name].tag] = value
return loc
loc = location_from_names({"Weight": 700, "Width": 75})
print("Built location:", {k: float(v) for k, v in loc.items()})
Print all axis values as normalized numbers
# Show what each instance looks like in the OpenType
# normalized range (−1, 0, 1 scale).
import fontlab as fl
font = fl.CurrentFont()
axes_by_tag = {a.tag: a for a in font.axes}
for inst in font.instances:
normals = {}
for tag, val in inst.location.items():
if tag in axes_by_tag:
normals[tag] = round(axes_by_tag[tag].normalize(float(val)), 3)
print(f"'{inst.name}': {normals}")
Check whether two locations are identical
# Compare two locations to see if they point to the same place.
from fontlab import flLocation
def locations_equal(a, b, tolerance=0.01):
if set(a.keys()) != set(b.keys()):
return False
return all(
abs(float(a[tag]) - float(b[tag])) < tolerance
for tag in a
)
loc1 = flLocation({"wght": 700, "wdth": 100})
loc2 = flLocation({"wght": 700, "wdth": 100})
loc3 = flLocation({"wght": 700, "wdth": 75})
print(locations_equal(loc1, loc2)) # True
print(locations_equal(loc1, loc3)) # False
Walk all instances and print whether they're at an axis edge
# Identify which instances are at the min or max of any axis.
# These are your "extreme" corner masters.
import fontlab as fl
font = fl.CurrentFont()
axes_by_tag = {a.tag: a for a in font.axes}
for inst in font.instances:
edges = []
for tag, val in inst.location.items():
if tag in axes_by_tag:
if axes_by_tag[tag].onEdge(float(val)):
edges.append(tag)
if edges:
print(f"'{inst.name}' is on the edge of: {edges}")
else:
print(f"'{inst.name}' is in the interior of design space")
Create a grid of instances for a two-axis font
# Automatically create instances at every combination of
# axis stops in a two-axis Weight × Width font.
import fontlab as fl
from fontlab import flInstance, flLocation
font = fl.CurrentFont()
weight_stops = [300, 400, 600, 700] # Light, Regular, Semibold, Bold
width_stops = [75, 100, 125] # Condensed, Normal, Extended
weight_names = {300: "Light", 400: "Regular", 600: "Semibold", 700: "Bold"}
width_names = {75: "Condensed", 100: "", 125: "Extended"}
for wght in weight_stops:
for wdth in width_stops:
inst = flInstance()
# Combine weight + width name, strip extra spaces
parts = [weight_names[wght], width_names[wdth]]
inst.name = " ".join(p for p in parts if p)
inst.exportable = True
loc = flLocation()
loc["wght"] = wght
loc["wdth"] = wdth
inst.location = loc
font.addInstance(inst)
print(f"Added: '{inst.name}' wght={wght} wdth={wdth}")
fl.Update()
Constructors: LocationValue(flLocation) LocationValue(double)
Native bases: object
Captured native MRO: LocationValue, 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 location value, LocationValue. The captured declaration exposes no named members, only the native constructors LocationValue(flLocation) and LocationValue(double).
Source: FontLab Proteus API documentation
Source: generated/fontlab.py: LocationValue 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) |