Skip to main content

Cubic-to-quadratic bezier curve conversion

Project description

Build Status PyPI Version Coverage

cu2qu

This library provides functions which take in UFO objects (Defcon Fonts or Robofab RFonts) and converts any cubic curves to quadratic. The most useful function is probably fonts_to_quadratic:

from defcon import Font
from cu2qu.ufo import fonts_to_quadratic
thin_font = Font('MyFont-Thin.ufo')
bold_font = Font('MyFont-Bold.ufo')
fonts_to_quadratic([thin_font, bold_font])

Interpolation compatibility is guaranteed during conversion. If it’s not needed, converting one font at a time may yield more optimized results:

for font in [thin_font, bold_font]:
    fonts_to_quadratic([font])

Some fonts may need a different error threshold than the default (0.001 em). This can also be provided by the caller:

fonts_to_quadratic([thin_font, bold_font], max_err_em=0.005)
for font in [thin_font, bold_font]:
    fonts_to_quadratic([font], max_err_em=0.001)

fonts_to_quadratic can print a string reporting the number of curves of each length. For example fonts_to_quadratic([font], dump_stats=True) may print something like:

3: 1000
4: 2000
5: 100

meaning that the font now contains 1000 curves with three points, 2000 with four points, and 100 with five. Given multiple fonts, the function will report the total counts across all fonts. You can also accumulate statistics between calls by providing your own report dictionary:

stats = {}
for font in [thin_font, bold_font]:
    fonts_to_quadratic([font], stats=stats)
# "stats" will report combined statistics for both fonts

The library also provides a command-line script also named cu2qu. Check its --help to see all the options.

Installation

You can install/upgrade cu2qu using pip, like any other Python package.

$ pip install --upgrade cu2qu

This will download the latest stable version available from the Python Package Index (PyPI).

If you wish to modify the sources in-place, you can clone the git repository from Github and install in --editable (or -e) mode:

$ git clone https://github.com/googlefonts/cu2qu
$ cd cu2qu
$ pip install --editable .

Optionally, you can build an optimized version of cu2qu which uses Cython to compile Python to C. The extension module thus created is more than twice as fast than its pure-Python equivalent.

When installing cu2qu from PyPI using pip, as long as you have a C compiler available, the cu2qu setup script will automatically attempt to build a C/Python extension module. If the compilation fails for any reasons, an error is printed and cu2qu will be installed as pure-Python, without the optimized extension.

If you have cloned the git repository, the C source files are not present and need to be regenerated. To do that, you need to install the latest Cython (as usual, pip install -U cython), and then use the global option --with-cython when invoking the setup.py script. You can also export a CU2QU_WITH_CYTHON=1 environment variable if you prefer.

For example, to build the cu2qu extension module in-place (i.e. in the same source directory):

$ python setup.py --with-cython build_ext --inplace

You can also pass --global-option when installing with pip from a local source checkout, like so:

$ pip install --global-option="--with-cython" -e .

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cu2qu-1.6.7.zip (215.8 kB view hashes)

Uploaded Source

Built Distributions

cu2qu-1.6.7-cp39-cp39-win_amd64.whl (169.3 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

cu2qu-1.6.7-cp39-cp39-win32.whl (159.4 kB view hashes)

Uploaded CPython 3.9 Windows x86

cu2qu-1.6.7-cp39-cp39-manylinux1_x86_64.whl (175.2 kB view hashes)

Uploaded CPython 3.9

cu2qu-1.6.7-cp39-cp39-macosx_10_9_x86_64.whl (176.8 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

cu2qu-1.6.7-cp38-cp38-win_amd64.whl (166.6 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

cu2qu-1.6.7-cp38-cp38-win32.whl (157.1 kB view hashes)

Uploaded CPython 3.8 Windows x86

cu2qu-1.6.7-cp38-cp38-manylinux1_x86_64.whl (177.0 kB view hashes)

Uploaded CPython 3.8

cu2qu-1.6.7-cp38-cp38-manylinux1_i686.whl (168.0 kB view hashes)

Uploaded CPython 3.8

cu2qu-1.6.7-cp38-cp38-macosx_10_9_x86_64.whl (175.4 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

cu2qu-1.6.7-cp37-cp37m-win_amd64.whl (164.8 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

cu2qu-1.6.7-cp37-cp37m-win32.whl (156.1 kB view hashes)

Uploaded CPython 3.7m Windows x86

cu2qu-1.6.7-cp37-cp37m-manylinux1_x86_64.whl (176.4 kB view hashes)

Uploaded CPython 3.7m

cu2qu-1.6.7-cp37-cp37m-manylinux1_i686.whl (167.1 kB view hashes)

Uploaded CPython 3.7m

cu2qu-1.6.7-cp37-cp37m-macosx_10_9_x86_64.whl (174.1 kB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

cu2qu-1.6.7-cp36-cp36m-win_amd64.whl (164.9 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

cu2qu-1.6.7-cp36-cp36m-win32.whl (156.2 kB view hashes)

Uploaded CPython 3.6m Windows x86

cu2qu-1.6.7-cp36-cp36m-manylinux1_x86_64.whl (177.0 kB view hashes)

Uploaded CPython 3.6m

cu2qu-1.6.7-cp36-cp36m-manylinux1_i686.whl (167.6 kB view hashes)

Uploaded CPython 3.6m

cu2qu-1.6.7-cp36-cp36m-macosx_10_9_x86_64.whl (175.3 kB view hashes)

Uploaded CPython 3.6m macOS 10.9+ x86-64

cu2qu-1.6.7-cp27-cp27mu-manylinux1_x86_64.whl (174.2 kB view hashes)

Uploaded CPython 2.7mu

cu2qu-1.6.7-cp27-cp27mu-manylinux1_i686.whl (164.3 kB view hashes)

Uploaded CPython 2.7mu

cu2qu-1.6.7-cp27-cp27m-win_amd64.whl (162.4 kB view hashes)

Uploaded CPython 2.7m Windows x86-64

cu2qu-1.6.7-cp27-cp27m-win32.whl (153.9 kB view hashes)

Uploaded CPython 2.7m Windows x86

cu2qu-1.6.7-cp27-cp27m-manylinux1_x86_64.whl (174.2 kB view hashes)

Uploaded CPython 2.7m

cu2qu-1.6.7-cp27-cp27m-manylinux1_i686.whl (164.3 kB view hashes)

Uploaded CPython 2.7m

cu2qu-1.6.7-cp27-cp27m-macosx_10_9_x86_64.whl (172.5 kB view hashes)

Uploaded CPython 2.7m macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page