Shapes and Text

Slides draws editable shapes, connectors, and shape text with the shared Shape engine. FSlide.insertShape() returns a shape Facade, and every operation on it passes through the Slides command pipeline.

Custom font sources for merging text

UniverSlidesUIPlugin

  • mergeShapeFontResolver
    (font: string, unitId: string, text: string) => ArrayBuffer | Promise<ArrayBuffer | undefined> | undefined
    Resolve the exact font bytes used to draw the text.

The Slides UI plugin can read supported Web fonts that are already loaded. If the application loads its own fonts, set mergeShapeFontResolver(font, unitId, text) in UniverSlidesUIPlugin. Return the bytes of the exact face that will be used, with the weight, style, and fallback already matched, as an ArrayBuffer or a promise. Return undefined when that exact face is unavailable.

Insert a shape

TypeScript
const slide = univerAPI.getActivePresentation()?.getActiveSlide()if (!slide) {  throw new Error('No active slide')}const shape = slide.insertShape({  shapeType: univerAPI.Enum.ShapeTypeEnum.RoundRect,  transform: { left: 80, top: 64, width: 320, height: 120 },  visible: true,  selectable: true,  shapeData: {    fill: {      fillType: univerAPI.Enum.ShapeFillEnum.SolidFill,      color: '#dbeafe',    },  },})

insertShape() returns null when the Shape host adapter is unavailable or the input cannot be created. Register the Shape dependencies required by the Slides setup before inserting shapes.

Add rich text

TypeScript
if (shape) {  const richText = univerAPI.newRichText()    .text('Quarterly ')    .bold('review')  shape.getText()    .setRichText(richText)    .setHorizontalAlign(univerAPI.Enum.HorizontalAlign.CENTER)    .setVerticalAlign(univerAPI.Enum.VerticalAlign.MIDDLE)}

Shape Facades are available from slide.getShape(id) or slide.getShapes(). The common element methods set the position, size, visibility, name, and description, and slide.deleteElement(shape) removes the shape.

Edit shape text

The following example uses the shape object that insertShape() returned earlier. getText() returns a live FShapeText handle. Read the plain text with getPlainText(), replace all of it with setText(), and apply formatting through the font, color, and alignment methods.

TypeScript
if (!shape) throw new Error('Shape is not available')const shapeText = shape.getText()console.log(shapeText.getPlainText())shapeText  .setText('Quarterly review')  .setFontSize(18)  .setColor('#2563eb')  .setBold(true)  .setHorizontalAlign(univerAPI.Enum.HorizontalAlign.CENTER)  .setVerticalAlign(univerAPI.Enum.VerticalAlign.MIDDLE)

setText() replaces the existing text. Use setRichText() when a single shape requires several text styles. To change existing rich text, call getRichText()?.copy(), edit the builder, and pass it to setRichText(); editing the detached builder alone does not write any change back. More options are described in text style and text box padding and layout.

TypeScript
const richText = univerAPI.newRichText()  .text('Quarterly ')  .bold('review')shapeText.setRichText(richText)

SmartArt

SmartArt is a composite shape with a logical node tree and independently editable presentation shapes. FSlide.insertSmartArt(layoutId, transform?) returns an FShape or FConnectorShape facade, and null when the layout or Shape host is unavailable. In the editor, insert SmartArt from the Insert toolbar. The SmartArt Design tab and Text Pane edit the same nodes.

TypeScript
const smartArt = slide.insertSmartArt(  'urn:microsoft.com/office/officeart/2005/8/layout/default',  { left: 120, top: 90, width: 720, height: 360 },)if (!smartArt) throw new Error('Cannot insert SmartArt')

isSmartArt() identifies a SmartArt shape. getSmartArtData() returns a detached copy of the layout, nodes, and presentation shapes. Edits to that copy do not affect the slide until you pass it to setSmartArtData().

TypeScript
const data = smartArt.getSmartArtData()const nodeId = data?.rootNodeIds[0]if (nodeId && data) {  smartArt.updateSmartArtNode(nodeId, {    text: { ...data.nodes[nodeId].text, text: 'Discovery' },    fontSizeMode: univerAPI.Enum.SmartArtTextFontSizeModeEnum.Auto,  })}

Use insertSmartArtNode(), deleteSmartArtNode(), moveSmartArtNode(), promoteSmartArtNode(), and demoteSmartArtNode() to change the node tree. setSmartArtLayout(id, category?) switches the layout while retaining the logical nodes, and setSmartArtDirection() sets the reading direction.

TypeScript
smartArt.setSmartArtLayout(  'urn:microsoft.com/office/officeart/2005/8/layout/lProcess2',  univerAPI.Enum.SmartArtCategoryEnum.Process,)

univerAPI.Enum exposes five SmartArt enums: SmartArtCategoryEnum, SmartArtDirectionEnum, SmartArtInsertPositionEnum, SmartArtNodeRoleEnum, and SmartArtTextFontSizeModeEnum.

convertSmartArtToShapes() returns the converted ordinary shape facades in one undoable step. After conversion succeeds, those shapes replace the original SmartArt shape.

Shape format painter

Select a source shape, activate the format painter, then select the target shape. The painter copies the fill, stroke, effects, and supported text formatting, and leaves the target's identity, geometry, text content, and formula bindings unchanged. Clear formatting restores the defaults from insertion. SmartArt is excluded. The matching shape UI plugin registers this behavior automatically.

Merge shapes

Select 2–10 supported objects on the same slide, then use Merge Shapes. The operations are union (all areas), combine (overlaps excluded), intersect (shared area), subtract (removes the other objects from the primary object), and fragment (split into regions). Formatting comes from the primary object. Merging replaces the selected objects and supports undo, redo, and collaboration.

The following command acts on the current selection. merged is false when the selection or the operation cannot be applied. Objects must be editable and within the same group scope. Connectors, SmartArt, OLE objects, charts, and tables cannot be merge operands, and some effects, animations, and complex text layouts also prevent merging.

A text box that takes part in a merge is converted to outlines, and its text can no longer be edited as text afterward. If the font used to render it cannot be read, the merge stops and the original shapes remain unchanged. See font configuration.

TypeScript
import { MergeSlideShapesCommand } from '@univerjs-pro/slides-ui'const merged = await univerAPI.executeCommand(MergeSlideShapesCommand.id, {  operation: 'union',})

How is this guide?

© 2026 DreamNum Co., Ltd.