libdxfrw项目中dxf2text命令可以抽取dwg文件中的文字部分,编译完工程后对手头上的dwg文件提取时发现抽取不完整,对源码进行分析时发现该命令只处理了text部分,不处理mtext部分
bool dx_iface::printText(const std::string& fileI, dx_data *fData){
unsigned int found = fileI.find_last_of(".");
std::string fileExt = fileI.substr(found+1);
std::transform(fileExt.begin(), fileExt.end(),fileExt.begin(), ::toupper);
cData = fData;
currentBlock = cData->mBlock;
bool success = false;
if (fileExt == "DXF"){
//loads dxf
dxfRW* dxf = new dxfRW(fileI.c_str());
success = dxf->read(this, false);
delete dxf;
} else if (fileExt == "DWG"){
//loads dwg
dwgR* dwg = new dwgR(fileI.c_str());
success = dwg->read(this, false);
delete dwg;
}
if (success) {
for (std::list<DRW_Entity*>::const_iterator it =
cData->mBlock->ent.begin(); it != cData->mBlock->ent.end();
++it) {
DRW_Entity* e = *it;
switch (e->eType) {
case DRW::TEXT:
std::cout << static_cast<DRW_Text*>(e)->text << std::endl;
break;
default:
break;
}
}
}
return success;
}