ObjectARX学习笔记(二十五)---如何在两个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::ErrorStatus  bEs = 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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值