or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

advanced-rendering.mdcli.mdcolor-support.mdfont-management.mdindex.mdstring-manipulation.mdtext-rendering.md

font-management.mddocs/

0

# Font Management

1

2

Comprehensive font system for managing FIGlet fonts including discovery, validation, installation, and information retrieval. Supports .flf, .tlf font formats and ZIP archives containing multiple fonts.

3

4

## Capabilities

5

6

### Font Discovery

7

8

Retrieves a list of all available fonts from both built-in and user-installed locations.

9

10

```python { .api }

11

@classmethod

12

def getFonts(cls) -> list[str]:

13

"""

14

Get list of all available font names.

15

16

Returns:

17

list[str]: Sorted list of available font names (without extensions)

18

19

Searches:

20

- Built-in fonts in pyfiglet.fonts package

21

- User fonts in SHARED_DIRECTORY

22

- Validates each font file before including

23

"""

24

```

25

26

#### Usage Example

27

28

```python

29

from pyfiglet import FigletFont

30

31

# Get all available fonts

32

fonts = FigletFont.getFonts()

33

print(f"Available fonts: {len(fonts)}")

34

for font in fonts[:10]: # Show first 10

35

print(f" {font}")

36

37

# Check if a specific font exists

38

if "slant" in FigletFont.getFonts():

39

print("Slant font is available")

40

```

41

42

### Font Information

43

44

Retrieves detailed information about a specific font including metadata, character descriptions, and font properties.

45

46

```python { .api }

47

@classmethod

48

def infoFont(cls, font: str, short: bool = False) -> str:

49

"""

50

Get information about a specific font.

51

52

Parameters:

53

- font (str): Font name to get information about

54

- short (bool): If True, return only the first line of info

55

56

Returns:

57

str: Font information including metadata and description

58

59

Raises:

60

FontNotFound: If the specified font cannot be located

61

"""

62

```

63

64

#### Usage Example

65

66

```python

67

from pyfiglet import FigletFont

68

69

# Get full font information

70

info = FigletFont.infoFont("standard")

71

print(info)

72

73

# Get short description only

74

short_info = FigletFont.infoFont("standard", short=True)

75

print(f"Font info: {short_info}")

76

77

# Info for multiple fonts

78

for font in ["big", "slant", "shadow"]:

79

try:

80

info = FigletFont.infoFont(font, short=True)

81

print(f"{font}: {info}")

82

except Exception as e:

83

print(f"{font}: Error - {e}")

84

```

85

86

### Font Installation

87

88

Installs new font files or font archives to the system for use with PyFiglet.

89

90

```python { .api }

91

@staticmethod

92

def installFonts(file_name: str) -> None:

93

"""

94

Install the specified font file to the system.

95

96

Parameters:

97

- file_name (str): Path to font file (.flf, .tlf) or ZIP archive

98

99

Returns:

100

None: Prints installation progress to stdout

101

102

Installation locations:

103

- Standard install: Package fonts directory

104

- Zipped package: SHARED_DIRECTORY

105

106

Raises:

107

FileNotFoundError: If the font file cannot be found

108

PermissionError: If unable to write to installation directory

109

"""

110

```

111

112

#### Usage Example

113

114

```python

115

from pyfiglet import FigletFont

116

117

# Install a single font file

118

FigletFont.installFonts("path/to/newfont.flf")

119

120

# Install fonts from ZIP archive

121

FigletFont.installFonts("path/to/font-collection.zip")

122

123

# The installation creates necessary directories automatically

124

# and extracts fonts from ZIP files preserving their names

125

```

126

127

### Font Validation

128

129

Checks if a font file is valid FIGlet format before attempting to load it.

130

131

```python { .api }

132

@classmethod

133

def isValidFont(cls, font: str) -> bool:

134

"""

135

Check if a font file is valid FIGlet format.

136

137

Parameters:

138

- font (str): Font filename (with extension) to validate

139

140

Returns:

141

bool: True if font file is valid FIGlet format

142

143

Validation checks:

144

- File extension (.flf or .tlf)

145

- FIGlet magic number in header

146

- Supports ZIP archives (validates first file)

147

"""

148

```

149

150

#### Usage Example

151

152

```python

153

from pyfiglet import FigletFont

154

155

# Validate font files

156

valid_fonts = []

157

test_files = ["standard.flf", "big.flf", "invalid.txt"]

158

159

for font_file in test_files:

160

if FigletFont.isValidFont(font_file):

161

valid_fonts.append(font_file)

162

print(f"✓ {font_file} is valid")

163

else:

164

print(f"✗ {font_file} is invalid")

165

```

166

167

## Font File Formats

168

169

PyFiglet supports multiple font formats:

170

171

- **.flf**: Standard FIGlet Font format

172

- **.tlf**: Transitional FIGlet Font format

173

- **.zip**: ZIP archives containing font files

174

175

## Font Locations

176

177

Fonts are searched in this order:

178

1. **Package fonts**: Built-in fonts in `pyfiglet.fonts` package

179

2. **Shared directory**: User-installed fonts in platform-specific location

180

- Windows: `%APPDATA%/pyfiglet`

181

- Unix/Linux: `/usr/local/share/pyfiglet/`

182

183

## Font Installation Behavior

184

185

- Creates target directories if they don't exist

186

- ZIP files are extracted automatically

187

- Existing fonts are overwritten

188

- Installation progress is printed to stdout

189

- Font names are derived from filenames (without extension)