|
- AcDbObjectId GetTextstyleId(CString sTextstylename)
- {
- AcDbTextStyleTable *pTable;
- AcDbObjectId textstyleId = AcDbObjectId::kNull;
- Acad::ErrorStatus es = Acad::eOk;
- if ((es = acdbHostApplicationServices()->workingDatabase()->getTextStyleTable(pTable, AcDb::kForRead)) == Acad::eOk){
- if ((es =pTable->getAt(sTextstylename, textstyleId, Adesk::kFalse)) != Acad::eOk){
- textstyleId =AcDbObjectId::kNull;
- }
- pTable->close();
- }
- return textstyleId;
- }
- double GetTextWidth(CString sText, CString sTextStyle, double dTextHeight)
- {
- AcDbObjectId idTextStyle = GetTextstyleId(sTextStyle);
- AcGiTextStyle giTextStyle;
- fromAcDbTextStyle(giTextStyle, idTextStyle);
- giTextStyle.setTextSize(dTextHeight);
- AcGePoint2d ptExt = giTextStyle.extents(sText.GetBuffer(), Adesk::kFalse, sText.GetLength(), Adesk::kFalse);
- return ptExt.x;
- }
- OR
- double GetTextWidth(AcDbObjectId idText)
- {
- ads_point ptLowerLeft, ptUpperRight;
- ads_name ent;
- struct resbuf * textent;
- acdbGetAdsName(ent, idText);
- textent = acdbEntGet(ent);
- acedTextBox(textent, ptLowerLeft, ptUpperRight);
- //acutPrintf("\nHeight: %.2f, Width: %.2f", ptUpperRight - ptLowerLeft, ptUpperRight - ptLowerLeft);
- return ptUpperRight - ptLowerLeft;
- }
复制代码 |
|