|
- 在AutoCAD中,经常需要在一个创建一个文字实体之前,先要计算出它根据字体样式,字高和宽高比在图纸中所占的宽度,比如在一大段文字排版的时候很有用。于是整理封装了一下这个函数:
- double YgxGeometry::TextLength(LPCSTR str, double h, double wr)
- {
- if(strlen(str) == 0) return(0.);
- struct resbuf *list = NULL;
- ads采用point bl,rt;
- char styleName[31] = {0};
- YgxAu()->CurrTextStyle(styleName);
- list = acutBuildList(RTDXF0,"text",1,str,7,styleName,40,h,41,wr,51,0.,NULL);
- acedTextBox(list,bl,rt);
- acutRelRb(list);
- return fabs(bl[0]-rt[0]);
- }
- 其中YgxAu()->CurrTextStyle(styleName)是得到当前字体样式,函数如下:
- view plaincopy to clipboardprint?
- void YgxAcadUtil::CurrTextStyle(char styleName[])
- {
- AcDbObjectId Id = CurrDB()->textstyle();
- AcDbTextStyleTableRecord* pStyleRecord;
- if(acdbOpenObject((AcDbObject *&)pStyleRecord, Id, AcDb::kForRead) == Acad::eOk) {
- const char *name;
- pStyleRecord->getName(name);
- strcpy(styleName, name);
- pStyleRecord->close();
- }
- else strcpy(styleName, "STANDARD");
- }
- 其中CurrDB()就是得到当前数据库,acdbHostApplicationServices()->workingDatabase();
复制代码 |
|