Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Liberation font family to Arcade #2477

Merged
merged 8 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions arcade/examples/drawing_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
DEFAULT_LINE_HEIGHT = 45
DEFAULT_FONT_SIZE = 20

# Load fonts bumbled with Arcade such as the Kenney fonts
# Load fonts bundled with Arcade such as the Kenney fonts
arcade.resources.load_kenney_fonts()
arcade.resources.load_liberation_fonts()


class GameView(arcade.View):
Expand Down Expand Up @@ -158,7 +159,8 @@ def on_draw(self):
font_name=(
"Times New Roman", # Comes with Windows
"Times", # MacOS may sometimes have this variant
"Liberation Serif" # Common on Linux systems
# Common on Linux systems + we ship it with Arcade
"Liberation Serif"
))

start_y -= DEFAULT_LINE_HEIGHT
Expand Down
6 changes: 4 additions & 2 deletions arcade/examples/drawing_text_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
DEFAULT_LINE_HEIGHT = 45
DEFAULT_FONT_SIZE = 20

# Load fonts bumbled with Arcade such as the Kenney fonts
# Load fonts bundled with Arcade such as the Kenney fonts
arcade.resources.load_kenney_fonts()
arcade.resources.load_liberation_fonts()


class GameView(arcade.View):
Expand Down Expand Up @@ -171,7 +172,8 @@ def __init__(self,):
font_name=(
"Times New Roman", # Comes with Windows
"Times", # MacOS may sometimes have this variant
"Liberation Serif" # Common on Linux systems
# Common on Linux systems + we ship it with Arcade
"Liberation Serif"
)
)

Expand Down
6 changes: 4 additions & 2 deletions arcade/examples/drawing_text_objects_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
import arcade
from pyglet.graphics import Batch

# Load fonts bumbled with Arcade such as the Kenney fonts
# Load fonts bundled with Arcade such as the Kenney fonts
arcade.resources.load_kenney_fonts()
arcade.resources.load_liberation_fonts()

WINDOW_WIDTH = 1280 # Window width in pixels
WINDOW_HEIGHT = 800 # Window height in pixels
Expand Down Expand Up @@ -193,7 +194,8 @@ def __init__(self):
font_name=(
"Times New Roman", # Comes with Windows
"Times", # MacOS may sometimes have this variant
"Liberation Serif" # Common on Linux systems
# Common on Linux systems + we ship it with Arcade
"Liberation Serif"
),
batch=self.batch,
)
Expand Down
118 changes: 92 additions & 26 deletions arcade/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@

#: The absolute path to this directory
RESOURCE_DIR = Path(__file__).parent.resolve()

# The "system" resources common to Arcade
SYSTEM_PATH = RESOURCE_DIR / "system"
FONTS_PATH = SYSTEM_PATH / "fonts"
TTF_PATH = FONTS_PATH / "ttf"

# Basic resources in the :assets: handle
ASSET_PATH = RESOURCE_DIR / "assets"


