DrawingML shape properties — <a:prstGeom>, <a:xfrm>, <a:solidFill>, <a:ln>.

Module drawingmlShape | Source packages/front/office/ooxml/src/drawingml/shape.js | Deps xml, ooxmlShared | Worker-safe yes

Models the content of <spPr>, shared by the pptx (<p:sp>), docx (<wps:wsp>) and xlsx (<xdr:sp>) hosts. Covers geometry (rect, roundRect, ellipse and other presets), the 2D transform (offset/extent/rotation/flip), simple fills and lines. Anything not modelled stays in _extras for round-trip fidelity.

Resolve

const sh = runtime.resolve('drawingmlShape');
// Returns: { parseShapeProperties, renderShapeProperties,
//            parsePrstGeom, renderPrstGeom,
//            parseXfrm, renderXfrm,
//            parseFill, renderFill,
//            parseLine, renderLine,
//            shapeProps,
//            toEmu, EMU_PER_INCH, EMU_PER_CM, EMU_PER_PT, EMU_PER_PX_96,
//            PRESETS, A_NS }

API

Method Signature Returns
parseShapeProperties (spPrEl, opts?) => shapeProps Typed model; opts.typedLineColors types a line's colour (see below).
renderShapeProperties (props) => element <*:spPr>.
parsePrstGeom / renderPrstGeom symmetric Preset geometry.
parseXfrm / renderXfrm symmetric 2D transform.
parseFill / renderFill symmetric solid / scheme / none.
parseLine / renderLine symmetric Typed <a:ln>.
shapeProps ({geom, cx, cy, offsetX?, offsetY?, fill?, line?, …}) => props Convenience builder.
toEmu (value: string|number) => number Converts '2in', '5cm', '12pt', '96px' or a raw EMU number.
EMU_PER_INCH, EMU_PER_CM, EMU_PER_PT, EMU_PER_PX_96 number EMU constants.
PRESETS frozen object Catalogue of 38 prst ids (rect, roundRect, ellipse, arrows, callouts, …).
A_NS string DrawingML namespace.

Model

shapeProps := {
    geom?: string,                  // 'rect'|'roundRect'|'ellipse'|'triangle'|…
    avLst?: [{ name, fmla }],
    cx?, cy?, offsetX?, offsetY?,   // EMU
    rotation?: number,              // 60000ths of a degree
    flipH?: boolean, flipV?: boolean,
    bwMode?: string,                // the spPr's black-and-white mode
    fill?: 'none' | { rgb: 'RRGGBB', mods?: [{ name, val? }] }
                  | { schemeColor: string, mods?: [{ name, val? }] },
    line?: 'none' | {
        width?: number,             // EMU
        color?: 'RRGGBB'            // with opts.typedLineColors also
              | { rgb | schemeColor, mods? },  // a typed colour (see below)
        dash?: 'solid'|'dash'|'dot'|'dashDot'|…,
        cap?: 'flat'|'rnd'|'sq',
        compound?: 'sng'|'dbl'|'thickThin'|'thinThick'|'tri',
        extraAttrs?: { [name: string]: string },  // other a:ln attributes (algn), verbatim
        _extras?: [xmlNode]         // other a:ln children, verbatim (see below)
    },
    _extras?: [xmlNode]
}

A read a:ln keeps what the typed fields do not hold: a solidFill whose colour is not an a:srgbClr (a theme schemeClr, prstClr, sysClr, with its transforms), gradFill, pattFill, custDash, the joins (round, bevel, miter), headEnd, tailEnd and extLst go to line._extras, attributes other than w, cap and cmpd to line.extraAttrs, and the writer puts them back in schema order. color stays the RRGGBB string of an a:srgbClr (its transforms dropped) or null for noFill. A typed color (or null) set on such a line replaces the kept fill, a typed dash the kept custDash.

With opts.typedLineColors: true (threaded from pptx.read and xlsx.read) a line's colour reads as the fill's does: 'RRGGBB' for a bare a:srgbClr, else the typed { rgb | schemeColor, mods? } of the shared colour codec (an a:srgbClr's transforms kept). A colour the codec does not type (prstClr, sysClr) stays verbatim in line._extras. The writer writes either form. The spPr children kept in _extras (custGeom, gradFill, blipFill, effectLst, scene3d, …) are written at their schema place too: geometry and fill before a:ln, effects after it.

Examples

Blue rectangle with a border

const sh = runtime.resolve('drawingmlShape');
const props = sh.shapeProps({
    geom: sh.PRESETS.roundRect,
    cx: sh.toEmu('3in'),
    cy: sh.toEmu('1in'),
    fill: { rgb: '4472C4' },
    line: { width: 12700, color: '2E5597' }   // 1pt
});
sh.renderShapeProperties(props);

Position and rotation

sh.shapeProps({
    geom: 'ellipse',
    offsetX: sh.toEmu('1cm'), offsetY: sh.toEmu('1cm'),
    cx: sh.toEmu('5cm'),      cy: sh.toEmu('5cm'),
    rotation: 30 * 60000      // 30°
});

Notes

  • Line width is in EMU (12700 = 1pt). There is no unit inference — compute it with toEmu.
  • PRESETS is a convenience catalogue of 38 entries, not the full ECMA list; any string passed as geom is accepted.
  • fill: 'none' emits <a:noFill/>; omitting fill emits no element at all (inheritance from the parent).
  • A solid fill is { rgb } (a:srgbClr) or { schemeColor } (a:schemeClr); shapeProps also accepts the 'RRGGBB' string. Its colour transforms (lumMod, lumOff, tint, shade, alpha, satMod, comp, …, ECMA-376 §20.1.2.3) are kept in document order as mods: [{ name, val? }] (val a number) and written back; a transform that does not fit that shape leaves the fill without mods.
  • <a:gradFill>, <a:effectLst> and similar are not modelled here — see the DrawingML extras (dmlFillsAdvanced, dmlEffects, dmlShapesAdvanced).

See also