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 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 |
def curveLineIntersections(curve, line):
"""Finds intersections between a curve and a line.
Args:
curve: List of coordinates of the curve segment as 2D tuples.
line: List of coordinates of the line segment as 2D tuples.
Returns:
A list of ``Intersection`` objects, each object havin... | Finds intersections between a curve and a line.
Args:
curve: List of coordinates of the curve segment as 2D tuples.
line: List of coordinates of the line segment as 2D tuples.
Returns:
A list of ``Intersection`` objects, each object having ``pt``, ``t1``
and ``t2`` attributes c... | curveLineIntersections | python | fonttools/fonttools | Lib/fontTools/misc/bezierTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/bezierTools.py | MIT |
def curveCurveIntersections(curve1, curve2):
"""Finds intersections between a curve and a curve.
Args:
curve1: List of coordinates of the first curve segment as 2D tuples.
curve2: List of coordinates of the second curve segment as 2D tuples.
Returns:
A list of ``Intersection`` obje... | Finds intersections between a curve and a curve.
Args:
curve1: List of coordinates of the first curve segment as 2D tuples.
curve2: List of coordinates of the second curve segment as 2D tuples.
Returns:
A list of ``Intersection`` objects, each object having ``pt``, ``t1``
and `... | curveCurveIntersections | python | fonttools/fonttools | Lib/fontTools/misc/bezierTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/bezierTools.py | MIT |
def segmentSegmentIntersections(seg1, seg2):
"""Finds intersections between two segments.
Args:
seg1: List of coordinates of the first segment as 2D tuples.
seg2: List of coordinates of the second segment as 2D tuples.
Returns:
A list of ``Intersection`` objects, each object having... | Finds intersections between two segments.
Args:
seg1: List of coordinates of the first segment as 2D tuples.
seg2: List of coordinates of the second segment as 2D tuples.
Returns:
A list of ``Intersection`` objects, each object having ``pt``, ``t1``
and ``t2`` attributes contai... | segmentSegmentIntersections | python | fonttools/fonttools | Lib/fontTools/misc/bezierTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/bezierTools.py | MIT |
def add(self, set_of_things):
"""
Add a set to the classifier. Any iterable is accepted.
"""
if not set_of_things:
return
self._dirty = True
things, sets, mapping = self._things, self._sets, self._mapping
s = set(set_of_things)
intersection... |
Add a set to the classifier. Any iterable is accepted.
| add | python | fonttools/fonttools | Lib/fontTools/misc/classifyTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/classifyTools.py | MIT |
def classify(list_of_sets, sort=True):
"""
Takes a iterable of iterables (list of sets from here on; but any
iterable works.), and returns the smallest list of sets such that
each set, is either a subset, or is disjoint from, each of the input
sets.
In other words, this function classifies all ... |
Takes a iterable of iterables (list of sets from here on; but any
iterable works.), and returns the smallest list of sets such that
each set, is either a subset, or is disjoint from, each of the input
sets.
In other words, this function classifies all the things present in
any of the input set... | classify | python | fonttools/fonttools | Lib/fontTools/misc/classifyTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/classifyTools.py | MIT |
def register_option(
cls,
name: str,
help: str,
default: Any,
parse: Callable[[str], Any],
validate: Optional[Callable[[Any], bool]] = None,
) -> Option:
"""Register an available option in this config system."""
return cls.options.register(
... | Register an available option in this config system. | register_option | python | fonttools/fonttools | Lib/fontTools/misc/configTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/configTools.py | MIT |
def set(
self,
option_or_name: Union[Option, str],
value: Any,
parse_values: bool = False,
skip_unknown: bool = False,
):
"""Set the value of an option.
Args:
* `option_or_name`: an `Option` object or its name (`str`).
* `value`: the v... | Set the value of an option.
Args:
* `option_or_name`: an `Option` object or its name (`str`).
* `value`: the value to be assigned to given option.
* `parse_values`: parse the configuration value from a string into
its proper type, as per its `Option` object. ... | set | python | fonttools/fonttools | Lib/fontTools/misc/configTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/configTools.py | MIT |
def get(
self, option_or_name: Union[Option, str], default: Any = _USE_GLOBAL_DEFAULT
) -> Any:
"""
Get the value of an option. The value which is returned is the first
provided among:
1. a user-provided value in the options's ``self._values`` dict
2. a caller-provid... |
Get the value of an option. The value which is returned is the first
provided among:
1. a user-provided value in the options's ``self._values`` dict
2. a caller-provided default value to this method call
3. the global default for the option provided in ``fontTools.config``
... | get | python | fonttools/fonttools | Lib/fontTools/misc/configTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/configTools.py | MIT |
def decrypt(cipherstring, R):
r"""
Decrypts a string using the Type 1 encryption algorithm.
Args:
cipherstring: String of ciphertext.
R: Initial key.
Returns:
decryptedStr: Plaintext string.
R: Output key for subsequent decryptions.
Examples::
... |
Decrypts a string using the Type 1 encryption algorithm.
Args:
cipherstring: String of ciphertext.
R: Initial key.
Returns:
decryptedStr: Plaintext string.
R: Output key for subsequent decryptions.
Examples::
>>> testStr = b"\0\0asdadads a... | decrypt | python | fonttools/fonttools | Lib/fontTools/misc/eexec.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/eexec.py | MIT |
def encrypt(plainstring, R):
r"""
Encrypts a string using the Type 1 encryption algorithm.
Note that the algorithm as described in the Type 1 specification requires the
plaintext to be prefixed with a number of random bytes. (For ``eexec`` the
number of random bytes is set to 4.) This routine does ... |
Encrypts a string using the Type 1 encryption algorithm.
Note that the algorithm as described in the Type 1 specification requires the
plaintext to be prefixed with a number of random bytes. (For ``eexec`` the
number of random bytes is set to 4.) This routine does *not* add the random
prefix to it... | encrypt | python | fonttools/fonttools | Lib/fontTools/misc/eexec.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/eexec.py | MIT |
def getEncoding(platformID, platEncID, langID, default=None):
"""Returns the Python encoding name for OpenType platformID/encodingID/langID
triplet. If encoding for these values is not known, by default None is
returned. That can be overriden by passing a value to the default argument.
"""
encodin... | Returns the Python encoding name for OpenType platformID/encodingID/langID
triplet. If encoding for these values is not known, by default None is
returned. That can be overriden by passing a value to the default argument.
| getEncoding | python | fonttools/fonttools | Lib/fontTools/misc/encodingTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/encodingTools.py | MIT |
def SubElement(parent, tag, attrib=_Attrib(), **extra):
"""Must override SubElement as well otherwise _elementtree.SubElement
fails if 'parent' is a subclass of Element object.
"""
element = parent.__class__(tag, attrib, **extra)
parent.append(element)
return element | Must override SubElement as well otherwise _elementtree.SubElement
fails if 'parent' is a subclass of Element object.
| SubElement | python | fonttools/fonttools | Lib/fontTools/misc/etree.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/etree.py | MIT |
def iterwalk(element_or_tree, events=("end",), tag=None):
"""A tree walker that generates events from an existing tree as
if it was parsing XML data with iterparse().
Drop-in replacement for lxml.etree.iterwalk.
"""
if iselement(element_or_tree):
element = element_or_... | A tree walker that generates events from an existing tree as
if it was parsing XML data with iterparse().
Drop-in replacement for lxml.etree.iterwalk.
| iterwalk | python | fonttools/fonttools | Lib/fontTools/misc/etree.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/etree.py | MIT |
def tostring(
element,
encoding=None,
xml_declaration=None,
method=None,
doctype=None,
pretty_print=False,
):
"""Custom 'tostring' function that uses our ElementTree subclass, with
pretty_print support.
"""
stream = io.StringIO() if enc... | Custom 'tostring' function that uses our ElementTree subclass, with
pretty_print support.
| tostring | python | fonttools/fonttools | Lib/fontTools/misc/etree.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/etree.py | MIT |
def _tounicode(s):
"""Test if a string is valid user input and decode it to unicode string
using ASCII encoding if it's a bytes string.
Reject all bytes/unicode input that contains non-XML characters.
Reject all bytes input that contains non-ASCII characters.
"""
try:
... | Test if a string is valid user input and decode it to unicode string
using ASCII encoding if it's a bytes string.
Reject all bytes/unicode input that contains non-XML characters.
Reject all bytes input that contains non-ASCII characters.
| _tounicode | python | fonttools/fonttools | Lib/fontTools/misc/etree.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/etree.py | MIT |
def userNameToFileName(userName, existing=[], prefix="", suffix=""):
"""Converts from a user name to a file name.
Takes care to avoid illegal characters, reserved file names, ambiguity between
upper- and lower-case characters, and clashes with existing files.
Args:
userName (str): The inpu... | Converts from a user name to a file name.
Takes care to avoid illegal characters, reserved file names, ambiguity between
upper- and lower-case characters, and clashes with existing files.
Args:
userName (str): The input file name.
existing: A case-insensitive list of all existing f... | userNameToFileName | python | fonttools/fonttools | Lib/fontTools/misc/filenames.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/filenames.py | MIT |
def handleClash1(userName, existing=[], prefix="", suffix=""):
"""
existing should be a case-insensitive list
of all existing file names.
>>> prefix = ("0" * 5) + "."
>>> suffix = "." + ("0" * 10)
>>> existing = ["a" * 5]
>>> e = list(existing)
>>> handleClash1(userName="A" * 5, existi... |
existing should be a case-insensitive list
of all existing file names.
>>> prefix = ("0" * 5) + "."
>>> suffix = "." + ("0" * 10)
>>> existing = ["a" * 5]
>>> e = list(existing)
>>> handleClash1(userName="A" * 5, existing=e,
... prefix=prefix, suffix=suffix) == (
... '00000.AAAA... | handleClash1 | python | fonttools/fonttools | Lib/fontTools/misc/filenames.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/filenames.py | MIT |
def handleClash2(existing=[], prefix="", suffix=""):
"""
existing should be a case-insensitive list
of all existing file names.
>>> prefix = ("0" * 5) + "."
>>> suffix = "." + ("0" * 10)
>>> existing = [prefix + str(i) + suffix for i in range(100)]
>>> e = list(existing)
>>> handleClas... |
existing should be a case-insensitive list
of all existing file names.
>>> prefix = ("0" * 5) + "."
>>> suffix = "." + ("0" * 10)
>>> existing = [prefix + str(i) + suffix for i in range(100)]
>>> e = list(existing)
>>> handleClash2(existing=e, prefix=prefix, suffix=suffix) == (
... '... | handleClash2 | python | fonttools/fonttools | Lib/fontTools/misc/filenames.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/filenames.py | MIT |
def floatToFixedToFloat(value, precisionBits):
"""Converts a float to a fixed-point number and back again.
By converting the float to fixed, rounding it, and converting it back
to float again, this returns a floating point values which is exactly
representable in fixed-point format.
Note: this **i... | Converts a float to a fixed-point number and back again.
By converting the float to fixed, rounding it, and converting it back
to float again, this returns a floating point values which is exactly
representable in fixed-point format.
Note: this **is** equivalent to ``fixedToFloat(floatToFixed(value))`... | floatToFixedToFloat | python | fonttools/fonttools | Lib/fontTools/misc/fixedTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/fixedTools.py | MIT |
def fixedToStr(value, precisionBits):
"""Converts a fixed-point number to a string representing a decimal float.
This chooses the float that has the shortest decimal representation (the least
number of fractional decimal digits).
For example, to convert a fixed-point number in a 2.14 format, use
`... | Converts a fixed-point number to a string representing a decimal float.
This chooses the float that has the shortest decimal representation (the least
number of fractional decimal digits).
For example, to convert a fixed-point number in a 2.14 format, use
``precisionBits=14``::
>>> fixedT... | fixedToStr | python | fonttools/fonttools | Lib/fontTools/misc/fixedTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/fixedTools.py | MIT |
def strToFixed(string, precisionBits):
"""Converts a string representing a decimal float to a fixed-point number.
Args:
string (str): A string representing a decimal float.
precisionBits (int): Number of precision bits, *up to a maximum of 16*.
Returns:
int: Fixed-point... | Converts a string representing a decimal float to a fixed-point number.
Args:
string (str): A string representing a decimal float.
precisionBits (int): Number of precision bits, *up to a maximum of 16*.
Returns:
int: Fixed-point representation.
Examples::
... | strToFixed | python | fonttools/fonttools | Lib/fontTools/misc/fixedTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/fixedTools.py | MIT |
def strToFixedToFloat(string, precisionBits):
"""Convert a string to a decimal float with fixed-point rounding.
This first converts string to a float, then turns it into a fixed-point
number with ``precisionBits`` fractional binary digits, then back to a
float again.
This is simply a shorthand for... | Convert a string to a decimal float with fixed-point rounding.
This first converts string to a float, then turns it into a fixed-point
number with ``precisionBits`` fractional binary digits, then back to a
float again.
This is simply a shorthand for fixedToFloat(floatToFixed(float(s))).
Args:
... | strToFixedToFloat | python | fonttools/fonttools | Lib/fontTools/misc/fixedTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/fixedTools.py | MIT |
def floatToFixedToStr(value, precisionBits):
"""Convert float to string with fixed-point rounding.
This uses the shortest decimal representation (ie. the least
number of fractional decimal digits) to represent the equivalent
fixed-point number with ``precisionBits`` fractional binary digits.
It use... | Convert float to string with fixed-point rounding.
This uses the shortest decimal representation (ie. the least
number of fractional decimal digits) to represent the equivalent
fixed-point number with ``precisionBits`` fractional binary digits.
It uses nearestMultipleShortestRepr under the hood.
>... | floatToFixedToStr | python | fonttools/fonttools | Lib/fontTools/misc/fixedTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/fixedTools.py | MIT |
def ensureVersionIsLong(value):
"""Ensure a table version is an unsigned long.
OpenType table version numbers are expressed as a single unsigned long
comprising of an unsigned short major version and unsigned short minor
version. This function detects if the value to be used as a version number
loo... | Ensure a table version is an unsigned long.
OpenType table version numbers are expressed as a single unsigned long
comprising of an unsigned short major version and unsigned short minor
version. This function detects if the value to be used as a version number
looks too small (i.e. is less than ``0x100... | ensureVersionIsLong | python | fonttools/fonttools | Lib/fontTools/misc/fixedTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/fixedTools.py | MIT |
def versionToFixed(value):
"""Ensure a table version number is fixed-point.
Args:
value (str): a candidate table version number.
Returns:
int: A table version number, possibly corrected to fixed-point.
"""
value = int(value, 0) if value.startswith("0") else float(value)
... | Ensure a table version number is fixed-point.
Args:
value (str): a candidate table version number.
Returns:
int: A table version number, possibly corrected to fixed-point.
| versionToFixed | python | fonttools/fonttools | Lib/fontTools/misc/fixedTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/fixedTools.py | MIT |
def configLogger(**kwargs):
"""A more sophisticated logging system configuation manager.
This is more or less the same as :py:func:`logging.basicConfig`,
with some additional options and defaults.
The default behaviour is to create a ``StreamHandler`` which writes to
sys.stderr, set a formatter us... | A more sophisticated logging system configuation manager.
This is more or less the same as :py:func:`logging.basicConfig`,
with some additional options and defaults.
The default behaviour is to create a ``StreamHandler`` which writes to
sys.stderr, set a formatter using the ``DEFAULT_FORMATS`` strings... | configLogger | python | fonttools/fonttools | Lib/fontTools/misc/loggingTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/loggingTools.py | MIT |
def _resetExistingLoggers(parent="root"):
"""Reset the logger named 'parent' and all its children to their initial
state, if they already exist in the current configuration.
"""
root = logging.root
# get sorted list of all existing loggers
existing = sorted(root.manager.loggerDict.keys())
if... | Reset the logger named 'parent' and all its children to their initial
state, if they already exist in the current configuration.
| _resetExistingLoggers | python | fonttools/fonttools | Lib/fontTools/misc/loggingTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/loggingTools.py | MIT |
def reset(self, start=None):
"""Reset timer to 'start_time' or the current time."""
if start is None:
self.start = self._time()
else:
self.start = start
self.last = self.start
self.elapsed = 0.0 | Reset timer to 'start_time' or the current time. | reset | python | fonttools/fonttools | Lib/fontTools/misc/loggingTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/loggingTools.py | MIT |
def split(self):
"""Split and return the lap time (in seconds) in between splits."""
current = self._time()
self.elapsed = current - self.last
self.last = current
return self.elapsed | Split and return the lap time (in seconds) in between splits. | split | python | fonttools/fonttools | Lib/fontTools/misc/loggingTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/loggingTools.py | MIT |
def formatTime(self, msg, time):
"""Format 'time' value in 'msg' and return formatted string.
If 'msg' contains a '%(time)' format string, try to use that.
Otherwise, use the predefined 'default_format'.
If 'msg' is empty or None, fall back to 'default_msg'.
"""
if not ms... | Format 'time' value in 'msg' and return formatted string.
If 'msg' contains a '%(time)' format string, try to use that.
Otherwise, use the predefined 'default_format'.
If 'msg' is empty or None, fall back to 'default_msg'.
| formatTime | python | fonttools/fonttools | Lib/fontTools/misc/loggingTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/loggingTools.py | MIT |
def __exit__(self, exc_type, exc_value, traceback):
"""End the current lap. If timer has a logger, log the time elapsed,
using the format string in self.msg (or the default one).
"""
time = self.split()
if self.logger is None or exc_type:
# if there's no logger attach... | End the current lap. If timer has a logger, log the time elapsed,
using the format string in self.msg (or the default one).
| __exit__ | python | fonttools/fonttools | Lib/fontTools/misc/loggingTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/loggingTools.py | MIT |
def __call__(self, func_or_msg=None, **kwargs):
"""If the first argument is a function, return a decorator which runs
the wrapped function inside Timer's context manager.
Otherwise, treat the first argument as a 'msg' string and return an updated
Timer instance, referencing the same logg... | If the first argument is a function, return a decorator which runs
the wrapped function inside Timer's context manager.
Otherwise, treat the first argument as a 'msg' string and return an updated
Timer instance, referencing the same logger.
A 'level' keyword can also be passed to overrid... | __call__ | python | fonttools/fonttools | Lib/fontTools/misc/loggingTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/loggingTools.py | MIT |
def deprecateFunction(msg, category=UserWarning):
"""Decorator to raise a warning when a deprecated function is called."""
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
warnings.warn(
"%r is deprecated; %s" % (func.__name__, msg),
ca... | Decorator to raise a warning when a deprecated function is called. | deprecateFunction | python | fonttools/fonttools | Lib/fontTools/misc/loggingTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/loggingTools.py | MIT |
def getMacCreatorAndType(path):
"""Returns file creator and file type codes for a path.
Args:
path (str): A file path.
Returns:
A tuple of two :py:class:`fontTools.textTools.Tag` objects, the first
representing the file creator and the second representing the
... | Returns file creator and file type codes for a path.
Args:
path (str): A file path.
Returns:
A tuple of two :py:class:`fontTools.textTools.Tag` objects, the first
representing the file creator and the second representing the
file type.
| getMacCreatorAndType | python | fonttools/fonttools | Lib/fontTools/misc/macCreatorType.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/macCreatorType.py | MIT |
def setMacCreatorAndType(path, fileCreator, fileType):
"""Set file creator and file type codes for a path.
Note that if the ``xattr`` module is not installed, no action is
taken but no error is raised.
Args:
path (str): A file path.
fileCreator: A four-character file creator ta... | Set file creator and file type codes for a path.
Note that if the ``xattr`` module is not installed, no action is
taken but no error is raised.
Args:
path (str): A file path.
fileCreator: A four-character file creator tag.
fileType: A four-character file type tag.
| setMacCreatorAndType | python | fonttools/fonttools | Lib/fontTools/misc/macCreatorType.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/macCreatorType.py | MIT |
def __init__(self, fileOrPath):
"""Open a file
Args:
fileOrPath: Either an object supporting a ``read`` method, an
``os.PathLike`` object, or a string.
"""
self._resources = OrderedDict()
if hasattr(fileOrPath, "read"):
self.fi... | Open a file
Args:
fileOrPath: Either an object supporting a ``read`` method, an
``os.PathLike`` object, or a string.
| __init__ | python | fonttools/fonttools | Lib/fontTools/misc/macRes.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/macRes.py | MIT |
def countResources(self, resType):
"""Return the number of resources of a given type."""
try:
return len(self[resType])
except KeyError:
return 0 | Return the number of resources of a given type. | countResources | python | fonttools/fonttools | Lib/fontTools/misc/macRes.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/macRes.py | MIT |
def getIndices(self, resType):
"""Returns a list of indices of resources of a given type."""
numRes = self.countResources(resType)
if numRes:
return list(range(1, numRes + 1))
else:
return [] | Returns a list of indices of resources of a given type. | getIndices | python | fonttools/fonttools | Lib/fontTools/misc/macRes.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/macRes.py | MIT |
def getIndResource(self, resType, index):
"""Return resource of given type located at an index ranging from 1
to the number of resources for that type, or None if not found.
"""
if index < 1:
return None
try:
res = self[resType][index - 1]
except (... | Return resource of given type located at an index ranging from 1
to the number of resources for that type, or None if not found.
| getIndResource | python | fonttools/fonttools | Lib/fontTools/misc/macRes.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/macRes.py | MIT |
def getNamedResource(self, resType, name):
"""Return the named resource of given type, else return None."""
name = tostr(name, encoding="mac-roman")
for res in self.get(resType, []):
if res.name == name:
return res
return None | Return the named resource of given type, else return None. | getNamedResource | python | fonttools/fonttools | Lib/fontTools/misc/macRes.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/macRes.py | MIT |
def op_rrcurveto(self, index):
"""{dxa dya dxb dyb dxc dyc}+ rrcurveto"""
args = self.popall()
for i in range(0, len(args), 6):
(
dxa,
dya,
dxb,
dyb,
dxc,
dyc,
) = args[i : i +... | {dxa dya dxb dyb dxc dyc}+ rrcurveto | op_rrcurveto | python | fonttools/fonttools | Lib/fontTools/misc/psCharStrings.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/psCharStrings.py | MIT |
def op_rcurveline(self, index):
"""{dxa dya dxb dyb dxc dyc}+ dxd dyd rcurveline"""
args = self.popall()
for i in range(0, len(args) - 2, 6):
dxb, dyb, dxc, dyc, dxd, dyd = args[i : i + 6]
self.rCurveTo((dxb, dyb), (dxc, dyc), (dxd, dyd))
self.rLineTo(args[-2:]) | {dxa dya dxb dyb dxc dyc}+ dxd dyd rcurveline | op_rcurveline | python | fonttools/fonttools | Lib/fontTools/misc/psCharStrings.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/psCharStrings.py | MIT |
def op_rlinecurve(self, index):
"""{dxa dya}+ dxb dyb dxc dyc dxd dyd rlinecurve"""
args = self.popall()
lineArgs = args[:-6]
for i in range(0, len(lineArgs), 2):
self.rLineTo(lineArgs[i : i + 2])
dxb, dyb, dxc, dyc, dxd, dyd = args[-6:]
self.rCurveTo((dxb, dy... | {dxa dya}+ dxb dyb dxc dyc dxd dyd rlinecurve | op_rlinecurve | python | fonttools/fonttools | Lib/fontTools/misc/psCharStrings.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/psCharStrings.py | MIT |
def op_vhcurveto(self, index):
"""dy1 dx2 dy2 dx3 {dxa dxb dyb dyc dyd dxe dye dxf}* dyf? vhcurveto (30)
{dya dxb dyb dxc dxd dxe dye dyf}+ dxf? vhcurveto
"""
args = self.popall()
while args:
args = self.vcurveto(args)
if args:
args = self.... | dy1 dx2 dy2 dx3 {dxa dxb dyb dyc dyd dxe dye dxf}* dyf? vhcurveto (30)
{dya dxb dyb dxc dxd dxe dye dyf}+ dxf? vhcurveto
| op_vhcurveto | python | fonttools/fonttools | Lib/fontTools/misc/psCharStrings.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/psCharStrings.py | MIT |
def op_hvcurveto(self, index):
"""dx1 dx2 dy2 dy3 {dya dxb dyb dxc dxd dxe dye dyf}* dxf?
{dxa dxb dyb dyc dyd dxe dye dxf}+ dyf?
"""
args = self.popall()
while args:
args = self.hcurveto(args)
if args:
args = self.vcurveto(args) | dx1 dx2 dy2 dy3 {dya dxb dyb dxc dxd dxe dye dyf}* dxf?
{dxa dxb dyb dyc dyd dxe dye dxf}+ dyf?
| op_hvcurveto | python | fonttools/fonttools | Lib/fontTools/misc/psCharStrings.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/psCharStrings.py | MIT |
def op_seac(self, index):
"asb adx ady bchar achar seac"
from fontTools.encodings.StandardEncoding import StandardEncoding
asb, adx, ady, bchar, achar = self.popall()
baseGlyph = StandardEncoding[bchar]
self.pen.addComponent(baseGlyph, (1, 0, 0, 1, 0, 0))
accentGlyph = S... | asb adx ady bchar achar seac | op_seac | python | fonttools/fonttools | Lib/fontTools/misc/psCharStrings.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/psCharStrings.py | MIT |
def arg_blendList(self, name):
"""
There may be non-blend args at the top of the stack. We first calculate
where the blend args start in the stack. These are the last
numMasters*numBlends) +1 args.
The blend args starts with numMasters relative coordinate values, the BlueValues ... |
There may be non-blend args at the top of the stack. We first calculate
where the blend args start in the stack. These are the last
numMasters*numBlends) +1 args.
The blend args starts with numMasters relative coordinate values, the BlueValues in the list from the default master font. ... | arg_blendList | python | fonttools/fonttools | Lib/fontTools/misc/psCharStrings.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/psCharStrings.py | MIT |
def round2(number, ndigits=None):
"""
Implementation of Python 2 built-in round() function.
Rounds a number to a given precision in decimal digits (default
0 digits). The result is a floating point number. Values are rounded
to the closest multiple of 10 to the power minus ndigits; if two
multip... |
Implementation of Python 2 built-in round() function.
Rounds a number to a given precision in decimal digits (default
0 digits). The result is a floating point number. Values are rounded
to the closest multiple of 10 to the power minus ndigits; if two
multiples are equally close, rounding is done a... | round2 | python | fonttools/fonttools | Lib/fontTools/misc/py23.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/py23.py | MIT |
def otRound(value):
"""Round float value to nearest integer towards ``+Infinity``.
The OpenType spec (in the section on `"normalization" of OpenType Font Variations <https://docs.microsoft.com/en-us/typography/opentype/spec/otvaroverview#coordinate-scales-and-normalization>`_)
defines the required method f... | Round float value to nearest integer towards ``+Infinity``.
The OpenType spec (in the section on `"normalization" of OpenType Font Variations <https://docs.microsoft.com/en-us/typography/opentype/spec/otvaroverview#coordinate-scales-and-normalization>`_)
defines the required method for converting floating poin... | otRound | python | fonttools/fonttools | Lib/fontTools/misc/roundTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/roundTools.py | MIT |
def nearestMultipleShortestRepr(value: float, factor: float) -> str:
"""Round to nearest multiple of factor and return shortest decimal representation.
This chooses the float that is closer to a multiple of the given factor while
having the shortest decimal representation (the least number of fractional de... | Round to nearest multiple of factor and return shortest decimal representation.
This chooses the float that is closer to a multiple of the given factor while
having the shortest decimal representation (the least number of fractional decimal
digits).
For example, given the following:
>>> nearestMu... | nearestMultipleShortestRepr | python | fonttools/fonttools | Lib/fontTools/misc/roundTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/roundTools.py | MIT |
def parseXML(xmlSnippet):
"""Parses a snippet of XML.
Input can be either a single string (unicode or UTF-8 bytes), or a
a sequence of strings.
The result is in the same format that would be returned by
XMLReader, but the parser imposes no constraints on the root
element so it can be called on... | Parses a snippet of XML.
Input can be either a single string (unicode or UTF-8 bytes), or a
a sequence of strings.
The result is in the same format that would be returned by
XMLReader, but the parser imposes no constraints on the root
element so it can be called on small snippets of TTX files.
... | parseXML | python | fonttools/fonttools | Lib/fontTools/misc/testTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/testTools.py | MIT |
def getXML(func, ttFont=None):
"""Call the passed toXML function and return the written content as a
list of lines (unicode strings).
Result is stripped of XML declaration and OS-specific newline characters.
"""
writer = makeXMLWriter()
func(writer, ttFont)
xml = writer.file.getvalue().decod... | Call the passed toXML function and return the written content as a
list of lines (unicode strings).
Result is stripped of XML declaration and OS-specific newline characters.
| getXML | python | fonttools/fonttools | Lib/fontTools/misc/testTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/testTools.py | MIT |
def stripVariableItemsFromTTX(
string: str,
ttLibVersion: bool = True,
checkSumAdjustment: bool = True,
modified: bool = True,
created: bool = True,
sfntVersion: bool = False, # opt-in only
) -> str:
"""Strip stuff like ttLibVersion, checksums, timestamps, etc. from TTX dumps."""
# ttli... | Strip stuff like ttLibVersion, checksums, timestamps, etc. from TTX dumps. | stripVariableItemsFromTTX | python | fonttools/fonttools | Lib/fontTools/misc/testTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/testTools.py | MIT |
def deHexStr(hexdata):
"""Convert a hex string to binary data."""
hexdata = strjoin(hexdata.split())
if len(hexdata) % 2:
hexdata = hexdata + "0"
data = []
for i in range(0, len(hexdata), 2):
data.append(bytechr(int(hexdata[i : i + 2], 16)))
return bytesjoin(data) | Convert a hex string to binary data. | deHexStr | python | fonttools/fonttools | Lib/fontTools/misc/textTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/textTools.py | MIT |
def hexStr(data):
"""Convert binary data to a hex string."""
h = string.hexdigits
r = ""
for c in data:
i = byteord(c)
r = r + h[(i >> 4) & 0xF] + h[i & 0xF]
return r | Convert binary data to a hex string. | hexStr | python | fonttools/fonttools | Lib/fontTools/misc/textTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/textTools.py | MIT |
def caselessSort(alist):
"""Return a sorted copy of a list. If there are only strings
in the list, it will not consider case.
"""
try:
return sorted(alist, key=lambda a: (a.lower(), a))
except TypeError:
return sorted(alist) | Return a sorted copy of a list. If there are only strings
in the list, it will not consider case.
| caselessSort | python | fonttools/fonttools | Lib/fontTools/misc/textTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/textTools.py | MIT |
def pad(data, size):
r"""Pad byte string 'data' with null bytes until its length is a
multiple of 'size'.
>>> len(pad(b'abcd', 4))
4
>>> len(pad(b'abcde', 2))
6
>>> len(pad(b'abcde', 4))
8
>>> pad(b'abcdef', 4) == b'abcdef\x00\x00'
True
"""
data = tobytes(data)
if si... | Pad byte string 'data' with null bytes until its length is a
multiple of 'size'.
>>> len(pad(b'abcd', 4))
4
>>> len(pad(b'abcde', 2))
6
>>> len(pad(b'abcde', 4))
8
>>> pad(b'abcdef', 4) == b'abcdef\x00\x00'
True
| pad | python | fonttools/fonttools | Lib/fontTools/misc/textTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/textTools.py | MIT |
def asctime(t=None):
"""
Convert a tuple or struct_time representing a time as returned by gmtime()
or localtime() to a 24-character string of the following form:
>>> asctime(time.gmtime(0))
'Thu Jan 1 00:00:00 1970'
If t is not provided, the current time as returned by localtime() is used.
... |
Convert a tuple or struct_time representing a time as returned by gmtime()
or localtime() to a 24-character string of the following form:
>>> asctime(time.gmtime(0))
'Thu Jan 1 00:00:00 1970'
If t is not provided, the current time as returned by localtime() is used.
Locale information is not... | asctime | python | fonttools/fonttools | Lib/fontTools/misc/timeTools.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/timeTools.py | MIT |
def transformPoint(self, p):
"""Transform a point.
:Example:
>>> t = Transform()
>>> t = t.scale(2.5, 5.5)
>>> t.transformPoint((100, 100))
(250.0, 550.0)
"""
(x, y) = p
xx, xy, yx, yy, dx, dy = self
return... | Transform a point.
:Example:
>>> t = Transform()
>>> t = t.scale(2.5, 5.5)
>>> t.transformPoint((100, 100))
(250.0, 550.0)
| transformPoint | python | fonttools/fonttools | Lib/fontTools/misc/transform.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/transform.py | MIT |
def transformPoints(self, points):
"""Transform a list of points.
:Example:
>>> t = Scale(2, 3)
>>> t.transformPoints([(0, 0), (0, 100), (100, 100), (100, 0)])
[(0, 0), (0, 300), (200, 300), (200, 0)]
>>>
"""
xx, xy, yx, y... | Transform a list of points.
:Example:
>>> t = Scale(2, 3)
>>> t.transformPoints([(0, 0), (0, 100), (100, 100), (100, 0)])
[(0, 0), (0, 300), (200, 300), (200, 0)]
>>>
| transformPoints | python | fonttools/fonttools | Lib/fontTools/misc/transform.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/transform.py | MIT |
def transformVector(self, v):
"""Transform an (dx, dy) vector, treating translation as zero.
:Example:
>>> t = Transform(2, 0, 0, 2, 10, 20)
>>> t.transformVector((3, -4))
(6, -8)
>>>
"""
(dx, dy) = v
xx, xy, yx, y... | Transform an (dx, dy) vector, treating translation as zero.
:Example:
>>> t = Transform(2, 0, 0, 2, 10, 20)
>>> t.transformVector((3, -4))
(6, -8)
>>>
| transformVector | python | fonttools/fonttools | Lib/fontTools/misc/transform.py | https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/transform.py | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.