跳转到主要内容
文本框只能插入到主图层,无法插入到其他图层。该接口支持笔记中的撤销还原操作
static insertText(textBox: {
  fontSize?: number;
  fontPath?: string;
  textContentFull: string;
  textRect: Rect;
  textAlign?: number;
  textBold?: number;
  textItalics?: number;
  textFrameWidthType?: number;
  textFrameStyle?: number;
  textEditable?: number;
}): Promise<APIResponse<boolean>>;
参数
参数类型说明
textBox.textContentFullstring文本内容(必填,非空)
textBox.textRectRect文本框矩形(必填,需为非零面积)
textBox.fontSizenumber字体大小(需为正数)
textBox.fontPathstring字体路径(可选)
textBox.textAlignnumber对齐方式:0 居左,1 居中,2 居右
textBox.textBoldnumber是否粗体:0 正常,1 粗体
textBox.textItalicsnumber是否斜体:0 正常,1 倾斜
textBox.textFrameWidthTypenumber边框宽度类型:0 固定宽度,1 自适应宽度
textBox.textFrameStylenumber边框样式:0 无边框,3 描边
textBox.textEditablenumber可编辑状态:0 可编辑,1 不可编辑
返回

示例

import { PluginNoteAPI, type Rect } from 'sn-plugin-lib';

/**
 * 插入文本框的示例。
 */
export async function exampleInsertText() {
  const textRect: Rect = { left: 100, top: 100, right: 320, bottom: 180 };
  const res = await PluginNoteAPI.insertText({
    textContentFull: 'Hello from plugin',
    textRect,
    fontSize: 32,
    textAlign: 0,
    textBold: 0,
    textItalics: 0,
    textFrameWidthType: 0,
    textFrameStyle: 0,
    textEditable: 0,
  });

  if (!res.success) {
    throw new Error(res.error?.message ?? 'insertText 调用失败');
  }
  return res.result;
}