Skip to content

mxcad_2d API 文档 / 2d / McDbTextStyleTableRecord

Class: McDbTextStyleTableRecord ​

2d.McDbTextStyleTableRecord

McDbTextStyleTableRecord 是文字样式表中的单条记录,用于保存和管理文本字体样式参数。

Description

该类用于描述一套文本样式,如字体名称、大小、倾斜角、宽度因子和大字体参数。 通过它可以完成:

  • 创建和配置文字样式;
  • 设置字体、大小、斜体、宽度和标志位;
  • 保存到文字样式表中;
  • 将样式应用到文本对象或注释对象上。

使用方式:

  1. 创建 McDbTextStyleTableRecord 实例;
  2. 设置 name、fileName、textSize、xScale 等属性;
  3. 添加到文字样式表后应用到文本对象中。

总结:在实际开发中,McDbTextStyleTableRecord 是文字风格和字体控制的最细粒度对象,适合统一管理文本样式。

Example

ts
import { McCmColor, MxCpp, McDbTextStyleTableRecord, McDb } from "mxcad"

// 创建并设置文字样式记录。
async function testTextStyleRecord() {

   const mxcad = MxCpp.getCurrentMxCAD();
   // 拿到当前文字样式表
   const textSyleTable = mxcad.getDatabase().getTextStyleTable();
   // 构造一个文字样式表记录对象
   let newTextStyleRecord = new McDbTextStyleTableRecord();
   // 设置对象文件名
   newTextStyleRecord.fileName = "txt.shx";
   // 设置对象大字体名称
   newTextStyleRecord.bigFontFileName = "hztxt.shx";
   // 设置对象文字大小
   newTextStyleRecord.textSize = 10;
   // 设置对象名
   newTextStyleRecord.name = sMyTextStyle;
   // 设置对象宽度因子
   newTextStyleRecord.xScale = 0.7;
   // 添加文字样式
   const res = textSyleTable.add(newTextStyleRecord).isValid()
   if (res) {
     console.log("add ok");
   }
}

Hierarchy ​

Table of contents ​

Constructors ​

Properties ​

Accessors ​

Methods ​

Constructors ​

constructor ​

• new McDbTextStyleTableRecord(imp?)

构造函数。

Parameters ​

NameTypeDescription
imp?any内部实现对象。

Overrides ​

McDbObject.constructor

Properties ​

imp ​

• imp: any = 0

内部实现对象。

Inherited from ​

McDbObject.imp

Accessors ​

bigFontFileName ​

• get bigFontFileName(): string

大字体文件名称

Returns ​

string

• set bigFontFileName(val): void

Parameters ​

NameType
valstring

Returns ​

void


dxf0 ​

• get dxf0(): string

得到对象的DXF组码的类型名,这个和AutoCAD中的DXF组码是一样。 比如直线的类型名为:McDbLine,DXF0组码值: LINE,DXF0组码值可以用来构造集时的类型过滤。

Returns ​

string

Inherited from ​

McDbObject.dxf0


fileName ​

• get fileName(): string

字体文件名称

Returns ​

string

• set fileName(val): void

Parameters ​

NameType
valstring

Returns ​

void


flagBits ​

• get flagBits(): number

获取或设置文本样式表记录的一组标志位

Returns ​

number

• set flagBits(val): void

Parameters ​

NameType
valnumber

Returns ​

void


isShapeFile ​

• get isShapeFile(): boolean

获取或设置文本样式是否使用形状字体

Returns ​

boolean

• set isShapeFile(val): void

Parameters ​

NameType
valboolean

Returns ​

void


isVertical ​

• get isVertical(): boolean

获取或设置文本样式是否使用斜体

Returns ​

boolean

• set isVertical(val): void

Parameters ​

NameType
valboolean

Returns ​

void


name ​

• get name(): string

获取或设置文字样式名称。

Returns ​

string

• set name(val): void

Parameters ​

NameType
valstring

Returns ​

void


objectName ​

• get objectName(): string

获取对象名称。

Returns ​

string

返回对象名

Inherited from ​

McDbObject.objectName


obliquingAngle ​

• get obliquingAngle(): number

倾斜角度

Returns ​

number

• set obliquingAngle(val): void

Parameters ​

NameType
valnumber

Returns ​

void


textSize ​

• get textSize(): number

文字大小(高度)

Returns ​

number

• set textSize(val): void

Parameters ​

NameType
valnumber

Returns ​

void


xScale ​

• get xScale(): number

缩放因子大小

Returns ​

number

• set xScale(val): void

Parameters ​

NameType
valnumber

Returns ​

void

Methods ​

assertObjectModification ​

▸ assertObjectModification(autoUndo?): number

设置对象被改变的状态,可自动触发更新显示函数,更新显示。 比如块表记录更新了,需要通知块引用更新显示,可以调用该函数。

Parameters ​

NameTypeDefault valueDescription
autoUndobooleanfalse这次修改是否要自动支持撤销,默认为false

Returns ​

number

Inherited from ​

McDbObject.assertObjectModification


clone ​

▸ clone(): null | McDbObject

克隆对象。

Returns ​

null | McDbObject

克隆出的对象。

Inherited from ​

McDbObject.clone


createExtensionDictionary ​

▸ createExtensionDictionary(): boolean

