code stringlengths 66 870k | docstring stringlengths 19 26.7k | func_name stringlengths 1 138 | language stringclasses 1
value | repo stringlengths 7 68 | path stringlengths 5 324 | url stringlengths 46 389 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
def evaluateConditions(conditions, location):
"""Return True if all the conditions matches the given location.
- If a condition has no minimum, check for < maximum.
- If a condition has no maximum, check for > minimum.
"""
for cd in conditions:
value = location[cd["name"]]
if cd.get... | Return True if all the conditions matches the given location.
- If a condition has no minimum, check for < maximum.
- If a condition has no maximum, check for > minimum.
| evaluateConditions | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def processRules(rules, location, glyphNames):
"""Apply these rules at this location to these glyphnames.
Return a new list of glyphNames with substitutions applied.
- rule order matters
"""
newNames = []
for rule in rules:
if evaluateRule(rule, location):
for name in glyph... | Apply these rules at this location to these glyphnames.
Return a new list of glyphNames with substitutions applied.
- rule order matters
| processRules | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def clearLocation(self, axisName: Optional[str] = None):
"""Clear all location-related fields. Ensures that
:attr:``designLocation`` and :attr:``userLocation`` are dictionaries
(possibly empty if clearing everything).
In order to update the location of this instance wholesale, a user
... | Clear all location-related fields. Ensures that
:attr:``designLocation`` and :attr:``userLocation`` are dictionaries
(possibly empty if clearing everything).
In order to update the location of this instance wholesale, a user
should first clear all the fields, then change the field(s) fo... | clearLocation | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def getLocationLabelDescriptor(
self, doc: "DesignSpaceDocument"
) -> Optional[LocationLabelDescriptor]:
"""Get the :class:`LocationLabelDescriptor` instance that matches
this instances's :attr:`locationLabel`.
Raises if the named label can't be found.
.. versionadded:: 5.0... | Get the :class:`LocationLabelDescriptor` instance that matches
this instances's :attr:`locationLabel`.
Raises if the named label can't be found.
.. versionadded:: 5.0
| getLocationLabelDescriptor | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def getFullDesignLocation(
self, doc: "DesignSpaceDocument"
) -> AnisotropicLocationDict:
"""Get the complete design location of this instance, by combining data
from the various location fields, default axis values and mappings, and
top-level location labels.
The source of ... | Get the complete design location of this instance, by combining data
from the various location fields, default axis values and mappings, and
top-level location labels.
The source of truth for this instance's location is determined for each
axis independently by taking the first not-None... | getFullDesignLocation | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def map_forward(self, v):
"""Maps value from axis mapping's input (user) to output (design)."""
from fontTools.varLib.models import piecewiseLinearMap
if not self.map:
return v
return piecewiseLinearMap(v, {k: v for k, v in self.map}) | Maps value from axis mapping's input (user) to output (design). | map_forward | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def map_backward(self, v):
"""Maps value from axis mapping's output (design) to input (user)."""
from fontTools.varLib.models import piecewiseLinearMap
if isinstance(v, tuple):
v = v[0]
if not self.map:
return v
return piecewiseLinearMap(v, {v: k for k, v... | Maps value from axis mapping's output (design) to input (user). | map_backward | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def map_backward(self, value):
"""Maps value from axis mapping's output to input.
Returns value unchanged if no mapping entry is found.
Note: for discrete axes, each value must have its mapping entry, if
you intend that value to be mapped.
"""
if isinstance(value, tuple... | Maps value from axis mapping's output to input.
Returns value unchanged if no mapping entry is found.
Note: for discrete axes, each value must have its mapping entry, if
you intend that value to be mapped.
| map_backward | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def getFullUserLocation(self, doc: "DesignSpaceDocument") -> SimpleLocationDict:
"""Get the complete user location of this label, by combining data
from the explicit user location and default axis values.
.. versionadded:: 5.0
"""
return {
axis.name: self.userLocatio... | Get the complete user location of this label, by combining data
from the explicit user location and default axis values.
.. versionadded:: 5.0
| getFullUserLocation | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def _getEffectiveFormatTuple(self):
"""Try to use the version specified in the document, or a sufficiently
recent version to be able to encode what the document contains.
"""
minVersion = self.documentObject.formatTuple
if (
any(
hasattr(axis, "values"... | Try to use the version specified in the document, or a sufficiently
recent version to be able to encode what the document contains.
| _getEffectiveFormatTuple | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def locationFromElement(self, element):
"""Read a nested ``<location>`` element inside the given ``element``.
.. versionchanged:: 5.0
Return a tuple of (designLocation, userLocation)
"""
elementLocation = (None, None)
for locationElement in element.findall(".location"... | Read a nested ``<location>`` element inside the given ``element``.
.. versionchanged:: 5.0
Return a tuple of (designLocation, userLocation)
| locationFromElement | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def readLocationElement(self, locationElement):
"""Read a ``<location>`` element.
.. versionchanged:: 5.0
Return a tuple of (designLocation, userLocation)
"""
if self._strictAxisNames and not self.documentObject.axes:
raise DesignSpaceDocumentError("No axes define... | Read a ``<location>`` element.
.. versionchanged:: 5.0
Return a tuple of (designLocation, userLocation)
| readLocationElement | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def readGlyphElement(self, glyphElement, instanceObject):
"""
Read the glyph element, which could look like either one of these:
.. code-block:: xml
<glyph name="b" unicode="0x62"/>
<glyph name="b"/>
<glyph name="b">
<master location="locat... |
Read the glyph element, which could look like either one of these:
.. code-block:: xml
<glyph name="b" unicode="0x62"/>
<glyph name="b"/>
<glyph name="b">
<master location="location-token-bbb" source="master-token-aaa2"/>
<master g... | readGlyphElement | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def readLib(self):
"""Read the lib element for the whole document."""
for libElement in self.root.findall(".lib"):
self.documentObject.lib = plistlib.fromtree(libElement[0]) | Read the lib element for the whole document. | readLib | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def fromfile(cls, path, readerClass=None, writerClass=None):
"""Read a designspace file from ``path`` and return a new instance of
:class:.
"""
self = cls(readerClass=readerClass, writerClass=writerClass)
self.read(path)
return self | Read a designspace file from ``path`` and return a new instance of
:class:.
| fromfile | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def tostring(self, encoding=None):
"""Returns the designspace as a string. Default encoding ``utf-8``."""
if encoding is str or (encoding is not None and encoding.lower() == "unicode"):
f = StringIO()
xml_declaration = False
elif encoding is None or encoding == "utf-8":
... | Returns the designspace as a string. Default encoding ``utf-8``. | tostring | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def read(self, path):
"""Read a designspace file from ``path`` and populates the fields of
``self`` with the data.
"""
if hasattr(path, "__fspath__"): # support os.PathLike objects
path = path.__fspath__()
self.path = path
self.filename = os.path.basename(pat... | Read a designspace file from ``path`` and populates the fields of
``self`` with the data.
| read | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def updatePaths(self):
"""
Right before we save we need to identify and respond to the following situations:
In each descriptor, we have to do the right thing for the filename attribute.
::
case 1.
descriptor.filename == None
descriptor.path == None
... |
Right before we save we need to identify and respond to the following situations:
In each descriptor, we have to do the right thing for the filename attribute.
::
case 1.
descriptor.filename == None
descriptor.path == None
-- action:
... | updatePaths | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def addSourceDescriptor(self, **kwargs):
"""Instantiate a new :class:`SourceDescriptor` using the given
``kwargs`` and add it to ``doc.sources``.
"""
source = self.writerClass.sourceDescriptorClass(**kwargs)
self.addSource(source)
return source | Instantiate a new :class:`SourceDescriptor` using the given
``kwargs`` and add it to ``doc.sources``.
| addSourceDescriptor | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def addInstanceDescriptor(self, **kwargs):
"""Instantiate a new :class:`InstanceDescriptor` using the given
``kwargs`` and add it to :attr:`instances`.
"""
instance = self.writerClass.instanceDescriptorClass(**kwargs)
self.addInstance(instance)
return instance | Instantiate a new :class:`InstanceDescriptor` using the given
``kwargs`` and add it to :attr:`instances`.
| addInstanceDescriptor | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def addAxisDescriptor(self, **kwargs):
"""Instantiate a new :class:`AxisDescriptor` using the given
``kwargs`` and add it to :attr:`axes`.
The axis will be and instance of :class:`DiscreteAxisDescriptor` if
the ``kwargs`` provide a ``value``, or a :class:`AxisDescriptor` otherwise.
... | Instantiate a new :class:`AxisDescriptor` using the given
``kwargs`` and add it to :attr:`axes`.
The axis will be and instance of :class:`DiscreteAxisDescriptor` if
the ``kwargs`` provide a ``value``, or a :class:`AxisDescriptor` otherwise.
| addAxisDescriptor | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def addAxisMappingDescriptor(self, **kwargs):
"""Instantiate a new :class:`AxisMappingDescriptor` using the given
``kwargs`` and add it to :attr:`rules`.
"""
axisMapping = self.writerClass.axisMappingDescriptorClass(**kwargs)
self.addAxisMapping(axisMapping)
return axisMa... | Instantiate a new :class:`AxisMappingDescriptor` using the given
``kwargs`` and add it to :attr:`rules`.
| addAxisMappingDescriptor | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def addRuleDescriptor(self, **kwargs):
"""Instantiate a new :class:`RuleDescriptor` using the given
``kwargs`` and add it to :attr:`rules`.
"""
rule = self.writerClass.ruleDescriptorClass(**kwargs)
self.addRule(rule)
return rule | Instantiate a new :class:`RuleDescriptor` using the given
``kwargs`` and add it to :attr:`rules`.
| addRuleDescriptor | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def addVariableFontDescriptor(self, **kwargs):
"""Instantiate a new :class:`VariableFontDescriptor` using the given
``kwargs`` and add it to :attr:`variableFonts`.
.. versionadded:: 5.0
"""
variableFont = self.writerClass.variableFontDescriptorClass(**kwargs)
self.addVar... | Instantiate a new :class:`VariableFontDescriptor` using the given
``kwargs`` and add it to :attr:`variableFonts`.
.. versionadded:: 5.0
| addVariableFontDescriptor | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def addLocationLabelDescriptor(self, **kwargs):
"""Instantiate a new :class:`LocationLabelDescriptor` using the given
``kwargs`` and add it to :attr:`locationLabels`.
.. versionadded:: 5.0
"""
locationLabel = self.writerClass.locationLabelDescriptorClass(**kwargs)
self.a... | Instantiate a new :class:`LocationLabelDescriptor` using the given
``kwargs`` and add it to :attr:`locationLabels`.
.. versionadded:: 5.0
| addLocationLabelDescriptor | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def newDefaultLocation(self):
"""Return a dict with the default location in design space coordinates."""
# Without OrderedDict, output XML would be non-deterministic.
# https://github.com/LettError/designSpaceDocument/issues/10
loc = collections.OrderedDict()
for axisDescriptor i... | Return a dict with the default location in design space coordinates. | newDefaultLocation | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def labelForUserLocation(
self, userLocation: SimpleLocationDict
) -> Optional[LocationLabelDescriptor]:
"""Return the :class:`LocationLabel` that matches the given
``userLocation``, or ``None`` if no such label exists.
.. versionadded:: 5.0
"""
return next(
... | Return the :class:`LocationLabel` that matches the given
``userLocation``, or ``None`` if no such label exists.
.. versionadded:: 5.0
| labelForUserLocation | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def updateFilenameFromPath(self, masters=True, instances=True, force=False):
"""Set a descriptor filename attr from the path and this document path.
If the filename attribute is not None: skip it.
"""
if masters:
for descriptor in self.sources:
if descriptor.... | Set a descriptor filename attr from the path and this document path.
If the filename attribute is not None: skip it.
| updateFilenameFromPath | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def getAxisOrder(self):
"""Return a list of axis names, in the same order as defined in the document."""
names = []
for axisDescriptor in self.axes:
names.append(axisDescriptor.name)
return names | Return a list of axis names, in the same order as defined in the document. | getAxisOrder | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def getLocationLabel(self, name: str) -> Optional[LocationLabelDescriptor]:
"""Return the top-level location label with the given ``name``, or
``None`` if no such label exists.
.. versionadded:: 5.0
"""
for label in self.locationLabels:
if label.name == name:
... | Return the top-level location label with the given ``name``, or
``None`` if no such label exists.
.. versionadded:: 5.0
| getLocationLabel | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def map_forward(self, userLocation: SimpleLocationDict) -> SimpleLocationDict:
"""Map a user location to a design location.
Assume that missing coordinates are at the default location for that axis.
Note: the output won't be anisotropic, only the xvalue is set.
.. versionadded:: 5.0
... | Map a user location to a design location.
Assume that missing coordinates are at the default location for that axis.
Note: the output won't be anisotropic, only the xvalue is set.
.. versionadded:: 5.0
| map_forward | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def map_backward(
self, designLocation: AnisotropicLocationDict
) -> SimpleLocationDict:
"""Map a design location to a user location.
Assume that missing coordinates are at the default location for that axis.
When the input has anisotropic locations, only the xvalue is used.
... | Map a design location to a user location.
Assume that missing coordinates are at the default location for that axis.
When the input has anisotropic locations, only the xvalue is used.
.. versionadded:: 5.0
| map_backward | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def findDefault(self):
"""Set and return SourceDescriptor at the default location or None.
The default location is the set of all `default` values in user space
of all axes.
This function updates the document's :attr:`default` value.
.. versionchanged:: 5.0
Allow th... | Set and return SourceDescriptor at the default location or None.
The default location is the set of all `default` values in user space
of all axes.
This function updates the document's :attr:`default` value.
.. versionchanged:: 5.0
Allow the default source to not specify so... | findDefault | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def normalizeLocation(self, location):
"""Return a dict with normalized axis values."""
from fontTools.varLib.models import normalizeValue
new = {}
for axis in self.axes:
if axis.name not in location:
# skipping this dimension it seems
continu... | Return a dict with normalized axis values. | normalizeLocation | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def normalize(self):
"""
Normalise the geometry of this designspace:
- scale all the locations of all masters and instances to the -1 - 0 - 1 value.
- we need the axis data to do the scaling, so we do those last.
"""
# masters
for item in self.sources:
... |
Normalise the geometry of this designspace:
- scale all the locations of all masters and instances to the -1 - 0 - 1 value.
- we need the axis data to do the scaling, so we do those last.
| normalize | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def loadSourceFonts(self, opener, **kwargs):
"""Ensure SourceDescriptor.font attributes are loaded, and return list of fonts.
Takes a callable which initializes a new font object (e.g. TTFont, or
defcon.Font, etc.) from the SourceDescriptor.path, and sets the
SourceDescriptor.font attri... | Ensure SourceDescriptor.font attributes are loaded, and return list of fonts.
Takes a callable which initializes a new font object (e.g. TTFont, or
defcon.Font, etc.) from the SourceDescriptor.path, and sets the
SourceDescriptor.font attribute.
If the font attribute is already not None,... | loadSourceFonts | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def formatTuple(self):
"""Return the formatVersion as a tuple of (major, minor).
.. versionadded:: 5.0
"""
if self.formatVersion is None:
return (5, 0)
numbers = (int(i) for i in self.formatVersion.split("."))
major = next(numbers)
minor = next(number... | Return the formatVersion as a tuple of (major, minor).
.. versionadded:: 5.0
| formatTuple | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def getVariableFonts(self) -> List[VariableFontDescriptor]:
"""Return all variable fonts defined in this document, or implicit
variable fonts that can be built from the document's continuous axes.
In the case of Designspace documents before version 5, the whole
document was implicitly d... | Return all variable fonts defined in this document, or implicit
variable fonts that can be built from the document's continuous axes.
In the case of Designspace documents before version 5, the whole
document was implicitly describing a variable font that covers the
whole space.
... | getVariableFonts | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def deepcopyExceptFonts(self):
"""Allow deep-copying a DesignSpace document without deep-copying
attached UFO fonts or TTFont objects. The :attr:`font` attribute
is shared by reference between the original and the copy.
.. versionadded:: 5.0
"""
fonts = [source.font for ... | Allow deep-copying a DesignSpace document without deep-copying
attached UFO fonts or TTFont objects. The :attr:`font` attribute
is shared by reference between the original and the copy.
.. versionadded:: 5.0
| deepcopyExceptFonts | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def main(args=None):
"""Roundtrip .designspace file through the DesignSpaceDocument class"""
if args is None:
import sys
args = sys.argv[1:]
from argparse import ArgumentParser
parser = ArgumentParser(prog="designspaceLib", description=main.__doc__)
parser.add_argument("input")
... | Roundtrip .designspace file through the DesignSpaceDocument class | main | python | fonttools/fonttools | Lib/fontTools/designspaceLib/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py | MIT |
def add_range(self, start, end, glyphs):
"""Add a range (e.g. ``A-Z``) to the class. ``start`` and ``end``
are either :class:`GlyphName` objects or strings representing the
start and end glyphs in the class, and ``glyphs`` is the full list of
:class:`GlyphName` objects in the range."""
... | Add a range (e.g. ``A-Z``) to the class. ``start`` and ``end``
are either :class:`GlyphName` objects or strings representing the
start and end glyphs in the class, and ``glyphs`` is the full list of
:class:`GlyphName` objects in the range. | add_range | python | fonttools/fonttools | Lib/fontTools/feaLib/ast.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/feaLib/ast.py | MIT |
def add_cid_range(self, start, end, glyphs):
"""Add a range to the class by glyph ID. ``start`` and ``end`` are the
initial and final IDs, and ``glyphs`` is the full list of
:class:`GlyphName` objects in the range."""
if self.curr < len(self.glyphs):
self.original.extend(self... | Add a range to the class by glyph ID. ``start`` and ``end`` are the
initial and final IDs, and ``glyphs`` is the full list of
:class:`GlyphName` objects in the range. | add_cid_range | python | fonttools/fonttools | Lib/fontTools/feaLib/ast.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/feaLib/ast.py | MIT |
def add_class(self, gc):
"""Add glyphs from the given :class:`GlyphClassName` object to the
class."""
if self.curr < len(self.glyphs):
self.original.extend(self.glyphs[self.curr :])
self.original.append(gc)
self.glyphs.extend(gc.glyphSet())
self.curr = len(sel... | Add glyphs from the given :class:`GlyphClassName` object to the
class. | add_class | python | fonttools/fonttools | Lib/fontTools/feaLib/ast.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/feaLib/ast.py | MIT |
def build(self, builder):
"""Call the ``start_feature`` callback on the builder object, visit
all the statements in this feature, and then call ``end_feature``."""
builder.start_feature(self.location, self.name, self.use_extension)
# language exclude_dflt statements modify builder.featur... | Call the ``start_feature`` callback on the builder object, visit
all the statements in this feature, and then call ``end_feature``. | build | python | fonttools/fonttools | Lib/fontTools/feaLib/ast.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/feaLib/ast.py | MIT |
def addDefinition(self, definition):
"""Add a :class:`MarkClassDefinition` statement to this mark class."""
assert isinstance(definition, MarkClassDefinition)
self.definitions.append(definition)
for glyph in definition.glyphSet():
if glyph in self.glyphs:
othe... | Add a :class:`MarkClassDefinition` statement to this mark class. | addDefinition | python | fonttools/fonttools | Lib/fontTools/feaLib/ast.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/feaLib/ast.py | MIT |
def build(self, builder):
"""Calls the builder object's ``add_chain_context_pos`` callback on each
rule context."""
for prefix, glyphs, suffix in self.chainContexts:
prefix = [p.glyphSet() for p in prefix]
glyphs = [g.glyphSet() for g in glyphs]
suffix = [s.gl... | Calls the builder object's ``add_chain_context_pos`` callback on each
rule context. | build | python | fonttools/fonttools | Lib/fontTools/feaLib/ast.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/feaLib/ast.py | MIT |
def build(self, builder):
"""Calls the builder object's ``add_chain_context_subst`` callback on
each rule context."""
for prefix, glyphs, suffix in self.chainContexts:
prefix = [p.glyphSet() for p in prefix]
glyphs = [g.glyphSet() for g in glyphs]
suffix = [s.... | Calls the builder object's ``add_chain_context_subst`` callback on
each rule context. | build | python | fonttools/fonttools | Lib/fontTools/feaLib/ast.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/feaLib/ast.py | MIT |
def build(self, builder):
"""Calls a callback on the builder object:
* If the rule is enumerated, calls ``add_specific_pair_pos`` on each
combination of first and second glyphs.
* If the glyphs are both single :class:`GlyphName` objects, calls
``add_specific_pair_pos``.
... | Calls a callback on the builder object:
* If the rule is enumerated, calls ``add_specific_pair_pos`` on each
combination of first and second glyphs.
* If the glyphs are both single :class:`GlyphName` objects, calls
``add_specific_pair_pos``.
* Else, calls ``add_class_pair_po... | build | python | fonttools/fonttools | Lib/fontTools/feaLib/ast.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/feaLib/ast.py | MIT |
def build(self, builder):
"""Call the ``start_feature`` callback on the builder object, visit
all the statements in this feature, and then call ``end_feature``."""
builder.start_feature(self.location, self.name, self.use_extension)
if (
self.conditionset != "NULL"
... | Call the ``start_feature`` callback on the builder object, visit
all the statements in this feature, and then call ``end_feature``. | build | python | fonttools/fonttools | Lib/fontTools/feaLib/ast.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/feaLib/ast.py | MIT |
def addOpenTypeFeaturesFromString(
font, features, filename=None, tables=None, debug=False
):
"""Add features from a string to a font. Note that this replaces any
features currently present.
Args:
font (feaLib.ttLib.TTFont): The font object.
features: A string containing feature code.
... | Add features from a string to a font. Note that this replaces any
features currently present.
Args:
font (feaLib.ttLib.TTFont): The font object.
features: A string containing feature code.
filename: The directory containing ``filename`` is used as the root of
relative ``incl... | addOpenTypeFeaturesFromString | python | fonttools/fonttools | Lib/fontTools/feaLib/builder.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/feaLib/builder.py | MIT |
def find_lookup_builders_(self, lookups):
"""Helper for building chain contextual substitutions
Given a list of lookup names, finds the LookupBuilder for each name.
If an input name is None, it gets mapped to a None LookupBuilder.
"""
lookup_builders = []
for lookuplist ... | Helper for building chain contextual substitutions
Given a list of lookup names, finds the LookupBuilder for each name.
If an input name is None, it gets mapped to a None LookupBuilder.
| find_lookup_builders_ | python | fonttools/fonttools | Lib/fontTools/feaLib/builder.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/feaLib/builder.py | MIT |
def add_to_cv_num_named_params(self, tag):
"""Adds new items to ``self.cv_num_named_params_``
or increments the count of existing items."""
if tag in self.cv_num_named_params_:
self.cv_num_named_params_[tag] += 1
else:
self.cv_num_named_params_[tag] = 1 | Adds new items to ``self.cv_num_named_params_``
or increments the count of existing items. | add_to_cv_num_named_params | python | fonttools/fonttools | Lib/fontTools/feaLib/builder.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/feaLib/builder.py | MIT |
def __init__(self, featurefile, *, includeDir=None):
"""Initializes an IncludingLexer.
Behavior:
If includeDir is passed, it will be used to determine the top-level
include directory to use for all encountered include statements. If it is
not passed, ``os.path.dirnam... | Initializes an IncludingLexer.
Behavior:
If includeDir is passed, it will be used to determine the top-level
include directory to use for all encountered include statements. If it is
not passed, ``os.path.dirname(featurefile)`` will be considered the
include dire... | __init__ | python | fonttools/fonttools | Lib/fontTools/feaLib/lexer.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/feaLib/lexer.py | MIT |
def parse(self):
"""Parse the file, and return a :class:`fontTools.feaLib.ast.FeatureFile`
object representing the root of the abstract syntax tree containing the
parsed contents of the file."""
statements = self.doc_.statements
while self.next_token_type_ is not None or self.cur... | Parse the file, and return a :class:`fontTools.feaLib.ast.FeatureFile`
object representing the root of the abstract syntax tree containing the
parsed contents of the file. | parse | python | fonttools/fonttools | Lib/fontTools/feaLib/parser.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/feaLib/parser.py | MIT |
def parse_name_(self):
"""Parses a name record. See `section 9.e <https://adobe-type-tools.github.io/afdko/OpenTypeFeatureFileSpecification.html#9.e>`_."""
platEncID = None
langID = None
if self.next_token_type_ in Lexer.NUMBERS:
platformID = self.expect_any_number_()
... | Parses a name record. See `section 9.e <https://adobe-type-tools.github.io/afdko/OpenTypeFeatureFileSpecification.html#9.e>`_. | parse_name_ | python | fonttools/fonttools | Lib/fontTools/feaLib/parser.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/feaLib/parser.py | MIT |
def parse_featureNames_(self, tag):
"""Parses a ``featureNames`` statement found in stylistic set features.
See section `8.c <https://adobe-type-tools.github.io/afdko/OpenTypeFeatureFileSpecification.html#8.c>`_.
"""
assert self.cur_token_ == "featureNames", self.cur_token_
block... | Parses a ``featureNames`` statement found in stylistic set features.
See section `8.c <https://adobe-type-tools.github.io/afdko/OpenTypeFeatureFileSpecification.html#8.c>`_.
| parse_featureNames_ | python | fonttools/fonttools | Lib/fontTools/feaLib/parser.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/feaLib/parser.py | MIT |
def check_glyph_name_in_glyph_set(self, *names):
"""Adds a glyph name (just `start`) or glyph names of a
range (`start` and `end`) which are not in the glyph set
to the "missing list" for future error reporting.
If no glyph set is present, does nothing.
"""
if self.glyph... | Adds a glyph name (just `start`) or glyph names of a
range (`start` and `end`) which are not in the glyph set
to the "missing list" for future error reporting.
If no glyph set is present, does nothing.
| check_glyph_name_in_glyph_set | python | fonttools/fonttools | Lib/fontTools/feaLib/parser.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/feaLib/parser.py | MIT |
def make_glyph_range_(self, location, start, limit):
"""(location, "a.sc", "d.sc") --> ["a.sc", "b.sc", "c.sc", "d.sc"]"""
result = list()
if len(start) != len(limit):
raise FeatureLibError(
'Bad range: "%s" and "%s" should have the same length' % (start, limit),
... | (location, "a.sc", "d.sc") --> ["a.sc", "b.sc", "c.sc", "d.sc"] | make_glyph_range_ | python | fonttools/fonttools | Lib/fontTools/feaLib/parser.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/feaLib/parser.py | MIT |
def main(args=None):
"""Add features from a feature file (.fea) into an OTF font"""
parser = argparse.ArgumentParser(
description="Use fontTools to compile OpenType feature files (*.fea)."
)
parser.add_argument(
"input_fea", metavar="FEATURES", help="Path to the feature file"
)
p... | Add features from a feature file (.fea) into an OTF font | main | python | fonttools/fonttools | Lib/fontTools/feaLib/__main__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/feaLib/__main__.py | MIT |
def add_method(*clazzes, **kwargs):
"""Returns a decorator function that adds a new method to one or
more classes."""
allowDefault = kwargs.get("allowDefaultTable", False)
def wrapper(method):
done = []
for clazz in clazzes:
if clazz in done:
continue # Supp... | Returns a decorator function that adds a new method to one or
more classes. | add_method | python | fonttools/fonttools | Lib/fontTools/merge/base.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/merge/base.py | MIT |
def computeMegaGlyphOrder(merger, glyphOrders):
"""Modifies passed-in glyphOrders to reflect new glyph names.
Stores merger.glyphOrder."""
megaOrder = {}
for glyphOrder in glyphOrders:
for i, glyphName in enumerate(glyphOrder):
if glyphName in megaOrder:
n = megaOrder... | Modifies passed-in glyphOrders to reflect new glyph names.
Stores merger.glyphOrder. | computeMegaGlyphOrder | python | fonttools/fonttools | Lib/fontTools/merge/cmap.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/merge/cmap.py | MIT |
def computeMegaUvs(merger, uvsTables):
"""Returns merged UVS subtable (cmap format=14)."""
uvsDict = {}
cmap = merger.cmap
for table in uvsTables:
for variationSelector, uvsMapping in table.uvsDict.items():
if variationSelector not in uvsDict:
uvsDict[variationSelecto... | Returns merged UVS subtable (cmap format=14). | computeMegaUvs | python | fonttools/fonttools | Lib/fontTools/merge/cmap.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/merge/cmap.py | MIT |
def computeMegaCmap(merger, cmapTables):
"""Sets merger.cmap and merger.uvsDict."""
# TODO Handle format=14.
# Only merge format 4 and 12 Unicode subtables, ignores all other subtables
# If there is a format 12 table for a font, ignore the format 4 table of it
chosenCmapTables = []
chosenUvsTab... | Sets merger.cmap and merger.uvsDict. | computeMegaCmap | python | fonttools/fonttools | Lib/fontTools/merge/cmap.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/merge/cmap.py | MIT |
def renameCFFCharStrings(merger, glyphOrder, cffTable):
"""Rename topDictIndex charStrings based on glyphOrder."""
td = cffTable.cff.topDictIndex[0]
charStrings = {}
for i, v in enumerate(td.CharStrings.charStrings.values()):
glyphName = glyphOrder[i]
charStrings[glyphName] = v
td.C... | Rename topDictIndex charStrings based on glyphOrder. | renameCFFCharStrings | python | fonttools/fonttools | Lib/fontTools/merge/cmap.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/merge/cmap.py | MIT |
def onlyExisting(func):
"""Returns a filter func that when called with a list,
only calls func on the non-NotImplemented items of the list,
and only so if there's at least one item remaining.
Otherwise returns NotImplemented."""
def wrapper(lst):
items = [item for item in lst if item is not... | Returns a filter func that when called with a list,
only calls func on the non-NotImplemented items of the list,
and only so if there's at least one item remaining.
Otherwise returns NotImplemented. | onlyExisting | python | fonttools/fonttools | Lib/fontTools/merge/util.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/merge/util.py | MIT |
def merge(self, fontfiles):
"""Merges fonts together.
Args:
fontfiles: A list of file names to be merged
Returns:
A :class:`fontTools.ttLib.TTFont` object. Call the ``save`` method on
this to write it out to an OTF file.
"""
#
... | Merges fonts together.
Args:
fontfiles: A list of file names to be merged
Returns:
A :class:`fontTools.ttLib.TTFont` object. Call the ``save`` method on
this to write it out to an OTF file.
| merge | python | fonttools/fonttools | Lib/fontTools/merge/__init__.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/merge/__init__.py | MIT |
def calcBounds(array):
"""Calculate the bounding rectangle of a 2D points array.
Args:
array: A sequence of 2D tuples.
Returns:
A four-item tuple representing the bounding rectangle ``(xMin, yMin, xMax, yMax)``.
"""
if not array:
return 0, 0, 0, 0
xs = [x for x, y in ar... | Calculate the bounding rectangle of a 2D points array.
Args:
array: A sequence of 2D tuples.
Returns:
A four-item tuple representing the bounding rectangle ``(xMin, yMin, xMax, yMax)``.
| calcBounds | python | fonttools/fonttools | Lib/fontTools/misc/arrayTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/arrayTools.py | MIT |
def updateBounds(bounds, p, min=min, max=max):
"""Add a point to a bounding rectangle.
Args:
bounds: A bounding rectangle expressed as a tuple
``(xMin, yMin, xMax, yMax), or None``.
p: A 2D tuple representing a point.
min,max: functions to compute the minimum and maximum.
... | Add a point to a bounding rectangle.
Args:
bounds: A bounding rectangle expressed as a tuple
``(xMin, yMin, xMax, yMax), or None``.
p: A 2D tuple representing a point.
min,max: functions to compute the minimum and maximum.
Returns:
The updated bounding rectangle ``(... | updateBounds | python | fonttools/fonttools | Lib/fontTools/misc/arrayTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/arrayTools.py | MIT |
def pointInRect(p, rect):
"""Test if a point is inside a bounding rectangle.
Args:
p: A 2D tuple representing a point.
rect: A bounding rectangle expressed as a tuple
``(xMin, yMin, xMax, yMax)``.
Returns:
``True`` if the point is inside the rectangle, ``False`` otherwi... | Test if a point is inside a bounding rectangle.
Args:
p: A 2D tuple representing a point.
rect: A bounding rectangle expressed as a tuple
``(xMin, yMin, xMax, yMax)``.
Returns:
``True`` if the point is inside the rectangle, ``False`` otherwise.
| pointInRect | python | fonttools/fonttools | Lib/fontTools/misc/arrayTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/arrayTools.py | MIT |
def pointsInRect(array, rect):
"""Determine which points are inside a bounding rectangle.
Args:
array: A sequence of 2D tuples.
rect: A bounding rectangle expressed as a tuple
``(xMin, yMin, xMax, yMax)``.
Returns:
A list containing the points inside the rectangle.
... | Determine which points are inside a bounding rectangle.
Args:
array: A sequence of 2D tuples.
rect: A bounding rectangle expressed as a tuple
``(xMin, yMin, xMax, yMax)``.
Returns:
A list containing the points inside the rectangle.
| pointsInRect | python | fonttools/fonttools | Lib/fontTools/misc/arrayTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/arrayTools.py | MIT |
def vectorLength(vector):
"""Calculate the length of the given vector.
Args:
vector: A 2D tuple.
Returns:
The Euclidean length of the vector.
"""
x, y = vector
return math.sqrt(x**2 + y**2) | Calculate the length of the given vector.
Args:
vector: A 2D tuple.
Returns:
The Euclidean length of the vector.
| vectorLength | python | fonttools/fonttools | Lib/fontTools/misc/arrayTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/arrayTools.py | MIT |
def normRect(rect):
"""Normalize a bounding box rectangle.
This function "turns the rectangle the right way up", so that the following
holds::
xMin <= xMax and yMin <= yMax
Args:
rect: A bounding rectangle expressed as a tuple
``(xMin, yMin, xMax, yMax)``.
Returns:
... | Normalize a bounding box rectangle.
This function "turns the rectangle the right way up", so that the following
holds::
xMin <= xMax and yMin <= yMax
Args:
rect: A bounding rectangle expressed as a tuple
``(xMin, yMin, xMax, yMax)``.
Returns:
A normalized bounding... | normRect | python | fonttools/fonttools | Lib/fontTools/misc/arrayTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/arrayTools.py | MIT |
def scaleRect(rect, x, y):
"""Scale a bounding box rectangle.
Args:
rect: A bounding rectangle expressed as a tuple
``(xMin, yMin, xMax, yMax)``.
x: Factor to scale the rectangle along the X axis.
Y: Factor to scale the rectangle along the Y axis.
Returns:
A sca... | Scale a bounding box rectangle.
Args:
rect: A bounding rectangle expressed as a tuple
``(xMin, yMin, xMax, yMax)``.
x: Factor to scale the rectangle along the X axis.
Y: Factor to scale the rectangle along the Y axis.
Returns:
A scaled bounding rectangle.
| scaleRect | python | fonttools/fonttools | Lib/fontTools/misc/arrayTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/arrayTools.py | MIT |
def offsetRect(rect, dx, dy):
"""Offset a bounding box rectangle.
Args:
rect: A bounding rectangle expressed as a tuple
``(xMin, yMin, xMax, yMax)``.
dx: Amount to offset the rectangle along the X axis.
dY: Amount to offset the rectangle along the Y axis.
Returns:
... | Offset a bounding box rectangle.
Args:
rect: A bounding rectangle expressed as a tuple
``(xMin, yMin, xMax, yMax)``.
dx: Amount to offset the rectangle along the X axis.
dY: Amount to offset the rectangle along the Y axis.
Returns:
An offset bounding rectangle.
| offsetRect | python | fonttools/fonttools | Lib/fontTools/misc/arrayTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/arrayTools.py | MIT |
def insetRect(rect, dx, dy):
"""Inset a bounding box rectangle on all sides.
Args:
rect: A bounding rectangle expressed as a tuple
``(xMin, yMin, xMax, yMax)``.
dx: Amount to inset the rectangle along the X axis.
dY: Amount to inset the rectangle along the Y axis.
Retur... | Inset a bounding box rectangle on all sides.
Args:
rect: A bounding rectangle expressed as a tuple
``(xMin, yMin, xMax, yMax)``.
dx: Amount to inset the rectangle along the X axis.
dY: Amount to inset the rectangle along the Y axis.
Returns:
An inset bounding rectan... | insetRect | python | fonttools/fonttools | Lib/fontTools/misc/arrayTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/arrayTools.py | MIT |
def sectRect(rect1, rect2):
"""Test for rectangle-rectangle intersection.
Args:
rect1: First bounding rectangle, expressed as tuples
``(xMin, yMin, xMax, yMax)``.
rect2: Second bounding rectangle.
Returns:
A boolean and a rectangle.
If the input rectangles inter... | Test for rectangle-rectangle intersection.
Args:
rect1: First bounding rectangle, expressed as tuples
``(xMin, yMin, xMax, yMax)``.
rect2: Second bounding rectangle.
Returns:
A boolean and a rectangle.
If the input rectangles intersect, returns ``True`` and the inte... | sectRect | python | fonttools/fonttools | Lib/fontTools/misc/arrayTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/arrayTools.py | MIT |
def unionRect(rect1, rect2):
"""Determine union of bounding rectangles.
Args:
rect1: First bounding rectangle, expressed as tuples
``(xMin, yMin, xMax, yMax)``.
rect2: Second bounding rectangle.
Returns:
The smallest rectangle in which both input rectangles are fully
... | Determine union of bounding rectangles.
Args:
rect1: First bounding rectangle, expressed as tuples
``(xMin, yMin, xMax, yMax)``.
rect2: Second bounding rectangle.
Returns:
The smallest rectangle in which both input rectangles are fully
enclosed.
| unionRect | python | fonttools/fonttools | Lib/fontTools/misc/arrayTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/arrayTools.py | MIT |
def rectCenter(rect):
"""Determine rectangle center.
Args:
rect: Bounding rectangle, expressed as tuples
``(xMin, yMin, xMax, yMax)``.
Returns:
A 2D tuple representing the point at the center of the rectangle.
"""
(xMin, yMin, xMax, yMax) = rect
return (xMin + xMax)... | Determine rectangle center.
Args:
rect: Bounding rectangle, expressed as tuples
``(xMin, yMin, xMax, yMax)``.
Returns:
A 2D tuple representing the point at the center of the rectangle.
| rectCenter | python | fonttools/fonttools | Lib/fontTools/misc/arrayTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/arrayTools.py | MIT |
def rectArea(rect):
"""Determine rectangle area.
Args:
rect: Bounding rectangle, expressed as tuples
``(xMin, yMin, xMax, yMax)``.
Returns:
The area of the rectangle.
"""
(xMin, yMin, xMax, yMax) = rect
return (yMax - yMin) * (xMax - xMin) | Determine rectangle area.
Args:
rect: Bounding rectangle, expressed as tuples
``(xMin, yMin, xMax, yMax)``.
Returns:
The area of the rectangle.
| rectArea | python | fonttools/fonttools | Lib/fontTools/misc/arrayTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/arrayTools.py | MIT |
def intRect(rect):
"""Round a rectangle to integer values.
Guarantees that the resulting rectangle is NOT smaller than the original.
Args:
rect: Bounding rectangle, expressed as tuples
``(xMin, yMin, xMax, yMax)``.
Returns:
A rounded bounding rectangle.
"""
(xMin, ... | Round a rectangle to integer values.
Guarantees that the resulting rectangle is NOT smaller than the original.
Args:
rect: Bounding rectangle, expressed as tuples
``(xMin, yMin, xMax, yMax)``.
Returns:
A rounded bounding rectangle.
| intRect | python | fonttools/fonttools | Lib/fontTools/misc/arrayTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/arrayTools.py | MIT |
def quantizeRect(rect, factor=1):
"""
>>> bounds = (72.3, -218.4, 1201.3, 919.1)
>>> quantizeRect(bounds)
(72, -219, 1202, 920)
>>> quantizeRect(bounds, factor=10)
(70, -220, 1210, 920)
>>> quantizeRect(bounds, factor=100)
(0, -300, 1300, 1000)
"""
if factor < 1:
raise Va... |
>>> bounds = (72.3, -218.4, 1201.3, 919.1)
>>> quantizeRect(bounds)
(72, -219, 1202, 920)
>>> quantizeRect(bounds, factor=10)
(70, -220, 1210, 920)
>>> quantizeRect(bounds, factor=100)
(0, -300, 1300, 1000)
| quantizeRect | python | fonttools/fonttools | Lib/fontTools/misc/arrayTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/arrayTools.py | MIT |
def pairwise(iterable, reverse=False):
"""Iterate over current and next items in iterable.
Args:
iterable: An iterable
reverse: If true, iterate in reverse order.
Returns:
A iterable yielding two elements per iteration.
Example:
>>> tuple(pairwise([]))
()
... | Iterate over current and next items in iterable.
Args:
iterable: An iterable
reverse: If true, iterate in reverse order.
Returns:
A iterable yielding two elements per iteration.
Example:
>>> tuple(pairwise([]))
()
>>> tuple(pairwise([], reverse=True))
... | pairwise | python | fonttools/fonttools | Lib/fontTools/misc/arrayTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/arrayTools.py | MIT |
def _test():
"""
>>> import math
>>> calcBounds([])
(0, 0, 0, 0)
>>> calcBounds([(0, 40), (0, 100), (50, 50), (80, 10)])
(0, 10, 80, 100)
>>> updateBounds((0, 0, 0, 0), (100, 100))
(0, 0, 100, 100)
>>> pointInRect((50, 50), (0, 0, 100, 100))
True
>>> pointInRect((0, 0), (0, 0... |
>>> import math
>>> calcBounds([])
(0, 0, 0, 0)
>>> calcBounds([(0, 40), (0, 100), (50, 50), (80, 10)])
(0, 10, 80, 100)
>>> updateBounds((0, 0, 0, 0), (100, 100))
(0, 0, 100, 100)
>>> pointInRect((50, 50), (0, 0, 100, 100))
True
>>> pointInRect((0, 0), (0, 0, 100, 100))
Tru... | _test | python | fonttools/fonttools | Lib/fontTools/misc/arrayTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/arrayTools.py | MIT |
def calcCubicArcLength(pt1, pt2, pt3, pt4, tolerance=0.005):
"""Calculates the arc length for a cubic Bezier segment.
Whereas :func:`approximateCubicArcLength` approximates the length, this
function calculates it by "measuring", recursively dividing the curve
until the divided segments are shorter than... | Calculates the arc length for a cubic Bezier segment.
Whereas :func:`approximateCubicArcLength` approximates the length, this
function calculates it by "measuring", recursively dividing the curve
until the divided segments are shorter than ``tolerance``.
Args:
pt1,pt2,pt3,pt4: Control points o... | calcCubicArcLength | python | fonttools/fonttools | Lib/fontTools/misc/bezierTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/bezierTools.py | MIT |
def calcCubicArcLengthC(pt1, pt2, pt3, pt4, tolerance=0.005):
"""Calculates the arc length for a cubic Bezier segment.
Args:
pt1,pt2,pt3,pt4: Control points of the Bezier as complex numbers.
tolerance: Controls the precision of the calcuation.
Returns:
Arc length value.
"""
... | Calculates the arc length for a cubic Bezier segment.
Args:
pt1,pt2,pt3,pt4: Control points of the Bezier as complex numbers.
tolerance: Controls the precision of the calcuation.
Returns:
Arc length value.
| calcCubicArcLengthC | python | fonttools/fonttools | Lib/fontTools/misc/bezierTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/bezierTools.py | MIT |
def calcQuadraticArcLengthC(pt1, pt2, pt3):
"""Calculates the arc length for a quadratic Bezier segment.
Args:
pt1: Start point of the Bezier as a complex number.
pt2: Handle point of the Bezier as a complex number.
pt3: End point of the Bezier as a complex number.
Returns:
... | Calculates the arc length for a quadratic Bezier segment.
Args:
pt1: Start point of the Bezier as a complex number.
pt2: Handle point of the Bezier as a complex number.
pt3: End point of the Bezier as a complex number.
Returns:
Arc length value.
| calcQuadraticArcLengthC | python | fonttools/fonttools | Lib/fontTools/misc/bezierTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/bezierTools.py | MIT |
def calcQuadraticBounds(pt1, pt2, pt3):
"""Calculates the bounding rectangle for a quadratic Bezier segment.
Args:
pt1: Start point of the Bezier as a 2D tuple.
pt2: Handle point of the Bezier as a 2D tuple.
pt3: End point of the Bezier as a 2D tuple.
Returns:
A four-item t... | Calculates the bounding rectangle for a quadratic Bezier segment.
Args:
pt1: Start point of the Bezier as a 2D tuple.
pt2: Handle point of the Bezier as a 2D tuple.
pt3: End point of the Bezier as a 2D tuple.
Returns:
A four-item tuple representing the bounding rectangle ``(xMi... | calcQuadraticBounds | python | fonttools/fonttools | Lib/fontTools/misc/bezierTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/bezierTools.py | MIT |
def approximateCubicArcLength(pt1, pt2, pt3, pt4):
"""Approximates the arc length for a cubic Bezier segment.
Uses Gauss-Lobatto quadrature with n=5 points to approximate arc length.
See :func:`calcCubicArcLength` for a slower but more accurate result.
Args:
pt1,pt2,pt3,pt4: Control points of ... | Approximates the arc length for a cubic Bezier segment.
Uses Gauss-Lobatto quadrature with n=5 points to approximate arc length.
See :func:`calcCubicArcLength` for a slower but more accurate result.
Args:
pt1,pt2,pt3,pt4: Control points of the Bezier as 2D tuples.
Returns:
Arc length ... | approximateCubicArcLength | python | fonttools/fonttools | Lib/fontTools/misc/bezierTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/bezierTools.py | MIT |
def calcCubicBounds(pt1, pt2, pt3, pt4):
"""Calculates the bounding rectangle for a quadratic Bezier segment.
Args:
pt1,pt2,pt3,pt4: Control points of the Bezier as 2D tuples.
Returns:
A four-item tuple representing the bounding rectangle ``(xMin, yMin, xMax, yMax)``.
Example::
... | Calculates the bounding rectangle for a quadratic Bezier segment.
Args:
pt1,pt2,pt3,pt4: Control points of the Bezier as 2D tuples.
Returns:
A four-item tuple representing the bounding rectangle ``(xMin, yMin, xMax, yMax)``.
Example::
>>> calcCubicBounds((0, 0), (25, 100), (75, 1... | calcCubicBounds | python | fonttools/fonttools | Lib/fontTools/misc/bezierTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/bezierTools.py | MIT |
def splitLine(pt1, pt2, where, isHorizontal):
"""Split a line at a given coordinate.
Args:
pt1: Start point of line as 2D tuple.
pt2: End point of line as 2D tuple.
where: Position at which to split the line.
isHorizontal: Direction of the ray splitting the line. If true,
... | Split a line at a given coordinate.
Args:
pt1: Start point of line as 2D tuple.
pt2: End point of line as 2D tuple.
where: Position at which to split the line.
isHorizontal: Direction of the ray splitting the line. If true,
``where`` is interpreted as a Y coordinate; if ... | splitLine | python | fonttools/fonttools | Lib/fontTools/misc/bezierTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/bezierTools.py | MIT |
def splitQuadratic(pt1, pt2, pt3, where, isHorizontal):
"""Split a quadratic Bezier curve at a given coordinate.
Args:
pt1,pt2,pt3: Control points of the Bezier as 2D tuples.
where: Position at which to split the curve.
isHorizontal: Direction of the ray splitting the curve. If true,
... | Split a quadratic Bezier curve at a given coordinate.
Args:
pt1,pt2,pt3: Control points of the Bezier as 2D tuples.
where: Position at which to split the curve.
isHorizontal: Direction of the ray splitting the curve. If true,
``where`` is interpreted as a Y coordinate; if false,... | splitQuadratic | python | fonttools/fonttools | Lib/fontTools/misc/bezierTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/bezierTools.py | MIT |
def splitCubic(pt1, pt2, pt3, pt4, where, isHorizontal):
"""Split a cubic Bezier curve at a given coordinate.
Args:
pt1,pt2,pt3,pt4: Control points of the Bezier as 2D tuples.
where: Position at which to split the curve.
isHorizontal: Direction of the ray splitting the curve. If true,
... | Split a cubic Bezier curve at a given coordinate.
Args:
pt1,pt2,pt3,pt4: Control points of the Bezier as 2D tuples.
where: Position at which to split the curve.
isHorizontal: Direction of the ray splitting the curve. If true,
``where`` is interpreted as a Y coordinate; if false,... | splitCubic | python | fonttools/fonttools | Lib/fontTools/misc/bezierTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/bezierTools.py | MIT |
def splitQuadraticAtT(pt1, pt2, pt3, *ts):
"""Split a quadratic Bezier curve at one or more values of t.
Args:
pt1,pt2,pt3: Control points of the Bezier as 2D tuples.
*ts: Positions at which to split the curve.
Returns:
A list of curve segments (each curve segment being three 2D tu... | Split a quadratic Bezier curve at one or more values of t.
Args:
pt1,pt2,pt3: Control points of the Bezier as 2D tuples.
*ts: Positions at which to split the curve.
Returns:
A list of curve segments (each curve segment being three 2D tuples).
Examples::
>>> printSegments(... | splitQuadraticAtT | python | fonttools/fonttools | Lib/fontTools/misc/bezierTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/bezierTools.py | MIT |
def splitCubicAtT(pt1, pt2, pt3, pt4, *ts):
"""Split a cubic Bezier curve at one or more values of t.
Args:
pt1,pt2,pt3,pt4: Control points of the Bezier as 2D tuples.
*ts: Positions at which to split the curve.
Returns:
A list of curve segments (each curve segment being four 2D tu... | Split a cubic Bezier curve at one or more values of t.
Args:
pt1,pt2,pt3,pt4: Control points of the Bezier as 2D tuples.
*ts: Positions at which to split the curve.
Returns:
A list of curve segments (each curve segment being four 2D tuples).
Examples::
>>> printSegments(s... | splitCubicAtT | python | fonttools/fonttools | Lib/fontTools/misc/bezierTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/bezierTools.py | MIT |
def splitCubicAtTC(pt1, pt2, pt3, pt4, *ts):
"""Split a cubic Bezier curve at one or more values of t.
Args:
pt1,pt2,pt3,pt4: Control points of the Bezier as complex numbers..
*ts: Positions at which to split the curve.
Yields:
Curve segments (each curve segment being four complex ... | Split a cubic Bezier curve at one or more values of t.
Args:
pt1,pt2,pt3,pt4: Control points of the Bezier as complex numbers..
*ts: Positions at which to split the curve.
Yields:
Curve segments (each curve segment being four complex numbers).
| splitCubicAtTC | python | fonttools/fonttools | Lib/fontTools/misc/bezierTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/bezierTools.py | MIT |
def splitCubicIntoTwoAtTC(pt1, pt2, pt3, pt4, t):
"""Split a cubic Bezier curve at t.
Args:
pt1,pt2,pt3,pt4: Control points of the Bezier as complex numbers.
t: Position at which to split the curve.
Returns:
A tuple of two curve segments (each curve segment being four complex numbe... | Split a cubic Bezier curve at t.
Args:
pt1,pt2,pt3,pt4: Control points of the Bezier as complex numbers.
t: Position at which to split the curve.
Returns:
A tuple of two curve segments (each curve segment being four complex numbers).
| splitCubicIntoTwoAtTC | python | fonttools/fonttools | Lib/fontTools/misc/bezierTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/bezierTools.py | MIT |
def quadraticPointAtT(pt1, pt2, pt3, t):
"""Finds the point at time `t` on a quadratic curve.
Args:
pt1, pt2, pt3: Coordinates of the curve as 2D tuples.
t: The time along the curve.
Returns:
A 2D tuple with the coordinates of the point.
"""
x = (1 - t) * (1 - t) * pt1[0] +... | Finds the point at time `t` on a quadratic curve.
Args:
pt1, pt2, pt3: Coordinates of the curve as 2D tuples.
t: The time along the curve.
Returns:
A 2D tuple with the coordinates of the point.
| quadraticPointAtT | python | fonttools/fonttools | Lib/fontTools/misc/bezierTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/bezierTools.py | MIT |
def cubicPointAtT(pt1, pt2, pt3, pt4, t):
"""Finds the point at time `t` on a cubic curve.
Args:
pt1, pt2, pt3, pt4: Coordinates of the curve as 2D tuples.
t: The time along the curve.
Returns:
A 2D tuple with the coordinates of the point.
"""
t2 = t * t
_1_t = 1 - t
... | Finds the point at time `t` on a cubic curve.
Args:
pt1, pt2, pt3, pt4: Coordinates of the curve as 2D tuples.
t: The time along the curve.
Returns:
A 2D tuple with the coordinates of the point.
| cubicPointAtT | python | fonttools/fonttools | Lib/fontTools/misc/bezierTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/bezierTools.py | MIT |
def cubicPointAtTC(pt1, pt2, pt3, pt4, t):
"""Finds the point at time `t` on a cubic curve.
Args:
pt1, pt2, pt3, pt4: Coordinates of the curve as complex numbers.
t: The time along the curve.
Returns:
A complex number with the coordinates of the point.
"""
t2 = t * t
_1... | Finds the point at time `t` on a cubic curve.
Args:
pt1, pt2, pt3, pt4: Coordinates of the curve as complex numbers.
t: The time along the curve.
Returns:
A complex number with the coordinates of the point.
| cubicPointAtTC | python | fonttools/fonttools | Lib/fontTools/misc/bezierTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/bezierTools.py | MIT |
def lineLineIntersections(s1, e1, s2, e2):
"""Finds intersections between two line segments.
Args:
s1, e1: Coordinates of the first line as 2D tuples.
s2, e2: Coordinates of the second line as 2D tuples.
Returns:
A list of ``Intersection`` objects, each object having ``pt``, ``t1``... | Finds intersections between two line segments.
Args:
s1, e1: Coordinates of the first line as 2D tuples.
s2, e2: Coordinates of the second line as 2D tuples.
Returns:
A list of ``Intersection`` objects, each object having ``pt``, ``t1``
and ``t2`` attributes containing the inte... | lineLineIntersections | python | fonttools/fonttools | Lib/fontTools/misc/bezierTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/bezierTools.py | MIT |
Subsets and Splits
Django Code with Docstrings
Filters Python code examples from Django repository that contain Django-related code, helping identify relevant code snippets for understanding Django framework usage patterns.
SQL Console for Shuu12121/python-treesitter-filtered-datasetsV2
Retrieves specific code examples from the Flask repository but doesn't provide meaningful analysis or patterns beyond basic data retrieval.
HTTPX Repo Code and Docstrings
Retrieves specific code examples from the httpx repository, which is useful for understanding how particular libraries are used but doesn't provide broader analytical insights about the dataset.
Requests Repo Docstrings & Code
Retrieves code examples with their docstrings and file paths from the requests repository, providing basic filtering but limited analytical value beyond finding specific code samples.
Quart Repo Docstrings & Code
Retrieves code examples with their docstrings from the Quart repository, providing basic code samples but offering limited analytical value for understanding broader patterns or relationships in the dataset.