handles: dict[str, list[Path]] = {
"resources": [SYSTEM_PATH, ASSET_PATH],
"assets": [ASSET_PATH],
Expand Down Expand Up @@ -212,32 +219,91 @@ def list_built_in_assets(


def load_kenney_fonts() -> None:
"""Loads all the fonts in arcade's system directory.

Currently, this is only the Kenney fonts::

Kenney_Blocks.ttf - Kenney Blocks
Kenney_Future.ttf - Kenney Future
Kenney_Future_Narrow.ttf - Kenney Future Narrow
Kenney_High.ttf - Kenney High
Kenney_High_Square.ttf - Kenney High Square
Kenney_Mini.ttf - Kenney Mini
Kenney_Mini_Square.ttf - Kenney Mini Square
Kenney_Pixel.ttf - Kenney Pixel
Kenney_Pixel_Square.ttf - Kenney Pixel Square
Kenney_Rocket.ttf - Kenney Rocket
Kenney_Rocket_Square.ttf - Kenney Rocket Square
"""Loads all the Kenney.nl fonts bundled with Arcade.

.. tip:: This function is best for prototyping and experimenting!

For best performance, you may want to switch to
:py:class:`arcade.load_font` before release.

Please see :ref:`resources-fonts-kenney` for previews and
license information. The filename to load and ``font_name`` to use
when drawing text are summarized below:

.. might swap to this style for the resources listing once I figure out how to
.. cleanly modify the file to use it.

========================================= =========================================================================
``font_name`` for :py:class:`arcade.Text` :ref:`Resource handle <resource_handles>` for :py:func:`arcade.load_font`
========================================= =========================================================================
``"Kenney Blocks"`` ``:resources:fonts/ttf/Kenney/Kenney_Blocks.ttf``
``"Kenney Future"`` ``:resources:fonts/ttf/Kenney/Kenney_Future.ttf``
``"Kenney Future Narrow"`` ``:resources:fonts/ttf/Kenney/Kenney_Future_Narrow.ttf``
``"Kenney High"`` ``:resources:fonts/ttf/Kenney/Kenney_High.ttf``
``"Kenney High Square"`` ``:resources:fonts/ttf/Kenney/Kenney_High_Square.ttf``
``"Kenney Mini"`` ``:resources:fonts/ttf/Kenney/Kenney_Mini.ttf``
``"Kenney Mini Square"`` ``:resources:fonts/ttf/Kenney/Kenney_Mini_Square.ttf``
``"Kenney Pixel"`` ``:resources:fonts/ttf/Kenney/Kenney_Pixel.ttf``
``"Kenney Pixel Square"`` ``:resources:fonts/ttf/Kenney/Kenney_Pixel_Square.ttf``
``"Kenney Rocket"`` ``:resources:fonts/ttf/Kenney/Kenney_Rocket.ttf``
``"Kenney Rocket Square"`` ``:resources:fonts/ttf/Kenney/Kenney_Rocket_Square.ttf``
========================================= =========================================================================

""" # noqa: E501 # Silence ruff # pending: better generation
from arcade.text import load_font

load_font(":system:fonts/ttf/Kenney/Kenney_Blocks.ttf")
load_font(":system:fonts/ttf/Kenney/Kenney_Future.ttf")
load_font(":system:fonts/ttf/Kenney/Kenney_Future_Narrow.ttf")
load_font(":system:fonts/ttf/Kenney/Kenney_High.ttf")
load_font(":system:fonts/ttf/Kenney/Kenney_High_Square.ttf")
load_font(":system:fonts/ttf/Kenney/Kenney_Mini.ttf")
load_font(":system:fonts/ttf/Kenney/Kenney_Mini_Square.ttf")
load_font(":system:fonts/ttf/Kenney/Kenney_Pixel.ttf")
load_font(":system:fonts/ttf/Kenney/Kenney_Pixel_Square.ttf")
load_font(":system:fonts/ttf/Kenney/Kenney_Rocket.ttf")
load_font(":system:fonts/ttf/Kenney/Kenney_Rocket_Square.ttf")


def load_liberation_fonts() -> None:
"""Loads all styles for generic Arial, Courier, and Times New Roman replacements.

.. tip:: This function is best for prototyping and experimenting!

For best performance, you may want to switch to
:py:class:`arcade.load_font` before release.

The Liberation fonts are proven, permissively-licensed fonts.[
For previews and additional information, please see
:ref:`resources-fonts-liberation`.

.. list-table:: ``font_name`` values for :py:class:`arcade.Text`
:header-rows: 1

* - Proprietary Font(s)
- Liberation Replacemetn

* - ``"Courier"``
- ``"Liberation Mono"``

* - ``"Times New Roman"``, ``"Times"``
- ``"Liberation Serif"``

* - ``"Arial"``
- ``"Liberation Sans"``

"""
from arcade.text import load_font

load_font(":system:fonts/ttf/Kenney_Blocks.ttf")
load_font(":system:fonts/ttf/Kenney_Future.ttf")
load_font(":system:fonts/ttf/Kenney_Future_Narrow.ttf")
load_font(":system:fonts/ttf/Kenney_High.ttf")
load_font(":system:fonts/ttf/Kenney_High_Square.ttf")
load_font(":system:fonts/ttf/Kenney_Mini.ttf")
load_font(":system:fonts/ttf/Kenney_Mini_Square.ttf")
load_font(":system:fonts/ttf/Kenney_Pixel.ttf")
load_font(":system:fonts/ttf/Kenney_Pixel_Square.ttf")
load_font(":system:fonts/ttf/Kenney_Rocket.ttf")
load_font(":system:fonts/ttf/Kenney_Rocket_Square.ttf")
load_font(":system:fonts/ttf/Liberation/Liberation_Mono_BoldItalic.ttf")
load_font(":system:fonts/ttf/Liberation/Liberation_Mono_Bold.ttf")
load_font(":system:fonts/ttf/Liberation/Liberation_Mono_Italic.ttf")
load_font(":system:fonts/ttf/Liberation/Liberation_Mono_Regular.ttf")
load_font(":system:fonts/ttf/Liberation/Liberation_Sans_BoldItalic.ttf")
load_font(":system:fonts/ttf/Liberation/Liberation_Sans_Bold.ttf")
load_font(":system:fonts/ttf/Liberation/Liberation_Sans_Italic.ttf")
load_font(":system:fonts/ttf/Liberation/Liberation_Sans_Regular.ttf")
load_font(":system:fonts/ttf/Liberation/Liberation_Serif_BoldItalic.ttf")
load_font(":system:fonts/ttf/Liberation/Liberation_Serif_Bold.ttf")
load_font(":system:fonts/ttf/Liberation/Liberation_Serif_Italic.ttf")
load_font(":system:fonts/ttf/Liberation/Liberation_Serif_Regular.ttf")
102 changes: 102 additions & 0 deletions arcade/resources/system/fonts/ttf/Liberation/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
Digitized data copyright (c) 2010 Google Corporation
with Reserved Font Arimo, Tinos and Cousine.
Copyright (c) 2012 Red Hat, Inc.
with Reserved Font Name Liberation.

This Font Software is licensed under the SIL Open Font License,
Version 1.1.

This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL

SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007

PREAMBLE The goals of the Open Font License (OFL) are to stimulate
worldwide development of collaborative font projects, to support the font
creation efforts of academic and linguistic communities, and to provide
a free and open framework in which fonts may be shared and improved in
partnership with others.

The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves.
The fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply to
any document created using the fonts or their derivatives.



DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such.
This may include source files, build scripts and documentation.

"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).

"Original Version" refers to the collection of Font Software components
as distributed by the Copyright Holder(s).

"Modified Version" refers to any derivative made by adding to, deleting,
or substituting ? in part or in whole ?
any of the components of the Original Version, by changing formats or
by porting the Font Software to a new environment.

"Author" refers to any designer, engineer, programmer, technical writer
or other person who contributed to the Font Software.


PERMISSION & CONDITIONS

Permission is hereby granted, free of charge, to any person obtaining a
copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:

1) Neither the Font Software nor any of its individual components,in
Original or Modified Versions, may be sold by itself.

2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.

3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the
corresponding Copyright Holder. This restriction only applies to the
primary font name as presented to the users.

4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.

5) The Font Software, modified or unmodified, in part or in whole, must
be distributed entirely under this license, and must not be distributed
under any other license. The requirement for fonts to remain under
this license does not apply to any document created using the Font
Software.



TERMINATION
This license becomes null and void if any of the above conditions are not met.



DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER
DEALINGS IN THE FONT SOFTWARE.

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.
Binary file added doc/api_docs/images/fonts_liberation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions doc/links.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
.. Concepts
.. _CC0: https://creativecommons.org/publicdomain/#publicdomain-cc0-10
.. _Creative Commons licenses: https://creativecommons.org/share-your-work/cclicenses/
.. _SIL Open Font License: https://openfontlicense.org/

.. Licensing
.. _BibTeX: https://www.bibtex.org/Format/
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/text/test_text_instance_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def instance() -> arcade.Text:
("value", "New test value"),
("x", 12.0),
("y", 12.0),
("font_name", "Times New Roman"),
("font_name", "Liberation Serif"), # Generic Times New Roman we ship in-box
("font_size", 20.0),
("width", 600),
("bold", True),
Expand Down
Loading
Loading