使用AcGiTextStyle获得MTEXT的准确的宽度
void getTextStrWidth()
{
char str;
int rt = acedGetString(true, "/nEnter a string: ", str);
if (rt != RTNORM)
{
acutPrintf("/nInvalid input, try again.");
return;
}
AcGiTextStyle iStyle;
AcDbTextStyleTable* pTable = NULL;
AcDbTextStyleTableRecord* pRecord = NULL;
try {
ARXOK(curDoc()->database()->getTextStyleTable(pTable,
AcDb::kForRead));
const char styleName[] = "STANDARD";
ARXOK(pTable->getAt(styleName, pRecord, AcDb::kForRead));
ARXOK(fromAcDbTextStyle(iStyle, pRecord->objectId()));
pRecord->close();
pTable->close();
}
catch (const Acad::ErrorStatus es)
{
acutPrintf("/nError: %s", acadErrorStatusText(es));
pRecord->close();
pTable->close();
}
AcGePoint2d pt = iStyle.extents(str, Adesk::kFalse, _tcslen(str),
Adesk::kTrue);
// get the width
acutPrintf("/nText string width is: /t.", pt.x);
// get the height too
acutPrintf("/nText string height is: /t.", pt.y);
}
//declare the following inline function in a header file
inline void ARXOK(Acad::ErrorStatus what) throw(Acad::ErrorStatus)
{
if (what != Acad::eOk)
throw what;
}
页:
[1]