Tweaks in the documentation.
git-svn-id: http://svn.robofab.com/branches/ufo3k@553 b5fa9d6c-a76f-4ffd-b3cb-f825fc41095c
This commit is contained in:
parent
e05354fe33
commit
4875fc675f
@ -15,19 +15,16 @@ __all__ = ["AngledMarginPen", "getAngledMargins",
|
|||||||
|
|
||||||
class AngledMarginPen(BasePen):
|
class AngledMarginPen(BasePen):
|
||||||
"""
|
"""
|
||||||
Angled Margin Pen
|
Pen to calculate the margins according to a slanted coordinate system. Slant angle comes from font.info.italicAngle.
|
||||||
|
|
||||||
Pen to calculate the margins as if the margin lines were slanted
|
- this pen works on the on-curve points, and approximates the distance to curves.
|
||||||
according to the font.info.italicAngle.
|
- results will be float.
|
||||||
|
- when used in FontLab, the resulting margins may be slightly different from the values originally set, due to rounding errors.
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
- this pen works on the on-curve points, and approximates the distance to curves.
|
|
||||||
- results will be float.
|
- similar to what RoboFog used to do.
|
||||||
- when used in FontLab, the resulting margins may be slightly
|
- RoboFog had a special attribute for "italicoffset", horizontal shift of all glyphs. This is missing in Robofab.
|
||||||
different from the values originally set, due to rounding errors.
|
|
||||||
- similar to what RoboFog used to do.
|
|
||||||
- RoboFog had a special attribute for "italicoffset", horizontal
|
|
||||||
shift of all glyphs. This is missing in Robofab.
|
|
||||||
"""
|
"""
|
||||||
def __init__(self, glyphSet, width, italicAngle):
|
def __init__(self, glyphSet, width, italicAngle):
|
||||||
BasePen.__init__(self, glyphSet)
|
BasePen.__init__(self, glyphSet)
|
||||||
@ -81,27 +78,27 @@ class AngledMarginPen(BasePen):
|
|||||||
self.currentPt = pt3
|
self.currentPt = pt3
|
||||||
|
|
||||||
def getAngledMargins(glyph, font):
|
def getAngledMargins(glyph, font):
|
||||||
"""Get the angled margins for this glyph."""
|
"""Convenience function, returns the angled margins for this glyph. Adjusted for font.info.italicAngle."""
|
||||||
pen = AngledMarginPen(font, glyph.width, font.info.italicAngle)
|
pen = AngledMarginPen(font, glyph.width, font.info.italicAngle)
|
||||||
glyph.draw(pen)
|
glyph.draw(pen)
|
||||||
return pen.margin
|
return pen.margin
|
||||||
|
|
||||||
def setAngledLeftMargin(glyph, font, value):
|
def setAngledLeftMargin(glyph, font, value):
|
||||||
"""Set the left angled margin to value, adjusted for font.info.italicAngle."""
|
"""Convenience function, sets the left angled margin to value. Adjusted for font.info.italicAngle."""
|
||||||
pen = AngledMarginPen(font, glyph.width, font.info.italicAngle)
|
pen = AngledMarginPen(font, glyph.width, font.info.italicAngle)
|
||||||
g.draw(pen)
|
g.draw(pen)
|
||||||
isLeft, isRight = pen.margin
|
isLeft, isRight = pen.margin
|
||||||
glyph.leftMargin += value-isLeft
|
glyph.leftMargin += value-isLeft
|
||||||
|
|
||||||
def setAngledRightMargin(glyph, font, value):
|
def setAngledRightMargin(glyph, font, value):
|
||||||
"""Set the right angled margin to value, adjusted for font.info.italicAngle."""
|
"""Convenience function, sets the right angled margin to value. Adjusted for font.info.italicAngle."""
|
||||||
pen = AngledMarginPen(font, glyph.width, font.info.italicAngle)
|
pen = AngledMarginPen(font, glyph.width, font.info.italicAngle)
|
||||||
g.draw(pen)
|
g.draw(pen)
|
||||||
isLeft, isRight = pen.margin
|
isLeft, isRight = pen.margin
|
||||||
glyph.rightMargin += value-isRight
|
glyph.rightMargin += value-isRight
|
||||||
|
|
||||||
def centerAngledMargins(glyph, font):
|
def centerAngledMargins(glyph, font):
|
||||||
"""Center the glyph on angled margins."""
|
"""Convenience function, centers the glyph on angled margins."""
|
||||||
pen = AngledMarginPen(font, glyph.width, font.info.italicAngle)
|
pen = AngledMarginPen(font, glyph.width, font.info.italicAngle)
|
||||||
g.draw(pen)
|
g.draw(pen)
|
||||||
isLeft, isRight = pen.margin
|
isLeft, isRight = pen.margin
|
||||||
|
@ -7,16 +7,32 @@ from sets import Set
|
|||||||
class MarginPen(BasePen):
|
class MarginPen(BasePen):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Pen to calculate the margins at a given value.
|
Pen to calculate the margins at a given height or width.
|
||||||
When isHorizontal is True, the margins at <value> are horizontal.
|
|
||||||
When isHorizontal is False, the margins at <value> are vertical.
|
|
||||||
|
|
||||||
When a glyphset or font is given, MarginPen will also calculate for glyphs with components.
|
|
||||||
|
|
||||||
pen.getMargins() returns the minimum and maximum intersections of the glyph.
|
- isHorizontal = True: slice the glyph at y=value.
|
||||||
pen.getContourMargins() returns the minimum and maximum intersections for each contour.
|
- isHorizontal = False: slice the glyph at x=value.
|
||||||
|
|
||||||
|
|
||||||
|
>>> f = CurrentFont()
|
||||||
|
>>> g = CurrentGlyph()
|
||||||
|
>>> pen = MarginPen(f, 200, isHorizontal=True)
|
||||||
|
>>> g.draw(pen)
|
||||||
|
>>> print pen.getMargins()
|
||||||
|
(75.7881, 181.9713)
|
||||||
|
|
||||||
|
>>> pen = MarginPen(f, 200, isHorizontal=False)
|
||||||
|
>>> g.draw(pen)
|
||||||
|
>>> print pen.getMargins()
|
||||||
|
(26.385, 397.4469)
|
||||||
|
>>> print pen.getAll()
|
||||||
|
[75.7881, 181.9713]
|
||||||
|
|
||||||
|
>>> pen = MarginPen(f, 200, isHorizontal=False)
|
||||||
|
>>> g.draw(pen)
|
||||||
|
>>> print pen.getMargins()
|
||||||
|
(26.385, 397.4469)
|
||||||
|
>>> print pen.getAll()
|
||||||
|
[26.385, 171.6137, 268.0, 397.4469]
|
||||||
|
|
||||||
Possible optimisation:
|
Possible optimisation:
|
||||||
Initialise the pen object with a list of points we want to measure,
|
Initialise the pen object with a list of points we want to measure,
|
||||||
then draw the glyph once, but do the splitLine() math for all measure points.
|
then draw the glyph once, but do the splitLine() math for all measure points.
|
||||||
@ -109,7 +125,7 @@ class MarginPen(BasePen):
|
|||||||
glyph.draw(self)
|
glyph.draw(self)
|
||||||
|
|
||||||
def getMargins(self):
|
def getMargins(self):
|
||||||
"""Get the horizontal margins for all contours combined, i.e. the whole glyph."""
|
"""Return the extremes of the slice for all contours combined, i.e. the whole glyph."""
|
||||||
allHits = []
|
allHits = []
|
||||||
for index, pts in self.hits.items():
|
for index, pts in self.hits.items():
|
||||||
allHits.extend(pts)
|
allHits.extend(pts)
|
||||||
@ -118,7 +134,7 @@ class MarginPen(BasePen):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def getContourMargins(self):
|
def getContourMargins(self):
|
||||||
"""Get the horizontal margins for each contour."""
|
"""Return the extremes of the slice for each contour."""
|
||||||
allHits = {}
|
allHits = {}
|
||||||
for index, pts in self.hits.items():
|
for index, pts in self.hits.items():
|
||||||
unique = list(Set(pts))
|
unique = list(Set(pts))
|
||||||
@ -127,7 +143,7 @@ class MarginPen(BasePen):
|
|||||||
return allHits
|
return allHits
|
||||||
|
|
||||||
def getAll(self):
|
def getAll(self):
|
||||||
"""Get all the slices."""
|
"""Return all the slices."""
|
||||||
allHits = []
|
allHits = []
|
||||||
for index, pts in self.hits.items():
|
for index, pts in self.hits.items():
|
||||||
allHits.extend(pts)
|
allHits.extend(pts)
|
||||||
|
@ -92,7 +92,7 @@ class GetMathDataPointPen(AbstractPointPen):
|
|||||||
class CurveSegmentFilterPointPen(AbstractPointPen):
|
class CurveSegmentFilterPointPen(AbstractPointPen):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Point pen that turns curve segments that contain
|
Filtering Point pen that turns curve segments that contain
|
||||||
unnecessary anchor points into line segments.
|
unnecessary anchor points into line segments.
|
||||||
"""
|
"""
|
||||||
# XXX it would be great if this also checked to see if the
|
# XXX it would be great if this also checked to see if the
|
||||||
|
Loading…
x
Reference in New Issue
Block a user