A Python-based renderer for OpenType COLRv1 fonts, with multiple backends.
Project description
BlackRenderer
BlackRenderer is a Python-based renderer for OpenType COLR fonts, with multiple backends. It supports the new COLRv1 format as well as the old COLR format. It fully supports variable fonts, including variable COLRv1 data.
Features
- It's a Python library called "blackrenderer"
- It's a command line tool called "blackrenderer"
- Renders individual glyphs or text strings
- Supports multiple graphics backends:
- Skia
- Cairo
- CoreGraphics (macOS)
- SVG
- outline extractor
- bounding box calculator
- Supports multiple output formats:
- .png
- .svg
- It uses fonttools to parse COLRv1 data
- The "blackrenderer" tool is an "hb-view"-like command line app with switchable backend. It uses HarfBuzz for shaping
Tool usage example
BlackRenderer comes with an hb-view-like command line tool, that can be used like this:
$ blackrenderer font.ttf ABC🤩 output.png --font-size=100
Library usage examples
There is a high level function to render a text string:
from blackrenderer.render import renderText
renderText("myfont.ttf", "ABC", "output.png") # or "output.svg"
The full renderText()
signature is:
def renderText(
fontPath,
textString,
outputPath,
*,
fontSize=250,
margin=20,
features=None,
variations=None,
backendName=None,
)
For more control, the library exposes two main parts: the BlackRendererFont class, and a set of backend classes. Each backend provides a Canvas class. You pass a Canvas instance to a BlackRendererFont instance when drawing a glyph. Most backends also have a Surface class, which is a generalized convenience class to produce a canvas for a bitmap (or SVG document) for a specific box. Here is a minimal example:
from blackrenderer.font import BlackRendererFont
from blackrenderer.backends import getSurfaceClass
brFont = BlackRendererFont("my_colr_font.ttf")
glyphName = "A"
boundingBox = brFont.getGlyphBounds(glyphName)
surfaceClass = getSurfaceClass("skia")
surface = surfaceClass()
with surface.canvas(boundingBox)
brFont.drawGlyph(glyphName, canvas)
surface.saveImage("image.png")
Canvas objects support the following transformation methods:
canvas.translate(dx, dy)
canvas.scale(sx, sy)
canvas.transform((xx, yx, xy, yy, dx, dy))
Save/restore is done with a context manager:
with canvas.savedState():
canvas.scale(0.3)
...draw stuff...
Install
If you have a Python 3 environment set up, then all you need to do is:
$ pip install blackrenderer
Install for contributing / setting up an environment
Have Python 3.7 or higher installed.
Open Terminal.
"cd" into the project repo directory.
Create a virtual environment:
$ python3 -m venv venv --prompt=black-renderer
Activate the venv:
$ source venv/bin/activate
(You need to activate the virtual environment for every new terminal session.)
Upgrade pip:
$ pip install --upgrade pip
Install the requirements:
$ pip install -r requirements.txt
$ pip install -r requirements-dev.txt
Install blackrenderer in editable mode:
$ pip install -e .
Run the tests:
$ pytest
Maintainers: how to release
To cut a release, make an annotated git tag, where the tag is in this format: v1.2.3, where 1, 2 and 3 represent major, minor and micro version numbers. You can add "aN" or "bN" or "rc" to mark alpha, beta or "release candidate" versions. Examples: v1.2.3, v1.2.3b2, v1.2.3a4, v1.2.3rc.
The message for the annotated tag should contain the release notes.
Then use "git push --follow-tags" to trigger the release bot. Example session:
$ git tag -a v1.2.3 -m "v1.2.3 -- fixed issue #12345"
$ git push --follow-tags
This process will create a GitHub release, as well as upload the package to PyPI.
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 Distribution
File details
Details for the file blackrenderer-0.5.0.tar.gz
.
File metadata
- Download URL: blackrenderer-0.5.0.tar.gz
- Upload date:
- Size: 4.1 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ebded44c93b35d4109ed6067f5af21d6e74fd456b718fcef2a73a698ad46d2e4 |
|
MD5 | a7acb5fa33bee21c98e4d0c9aabc1d27 |
|
BLAKE2b-256 | dbb8034d7ae80e0fee34a67f98e4199fff6a650a0b8187b2d64e647b422a4be4 |
File details
Details for the file blackrenderer-0.5.0-py3-none-any.whl
.
File metadata
- Download URL: blackrenderer-0.5.0-py3-none-any.whl
- Upload date:
- Size: 30.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21aa1f6b6cded4e86780da3299da07e9eb11d54e0edaf94d08875b0cbcb6a0ef |
|
MD5 | 50f69983b9d802760d4fff0affec4e37 |
|
BLAKE2b-256 | 4398ad294902b6e60bd095a0540a4594936b333291a93375e09a8c264399e2c5 |