|
arx07中的AcDbMText类中增加了函数height()和setHeight()
用于获取和设置多行文字的高度(注意不是文字高度)
但是arx06及以下版本却没有提供,但是这是多行文字一个很常用属性。
通过查询扩展属性发现多行文字的高度是存储在扩展属性里面的
这就简单了,我们可以通过读取和设置扩展属性来修改多行文字的高度。
//获取多行文字高度,注意不是文字高度
double GetMTextHeight(AcDbMText* pText)
{
#if _MSC_VER>=1400
return pText->height();
#else
struct resbuf* rb=pText->xData(_T(“ACAD”));
struct resbuf* rbIter=rb;
while(rbIter!=NULL)
{
if(rbIter->restype==AcDb::kDxfXdAsciiString&&
lstrcmpi(rbIter->resval.rstring,_T(“ACAD_MTEXT_DEFINED_HEIGHT_BEGIN”))==0)
{
rbIter=rbIter->rbnext;
break;
}
rbIter=rbIter->rbnext;
}
if(rbIter==NULL)
{
acutRelRb(rb);
return 0.0;
}
double dHeight=0.0;
while(rbIter!=NULL)
{
if(rbIter->restype==kDxfXdReal)
{
dHeight=rbIter->resval.rreal;
rbIter=rbIter->rbnext;
break;
}
rbIter=rbIter->rbnext;
}
if(rbIter==NULL)
{
acutRelRb(rb);
return 0.0;
}
while(rbIter!=NULL)
{
if(rbIter->restype==AcDb::kDxfXdAsciiString&&
lstrcmpi(rbIter->resval.rstring,_T(“ACAD_MTEXT_DEFINED_HEIGHT_END”))==0)
{
acutRelRb(rb);
return dHeight;
}
rbIter=rbIter->rbnext;
}
acutRelRb(rb);
return 0.0;
#endif
}
//设置多行文字高度,注意不是文字高度
Acad::ErrorStatus SetMTextHeight(AcDbMText* pText,double dHeight)
{
#if _MSC_VER>=1400
return pText->setHeight(dHeight);
#else
struct resbuf* rb=pText->xData(_T(“ACAD”));
struct resbuf* rbIter=rb;
while(rbIter!=NULL)
{
if(rbIter->restype==AcDb::kDxfXdAsciiString&&
lstrcmpi(rbIter->resval.rstring,_T(“ACAD_MTEXT_DEFINED_HEIGHT_BEGIN”))==0)
{
rbIter=rbIter->rbnext;
break;
}
rbIter=rbIter->rbnext;
}
if(rbIter==NULL)
{
acutRelRb(rb);
return Acad::eInvalidInput;
}
while(rbIter!=NULL)
{
if(rbIter->restype==kDxfXdReal)
{
rbIter->resval.rreal=dHeight;
rbIter=rbIter->rbnext;
break;
}
rbIter=rbIter->rbnext;
}
if(rbIter==NULL)
{
acutRelRb(rb);
return Acad::eInvalidInput;
}
while(rbIter!=NULL)
{
if(rbIter->restype==AcDb::kDxfXdAsciiString&&
lstrcmpi(rbIter->resval.rstring,_T(“ACAD_MTEXT_DEFINED_HEIGHT_END”))==0)
{
pText->setXData(rb);
acutRelRb(rb);
return Acad::eOk;
}
rbIter=rbIter->rbnext;
}
acutRelRb(rb);
return Acad::eInvalidInput;
#endif
} |
|