Skip to content
On this page

TextPath Shape

TIP

This class is a descendant of Shape it also inherits all the options that Shape provides.

TIP

This component also supports a return function

To create an text path shape with fcanvas, we can instantiate a TextPath object.

In addition, this shape also provides a few other parameters:

Require Options

NameTypeDescription
textMayBeRef<string>text show
dataMayBeRef<string>data SVG path

Inherit Shape

NameTypeDescription
xMayBeRef<number>offset x
yMayBeRef<number>offset y

Optional Options

NameTypeDefaultDescription
fontFamilyMayBeRef<string>Font default BrowserFont apply to text
fontSizeMayBeRef<number>12Font size
fontStyleMayBeRef<"normal" | "bold" | "italic" | "italic bold">"normal"display font style
fontVariantMayBeRef<"normal" | "small-caps">"normal"can be normal or small-caps
textDecorationMayBeRef<"line-through" | "underline" | "none">"none"underline style
alignMayBeRef<"left" | "center" | "right" | "justify">"left"ext will display the same style as text-align in CSS
letterSpacingMayBeRef<number>0letter spacing for text
textBaselineMayBeRef<CanvasTextBaseline>"middle"This is similar to verticalAlign but instead of calculating it itself it uses the canvas api (may improve performance)

Demo

ts
import { Stage, Layer, Text, TextPath } from "fcanvas"

const stage = new Stage().mount("#app")
const layer = new Layer().addTo(stage)

const textpath = new TextPath({
  x: 0,
  y: 50,
  fill: "#333",
  fontSize: 16,
  fontFamily: "Arial",
  text: "All the world's a stage, and all the men and women merely players.",
  data: "M10,10 C0,0 10,150 100,100 S300,150 5.0.300"
}).addTo(layer)

Released under the MIT License.