创建对象的扩展字典数据.

Returns ​

boolean

Inherited from ​

McDbObject.createExtensionDictionary


erase ​

▸ erase(): boolean

删除对象。

Returns ​

boolean

是否删除成功。

Inherited from ​

McDbObject.erase


font ​

▸ font(): Object

获取字体样式

Returns ​

Object

sTypeface: 字体名称 | bold: 是否粗体 | italic: 是否斜体 | charset: 字符集 | pitchAndFamily: 字体间距和风格

NameType
boldboolean
charsetnumber
italicboolean
pitchAndFamilynumber
sTypefacestring

getDatabase ​

▸ getDatabase(): McDbDatabase

得到对象所在的数据库

Returns ​

McDbDatabase

返回数据库

Inherited from ​

McDbObject.getDatabase


getDatabaseIndexId ​

▸ getDatabaseIndexId(): number

获取对象的索引ID

Returns ​

number

Inherited from ​

McDbObject.getDatabaseIndexId


getExtensionDictionary ​

▸ getExtensionDictionary(): McDbDictionary

得到对象的扩展字典数据.

Returns ​

McDbDictionary

扩展字典数据

Inherited from ​

McDbObject.getExtensionDictionary


getGripEditBasePointsIndex ​

▸ getGripEditBasePointsIndex(): number[]

获取对象的夹点对应的编辑基点索引。

Returns ​

number[]

Inherited from ​

McDbObject.getGripEditBasePointsIndex


getGripPoints ​

▸ getGripPoints(): McGePoint3dArray

获取对象的夹点数组

Returns ​

McGePoint3dArray

Inherited from ​

McDbObject.getGripPoints


getHandle ​

▸ getHandle(): string

得到对象句柄

Returns ​

string

返回对象句柄

Inherited from ​

McDbObject.getHandle


getImp ​

▸ getImp(): any

获取内部实现对象。

Returns ​

any

内部实现对象。

Inherited from ​

McDbObject.getImp


getJson ​

▸ getJson(): string

获取 JSON 格式的字符串。

Returns ​

string

JSON 格式的字符串。

Inherited from ​

McDbObject.getJson


getObjectID ​

▸ getObjectID(): McObjectId

获取对象 ID。

Returns ​

McObjectId

对象 ID。

Inherited from ​

McDbObject.getObjectID


getOwnerID ​

▸ getOwnerID(): number

得到对象拥用者的id

Returns ​

number

Inherited from ​

McDbObject.getOwnerID


initTempObject ​

▸ initTempObject(imp): void

初始化临时对象。

Parameters ​

NameTypeDescription
impany内部实现对象。

Returns ​

void

Inherited from ​

McDbObject.initTempObject


isErased ​

▸ isErased(): boolean

对象是否已经删除

Returns ​

boolean

Inherited from ​

McDbObject.isErased


isHaveExtensionDictionary ​

▸ isHaveExtensionDictionary(): boolean

是否有扩展字典数据.

Returns ​

boolean

Inherited from ​

McDbObject.isHaveExtensionDictionary


isKindOf ​

▸ isKindOf(sObjectName): boolean

判断对象类型

Parameters ​

NameTypeDescription
sObjectNamestring类型名

Returns ​

boolean

返回对象是否是目标类型

Inherited from ​

McDbObject.isKindOf


isNull ​

▸ isNull(): any

判断是否为空对象

Returns ​

any

Inherited from ​

McDbObject.isNull


moveGripPointsAt ​

▸ moveGripPointsAt(iIndex, dXOffset, dYOffset, dZOffset): any

移动对象的夹点

Parameters ​

NameTypeDescription
iIndexnumber索引
dXOffsetnumberX轴偏移量
dYOffsetnumberY轴偏移量
dZOffsetnumberZ轴偏移量

Returns ​

any

Inherited from ​

McDbObject.moveGripPointsAt


setFont ​

▸ setFont(sTypeface, bold, italic, charset, pitchAndFamily): boolean

设置字体样式

Parameters ​

NameTypeDescription
sTypefacestring字体名称
boldboolean是否粗体
italicboolean是否斜体
charsetnumber字符集
pitchAndFamilynumber字体间距和风格

Returns ​

boolean

是否设置成功

Example

ts
import { McDbTextStyleTableRecord } from 'mxcad';

const newTextStyleRecord = new McDbTextStyleTableRecord();
// 设置字体
const typeface = "Arial"; // 字体名称
const isBold = true; // 是否粗体
const isItalic = false; // 是否斜体
const charset = 0; // 字符集
const pitchAndFamily = 0; // 字体间距和风格
const isSetFontSuccessful = newTextStyleRecord.setFont(typeface, isBold, isItalic, charset, pitchAndFamily);
// 检查设置是否成功
if (isSetFontSuccessful) {
 console.log("Font set successfully.");
} else {
 console.log("Failed to set font.");
}

setJson ​

▸ setJson(str): boolean

设置 JSON 格式的字符串。

Parameters ​

NameTypeDescription
strstringJSON 格式的字符串。

Returns ​

boolean

是否设置成功。

Inherited from ​

McDbObject.setJson


unErase ​

▸ unErase(): boolean

反删除对象。

Returns ​

boolean

Inherited from ​

McDbObject.unErase