Bitmap fonts, and in the future more for Pyxel.
Project description
PyxelXL
I am using this for my own game dev purposes, and this is beta-quality software.
Fast TTF drawing for Pyxel, including support for layout (align, wrapping) and experimental support for anti-aliasing. This library is in the works to become a general purpose "bloated" set of extensions for Pyxel, but for now it only includes a font rendering extension.
Installation
You can install PyxelXL using pip:
pip install pyxelxl
Usage
To use a TTF font in your Pyxel application:
import pyxel
from pyxelxl.font import Font
from pyxelxl import LayoutOpts
roboto = Font("/path/to/Roboto-Regular.ttf")
zh_font = Font("/path/to/zpix.ttf")
class App:
def __init__(self):
pyxel.init(160, 120, title="PyxelXL Example")
pyxel.run(self.update, self.draw)
def update(self):
pass
def draw(self):
pyxel.cls(1)
roboto.text(
0,
0,
"Hello, World! Antialiased",
7,
font_size=16,
layout=LayoutOpts(max_width=160, horizontal_align="center"),
)
zh_font.text(
0,
40,
"我能吞下玻璃而不伤身体" * 5,
7,
font_size=12,
layout=LayoutOpts(max_width=160),
)
roboto.text(
0, 80, "Hello, World! Not antialiased", 15, font_size=16, threshold=128
) # layout is optional. Thresholding makes the text look pixelated.
App()
LayoutOpts, Text Wrapping, and Alignment
LayoutOpts
is a class used to define layout options for text rendering in pyxelxl
.
Attributes
-
max_width
:Optional[int]
- The maximum width of the text layout in pixels. If
None
, the width is not constrained. Wrapping will occur if the text exceeds this width.
- The maximum width of the text layout in pixels. If
-
max_height
:Optional[int]
- The maximum height of the text layout in pixels. If
None
, the height is not constrained.
- The maximum height of the text layout in pixels. If
-
horizontal_align
:str
- The horizontal alignment of the text. It can be one of the following values:
"left"
"center"
"right"
- Default is
"left"
.
- The horizontal alignment of the text. It can be one of the following values:
-
vertical_align
:str
- The vertical alignment of the text. It can be one of the following values:
"top"
"center"
"bottom"
- Default is
"top"
.
- The vertical alignment of the text. It can be one of the following values:
-
line_height_mult
:Optional[float]
- The multiplier for line height. If
None
, the line height is determined by the font size.
- The multiplier for line height. If
Center Rotation
from pyxelxl.rotate import blt
blt(80 - 32, 60 - 32, self.square, 0, 0, 64, 64, colkey=0, rot=self.angle)
# The rotation center is at (80, 60) in the global coordinate system.
Advantages
- Fast
- Easy multi-font size support
- Anti-aliasing algorithm for non-pixel fonts
Acknowledgements
Heavy-lifting done by fontdue, and obviously this library will not be here if not for Pyxel.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for pyxelxl-0.0.11-cp37-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b7c7a52ba699da45fee3c0a4db58128112fd076744e6e02cf63bef9b6cb873d |
|
MD5 | 042cbbe843a83582f3106dc8d3189eac |
|
BLAKE2b-256 | 7e163e0e60b7353db2bbbbd495f12314476036d3d799fa853625719edf1814cf |
Hashes for pyxelxl-0.0.11-cp37-abi3-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b7afa894d14e605f2fa1cb6b883dde3846d524b71f913d725a3aa66ea9fbf18 |
|
MD5 | a1095d54130cadf7cd843fc1dcf2de2b |
|
BLAKE2b-256 | ada51168a3f2572ded06d3a1e76a8560b63346f214f7936cf723a0aec09cec5f |
Hashes for pyxelxl-0.0.11-cp37-abi3-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab6e61b9fdb1af676790064869ad6701eda7d6026c183f9a9463488e7314ce0c |
|
MD5 | 709fc6c513bb6f5d0bceab4d62a9295a |
|
BLAKE2b-256 | ed77f5b45182c908266954f881ba3550f8631aca6b57731ab4df6d6cbcf68dad |
Hashes for pyxelxl-0.0.11-cp37-abi3-musllinux_1_2_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84c2b1fcb9da85723d3344f34aa5d03ebdeb79fbdc6e61774b2fb1d005b700aa |
|
MD5 | 86353d316c6f48ef81b6417d6a7baa26 |
|
BLAKE2b-256 | 77442f71e21f09d20278dbd1b510c304ae8001ee99184f06645490f6972db56f |
Hashes for pyxelxl-0.0.11-cp37-abi3-musllinux_1_2_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f8dca789474f216889e9eb04aabde2e1384b24ef96378f3aa159f363dbadd70 |
|
MD5 | 45a0c15b703b27899c457e0c089a82f5 |
|
BLAKE2b-256 | c3f3b7245b9b7719ba7853320cf304ea7f5ae778b50b2609e996e339fbf32415 |
Hashes for pyxelxl-0.0.11-cp37-abi3-musllinux_1_2_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 709862259fe0a3ecb7c1e5017412afb59b236d86cd20e29c7fbfca4a0ee285c7 |
|
MD5 | adff5789d4a8bb81bdb44fbe7c3e1c8c |
|
BLAKE2b-256 | 5324ea53a18afc881d8ded6e08b37c7a4f901de1ba076ac7903165d57e7e0499 |
Hashes for pyxelxl-0.0.11-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5fc41e195972a26b6a5d0a5fa600b1242425d10b643c00782cc5c9be91279f1e |
|
MD5 | d781f30434151b71e46db5adee0fe24e |
|
BLAKE2b-256 | 24e41cd97a9cde0603c7d98e27112bd3a15534c5d368b25788b6b149baf7eebb |
Hashes for pyxelxl-0.0.11-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a60eb479156d717b8b6f9286f91e3d5cc8b79c8de06c283c67c1678c9bb36c6 |
|
MD5 | 64821c30faca5ca44fca735bf112f4df |
|
BLAKE2b-256 | 9292d168aeb9712ba1f21eeb12d9f6f17f32943dc95053a932bd683f254d61b7 |
Hashes for pyxelxl-0.0.11-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e93ae9f4ae29021c06ecd985dada778f96995debfd52d71f24e48d182b52288 |
|
MD5 | 0a3d23272b6d45d77615dc8b8c0b2a23 |
|
BLAKE2b-256 | c8e8db18db64369436175bd1e715358529e22d7d85e3e401bb41c18d7470cb88 |
Hashes for pyxelxl-0.0.11-cp37-abi3-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b940a96413aa9a8e4cf072ec63fc400264485ab77048a5a0e465955655b5a7c |
|
MD5 | 87ef3527fc3ac669b541aad9f82db75e |
|
BLAKE2b-256 | 4dc317c918403b82f0c2248ba3384d7b7ccceb3cbf42a935f65eae2e98cd0b8f |
Hashes for pyxelxl-0.0.11-cp37-abi3-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9b16c3ae620dbcc9beca0121256d3d0edfd6dd7d4d9daf34a05a0a70a83657c |
|
MD5 | 39bbf9338911124d42e220e6474f34a6 |
|
BLAKE2b-256 | 7660831d8794b7eeb37b4deef670fc35215fc6489b9fa27621d0ab988a8cb5d6 |
Hashes for pyxelxl-0.0.11-cp37-abi3-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f75ff1e9812e3727cc2d99d50d7c03daff5d7fc6c24f1111541c138d48e82adc |
|
MD5 | 1a42f8ffb65274b122a5f207f3b01694 |
|
BLAKE2b-256 | c95ff19ad3bd96c70b66c7adc7c79f73f48ec313b5908e676ec7704e34026d51 |