Package: blackrenderer
BlackRendererBlackRenderer 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.FeaturesIt's a Python library called "blackrenderer"It's a command line tool called "blackrenderer"Renders individual glyphs or text stringsSupports multiple graphics backends:SkiaCairoCoreGraphics (macOS)SVGoutline extractorbounding box calculatorSupports multiple output formats:.png.pdf.svgIt uses fonttools to parse COLRv1 dataThe "blackrenderer" tool is an "hb-view"-like command line app with switchable
backend. It uses HarfBuzz for shapingTool usage exampleBlackRenderer comes with an hb-view-like command line tool, that can be used like this:$ blackrenderer font.ttf ABC🤩 output.png --font-size=100Library usage examplesThere is a high level function to render a text string:fromblackrenderer.renderimportrenderTextrenderText("myfont.ttf","ABC","output.png")# or "output.svg"The fullrenderText()signature is:defrenderText(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:fromblackrenderer.fontimportBlackRendererFontfromblackrenderer.backendsimportgetSurfaceClassbrFont=BlackRendererFont("my_colr_font.ttf")glyphName="A"boundingBox=brFont.getGlyphBounds(glyphName)surfaceClass=getSurfaceClass("skia")surface=surfaceClass()withsurface.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:withcanvas.savedState():canvas.scale(0.3)...drawstuff...InstallIf you have a Python 3 environment set up, then all you need to do is:$ pip install blackrendererInstall for contributing / setting up an environmentHave Python 3.7 or higher installed.Open Terminal."cd" into the project repo directory.Create a virtual environment:$ python3 -m venv venv --prompt=black-rendererActivate the venv:$ source venv/bin/activate(You need to activate the virtual environment for every new terminal session.)Upgrade pip:$ pip install --upgrade pipInstall the requirements:$ pip install -r requirements.txt$ pip install -r requirements-dev.txtInstall blackrenderer in editable mode:$ pip install -e .Run the tests:$ pytestMaintainers: how to releaseTo 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-tagsThis process will create a GitHub release, as well as upload the package to
PyPI.