Skip to content

Commit 9b3e42f

Browse files
authored
Add liberation font family to Arcade (#2477)
* Add Liberation font family plus loading helper * Add Liberation font TTFs (Generic versions of Arial, Courier, and Times) * Add OFL license in new folder * Add load function modeled after load_kenney_fonts * Move Kenney fonts into their own folder * Add font loading to examples * Add Liberation font loading to text drawing examples * Add comments explaining usage of fonts * Fix typo (s/bumbled/bundled/) * Add fix for README / LICENSE files in asset folders * Split the fonts from tiled maps * Get Kenney and Liberation to show in resources * Add initial graphic courtesy of @DigiDuncan * Add SIL Open Font License to links.rst * Add basic inset for the Liberation fonts * Add printing for the Liberation font info + SIL link * Add cross-refs and some temp tables * Silence ruff on very long docstring line length for one function :D
1 parent 0685cc4 commit 9b3e42f

32 files changed

+283
-50
lines changed

arcade/examples/drawing_text.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
DEFAULT_LINE_HEIGHT = 45
1313
DEFAULT_FONT_SIZE = 20
1414

15-
# Load fonts bumbled with Arcade such as the Kenney fonts
15+
# Load fonts bundled with Arcade such as the Kenney fonts
1616
arcade.resources.load_kenney_fonts()
17+
arcade.resources.load_liberation_fonts()
1718

1819

1920
class GameView(arcade.View):
@@ -158,7 +159,8 @@ def on_draw(self):
158159
font_name=(
159160
"Times New Roman", # Comes with Windows
160161
"Times", # MacOS may sometimes have this variant
161-
"Liberation Serif" # Common on Linux systems
162+
# Common on Linux systems + we ship it with Arcade
163+
"Liberation Serif"
162164
))
163165

164166
start_y -= DEFAULT_LINE_HEIGHT

arcade/examples/drawing_text_objects.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
DEFAULT_LINE_HEIGHT = 45
1414
DEFAULT_FONT_SIZE = 20
1515

16-
# Load fonts bumbled with Arcade such as the Kenney fonts
16+
# Load fonts bundled with Arcade such as the Kenney fonts
1717
arcade.resources.load_kenney_fonts()
18+
arcade.resources.load_liberation_fonts()
1819

1920

2021
class GameView(arcade.View):
@@ -171,7 +172,8 @@ def __init__(self,):
171172
font_name=(
172173
"Times New Roman", # Comes with Windows
173174
"Times", # MacOS may sometimes have this variant
174-
"Liberation Serif" # Common on Linux systems
175+
# Common on Linux systems + we ship it with Arcade
176+
"Liberation Serif"
175177
)
176178
)
177179

arcade/examples/drawing_text_objects_batch.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
import arcade
1616
from pyglet.graphics import Batch
1717

18-
# Load fonts bumbled with Arcade such as the Kenney fonts
18+
# Load fonts bundled with Arcade such as the Kenney fonts
1919
arcade.resources.load_kenney_fonts()
20+
arcade.resources.load_liberation_fonts()
2021

2122
WINDOW_WIDTH = 1280 # Window width in pixels
2223
WINDOW_HEIGHT = 800 # Window height in pixels
@@ -193,7 +194,8 @@ def __init__(self):
193194
font_name=(
194195
"Times New Roman", # Comes with Windows
195196
"Times", # MacOS may sometimes have this variant
196-
"Liberation Serif" # Common on Linux systems
197+
# Common on Linux systems + we ship it with Arcade
198+
"Liberation Serif"
197199
),
198200
batch=self.batch,
199201
)

arcade/resources/__init__.py

Lines changed: 92 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,16 @@
66

77
#: The absolute path to this directory
88
RESOURCE_DIR = Path(__file__).parent.resolve()
9+
10+
# The "system" resources common to Arcade
911
SYSTEM_PATH = RESOURCE_DIR / "system"
12+
FONTS_PATH = SYSTEM_PATH / "fonts"
13+
TTF_PATH = FONTS_PATH / "ttf"
14+
15+
# Basic resources in the :assets: handle
1016
ASSET_PATH = RESOURCE_DIR / "assets"
1117

