fontlab.fgSymbolList
fgSymbolList
A string of characters.
What is fgSymbolList?
An fgSymbolList is an ordered, mutable sequence of fgSymbol objects — essentially, a text string at the font object level. Where Python's str stores Unicode code points and knows nothing about your font, fgSymbolList stores symbols that are already resolved to specific glyphs in a specific font.
You use fgSymbolList when you need to:
- Programmatically set the text string in a metrics view text block
- Inspect which characters are selected in a metrics view
- Build a sequence of glyphs for batch measurement or spacing work
Tutorial
import fontlab as fl
from fontlab import fgSymbol, fgSymbolList
# ============================================================
# Build a symbol list from a Unicode string — the easiest way.
# This creates one symbol per character in the string.
# ============================================================
sl = fgSymbolList()
sl.setString("HAMBURGEFONS") # a classic font-testing string
print(f"String: '{sl.string(False)}' ({sl.size()} chars)")
# ============================================================
# Iterate symbols and print each character's name and unicode.
# ============================================================
for i in range(sl.size()):
s = sl.at(i)
print(f" [{i}] U+{s.unicode:04X} '{s.name}'")
# ============================================================
# Build a list from Unicode code points directly.
# Useful when you have a list of codepoints from another source.
# ============================================================
sl2 = fgSymbolList()
sl2.setUnicodeList([0x0041, 0x0042, 0x0043]) # A, B, C
print(f"\nFrom unicodes: '{sl2.string(False)}'")
# ============================================================
# Build a list from glyph names.
# Useful when working with non-unicode glyphs like ligatures.
# ============================================================
sl3 = fgSymbolList()
sl3.setNamesList("H A M B U R G")
print(f"From names: '{sl3.string(False)}' ({sl3.size()} symbols)")
# ============================================================
# Extract a sub-string — like Python's slicing.
# ============================================================
sub = sl.mid(0, 7) # first 7 characters: "HAMBURG"
print(f"\nFirst 7: '{sub.string(False)}'")
# ============================================================
# Append one list to another.
# ============================================================
tail = fgSymbolList()
tail.setString(" test")
sl.append(tail)
print(f"After append: '{sl.string(False)}' ({sl.size()} chars)")
# ============================================================
# Compare two lists for equality.
# ============================================================
sl_a = fgSymbolList()
sl_a.setString("ABC")
sl_b = fgSymbolList()
sl_b.setString("ABC")
sl_c = fgSymbolList()
sl_c.setString("ABD")
print(f"\nABC == ABC: {sl_a.equals(sl_b)}") # True
print(f"ABC == ABD: {sl_a.equals(sl_c)}") # False
# ============================================================
# Remove a range of symbols.
# ============================================================
sl4 = fgSymbolList()
sl4.setString("Hello World")
sl4.remove(5, 6) # remove " World" (index 5, count 6)
print(f"After remove: '{sl4.string(False)}'") # "Hello"
# ============================================================
# Use symbols() to get a plain Python list for iteration.
# ============================================================
all_syms = sl_a.symbols() # returns a Python list
for sym in all_syms:
print(f" {sym.name}")
Common Scripting Patterns
Build a metrics-view text string from a font's glyph names
from fontlab import fgSymbolList
sl = fgSymbolList()
sl.setNamesList("H O spacing A B C D E F G")
print(sl.string(False))
Get the selected characters from the metrics view
import fontlab as fl
ws = fl.flWorkspace.instance()
canvas = ws.getActiveCanvas()
if canvas:
tb = canvas.textBlock() if hasattr(canvas, 'textBlock') else None
if tb:
selected = tb.getSelectedCharacters()
if selected:
print("Selected:", selected.string(False))
Truncate a long string to fit a line
from fontlab import fgSymbolList
sl = fgSymbolList()
sl.setString("A very long string that might not fit in a single line of the metrics view")
truncated = sl.limitLineLength(20)
if truncated:
print("String was truncated to 20 chars")
print(sl.string(False))
Constructors: fgSymbolList() - default fgSymbolList(fgSymbolList) - copy fgSymbolList(list(fgSymbol)) fgSymbolList(string[, bool advancedProcessing = false]) fgSymbolList(fgSymbolList, int len) fgSymbolList(fgFont, fgGlyphIDsSet) fgSymbolList(fgFont, list(glyph_id))
Native bases: object
Captured native MRO: fgSymbolList, 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 list of symbols. The captured declaration exposes the list methods append, insert, remove, replace, clear, at, last, mid, size, empty, assign, compare and equals, the loading methods set, setList, setGlyphsList, setIdList, setNamesList, setUnicodeList, setData, setString and setSterile, and the reading and storage methods data, string, symbols, computeString, store, restore, reserve, clearData, clearString and limitLineLength. It is created with no captured constructor overloads.
Source: FontLab Proteus API documentation
Source: generated/fontlab.py: fgSymbolList 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) |
append |
function | (self, fgSymbolList: Any) -> Any |
Appends a single symbol or an entire list to the end. |
assign |
function | (self, *args: Any, **kwargs: Any) -> Any |
Assigns symbols from a list of glyph IDs within fgFont. |
at |
function | (self, index: Any) -> fgSymbol |
Returns the symbol at index. |
clear |
function | (self) -> Any |
Removes all symbols. |
clearData |
function | (self, dataCode: int) -> Any |
Removes the custom data entry with dataCode from every symbol in the list. |
clearString |
function | (self) -> Any |
Clears the cached string representation (forces recomputation the next time string() is called). |
compare |
function | (self, arg0: fgSymbolList) -> bool |
Returns True if both lists have the same symbols by ID (structural equality, not deep value equality). |
computeString |
function | (self, advancedProcessing: bool) -> Any |
Rebuilds the string representation of this list. |
data |
function | (self, index: int, v: Any=...) -> Any |
Returns the custom data at dataCode for symbol index. |
empty |
function | (self) -> bool |
Returns True if the list has no symbols. |
equals |
function | (self, arg0: fgSymbolList) -> bool |
Returns True if both lists are identical — same length and same content. |
insert |
function | (self, index: Any, arg1: fgSymbol) -> Any |
Inserts a single symbol at index. |
last |
function | (self) -> fgSymbol |
Returns the last symbol in the list without removing it. |
limitLineLength |
function | (self, len: int) -> bool |
Truncates the list to at most len symbols. |
mid |
function | (self, count: Any=...) -> fgSymbolList |
Returns a new sub-list starting at index. |
remove |
function | (self, index: Any, count: Any) -> Any |
Removes count symbols starting at position index. |
replace |
function | (self, index: Any, count: Any, arg2: fgSymbolList) -> Any |
Replaces count symbols starting at index with the contents of fgSymbolList. |
reserve |
function | (self, count: int) -> Any |
Pre-allocates memory for count symbols. |
restore |
function | (self, *args: Any, **kwargs: Any) -> Any |
Deserialises a symbol list from a binary blob previously created with store(). |
set |
function | (self, index: Any, arg1: fgSymbol) -> Any |
Replaces the symbol at index with the given fgSymbol. |
setData |
function | (self, index: Any, DataCode: Any, arg2: Any) -> Any |
Sets custom data for the symbol at index. |
setGlyphsList |
function | (self, *args: Any, **kwargs: Any) -> Any |
Replaces the list by creating one symbol per glyph in the provided glyph list, all resolved within fgFont. |
setIdList |
function | (self, *args: Any, **kwargs: Any) -> Any |
Replaces the list using a list of glyph IDs. |
setList |
function | (self, list: fgSymbols) -> Any |
Replaces the entire list content with a pre-built list of fgSymbol objects. |
setNamesList |
function | (self, QStringList: Any) -> Any |
Builds the symbol list from a space-separated glyph name string or a Python list of glyph name strings. |
setSterile |
function | (self) -> Any |
Marks every symbol in the list as sterile — useful for text that should be processed by the shaping engine for measurement but not visually rendered. |
setString |
function | (self, advancedProcessing: Any=...) -> Any |
Parses a standard Unicode text string and populates the list. |
setUnicodeList |
function | (self, *args: Any, **kwargs: Any) -> Any |
Builds the symbol list from a Python list of Unicode code points. |
size |
function | (self) -> int |
Returns the number of symbols. |
store |
function | (self, packageID: Any) -> bytes |
Serialises the entire symbol list to a binary blob tied to a specific font (identified by packageID). |
string |
function | (self, advancedProcessing: bool) -> str |
Returns the text as a Python string. |
symbols |
function | (self) -> Any |