Skip to content

fontlab.flLocation

flLocation

What is a location?

A location is a coordinate in design space. It answers the question: "Which specific style am I looking at right now?"

If your font has two axes — Weight (wght) and Width (wdth) — then every style you can imagine in that font lives somewhere in a 2D grid. The Regular lives at {wght: 400, wdth: 100}. The Bold Condensed lives at {wght: 700, wdth: 75}. The Thin Extended lives at {wght: 100, wdth: 125}. Each of those coordinates is an flLocation.

Think of it as a Python dictionary where: - Keys are axis tags (strings like "wght", "wdth", "ital") - Values are numbers representing where you sit on that axis

loc = flLocation({"wght": 700, "wdth": 100})
# This describes the Bold style in a Weight+Width variable font

flLocation is used throughout FontLab's scripting API wherever you need to specify or navigate to a particular point in design space: - Named instances (flInstance.location) — where does the "Bold" preset live? - The current editor view (font.currentLocation()) — which master/location am I viewing? - Variation layer lookups — which layer corresponds to this design-space point? - Interpolation calls — evaluate the font at this location

How flLocation behaves like a dictionary

flLocation supports the full Python mapping protocol. You can treat it almost exactly like a plain Python dict:

loc = flLocation()
loc["wght"] = 400         # set a value
loc["wdth"] = 100
x = loc["wght"]           # read a value
del loc["ital"]           # remove a key
for tag in loc:           # iterate over keys
    print(tag, loc[tag])
print(len(loc))           # number of axes set
print("wght" in loc)      # check for a key

The main difference from a plain dict: the values are LocationValue objects, not raw floats. For simple cases (the vast majority), they behave like numbers. For advanced cases, they can be anisotropic — see the LocationValue section below.

Mapping Protocol

flLocation behaves like a Python dict keyed by axis tag (str):

loc = flLocation({"Weight": 100, "Width": 75})
loc["Weight"]              # → LocationValue (reads as 100)
loc["Optical"] = (12, 14)  # anisotropic value as (x, y) tuple
len(loc)                   # → number of axes set
"Weight" in loc            # → True

Tutorial

flLocation is the everyday currency for navigating variable font design space. Here is how to create, read, and use locations in practical scenarios.

import fontlab as fl

# ============================================================
# Read the current design-space location in the active editor.
# ============================================================

font = fl.CurrentFont()
loc  = font.currentLocation()
print("Current location:")
for tag in loc:
    val = loc[tag]
    print(f"  {tag}: {val}")   # LocationValue prints as a number

# ============================================================
# Create a location dictionary and navigate to it.
# ============================================================

if font.axes:
    # Build a location at a specific point in design space:
    target = fl.flLocation()
    for axis in font.axes:
        # Place each axis at the midpoint of its range:
        mid = (axis.minimal + axis.maximum) / 2.0
        target[axis.tag] = mid
        print(f"  {axis.tag}: {mid:.0f} (midpoint of [{axis.minimal}, {axis.maximum}])")

    # Navigate to this location in the editor:
    font.setCurrentLocation(target)
    fl.Update()
    print("Navigated to midpoint location.")
else:
    print("This font has no axes — it's not a variable font.")

# ============================================================
# Inspect the locations of all named instances.
# ============================================================

print("\nNamed instances:")
for inst in font.instances:
    loc = inst.location
    coords = "  ".join(f"{tag}={loc[tag]}" for tag in loc)
    print(f"  '{inst.name}':  {coords}")

# ============================================================
# Compare two locations.
# ============================================================

if len(font.instances) >= 2:
    loc_a = font.instances[0].location
    loc_b = font.instances[1].location
    same = all(loc_a[tag] == loc_b[tag] for tag in loc_a if tag in loc_b)
    print(f"\nInstances at same location: {same}")

Common Scripting Patterns

Build a location from a plain Python dict

import fontlab as fl

font = fl.CurrentFont()
if font.axes:
    # Quick construction from a dict — values can be plain floats:
    loc = fl.flLocation({axis.tag: axis.default for axis in font.axes})
    print("Default location:", {tag: float(loc[tag]) for tag in loc})

Copy a location

import fontlab as fl

font = fl.CurrentFont()
if font.instances:
    original = font.instances[0].location
    copy     = fl.flLocation(original)   # copy constructor
    copy["wght"] = 900                   # modify the copy only
    print("Original:", {t: float(original[t]) for t in original})
    print("Copy:    ", {t: float(copy[t]) for t in copy})

Constructors: flLocation(flLocation) flLocation()

Native bases: object

Captured native MRO: flLocation, 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 design-space location. The captured declaration exposes no named members, only the native constructors flLocation() and flLocation(flLocation). The flAxis method locationName takes an flLocation.

Source: FontLab Proteus API documentation

Source: generated/fontlab.py: flLocation 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)