Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flatten components option #438

Merged
merged 8 commits into from
Dec 10, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Lib/ufo2ft/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def compileTTF(
rememberCurveType=True,
removeOverlaps=False,
overlapsBackend=None,
flattenComponents=None,
inplace=False,
layerName=None,
skipExportGlyphs=None,
Expand Down Expand Up @@ -205,6 +206,7 @@ def compileTTF(
inplace=inplace,
removeOverlaps=removeOverlaps,
overlapsBackend=overlapsBackend,
flattenComponents=flattenComponents,
convertCubics=convertCubics,
conversionError=cubicConversionError,
reverseDirection=reverseDirection,
Expand Down
15 changes: 11 additions & 4 deletions Lib/ufo2ft/preProcessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ class TTFPreProcessor(OTFPreProcessor):
"""Preprocessor for building TrueType-flavored OpenType fonts.

By default, it decomposes all the glyphs with mixed component/contour
outlines.
outlines. If the ``flattenComponents`` setting is True, glyphs with
nested components are flattened so that they have at most one level of
components.

If ``removeOverlaps`` is True, it performs a union boolean operation on
all the glyphs' contours.
Expand Down Expand Up @@ -144,6 +146,7 @@ def initDefaultFilters(
self,
removeOverlaps=False,
overlapsBackend=None,
flattenComponents=False,
convertCubics=True,
conversionError=None,
reverseDirection=True,
Expand All @@ -153,9 +156,13 @@ def initDefaultFilters(

_init_explode_color_layer_glyphs_filter(self.ufo, filters)

# len(g) is the number of contours, so we include the all glyphs
# that have both components and at least one contour
filters.append(DecomposeComponentsFilter(include=lambda g: len(g)))
if flattenComponents:
from ufo2ft.filters.flattenComponents import FlattenComponentsFilter
filters.append(FlattenComponentsFilter())
else:
# len(g) is the number of contours, so we include the all glyphs
# that have both components and at least one contour
filters.append(DecomposeComponentsFilter(include=lambda g: len(g)))

if removeOverlaps:
from ufo2ft.filters.removeOverlaps import RemoveOverlapsFilter
Expand Down
Loading