Skip to content

Commit faca9cd

Browse files
add a documentation section about fonts
1 parent 5e296e3 commit faca9cd

File tree

2 files changed

+94
-1
lines changed

2 files changed

+94
-1
lines changed

docs/font.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Fonts
2+
3+
`resvg_py` comes with sensible defaults for fonts across different operating systems. It also allows you to load your own fonts or font directories.
4+
5+
## Default Fonts
6+
7+
Depending on your operating system, `resvg_py` uses different default fonts if none are specified.
8+
9+
### Windows / MacOS
10+
11+
| Font Type | Font Family |
12+
| :------------- | :-------------- |
13+
| **Generic** | Times New Roman |
14+
| **Serif** | Times New Roman |
15+
| **Sans-serif** | Arial |
16+
| **Cursive** | Comic Sans MS |
17+
| **Fantasy** | Impact |
18+
| **Monospace** | Courier New |
19+
20+
### Linux
21+
22+
| Font Type | Font Family |
23+
| :------------- | :--------------- |
24+
| **Generic** | Liberation Serif |
25+
| **Serif** | Liberation Serif |
26+
| **Sans-serif** | Liberation Sans |
27+
| **Cursive** | Comic Neue |
28+
| **Fantasy** | Anton |
29+
| **Monospace** | Liberation Mono |
30+
31+
## Custom Fonts
32+
33+
You can load custom fonts by providing paths to font files or directories containing fonts.
34+
35+
```python
36+
import resvg_py
37+
38+
svg_string = "..." # your svg string
39+
40+
# load a specific font file
41+
resvg_py.svg_to_bytes(
42+
svg_string=svg_string,
43+
font_files=["/path/to/MyFont.ttf"]
44+
)
45+
46+
# load a directory of fonts
47+
resvg_py.svg_to_bytes(
48+
svg_string=svg_string,
49+
font_dirs=["/path/to/fonts/dir"]
50+
)
51+
```
52+
53+
## System Fonts
54+
55+
By default, certain system fonts are loaded. You can control this behavior using `skip_system_fonts`.
56+
57+
```python
58+
import resvg_py
59+
60+
# This is just an example variable
61+
svg_string = "..."
62+
63+
resvg_py.svg_to_bytes(
64+
svg_string=svg_string,
65+
skip_system_fonts=True,
66+
font_files=["/path/to/MyFont.ttf"] # You likely want to provide your own fonts if skipping system ones
67+
)
68+
```
69+
70+
## Font Families
71+
72+
You can specify which font family to use for different generic font families.
73+
74+
- `font_family`: The default font family to use.
75+
- `serif_family`
76+
- `sans_serif_family`
77+
- `cursive_family`
78+
- `fantasy_family`
79+
- `monospace_family`
80+
81+
```python
82+
import resvg_py
83+
84+
# This is just an example variable
85+
svg_string = "..."
86+
87+
resvg_py.svg_to_bytes(
88+
svg_string=svg_string,
89+
font_family="Arial",
90+
monospace_family="Fira Code"
91+
)
92+
```

docs/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ Safe bindings for `resvg`_
1414

1515
installation
1616
usage
17+
font
1718
resvg
1819
debugging
1920
contributing
2021
license
21-
22+
2223
Indices and tables
2324
==================
2425

0 commit comments

Comments
 (0)