Shape Block
About 2916 words
- Type ID:
5 - Type: Map
A Shape is a parametric shape that can be drawn directly: line, polyline, rectangle, square, ellipse, circle, polygon. It stores the final geometry, a single-color stroke and a single-color fill, so every reader that supports Shape draws the same appearance. Complex shapes (arrows, solids, etc.) are made of several Shape parts, combined into one editable whole by the shape object layer object.
Levels
- Core: the seven geometries (including rotation), stroke color and width, solid fill; may ignore opacity.
- Basic:
opacity, dashes, arrows, rounded corners,lineCap/lineJoin. - Standard: the shape object layer
object: multiple parts selected, moved and deleted as one object. - Full:
constructionand registered presets in the object layer (re-editable across apps), private geometries,renderOnlyWhenLatest.
When to use
- Lines, arrows, rectangles, circles, polygons, solids and so on drawn by the user.
- The result of recognizing a handwritten stroke as a shape.
- Curves (arcs, parabolas, hyperbolas, function graphs) and irregular free-form shapes: take points in order and write them as a Polyline or Polygon; see Curves and free-form shapes. UInk 1.1 registers neither curve equations nor Bézier curves.
Fields
| Field | Type | Requirement | Level | Description |
|---|---|---|---|---|
type | uint16 | Required | Core | Always 5 |
contentId | uint32 | Required | Core | Content sequence number shared with Ink (INK-2) |
undoId | uint32 | Required | Standard | Undo group number (INK-3) |
shapeType | int32 | Required | Core | Geometry type, see the table below |
geometry | Map | Required | Core | Geometry data determined by shapeType |
stroke | Map | Conditional | Core | Stroke; required for Line and Polyline |
fill | Map | Conditional | Core | Fill; closed shapes only |
object | Map | Optional | Standard | Shape object layer, see Shape object layer |
renderOnlyWhenLatest | bool | Optional | Full | Defaults to false; same rule as INK-15 |
extra | Map | Optional | — | App-private fields |
shapeType
| Value | Name | Geometry |
|---|---|---|
0 | Line | Two endpoints |
1 | Polyline | Polyline of at least two points |
2 | Rectangle | Rectangle or rounded rectangle; width and height may differ |
3 | Square | Square; keeps its aspect ratio when edited |
4 | Ellipse | Ellipse; width and height may differ |
5 | Circle | Circle; keeps its aspect ratio when edited |
6 | Polygon | Closed polygon of at least three points |
7–127 | Reserved | — |
128+ | Private | — |
0 Linepoints: 2 points1 Polylinepoints: at least 2 points2 RectanglecenterX/Y, width, height, rotation, corner radii3 SquarecenterX/Y, size, rotation4 EllipsecenterX/Y, width, height, rotation5 CirclecenterX/Y, radius6 Polygonpoints: at least 3 points, closed automaticallyGeometry
All coordinates are absolute Canvas coordinates (Ink's relative displacements are not used), in Device pixels, and must be finite numbers.
Line, Polyline, Polygon
geometry.points is Array<Map>, each point being { x: float32, y: float32 }.
- SHAPE-1 Line has exactly two points; Polyline at least two; Polygon at least three.
- SHAPE-2 Polygon connects the points in order and automatically connects the last point to the first; writers must not write the first point again. Fill uses the nonzero winding rule. Basic polygons such as triangles are represented as Polygon.
Rectangle and Ellipse
| Field | Type | Requirement | Level | Description |
|---|---|---|---|---|
centerX | float32 | Required | Core | Center X |
centerY | float32 | Required | Core | Center Y |
width | float32 | Required | Core | Width, greater than 0 |
height | float32 | Required | Core | Height, greater than 0 |
rotation | float32 | Optional | Core | Radians, clockwise positive; defaults to 0 |
cornerRadiusX | float32 | Optional | Basic | Rectangle only; horizontal corner radius, defaults to 0 |
cornerRadiusY | float32 | Optional | Basic | Rectangle only; vertical corner radius, defaults to 0 |
- SHAPE-3 The two corner fields must appear together: both
0(square corners), or both greater than0and not exceedingwidth / 2andheight / 2respectively. When only one appears or the values are invalid, readers show square corners and report a warning. Corner fields on an Ellipse are ignored.
Square
| Field | Type | Requirement | Description |
|---|---|---|---|
centerX | float32 | Required | Center X |
centerY | float32 | Required | Center Y |
size | float32 | Required | Side length, greater than 0 |
rotation | float32 | Optional | Radians; defaults to 0 |
Circle
| Field | Type | Requirement | Description |
|---|---|---|---|
centerX | float32 | Required | Center X |
centerY | float32 | Required | Center Y |
radius | float32 | Required | Radius, greater than 0 |
Curves and free-form shapes
UInk has only seven geometries and no "curve" type. Any curve or irregular shape is written by taking sufficiently dense points along it in order and connecting them with straight segments: open ones as Polyline, closed ones as Polygon. Readers only need to connect the points in order to draw it, without knowing what curve it originally was, so even Core readers display it correctly.
Take the hyperbola x² / a² − y² / b² = 1 as an example:
- Taking points: use the parametric form x = a·cosh t, y = b·sinh t, let t increase, compute the points on the curve one by one, then add the center coordinates.
- How dense: the points must be dense enough that the polyline is no more than 0.25 units from the true curve (SHAPE-24), so no corners are visible to the eye. Take more points where it bends sharply (near the vertex) and fewer where it is flat; with
a = 120,b = 90,t ∈ [−1.9, 1.9], each branch has about 30 points. - Write disconnected parts separately: the hyperbola has left and right branches that do not connect; write each as its own Polyline (SHAPE-25). Do not join the two branches into one polyline, or an extra line will appear between them.
- Auxiliary lines: the asymptotes are two ordinary Lines and may be dashed.
- Combine into one object (optional, Standard): use the shape object layer to group the two branches and two asymptotes into one object that is selected and moved together when editing; there is no matching preset, so
presetis not written.
Closed free-form shapes (a heart, a hand-drawn outline, a region bounded by functions) work the same way: take points along the boundary and write them as a Polygon, without repeating the first point (SHAPE-2); it may be filled.
- 0Left branch
Polylinefirst part, carries the full object - 1Right branch
Polylineref + partIndex - 2Asymptote
Linedashed [12, 8] - 3Asymptote
Linedashed [12, 8]
The maximum deviation from the true curve is about 5.35 units; more than 0.25, so more points are needed.
The figure samples evenly in t; adaptive sampling based on curvature can use fewer points (the public sample uses 29 per branch).
- SHAPE-24 Curves and irregular shapes beyond the seven geometries must be written as points sampled in order: open ones as Polyline, closed ones as Polygon. Writers should keep the maximum distance between the polyline and the original curve within 0.25 units (the same as PRESET-6); readers draw them as ordinary Polyline and Polygon and must not guess at or smooth them into other curves.
- SHAPE-25 When a curve consists of several disconnected pieces (for example the two branches of a hyperbola), each piece is written as one Shape, and they must not be joined by extra segments. When they need to be edited as a whole, combine them with the shape object layer (SHAPE-11); without a registered preset,
presetis not written.
Stroke and fill
Stroke Map
| Field | Type | Requirement | Level | Description |
|---|---|---|---|---|
color | Color Map | Required | Core | Stroke color |
opacity | float32 | Required | Basic | Stroke opacity, 0–1 |
width | float32 | Required | Core | Stroke width, greater than 0 |
dashArray | Array<float32> | Optional | Basic | Dash and gap lengths; solid when missing or empty |
dashOffset | float32 | Optional | Basic | Starting offset of the dash pattern, defaults to 0; a positive value shifts the pattern toward the start (SHAPE-26) |
lineCap | int32 | Optional | Basic | Cap, defaults to Round; see Nibs and Caps |
lineJoin | int32 | Optional | Basic | Join, defaults to Round |
startMarker | int32 | Optional | Basic | Start marker, defaults to 0 |
endMarker | int32 | Optional | Basic | End marker, defaults to 0 |
Fill Map
| Field | Type | Requirement | Level | Description |
|---|---|---|---|---|
fillType | int32 | Required | Core | 0 Solid; 1–127 reserved, 128+ private |
color | Color Map | Required | Core | Fill color |
opacity | float32 | Required | Basic | Fill opacity, 0–1 |
Marker
| Value | Name | Meaning |
|---|---|---|
0 | None | No marker |
1 | OpenArrow | Open arrowhead; exact shape is up to the app |
2–127 | Reserved | — |
128+ | Private | — |
dashArray omittedSolid when missing or emptydashArray: [16, 8]Round caps add w/2 to both ends of each dash, so the gaps look narrowerdashOffset: 6The pattern shifts 6 toward the start: the first dash is only 10 long and the rest move left (SHAPE-26). The light gray line above is dashOffset = 0dashArray: [0, 12]That is {0, 3w}: zero-length dashes are drawn as dots under round caps (NIB-5)dashArray: [16, 8, 0, 8]Dashes alternate with dotsendMarker: 1OpenArrow; its exact shape is up to the app. Line and Polyline onlyRules
- SHAPE-4 Every Shape has at least one of
strokeorfill. Line and Polyline must havestrokeand must not havefill. Closed shapes may have only a stroke, only a fill, or both. - SHAPE-5 Within one Shape, the stroke uses a single color, opacity and fixed width.
- SHAPE-6
width,dashArrayanddashOffsetuse the same units as coordinates (Device pixels) and are the final visible lengths at save time. After an app scales a shape, it saves the converted results; readers must not scale these values again. - SHAPE-7 A non-empty
dashArraymust contain an even number of non-negative finite values whose sum is greater than0. A zero-length dash is drawn as a round dot with a Round cap (NIB-5); writers expressing dotted lines must use a Round or Square cap. WhendashArrayordashOffsetis invalid, the stroke is shown as solid. - SHAPE-26
dashOffsetis the starting phase of the dash pattern: at distancesfrom the start of the path, the position in thedashArraypattern is(s + dashOffset) mod total pattern length. A positive value therefore shifts the dash pattern toward the start, and a negative value toward the end. This is the same as SVG'sstroke-dashoffsetand Canvas 2D'slineDashOffset; Direct2D'sdashOffsetanddashesare in units of stroke width, so divide bywidthwhen converting. - SHAPE-8 Line style (solid, dashed, dotted) is expressed only by
dashArray; writers must not split a dashed line into separate Shapes, one per dash. The only exception: to make the dashes of a closed shape symmetric at the corners, writers may split the closed stroke into several Polyline parts (each with its owndashOffset) and combine them with the shape object layer (SHAPE-11). - SHAPE-9 Markers apply only to Line and Polyline; on closed shapes they are ignored and a warning is reported. An arrow is written as one Line or Polyline with a Marker, without generating an extra Shape. When the arrow's shape needs precise control, the shape object layer may be used instead, writing the shaft and head as two parts.
- SHAPE-10 UInk does not register a
miterLimitfield. Miter joins should be drawn with a limit of 4: when the miter length (the distance from the outer tip to the inner corner point) exceeds 4 times the stroke width (a corner sharper than about 29°), that join is drawn as Bevel, the same as the SVG default. An app using a different limit is not an error; anti-aliasing is up to the app.
Shape object layer
Complex shapes are made of several Shape parts. For example, a cube is 12 edges (hidden edges are dashed), and a cylinder is the visible and hidden arcs of two ellipses plus two side edges. The shape object layer marks these parts as the same object so editors can select, move and delete them as a whole; Full editors can also regenerate them from construction and keep editing the parameters.
object."object": {
"id": "eeeeeeee-0009-4000-8000-000000000001",
"revision": 3,
"preset": "cuboid",
"partCount": 12,
"transform": [1.5, 0, 0, 1.5, 700, 620],
"construction": {
"start": { "x": 0, "y": 0 },
"height": -160,
"baseSize": { "x": 200, "y": 160 },
"baseRotation": 0.5
},
"style": { "width": 2, "linePattern": 0 }, // other styles omitted
"aux": 0
}The first part (partIndex 0) carries the full object.
object on the first part
| Field | Type | Requirement | Level | Description |
|---|---|---|---|---|
id | string(36) | Required | Standard | UUID of the object, unique within the file; must not be all zeros |
revision | uint64 | Required | Standard | Revision number, at least 1; uses a new value every time the object's content changes |
preset | string | Optional | Standard | Preset name, for example cuboid, arrow; see Shape Preset Registry. Missing means an ordinary object group without a preset |
partCount | uint32 | Required | Standard | Total number of parts (including auxiliary parts), at least 1 |
transform | Array<float32>(6) | Optional | Standard | Affine matrix of the object, same layout as Media (MEDIA-2); defaults to the identity matrix |
construction | Map | Optional | Full | Parameters needed to rebuild the object; used only with preset, defined by the preset |
style | Map | Optional | Full | Style used for editing, see the appendix |
aux | uint32 | Optional | Full | Bitmask of auxiliary markers, see the appendix |
object on subsequent parts
| Field | Type | Requirement | Description |
|---|---|---|---|
ref | string(36) | Required | id of the first part |
partIndex | uint32 | Required | Part number, from 1 to partCount − 1 |
Rules
- SHAPE-11 All parts of an object must appear contiguously in one Canvas in
partIndexorder; the first part (partIndex0) carries the fullobject, and all parts share the sameundoId. - SHAPE-12 Each part is itself a complete Shape that can be drawn directly; its geometry is already final. Readers must not apply
transformto the parts again;transformis used only by editors to regenerate parts fromconstruction. - SHAPE-13 Standard readers select, move and delete all parts of an object as a whole. After editing, writers update the geometry of all parts, use a new
revision, and keep the parts contiguous. If an object has nopresetor noconstruction, its parts are authoritative. - SHAPE-14 When parts are missing, their count disagrees with
partCount, their order is not contiguous,refcannot find the first part, oridis duplicated, readers show the affected parts as independent Shapes and report a warning; they must not reject the whole page. - SHAPE-15 When a Full reader recognizes
presetandconstructionis valid, it may rebuild the object from them for editing; when the rebuilt result differs from the parts in the file, the parts in the file are what is displayed. An unknown preset falls back to the object layer (SHAPE-13).
Undo, append and erase
- SHAPE-16 Shape shares
contentIdwith Ink, Media and Clear and is processed in object stream order (FILE-14). - SHAPE-17 A complete Shape may be appended to the last Canvas; when an existing Shape is modified, moved or deleted, append a new version of the whole page or perform a full save (SAVE-18).
- SHAPE-18 An Erase Ink in the Inkeys extension affects the Shapes before it (INK-11).
Error tolerance
- SHAPE-19 A Shape missing
type,contentId,undoId,shapeType,geometryor the necessary style is skipped and a warning is reported. - SHAPE-20 Unknown
shapeType: skip the whole Shape; it must not be guessed as another geometry. - SHAPE-21 An unknown Marker is shown as None, keeping the line itself; an unknown
fillTypeis shown as Solid. - SHAPE-22 When a field is invalid and has no corresponding fallback rule, that geometry or style is invalid; when in the end there is no valid geometry, a Line / Polyline has no valid stroke, or both the stroke and fill of a closed shape are invalid, the whole Shape is skipped.
- SHAPE-23 A finite but out-of-range
opacityis clamped to0–1.
Example
{
"type": 5,
"contentId": 2,
"undoId": 1,
"shapeType": 0,
"geometry": { "points": [ { "x": 120.0, "y": 240.0 }, { "x": 420.0, "y": 240.0 } ] },
"stroke": {
"color": { "fallback": 255 },
"opacity": 1.0,
"width": 4.0,
"dashArray": [16.0, 8.0],
"lineCap": 0,
"startMarker": 1,
"endMarker": 1
}
}{
"type": 5,
"contentId": 3,
"undoId": 2,
"shapeType": 2,
"geometry": {
"centerX": 360.0, "centerY": 240.0, "width": 240.0, "height": 120.0,
"cornerRadiusX": 24.0, "cornerRadiusY": 16.0
},
"stroke": { "color": { "fallback": 255 }, "opacity": 1.0, "width": 4.0 },
"fill": { "fillType": 0, "color": { "fallback": 16777215 }, "opacity": 1.0 }
}{
"type": 5, "contentId": 4, "undoId": 3, "shapeType": 0,
"geometry": { "points": [ { "x": 100.0, "y": 300.0 }, { "x": 260.0, "y": 300.0 } ] },
"stroke": { "color": { "fallback": 0 }, "opacity": 1.0, "width": 3.0 },
"object": {
"id": "eeeeeeee-eeee-4eee-8eee-eeeeeeeeeeee",
"revision": 2,
"preset": "cuboid",
"partCount": 12,
"transform": [1.0, 0.0, 0.0, 1.0, 0.0, 0.0]
}
}
{
"type": 5, "contentId": 5, "undoId": 3, "shapeType": 0,
"geometry": { "points": [ { "x": 260.0, "y": 300.0 }, { "x": 260.0, "y": 180.0 } ] },
"stroke": { "color": { "fallback": 0 }, "opacity": 1.0, "width": 3.0, "dashArray": [12.0, 18.0] },
"object": { "ref": "eeeeeeee-eeee-4eee-8eee-eeeeeeeeeeee", "partIndex": 1 }
}
// ... the remaining 10 parts// Left branch: Polyline, vertex (640, 540); coordinates already include the center (760, 540)
{
"type": 5, "contentId": 0, "undoId": 0, "shapeType": 1,
"geometry": { "points": [
{ "x": 349.87, "y": 834.13 }, // t = −1.9
// ... points taken as t increases, denser near the vertex
{ "x": 640.0, "y": 540.0 }, // t = 0, vertex
// ...
{ "x": 349.87, "y": 245.87 } // t = 1.9
] },
"stroke": { "color": { "fallback": 0 }, "opacity": 1.0, "width": 4.0 },
"object": {
"id": "eeeeeeee-0016-4000-8000-000000000001",
"revision": 1,
"partCount": 4 // left branch, right branch, two asymptotes; no preset
}
}
// Right branch: another Polyline, partIndex 1
// Two asymptotes: Line, dashArray [12, 8], partIndex 2 and 3For the complete data, see the public sample core-shape-curves.uink.
Fallback
| Capability the reader lacks | How it is shown |
|---|---|
opacity (Core) | Drawn opaque |
| Dashes, Markers, rounded corners (Core) | Solid line, no marker, square corners |
lineCap, lineJoin (Core) | Round cap, round join |
| Shape object layer (Core, Basic) | Each part treated as an independent Shape; appearance unchanged |
construction (below Full) | Edited as a whole through the object layer; parameters cannot be changed |
renderOnlyWhenLatest (below Full) | Marker ignored; everything shown |