RGlyph
class RGlyph()
A glyph object. This object will almost always be created by retrieving it from a font object.
convertToCubic(round=1)
Convert all curves to cubic curves.
Optionally a round
value can be provided.
convertToQuadratic(round=1)
Convert all curves to quadratic curves.
Optionally a round
value can be provided.
copyToLayer(layerName, clear=True)
Copies the glyph to the ‘layerName’, optional clear will clear the destination glyph.
getPointPen()
Return a type-pointpen
object for adding outline data
to the glyph.
>>> pointPen = glyph.getPointPen()
getRayLeftMargin(position, italicAngle=None)
Get the left margin at a given position
.
Optionally an italicAngle
can be provided.
getRayRightMargin(position, italicAngle=None)
Get the right margin at a given position
.
Optionally an italicAngle
can be provided.
isEmpty()
Return a bool indicting if the glyph is empty. An empty glyph does not contain any contours, segments, anchors, images or guidelines.
removeOverlap(round=1)
Perform a remove overlap in the glyph.
Optionally a round
value can be provided.
removeSelection(removePoints=True, removeComponents=True, removeAnchors=True, removeImages=True)
Remove the selection from the glyph.
Optionally parts can be toggled on or off: removePoints
, removeComponents
, removeAnchors
, removeImages
setRayLeftMargin(position, value, italicAngle=None)
Set the left margin at a given position
.
Optionally an italicAngle
can be provided.
setRayRightMargin(position, value, italicAngle=None)
Set the right margin at a given position
.
Optionally an italicAngle
can be provided.
addObserver(observer, methodName, notification)
Add an observer object. that will receive notification for the given methodName.
getRepresentation(name, **kwargs)
Get a representation by name.
Optionally arguments could be provided if the representation factory requires arguments.
undo(undoTitle='')
Capture the current state of the object and create a undo item in a with
statement.
Optionally an undoTitle
can be provided.
anchors
An type-immutable-list
of all anchors in the glyph.
>>> anchors = glyph.anchors
The list will contain BaseAnchor
objects.
area
The area of the glyph as a integer/float
or,
in the case of empty glyphs None
.
>>> glyph.area
583
bottomMargin
The glyph’s bottom margin.
>>> glyph.bottomMargin
35
>>> glyph.bottomMargin = 45
The value will be a integer/float
or None
if the glyph has no outlines.
bounds
The bounds of the glyph in the form
(x minimum, y minimum, x maximum, y maximum)
or,
in the case of empty glyphs None
.
>>> glyph.bounds
(10, 30, 765, 643)
components
An type-immutable-list
of all components in the glyph.
>>> components = glyph.components
The list will contain BaseComponent
objects.
contours
An type-immutable-list
of all contours in the glyph.
>>> contours = glyph.contours
The list will contain BaseContour
objects.
guidelines
An type-immutable-list
of all guidelines in the glyph.
>>> guidelines = glyph.guidelines
The list will contain BaseGuideline
objects.
layers
Immutable tuple of the glyph’s layers.
>>> glyphLayers = glyph.layers
This will return a tuple of all type-glyph-layer
in the glyph.
leftMargin
The glyph’s left margin.
>>> glyph.leftMargin
35
>>> glyph.leftMargin = 45
The value will be a integer/float
or None
if the glyph has no outlines.
markColor
The glyph’s mark color.
>>> glyph.markColor
(1, 0, 0, 0.5)
>>> glyph.markColor = None
The value may be a color
or None
.
name
The glyph’s name. This will be a string
.
>>> glyph.name
"A"
>>> glyph.name = "A.alt"
note
The glyph’s note.
>>> glyph.note
"P.B. said this looks 'awesome.'"
>>> glyph.note = "P.B. said this looks 'AWESOME.'"
The value may be a string
or None
.
rightMargin
The glyph’s right margin.
>>> glyph.rightMargin
35
>>> glyph.rightMargin = 45
The value will be a integer/float
or None
if the glyph has no outlines.
selectedAnchors
An type-immutable-list
of anchors selected in the glyph.
>>> anchors = glyph.selectedAnchors:
>>> glyph.selectedAnchors = otherAnchors
It is possible to use a list of type-int
representing
anchor indexes when setting the selected anchors.
>>> glyph.selectedAnchors = [0, 2]
selectedComponents
An type-immutable-list
of components selected in the glyph.
>>> components = glyph.selectedComponents:
>>> glyph.selectedComponents = otherComponents
It is possible to use a list of type-int
representing
component indexes when setting the selected components.
>>> glyph.selectedComponents = [0, 2]
selectedContours
An type-immutable-list
of contours selected in the glyph.
>>> contours = glyph.selectedContours:
>>> glyph.selectedContours = otherContours
It is possible to use a list of type-int
representing
contour indexes when setting the selected contours.
>>> glyph.selectedContours = [0, 2]
selectedGuidelines
An type-immutable-list
of guidelines selected in the glyph.
>>> guidelines = glyph.selectedGuidelines:
>>> glyph.selectedGuidelines = otherGuidelines
It is possible to use a list of type-int
representing
guidelines indexes when setting the selected guidelines.
>>> glyph.selectedGuidelines = [0, 2]
topMargin
The glyph’s top margin.
>>> glyph.topMargin
35
>>> glyph.topMargin = 45
The value will be a integer/float
or None
if the glyph has no outlines.
unicode
The glyph’s primary unicode value.
>>> glyph.unicode
65
>>> glyph.unicode = None
This is equivalent to glyph.unicodes[0]
. Setting a
glyph.unicode
value will reset glyph.unicodes
to a tuple
containing that value or an empty tuple if value
is None
.
>>> glyph.unicodes
(65, 67)
>>> glyph.unicode = 65
>>> glyph.unicodes
(65,)
>>> glyph.unicode = None
>>> glyph.unicodes
()
The returned value will be an type-int
or None
.
When setting you may send type-int
or type-hex
values or None
.
unicodes
The glyph’s unicode values in order from most to least important.
>>> glyph.unicodes
(65,)
>>> glyph.unicodes = [65, 66]
>>> glyph.unicodes = []
The values in the returned tuple will be type-int
.
When setting you may use a list of type-int
or
type-hex
values.
addImage(path=None, data=None, scale=None, position=None, color=None)
Set the image in the glyph. This will return the
assigned BaseImage
. The image data can be
defined via path
to an image file:
>>> image = glyph.addImage(path="/path/to/my/image.png")
The image data can be defined with raw image data
via data
.
>>> image = glyph.addImage(data=someImageData)
If path
and data
are both provided, a
FontPartsError
will be raised. The supported
image formats will vary across environments. Refer
to BaseImage
for complete details.
scale
indicates the x and y scale values that should be
applied to the image. It must be a type-scale
value
or None
.
>>> image = glyph.addImage(path="/p/t/image.png", scale=(0.5, 1.0))
position
indicates the x and y location of the lower left
point of the image.
>>> image = glyph.addImage(path="/p/t/image.png", position=(10, 20))
color
indicates the color to be applied to the image. It must
be a color
or None
.
>>> image = glyph.addImage(path="/p/t/image.png", color=(1, 0, 0, 0.5))
appendAnchor(name=None, position=None, color=None, anchor=None)
Append an anchor to this glyph.
>>> anchor = glyph.appendAnchor("top", (10, 20))
This will return a BaseAnchor
object representing
the new anchor in the glyph. name
indicated the name to
be assigned to the anchor. It must be a string
or None
. position
indicates the x and y location
to be applied to the anchor. It must be a
coordinate
value. color
indicates the color
to be applied to the anchor. It must be a color
or None
.
>>> anchor = glyph.appendAnchor("top", (10, 20), color=(1, 0, 0, 1))
anchor
may be a BaseAnchor
object from which
attribute values will be copied. If name
, position
or color
are specified as arguments, those values will
be used instead of the values in the given anchor object.
appendComponent(baseGlyph=None, offset=None, scale=None, component=None)
Append a component to this glyph.
>>> component = glyph.appendComponent("A")
This will return a BaseComponent
object representing
the new component in the glyph. offset
indicates the x and
y shift values that should be applied to the appended component.
It must be a coordinate
value or None
. If
None
is given, the offset will be (0, 0)
.
>>> component = glyph.appendComponent("A", offset=(10, 20))
scale
indicates the x and y scale values that should be
applied to the appended component. It must be a
type-scale
value or None
. If None
is given,
the scale will be (1.0, 1.0)
.
>>> component = glyph.appendComponent("A", scale=(1.0, 2.0))
component
may be a BaseComponent
object from which
attribute values will be copied. If baseGlyph
, offset
or scale
are specified as arguments, those values will be used
instead of the values in the given component object.
appendContour(contour, offset=None)
Append a contour containing the same data as contour
to this glyph.
>>> contour = glyph.appendContour(contour)
This will return a BaseContour
object representing
the new contour in the glyph. offset
indicates the x and
y shift values that should be applied to the appended data.
It must be a coordinate
value or None
. If
None
is given, the offset will be (0, 0)
.
>>> contour = glyph.appendContour(contour, (100, 0))
appendGlyph(other, offset=None)
Append the data from other
to new objects in this glyph.
>>> glyph.appendGlyph(otherGlyph)
This will append:
- contours
- components
- anchors
- guidelines
offset
indicates the x and y shift values that should
be applied to the appended data. It must be a coordinate
value or None
. If None
is given, the offset will be (0, 0)
.
>>> glyph.appendGlyph(otherGlyph, (100, 0))
appendGuideline(position=None, angle=None, name=None, color=None, guideline=None)
Append a guideline to this glyph.
>>> guideline = glyph.appendGuideline((100, 0), 90)
This will return a BaseGuideline
object representing
the new guideline in the glyph. position
indicates the
x and y location to be used as the center point of the anchor.
It must be a coordinate
value. angle
indicates
the angle of the guideline, in degrees. This must be a
integer/float
between 0 and 360. name
indicates
an name to be assigned to the guideline. It must be a
string
or None
.
>>> guideline = glyph.appendGuideline((100, 0), 90, name="left")
color
indicates the color to be applied to the guideline.
It must be a color
or None
.
>>> guideline = glyph.appendGuideline((100, 0), 90, color=(1, 0, 0, 1))
guideline
may be a BaseGuideline
object from which
attribute values will be copied. If position
, angle
, name
or color
are specified as arguments, those values will be used
instead of the values in the given guideline object.
autoContourOrder()
Automatically order the contours based on heuristics.
>>> glyph.autoContourOrder()
The results of this may vary across environments.
autoUnicodes()
Use heuristics to set the Unicode values in the glyph.
>>> glyph.autoUnicodes()
Environments will define their own heuristics for automatically determining values.
clear(contours=True, components=True, anchors=True, guidelines=True, image=True)
Clear the glyph.
>>> glyph.clear()
This clears:
- contours
- components
- anchors
- guidelines
- image
It’s possible to turn off the clearing of portions of the glyph with the listed arguments.
>>> glyph.clear(guidelines=False)
correctDirection(trueType=False)
Correct the winding direction of the contours following the PostScript recommendations.
>>> glyph.correctDirection()
If trueType
is True
the TrueType recommendations
will be followed.
draw(pen, contours=True, components=True)
Draw the glyph’s outline data (contours and components) to
the given type-pen
.
>>> glyph.draw(pen)
If contours
is set to False
, the glyph’s
contours will not be drawn.
>>> glyph.draw(pen, contours=False)
If components
is set to False
, the glyph’s
components will not be drawn.
>>> glyph.draw(pen, components=False)
drawPoints(pen, contours=True, components=True)
Draw the glyph’s outline data (contours and components) to
the given type-pointpen
.
>>> glyph.drawPoints(pointPen)
If contours
is set to False
, the glyph’s
contours will not be drawn.
>>> glyph.drawPoints(pointPen, contours=False)
If components
is set to False
, the glyph’s
components will not be drawn.
>>> glyph.drawPoints(pointPen, components=False)
dumpToGLIF(glyphFormatVersion=2)
This will return the glyph’s contents as a string in GLIF format .
>>> xml = glyph.writeGlyphToString()
glyphFormatVersion
must be a type-int
that defines
the preferred GLIF format version.
fromMathGlyph(mathGlyph, filterRedundantPoints=True)
Replaces the contents of this glyph with the contents of mathGlyph
.
>>> glyph.fromMathGlyph(mg)
mathGlyph
must be an object following the
MathGlyph protocol .
filterRedundantPoints enables the MathGlyph drawPoints
filterRedundantPoints
option.
interpolate(factor, minGlyph, maxGlyph, round=True, suppressError=True)
Interpolate the contents of this glyph at location factor
in a linear interpolation between minGlyph
and maxGlyph
.
>>> glyph.interpolate(0.5, otherGlyph1, otherGlyph2)
factor
may be a integer/float
or a tuple containing
two integer/float
values representing x and y factors.
>>> glyph.interpolate((0.5, 1.0), otherGlyph1, otherGlyph2)
minGlyph
must be a BaseGlyph
and will be located at 0.0
in the interpolation range. maxGlyph
must be a BaseGlyph
and will be located at 1.0 in the interpolation range. If round
is True
, the contents of the glyph will be rounded to integers
after the interpolation is performed.
>>> glyph.interpolate(0.5, otherGlyph1, otherGlyph2, round=True)
This method assumes that minGlyph
and maxGlyph
are completely
compatible with each other for interpolation. If not, any errors
encountered will raise a FontPartsError
. If suppressError
is True
, no exception will be raised and errors will be silently
ignored.
isCompatible(other)
Evaluate the interpolation compatibility of this glyph
and other
.
>>> compatible, report = self.isCompatible(otherGlyph)
>>> compatible
False
This will return a type-bool
indicating if this glyph is
compatible with other
and a GlyphCompatibilityReporter
containing a detailed report about compatibility errors.
loadFromGLIF(glifData)
Reads glifData
, in
GLIF format ,
into this glyph.
>>> glyph.readGlyphFromString(xmlData)
pointInside(point)
Determine if point
is in the black or white of the glyph.
>>> glyph.pointInside((40, 65))
True
point
must be a coordinate
.
removeAnchor(anchor)
Remove anchor
from the glyph.
>>> glyph.removeAnchor(anchor)
anchor
may be an BaseAnchor
or an
type-int
representing an anchor index.
removeComponent(component)
Remove component
from the glyph.
>>> glyph.removeComponent(component)
component
may be a BaseComponent
or an
type-int
representing a component index.
removeContour(contour)
Remove contour
from the glyph.
>>> glyph.removeContour(contour)
contour
may be a BaseContour
or an type-int
representing a contour index.
removeGuideline(guideline)
Remove guideline
from the glyph.
>>> glyph.removeGuideline(guideline)
guideline
may be a BaseGuideline
or an
type-int
representing an guideline index.
removeLayer(layer)
Remove layer
from this glyph.
>>> glyph.removeLayer("background")
Layer can be a type-glyph-layer
or a string
representing a layer name.
round()
Round coordinates to the nearest integer.
>>> glyph.round()
This applies to the following:
- width
- height
- contours
- components
- anchors
- guidelines
scaleBy(value, origin=None, width=False, height=False)
Scale the object.
>>> obj.scaleBy(2.0)
>>> obj.scaleBy((0.5, 2.0), origin=(500, 500))
value must be an iterable containing two
integer/float
values defining the x and y
values to scale the object by. origin defines the
point at with the scale should originate. It must be
a coordinate
or None
. The default is
(0, 0)
.
width indicates if the glyph’s width should be scaled. height indicates if the glyph’s height should be scaled.
The origin must not be specified when scaling the width or height.
toMathGlyph(scaleComponentTransform=True, strict=False)
Returns the glyph as an object that follows the MathGlyph protocol .
>>> mg = glyph.toMathGlyph()
scaleComponentTransform Enables the MathGlyph
scaleComponentTransform
option.
strict Enables the MathGlyph strict
option.
moveBy(value)
Move the object.
>>> obj.moveBy((10, 0))
value must be an iterable containing two
integer/float
values defining the x and y
values to move the object by.
rotateBy(value, origin=None)
Rotate the object.
>>> obj.rotateBy(45)
>>> obj.rotateBy(45, origin=(500, 500))
value must be a integer/float
values
defining the angle to rotate the object by. origin
defines the point at with the rotation should originate.
It must be a coordinate
or None
.
The default is (0, 0)
.
skewBy(value, origin=None)
Skew the object.
>>> obj.skewBy(11)
>>> obj.skewBy((25, 10), origin=(500, 500))
value must be rone of the following:
- single
integer/float
indicating the value to skew the x direction by. - iterable cointaining type
integer/float
defining the values to skew the x and y directions by.
origin defines the point at with the skew should
originate. It must be a coordinate
or
None
. The default is (0, 0)
.
transformBy(matrix, origin=None)
Transform the object.
>>> obj.transformBy((0.5, 0, 0, 2.0, 10, 0))
>>> obj.transformBy((0.5, 0, 0, 2.0, 10, 0), origin=(500, 500))
matrix must be a transformation
.
origin defines the point at with the transformation
should originate. It must be a coordinate
or None
. The default is (0, 0)
.