2015-11-05 15:45:38 -08:00
|
|
|
# cu2qu
|
2015-10-05 18:14:26 -07:00
|
|
|
|
|
|
|
This library provides functions which take in RoboFab objects (RFonts or their
|
|
|
|
children) and converts any cubic curves to quadratic. The most useful function
|
|
|
|
is probably `fonts_to_quadratic`:
|
|
|
|
|
|
|
|
```python
|
|
|
|
from robofab.world import OpenFont
|
2015-11-19 17:17:56 -08:00
|
|
|
from cu2qu.rf import fonts_to_quadratic
|
2015-11-05 15:54:04 -08:00
|
|
|
thin_font = OpenFont('MyFont-Thin.ufo')
|
|
|
|
bold_font = OpenFont('MyFont-Bold.ufo')
|
|
|
|
fonts_to_quadratic(thin_font, bold_font)
|
2015-10-05 18:14:26 -07:00
|
|
|
```
|
|
|
|
|
2015-11-05 15:54:04 -08:00
|
|
|
Interpolation compatibility is guaranteed during conversion. If it's not
|
|
|
|
needed, converting one font at a time may yield more optimized results:
|
2015-10-05 18:14:26 -07:00
|
|
|
|
|
|
|
```python
|
2015-11-05 15:54:04 -08:00
|
|
|
for font in [thin_font, bold_font]:
|
|
|
|
fonts_to_quadratic(font)
|
2015-10-05 18:14:26 -07:00
|
|
|
```
|
|
|
|
|
2015-11-20 12:08:28 -08:00
|
|
|
Some fonts may need a different error threshold than the default (0.0025 em).
|
|
|
|
This can also be provided by the caller:
|
2015-10-05 18:14:26 -07:00
|
|
|
|
|
|
|
```python
|
2015-11-24 12:52:03 -08:00
|
|
|
fonts_to_quadratic(thin_font, bold_font, max_err_em=0.005)
|
2015-11-05 15:54:04 -08:00
|
|
|
```
|
|
|
|
|
|
|
|
```python
|
|
|
|
for font in [thin_font, bold_font]:
|
2015-11-24 12:52:03 -08:00
|
|
|
fonts_to_quadratic(font, max_err_em=0.001)
|
2015-10-05 18:14:26 -07:00
|
|
|
```
|
|
|
|
|
2015-11-19 17:17:56 -08:00
|
|
|
`fonts_to_quadratic` can print a string reporting the number of curves of each
|
|
|
|
length. For example `fonts_to_quadratic(font, dump_report=True)` may print
|
|
|
|
something like:
|
2015-10-05 18:14:26 -07:00
|
|
|
|
|
|
|
```
|
|
|
|
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
|
2015-11-19 17:17:56 -08:00
|
|
|
total counts across all fonts. You can also accumulate statistics between calls
|
|
|
|
by providing your own report dictionary:
|
|
|
|
|
|
|
|
```python
|
|
|
|
stats = {}
|
|
|
|
for font in [thin_font, bold_font]:
|
|
|
|
fonts_to_quadratic(font, report=stats)
|
|
|
|
# "stats" will report combined statistics for both fonts
|
|
|
|
```
|
2015-10-05 18:14:26 -07:00
|
|
|
|
2015-12-08 12:41:33 -08:00
|
|
|
See the source for functions which operate on glyphs and segments.
|