18+
1219
handles: dict[str, list[Path]] = {
1320
"resources": [SYSTEM_PATH, ASSET_PATH],
1421
"assets": [ASSET_PATH],
@@ -212,32 +219,91 @@ def list_built_in_assets(
212219

213220

214221
def load_kenney_fonts() -> None:
215-
"""Loads all the fonts in arcade's system directory.
216-
217-
Currently, this is only the Kenney fonts::
218-
219-
Kenney_Blocks.ttf - Kenney Blocks
220-
Kenney_Future.ttf - Kenney Future
221-
Kenney_Future_Narrow.ttf - Kenney Future Narrow
222-
Kenney_High.ttf - Kenney High
223-
Kenney_High_Square.ttf - Kenney High Square
224-
Kenney_Mini.ttf - Kenney Mini
225-
Kenney_Mini_Square.ttf - Kenney Mini Square
226-
Kenney_Pixel.ttf - Kenney Pixel
227-
Kenney_Pixel_Square.ttf - Kenney Pixel Square
228-
Kenney_Rocket.ttf - Kenney Rocket
229-
Kenney_Rocket_Square.ttf - Kenney Rocket Square
222+
"""Loads all the Kenney.nl fonts bundled with Arcade.
223+
224+
.. tip:: This function is best for prototyping and experimenting!
225+
226+
For best performance, you may want to switch to
227+
:py:class:`arcade.load_font` before release.
228+
229+
Please see :ref:`resources-fonts-kenney` for previews and
230+
license information. The filename to load and ``font_name`` to use
231+
when drawing text are summarized below:
232+
233+
.. might swap to this style for the resources listing once I figure out how to
234+
.. cleanly modify the file to use it.
235+
236+
========================================= =========================================================================
237+
``font_name`` for :py:class:`arcade.Text` :ref:`Resource handle <resource_handles>` for :py:func:`arcade.load_font`
238+
========================================= =========================================================================
239+
``"Kenney Blocks"`` ``:resources:fonts/ttf/Kenney/Kenney_Blocks.ttf``
240+
``"Kenney Future"`` ``:resources:fonts/ttf/Kenney/Kenney_Future.ttf``
241+
``"Kenney Future Narrow"`` ``:resources:fonts/ttf/Kenney/Kenney_Future_Narrow.ttf``
242+
``"Kenney High"`` ``:resources:fonts/ttf/Kenney/Kenney_High.ttf``
243+
``"Kenney High Square"`` ``:resources:fonts/ttf/Kenney/Kenney_High_Square.ttf``
244+
``"Kenney Mini"`` ``:resources:fonts/ttf/Kenney/Kenney_Mini.ttf``
245+
``"Kenney Mini Square"`` ``:resources:fonts/ttf/Kenney/Kenney_Mini_Square.ttf``
246+
``"Kenney Pixel"`` ``:resources:fonts/ttf/Kenney/Kenney_Pixel.ttf``
247+
``"Kenney Pixel Square"`` ``:resources:fonts/ttf/Kenney/Kenney_Pixel_Square.ttf``
248+
``"Kenney Rocket"`` ``:resources:fonts/ttf/Kenney/Kenney_Rocket.ttf``
249+
``"Kenney Rocket Square"`` ``:resources:fonts/ttf/Kenney/Kenney_Rocket_Square.ttf``
250+
========================================= =========================================================================
251+
252+
""" # noqa: E501 # Silence ruff # pending: better generation
253+
from arcade.text import load_font
254+
255+
load_font(":system:fonts/ttf/Kenney/Kenney_Blocks.ttf")
256+
load_font(":system:fonts/ttf/Kenney/Kenney_Future.ttf")
257+
load_font(":system:fonts/ttf/Kenney/Kenney_Future_Narrow.ttf")
258+
load_font(":system:fonts/ttf/Kenney/Kenney_High.ttf")
259+
load_font(":system:fonts/ttf/Kenney/Kenney_High_Square.ttf")
260+
load_font(":system:fonts/ttf/Kenney/Kenney_Mini.ttf")
261+
load_font(":system:fonts/ttf/Kenney/Kenney_Mini_Square.ttf")
262+
load_font(":system:fonts/ttf/Kenney/Kenney_Pixel.ttf")
263+
load_font(":system:fonts/ttf/Kenney/Kenney_Pixel_Square.ttf")
264+
load_font(":system:fonts/ttf/Kenney/Kenney_Rocket.ttf")
265+
load_font(":system:fonts/ttf/Kenney/Kenney_Rocket_Square.ttf")
266+
267+
268+
def load_liberation_fonts() -> None:
269+
"""Loads all styles for generic Arial, Courier, and Times New Roman replacements.
270+
271+
.. tip:: This function is best for prototyping and experimenting!
272+
273+
For best performance, you may want to switch to
274+
:py:class:`arcade.load_font` before release.
275+
276+
The Liberation fonts are proven, permissively-licensed fonts.[
277+
For previews and additional information, please see
278+
:ref:`resources-fonts-liberation`.
279+
280+
.. list-table:: ``font_name`` values for :py:class:`arcade.Text`
281+
:header-rows: 1
282+
283+
* - Proprietary Font(s)
284+
- Liberation Replacemetn
285+
286+
* - ``"Courier"``
287+
- ``"Liberation Mono"``
288+
289+
* - ``"Times New Roman"``, ``"Times"``
290+
- ``"Liberation Serif"``
291+
292+
* - ``"Arial"``
293+
- ``"Liberation Sans"``
294+
230295
"""
231296
from arcade.text import load_font
232297

233-
load_font(":system:fonts/ttf/Kenney_Blocks.ttf")
234-
load_font(":system:fonts/ttf/Kenney_Future.ttf")
235-
load_font(":system:fonts/ttf/Kenney_Future_Narrow.ttf")
236-
load_font(":system:fonts/ttf/Kenney_High.ttf")
237-
load_font(":system:fonts/ttf/Kenney_High_Square.ttf")
238-
load_font(":system:fonts/ttf/Kenney_Mini.ttf")
239-
load_font(":system:fonts/ttf/Kenney_Mini_Square.ttf")
240-
load_font(":system:fonts/ttf/Kenney_Pixel.ttf")
241-
load_font(":system:fonts/ttf/Kenney_Pixel_Square.ttf")
242-
load_font(":system:fonts/ttf/Kenney_Rocket.ttf")
243-
load_font(":system:fonts/ttf/Kenney_Rocket_Square.ttf")
298+
load_font(":system:fonts/ttf/Liberation/Liberation_Mono_BoldItalic.ttf")
299+
load_font(":system:fonts/ttf/Liberation/Liberation_Mono_Bold.ttf")
300+
load_font(":system:fonts/ttf/Liberation/Liberation_Mono_Italic.ttf")
301+
load_font(":system:fonts/ttf/Liberation/Liberation_Mono_Regular.ttf")
302+
load_font(":system:fonts/ttf/Liberation/Liberation_Sans_BoldItalic.ttf")
303+
load_font(":system:fonts/ttf/Liberation/Liberation_Sans_Bold.ttf")
304+
load_font(":system:fonts/ttf/Liberation/Liberation_Sans_Italic.ttf")
305+
load_font(":system:fonts/ttf/Liberation/Liberation_Sans_Regular.ttf")
306+
load_font(":system:fonts/ttf/Liberation/Liberation_Serif_BoldItalic.ttf")
307+
load_font(":system:fonts/ttf/Liberation/Liberation_Serif_Bold.ttf")
308+
load_font(":system:fonts/ttf/Liberation/Liberation_Serif_Italic.ttf")
309+
load_font(":system:fonts/ttf/Liberation/Liberation_Serif_Regular.ttf")
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
Digitized data copyright (c) 2010 Google Corporation
2+
with Reserved Font Arimo, Tinos and Cousine.
3+
Copyright (c) 2012 Red Hat, Inc.
4+
with Reserved Font Name Liberation.
5+
6+
This Font Software is licensed under the SIL Open Font License,
7+
Version 1.1.
8+
9+
This license is copied below, and is also available with a FAQ at:
10+
http://scripts.sil.org/OFL
11+
12+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
13+
14+
PREAMBLE The goals of the Open Font License (OFL) are to stimulate
15+
worldwide development of collaborative font projects, to support the font
16+
creation efforts of academic and linguistic communities, and to provide
17+
a free and open framework in which fonts may be shared and improved in
18+
partnership with others.
19+
20+
The OFL allows the licensed fonts to be used, studied, modified and
21+
redistributed freely as long as they are not sold by themselves.
22+
The fonts, including any derivative works, can be bundled, embedded,
23+
redistributed and/or sold with any software provided that any reserved
24+
names are not used by derivative works. The fonts and derivatives,
25+
however, cannot be released under any other type of license. The
26+
requirement for fonts to remain under this license does not apply to
27+
any document created using the fonts or their derivatives.
28+
29+
30+
31+
DEFINITIONS
32+
"Font Software" refers to the set of files released by the Copyright
33+
Holder(s) under this license and clearly marked as such.
34+
This may include source files, build scripts and documentation.
35+
36+
"Reserved Font Name" refers to any names specified as such after the
37+
copyright statement(s).
38+
39+
"Original Version" refers to the collection of Font Software components
40+
as distributed by the Copyright Holder(s).
41+
42+
"Modified Version" refers to any derivative made by adding to, deleting,
43+
or substituting ? in part or in whole ?
44+
any of the components of the Original Version, by changing formats or
45+
by porting the Font Software to a new environment.
46+
47+
"Author" refers to any designer, engineer, programmer, technical writer
48+
or other person who contributed to the Font Software.
49+
50+
51+
PERMISSION & CONDITIONS
52+
53+
Permission is hereby granted, free of charge, to any person obtaining a
54+
copy of the Font Software, to use, study, copy, merge, embed, modify,
55+
redistribute, and sell modified and unmodified copies of the Font
56+
Software, subject to the following conditions:
57+
58+
1) Neither the Font Software nor any of its individual components,in
59+
Original or Modified Versions, may be sold by itself.
60+
61+
2) Original or Modified Versions of the Font Software may be bundled,
62+
redistributed and/or sold with any software, provided that each copy
63+
contains the above copyright notice and this license. These can be
64+
included either as stand-alone text files, human-readable headers or
65+
in the appropriate machine-readable metadata fields within text or
66+
binary files as long as those fields can be easily viewed by the user.
67+
68+
3) No Modified Version of the Font Software may use the Reserved Font
69+
Name(s) unless explicit written permission is granted by the
70+
corresponding Copyright Holder. This restriction only applies to the
71+
primary font name as presented to the users.
72+
73+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
74+
Software shall not be used to promote, endorse or advertise any
75+
Modified Version, except to acknowledge the contribution(s) of the
76+
Copyright Holder(s) and the Author(s) or with their explicit written
77+
permission.
78+
79+
5) The Font Software, modified or unmodified, in part or in whole, must
80+
be distributed entirely under this license, and must not be distributed
81+
under any other license. The requirement for fonts to remain under
82+
this license does not apply to any document created using the Font
83+
Software.
84+
85+
86+
87+
TERMINATION
88+
This license becomes null and void if any of the above conditions are not met.
89+
90+
91+
92+
DISCLAIMER
93+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
94+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
95+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
96+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
97+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
98+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
99+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
100+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER
101+
DEALINGS IN THE FONT SOFTWARE.
102+
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
79.9 KB
Loading

doc/links.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
.. Concepts
3030
.. _CC0: https://creativecommons.org/publicdomain/#publicdomain-cc0-10
3131
.. _Creative Commons licenses: https://creativecommons.org/share-your-work/cclicenses/
32+
.. _SIL Open Font License: https://openfontlicense.org/
3233

3334
.. Licensing
3435
.. _BibTeX: https://www.bibtex.org/Format/

tests/unit/text/test_text_instance_properties.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def instance() -> arcade.Text:
1313
("value", "New test value"),
1414
("x", 12.0),
1515
("y", 12.0),
16-
("font_name", "Times New Roman"),
16+
("font_name", "Liberation Serif"), # Generic Times New Roman we ship in-box
1717
("font_size", 20.0),
1818
("width", 600),
1919
("bold", True),

0 commit comments

Comments
 (0)