topdownengine.font Reference¶
Font
¶
A class built on top of pygame.Font that allows for caching of different sizes, prebuilt word wrap, and other features.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
str
|
The path to load from. If there is no font at that path, it will load a system font of that name. |
Source code in topdownengine\font.py
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
__init__(path)
¶
Initialize the Font object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The path to load from. If there is no font at that path, it will load a system font of that name. |
required |
draw_text(text, x, y, size, surface, color, align='center')
¶
Draws text to a surface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text to render to the surface. |
required |
x
|
int
|
The x-position. |
required |
y
|
int
|
The y-position. |
required |
size
|
int
|
The font size to use. |
required |
surface
|
Surface
|
The surface to render to. |
required |
color
|
ColorLike
|
The color to use. |
required |
align
|
str
|
The alignment to use. Defaults to "center". |
'center'
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If an invalid align argument is passed into the method. |
Source code in topdownengine\font.py
wrap(line, size, max_width)
¶
Break a single string into multiple lines based on width.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
str
|
The string to wrap. |
required |
size
|
int
|
The fontsize to use for calculations. |
required |
max_width
|
int
|
The maximum width for each wrapped line. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: The list of wrapped lines. |