如何在两个dwg里面拷贝字体样式表AcGiTextStyle ,AcDbTextStyleTableRecord
//两个dwg拷贝字体信息bool CopyTextStyleIdInfo(AcDbDatabase *pFromDataSrc/*in*/,AcDbDatabase *pToDataDes/*in*/)
{
if (pFromDataSrc == NULL || pToDataDes == NULL)
return false;
AcDbTextStyleTable *pStyleTable = NULL;
Acad::ErrorStatus es = Acad::eOk;
es = pFromDataSrc->getSymbolTable(pStyleTable,AcDb::kForRead);
if (es != Acad::eOk)
return false;
AcDbTextStyleTableIterator *pIterator = NULL;
es = pStyleTable->newIterator(pIterator);
if (es != Acad::eOk)
{
pStyleTable->close();
pStyleTable = NULL;
return false;
}
for (pIterator->start();!pIterator->done();pIterator->step())
{
AcDbObjectId styleId = AcDbObjectId::kNull;
if ((es = pIterator->getRecordId(styleId)) == Acad::eOk)
{
AcGiTextStyle *pTextStyle=new AcGiTextStyle(pToDataDes);
if((es =fromAcDbTextStyle(*pTextStyle,styleId)) == Acad::eOk )
{
AcDbTextStyleTableRecord* pNewRec = new AcDbTextStyleTableRecord;
setSymbolName(pNewRec,pTextStyle->styleName());
pNewRec->setFileName(pTextStyle->fileName());
/*待完善*/
ACHAR * pTypeface = NULL;
Adesk::Boolean bold;
Adesk::Boolean italic;
int charset;
int pitchAndFamily;
es = pTextStyle->font(pTypeface,bold,italic,charset,pitchAndFamily);
if (es == Acad::eOk)
pNewRec->setFont(pTypeface,bold,italic,charset,pitchAndFamily);
pNewRec->setBigFontFileName(_T(""));// must explicitly set to ""
pNewRec->setTextSize(pTextStyle->textSize());
pNewRec->setObliquingAngle(pTextStyle->obliquingAngle());
pNewRec->setXScale(pTextStyle->xScale());
addToSymbolTableAndClose(pNewRec,pToDataDes);
}
if (pTextStyle != NULL)
{
delete pTextStyle;
pTextStyle = NULL;
}
}
}
if (pIterator != NULL)
{
delete pIterator;
pIterator = NULL;
pStyleTable->close();
pStyleTable = NULL;
}
return true;
}
//添加文字样式块表记录
BOOL addToSymbolTableAndClose(AcDbSymbolTableRecord* systemTextRec/*in*/,AcDbDatabase *pDataBase/*in*/)
{
if (pDataBase == NULL || systemTextRec == NULL)
return FALSE;
AcDbTextStyleTable* symTextTbl = NULL;
Acad::ErrorStatus es = Acad::eOk;
es = pDataBase->getTextStyleTable(symTextTbl, AcDb::kForWrite);
if (es != Acad::eOk)
{
if (systemTextRec != NULL)
{
delete systemTextRec;
systemTextRec = NULL;
}
return FALSE;
}
AcDbSymbolTable *pSysRec = AcDbTextStyleTable::cast(symTextTbl);
//覆盖字体样式
es = pSysRec->add(systemTextRec);
if (es != Acad::eOk )
{
symTextTbl->close();
systemTextRec->close();
return FALSE;
}
else
{
systemTextRec->close();
symTextTbl->close();
}
return TRUE;
}
BOOL setSymbolName(AcDbSymbolTableRecord* newRec, LPCTSTR newName)
{
Acad::ErrorStatus es;
es = newRec->setName(newName);
if (es != Acad::eOk) {
newRec->close();
}
return(es);
}
//返回实体所在图层颜色
Adesk::UInt16 getColorIndexByLayer(Adesk::UInt16 icolorIndex,CString lyname,AcDbDatabase *pDb)
{
if (pDb == NULL)
return 7;
Adesk::UInt16 iclorIndexResult = 0;
Acad::ErrorStatusbEs = Acad::eOk;
if (icolorIndex == 256) //随层
{
AcDbLayerTable *pDbLy;
bEs = pDb->getLayerTable(pDbLy,AcDb::kForRead);
if (bEs == Acad::eOk)
{
Adesk::Boolean es=pDbLy->has(lyname);
if (es)
{
AcDbLayerTableRecord *pLayerTblRcd;
bEs = pDbLy->getAt(lyname,(AcDbLayerTableRecord*&)pLayerTblRcd, AcDb::kForRead);
if (bEs == Acad::eOk)
{
AcCmColor color = pLayerTblRcd->color();
iclorIndexResult = color.colorIndex();
pLayerTblRcd->close();
}
}
pDbLy->close();
}
}
else if(icolorIndex == 0) //随块
{
;//待完善
}
else
{
iclorIndexResult = icolorIndex;
}
return iclorIndexResult;
}
页:
[1]