本文整理汇总了Python中fontTools.designspaceLib.DesignSpaceDocument.findDefault方法的典型用法代码示例。如果您正苦于以下问题:Python DesignSpaceDocument.findDefault方法的具体用法?Python DesignSpaceDocument.findDefault怎么用?Python DesignSpaceDocument.findDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fontTools.designspaceLib.DesignSpaceDocument
的用法示例。
在下文中一共展示了DesignSpaceDocument.findDefault方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: from_designspace
# 需要导入模块: from fontTools.designspaceLib import DesignSpaceDocument [as 别名]
# 或者: from fontTools.designspaceLib.DesignSpaceDocument import findDefault [as 别名]
def from_designspace(
cls,
designspace: designspaceLib.DesignSpaceDocument,
round_geometry: bool = True,
):
"""Instantiates a new data class from a Designspace object."""
if designspace.default is None:
raise ValueError(
"Can't generate UFOs from this designspace: no default font."
)
designspace.loadSourceFonts(ufoLib2.Font.open)
glyph_names: Set[str] = set()
for source in designspace.sources:
glyph_names.update(source.font.keys())
# Construct Variators
axis_bounds: Dict[str, Tuple[float, float, float]] = {} # Design space!
axis_order: List[str] = []
weight_width_axes = {}
for axis in designspace.axes:
axis_order.append(axis.name)
axis_bounds[axis.name] = (
axis.map_forward(axis.minimum),
axis.map_forward(axis.default),
axis.map_forward(axis.maximum),
)
if axis.tag in ("wght", "wdth"):
weight_width_axes[axis.tag] = axis
masters_info = collect_info_masters(designspace, axis_bounds)
info_mutator = Variator.from_masters(masters_info, axis_order)
masters_kerning = collect_kerning_masters(designspace, axis_bounds)
kerning_mutator = Variator.from_masters(masters_kerning, axis_order)
default_font = designspace.findDefault().font
glyph_mutators: Dict[str, Variator] = {}
glyph_name_to_unicodes: Dict[str, List[int]] = {}
for glyph_name in glyph_names:
items = collect_glyph_masters(designspace, glyph_name, axis_bounds)
glyph_mutators[glyph_name] = Variator.from_masters(items, axis_order)
glyph_name_to_unicodes[glyph_name] = default_font[glyph_name].unicodes
# Construct defaults to copy over
copy_feature_text: str = default_font.features.text
copy_groups: Mapping[str, List[str]] = default_font.groups
copy_info: ufoLib2.objects.Info = default_font.info
copy_lib: Mapping[str, Any] = default_font.lib
# The list of glyphs not to export and decompose where used as a component is
# supposed to be taken from the Designspace when a Designspace is used as the
# starting point of the compilation process. It should be exported to all
# instance libs, where the ufo2ft compilation functions will pick it up.
skip_export_glyphs = designspace.lib.get("public.skipExportGlyphs", [])
return cls(
axis_bounds,
copy_feature_text,
copy_groups,
copy_info,
copy_lib,
designspace.rules,
glyph_mutators,
glyph_name_to_unicodes,
info_mutator,
kerning_mutator,
round_geometry,
skip_export_glyphs,
weight_width_axes,
)
示例2: from_designspace
# 需要导入模块: from fontTools.designspaceLib import DesignSpaceDocument [as 别名]
# 或者: from fontTools.designspaceLib.DesignSpaceDocument import findDefault [as 别名]
def from_designspace(
cls,
designspace: designspaceLib.DesignSpaceDocument,
round_geometry: bool = True,
):
"""Instantiates a new data class from a Designspace object."""
if designspace.default is None:
raise ValueError(
"Can't generate UFOs from this designspace: no default font."
)
glyph_names: Set[str] = set()
for source in designspace.sources:
if source.font is None:
if not Path(source.path).exists():
raise ValueError(f"Source at path '{source.path}' not found.")
source.font = ufoLib2.Font.open(source.path, lazy=False)
glyph_names.update(source.font.keys())
# Construct Variators
axis_bounds: Dict[str, Tuple[float, float, float]] = {}
axis_by_name: Dict[str, designspaceLib.AxisDescriptor] = {}
weight_width_axes = {}
for axis in designspace.axes:
axis_by_name[axis.name] = axis
axis_bounds[axis.name] = (axis.minimum, axis.default, axis.maximum)
if axis.tag in ("wght", "wdth"):
weight_width_axes[axis.tag] = axis
masters_info = collect_info_masters(designspace)
info_mutator = Variator.from_masters(masters_info, axis_by_name, axis_bounds)
masters_kerning = collect_kerning_masters(designspace)
kerning_mutator = Variator.from_masters(
masters_kerning, axis_by_name, axis_bounds
)
glyph_mutators: Dict[str, Variator] = {}
for glyph_name in glyph_names:
items = collect_glyph_masters(designspace, glyph_name)
mutator = Variator.from_masters(items, axis_by_name, axis_bounds)
glyph_mutators[glyph_name] = mutator
# Construct defaults to copy over
default_source = designspace.findDefault()
copy_feature_text: str = next(
(s.font.features.text for s in designspace.sources if s.copyFeatures),
default_source.font.features.text,
)
copy_groups: Mapping[str, List[str]] = next(
(s.font.groups for s in designspace.sources if s.copyGroups),
default_source.font.groups,
)
copy_info: ufoLib2.objects.Info = next(
(s.font.info for s in designspace.sources if s.copyInfo),
default_source.font.info,
)
copy_lib: Mapping[str, Any] = next(
(s.font.lib for s in designspace.sources if s.copyLib),
default_source.font.lib,
)
# The list of glyphs not to export and decompose where used as a component is
# supposed to be taken from the Designspace when a Designspace is used as the
# starting point of the compilation process. It should be exported to all
# instance libs, where the ufo2ft compilation functions will pick it up.
skip_export_glyphs = designspace.lib.get("public.skipExportGlyphs", [])
return cls(
copy_feature_text,
copy_groups,
copy_info,
copy_lib,
designspace.rules,
glyph_mutators,
info_mutator,
kerning_mutator,
round_geometry,
skip_export_glyphs,
weight_width_axes,
)