Path Markup syntax: XPS-style
This topic describes in detail the powerful and complex mini-language you can use to specify path geometries more compactly. Mako's implementation is based on "Abbreviated Geometry Syntax" described in the Open XPS Standard (Open XML Paper Specification (Open XPS®), ECMA 388).
White space
For brevity, a single space is shown in the syntax sections that follow, but multiple spaces are also acceptable wherever a single space is shown.
Two numbers don’t actually have to be separated by a comma or white space, but this can only be done when the resulting string is unambiguous. For instance, 2..3
is actually two numbers: "2." And ".3". Similarly, 2-3
is "2" and "-3". Spaces are not required before or after commands, either.
Syntax
The Path Markup syntax for a IDOMPathGeometry()
is composed of an optional FillRule
value and one or more figure descriptions. With it, you can create path geometry with simple markup, then create stoked or filled paths and shapes to add to a page or canvas. Use a render transform to resize, as required. For example:
auto mako = IJawsMako::create();
IJawsMako::enableAllFeatures(mako);
auto geometry = IDOMPathGeometry::create(mako, "F1 M 128,256 L 256,192 L 256,64 L 128,0 L 0,64 L 0,192 L 128,256 Z ");
auto redBrush = IDOMSolidColorBrush::create(mako, IDOMColor::create(mako, IDOMColorSpacesRGB::create(mako), 1.0f, 1.0f, 0.0f, 0.0f));
auto fillPath = IDOMPathNode::createFilled(mako, geometry, redBrush);
auto assembly = IDocumentAssembly::create(mako);
auto document = IDocument::create(mako);
auto page = IPage::create(mako);
document->appendPage(page);
assembly->appendDocument(document);
// Add the graphic to a new fixed page (Mako defaults to A4) then save as PDF
auto fixedPage = IDOMFixedPage::create(mako);
page->setContent(fixedPage);
fixedPage->appendChild(fillPath);
IPDFOutput::create(mako)->writeAssembly(assembly, "geometry.pdf");
A geometry is specified with an optional FillRule
command followed by one or more figure definitions. Figure definitions are specified with a Move
command, a set of one or more drawing commands to create segments, and an optional Close
command to create a closing segment. Drawing commands include:
Line
Horizontal Line
Vertical Line
Cubic Bézier Curve
Quadratic Bézier Curve
Smooth Cubic Bézier Curve
Elliptical Arc
A command is represented by a single letter and is followed by zero or more whitespace characters, which are followed by command parameters. Parameters are whitespace-delimited. Points are specified as a comma-delimited pair with zero or more whitespace characters.
Uppercase letters denote absolute values, and lowercase letters denote relative values. When relative coordinate values are specified, each coordinate pair expresses an offset relative to the current endpoint (the previous command’s terminating coordinate pair). If a relative value is used for the first Move
command, the current endpoint is, by definition, 0,0
. If a relative value is used following a Close
command, the current endpoint is the first point of the previous figure.
If entering more than one drawing command of the same type sequentially, the duplicate command entry MAY be omitted. For example: L 100,200 300,400
is equivalent to L 100,200 L 300,400
. The current endpoint is determined as though each command appears individually.
Values specifying coordinates can be real numbers.
Name | Syntax | Description | Example |
---|---|---|---|
FillRule |
| Establishes the fill rule that you should use for this geometry. A value of This command MUST appear only as the first command in the abbreviated geometry syntax. |
|
Move |
| Establishes a new current endpoint. Every geometry MAY specify one or more figures and MAY be preceded by a |
|
Line |
| Draws a straight line from the current point to the specified point |
|
Horizontal Line |
| Draws a horizontal line from the current endpoint to the specified |
|
Vertical Line |
| Draws a vertical line from the current endpoint to the specified |
|
Cubic Bézier Curve |
or
| Draws a cubic Bézier curve from the current endpoint to the specified point ( |
|
Quadratic Bézier Curve |
or
| Draws a quadratic Bézier curve from the current endpoint to the specified point ( |
|
Smooth Cubic Bézier Curve |
or
| Draws a cubic Bézier curve from the current endpoint to the specified point ( |
|
Elliptical Arc |
or
| Draws an elliptical arc from the current endpoint to the specified point ( If |
|
Close |
| Draws a straight line from the current endpoint to the first point of the current figure and then ends the figure. If the command following a |
|