Skip to content

Text

Text

It is used to render text content. The specific type is as follows:

ts
type Text = {
  type: 'text';
  x: number;
  y: number;
  w: number;
  h: number;
  angle: number;
  detail: {
    text: string;
    color?: string;
    fontSize?: string;
    fontFamily?: string;
    textAlign?: 'left' | 'center' | 'right';
};

Text.detail 详解

元素的基本属性详情可以看 元素介绍-数据基本格式

Text.detail 数据格式

Text元素的detail属性

ts
type TextDetail = {
  text: string;
  color?: string;
  fontSize?: number;
  lineHeight?: number;
  fontWeight?: 'bold' | string | number;
  fontFamily?: string;
  textAlign?: 'center' | 'left' | 'right';
  verticalAlign?: 'middle' | 'top' | 'bottom';
};

Text.detail Properties

PropertyDescriptionTypeDefaultRequiredOthers
textText Contentstring-true-
colorFont color of Textstring-trueeg. #000000
fontSizeFont size of Textnumber12false-
lineHeightLine height of Textnumber-false-
fontWeightFont boldnumber-false-
fontFamilyFont family of Textstring-false-
textAlignText align'left' | 'center' | 'right''left'false-
verticalAlignVertical Align'top' | 'middle' | 'bottom''top'false-

Complete Data Example

js
const elementText = {
  name: 'text',
  x: 160,
  y: 80,
  w: 200,
  h: 200,
  angle: 0,
  type: 'text',
  detail: {
    text: 'Hello World',
    color: '#3f51b5',
    fontSize: 60,
    textAlign: 'center',
    background: '#3f51b51f',
    borderRadius: 10,
    borderWidth: 2,
    borderColor: '#3f51b5'
  }
};

Demo Preview

More Demo