32 Commits

Author SHA1 Message Date
Cosimo Lupo
855166c518
cu2qu/ufo: must use PointToSegmentPen with outputImpliedClosingLine=True
When collecting a glyph's segments, we can't simply call the glyphs' draw
method with the GetSegmentsPen, but we must initialize the
PointToSegmentPen explicitly with outputImpliedClosingLine=True.

By default PointToSegmentPen does not outputImpliedClosingLine -- unless
last and first point on closed contour are duplicated.

Because we are converting multiple glyphs at the same time, we want to
make sure the _get_segments function returns the same number of segments,
whether or not the last and first point overlap.

Fixes https://github.com/googlefonts/fontmake/issues/572

Also see: https://github.com/fonttools/fonttools/pull/1720
2019-09-13 13:14:03 +02:00
Cosimo Lupo
0a2593b2c5
[cu2qu.ufo] remember the curve type in lib to skip converting twice 2018-04-10 18:22:32 +01:00
Cosimo Lupo
0b41ba3521
_set_segments must now handle 'curveTo' segments as well
since we let them pass now, and we only stop at the end
2018-01-18 14:33:49 +00:00
Cosimo Lupo
b627a778bf
Don't stop at first incompatibilty, log errors, raise at the end
Based on Miguel Sousa's original PR and the following discussion:
https://github.com/googlei18n/cu2qu/pull/114

Instead of raising an error at the first incompatible glyph, we
let it continue (keeping the original contours unmodified when
that happens), and use logging to print error messages.

A new `IncompatibleFontsError` exception is raised at the end of
`fonts_to_quadratic` if any glyph has incompatible number or types
of segments. The exception instance has a `glyph_errors` attribute
(dict) which collects all the individual IncompatibleGlyphsError
keyed by glyph name.
2018-01-18 13:21:08 +00:00
Cosimo Lupo
718228cb32 ufo: minor
No need to be verbose here. Message is never read anyway.
2017-10-31 19:10:35 +00:00
Cosimo Lupo
e648ef3f89 ufo: must scale max_err_em list by UPEM
When the 'max_err_em' argument is a float, we multiply it
by the font.info.unitsPerEm. However we were not doing it when
the argument is a list of floats...
2017-10-31 18:23:21 +00:00
Cosimo Lupo
fabada54b1 ufo: minor
_segments_to_quadratic is private, and always gets not-None 'stats' argument.
This if-branch is always true. Removed.
2017-10-31 18:22:56 +00:00
Cosimo Lupo
09c5856428 ufo: don't drop single points in GetSegmentsPen
We dropped robofab support. There is no reason to arbitrarily
drop any contour points. Anchors are handled as anchors in
latest ufoLib+defcon, also for UFO2. No more need to special-case.
2017-10-31 18:21:20 +00:00
Behdad Esfahbod
7a2f6383e4 Simplify log message 2017-07-28 16:41:52 +01:00
Denis Moyogo Jacquerye
b1626bd0e8 Change the default approximation error from 0.0025 to 0.001 2017-05-23 16:09:48 +01:00
James Godfrey-Kittle
19854ad27b [minor] Use submodule name in logger 2016-11-30 17:53:37 -08:00
James Godfrey-Kittle
ebebcd9f0d Use logger instead of printing info 2016-11-29 16:57:42 -08:00
Cosimo Lupo
6618095c36
ufo: raise custom IncompatibleGlyphsError exception with the name(s) of incompatible glyphs
Fixes https://github.com/googlei18n/cu2qu/issues/46
2016-11-04 15:30:40 +00:00
James Godfrey-Kittle
509b82204e [minor] rename variable 2016-10-20 11:25:02 -07:00
James Godfrey-Kittle
4782dd64d3 Merge pull request #50 from anthrotype/no-zip-fonts
[ufo] in fonts_to_quadratic, iterate over union of glyph names
2016-10-20 10:55:45 -07:00
Cosimo Lupo
a876671e6f [ufo] glyphs_modified = reverse_direction 2016-10-06 16:17:26 +01:00
Cosimo Lupo
c2792f858b [ufo] when reverse_direction is True, we always want to modify the input glyphs
otherwise, the direction would only flipped if the glyph contains at least one cubic curve; whereas, we want to reverse the contour direction of all the glyphs in the font, even if they are just made of straight lines.
2016-10-06 15:14:44 +01:00
Cosimo Lupo
9c229e6509 [ufo] max_errors and glyphs list must have same length
Else curves_to_quadratic raises AssertionError if len(max_errors) != len(curves)

https://github.com/googlei18n/cu2qu/blob/master/Lib/cu2qu/__init__.py#L244
2016-09-21 00:51:06 +01:00
Cosimo Lupo
a5f93a06b9 [ufo] in fonts_to_quadratic, iterate over union of glyph names and convert compatibly glyphs with same name.
Don't use zip(*fonts) as defcon fonts are dictionary-like objects and the ordering of the glyphs returned by __iter__ method is undefined.
Should fix #48
2016-09-20 23:34:32 +01:00
Cosimo Lupo
826b790147 [ufo] minor refactor 2016-09-19 13:10:57 +01:00
Cosimo Lupo
f2e962c78f [ufo] don't check glyph names in glyphs_to_quadratic 2016-08-12 16:00:20 +01:00
Cosimo Lupo
e7854e5039 [ufo] add glyph[s]_to_quadratic to convert (1+ compatible) glyphs
This was requested in https://github.com/googlei18n/cu2qu/issues/26

Plus:
- do not modify input glyphs unless they contain one cubic curve;
- make public functions return True/False to signal that the input
  was modified or not (eg. no curves, or all quadratic)
2016-08-12 15:30:51 +01:00
James Godfrey-Kittle
daaa1bd06f Report number of segments in result, not points (#41)
For some reason, I was subtracting 1 from the spline lengths in the
test report. Not sure why that is, so I've assumed it was wrong (and
now we subtract 2 to get the length in number of segments).
2016-08-01 14:08:26 -07:00
James Godfrey-Kittle
4d72a44d35 Remove unused code 2016-07-27 16:52:09 -07:00
James Godfrey-Kittle
039e35b212 No error returned from API, update tests 2016-07-27 13:21:47 -07:00
James Godfrey-Kittle
3307c5d62a Add reverse_direction argument
As described in
https://github.com/googlei18n/cu2qu/pull/20#issuecomment-213058410
2016-05-10 18:01:34 -07:00
James Godfrey-Kittle
7fe4fd0fe2 [ufo] Don't touch components or UFO2-style anchors 2016-04-05 10:41:48 -07:00
James Godfrey-Kittle
802bb813f5 [ufo] Changes for python 3 compatibility 2016-04-05 10:37:07 -07:00
James Godfrey-Kittle
983307d9cd [ufo] Allow input fonts with quadratic curves 2016-04-04 17:30:33 -07:00
James Godfrey-Kittle
0ec7495516 [ufo] Handle endPath 2016-04-04 16:08:15 -07:00
James Godfrey-Kittle
b8fa142bef [ufo] Clear existing contours when adding new ones 2016-04-04 15:30:39 -07:00
James Godfrey-Kittle
17e25e8ec9 Rename rf module to ufo 2016-04-04 15:18:27 -07:00