cad中的字体乱码问题?>
cad中的字体乱码问题?>
void addtext(char textstring[512])
{
acdbblocktable *pblocktablew;
acdbhostapplicationservices()->workingdatabase()->getsymboltable(pblocktablew, acdb::kforread);
acdbblocktablerecord *pblocktablerecordw;
pblocktablew->getat(acdb_model_space, pblocktablerecordw, acdb::kforwrite);
pblocktablew->close();
acgepoint3d textposition(10.0, 10.0, 0.0);
acgepoint3d atextposition(20.0, 10.0, 0.0);
//char textstring[512] = "建设项目选址意见书[5字] 号红线附图";
double textheight = 5.5296;
double textwidthfactor = 0.8000;
double textrotation = 0.0;
acdbtext *ptext=new acdbtext(textposition, textstring, acdbobjectid::knull, textheight, textrotation);
ptext->sethorizontalmode(acdb::ktextmid);
ptext->setalignmentpoint(atextposition);
//???? ptext->settextstyle(1);//=hztxt;
acdbobjectid textid;
pblocktablerecordw->appendacdbentity(textid, ptext);
pblocktablerecordw->close();
ptext->close();
}
如上 我在执行文字标注时 用到这个函数
acdbtext *ptext=new acdbtext(textposition, textstring, acdbobjectid::knull, textheight, textrotation);
结果文字是乱码,请问是不是acdbobjectid::knull这个变量需要改一下,我想字体设置成:hztxt,怎么改?
我帮你顶
共享一段mm给我的代码 一起研究!
acdbdatabase *pdb = acdbhostapplicationservices()->workingdatabase ();
acdbblocktable *pbt;
acdbblocktablerecord *pbtr;
acad::errorstatus es; //打开数据库->块表->块表记录
es = pdb->getblocktable (pbt,acdb::kforread );
// error handle
es = pbt->getat (acdb_model_space,pbtr,acdb::kforwrite );
//get the standard text style
acdbtextstyletable *ptst;
acdbtextstyletablerecord *ptstr;
es = pdb->gettextstyletable (ptst,acdb::kforread );
//文字样式表-〉文字样式表记录-〉打开记录读取
acdbobjectid idtextstyle;
es = ptst->getat("standard",idtextstyle);
es = ptst->getat("standard",ptstr,acdb::kforwrite );
ptstr->setfilename("iso");//****
if(es != acad::eok){
acutprintf("fail to get the standard text style\n");
}
//es = acdbopenobject(pent,idtextstyle,acdb::kforread );
acdbmtext *ptext = new acdbmtext();
ptext->setlocation (acgepoint3d(10,10,0));
ptext->settextstyle (idtextstyle);
ptext->setrotation (0.5);
ptext->setcontents ("
\\t1.2;this is only simple char");
ptext->setcolorindex (1);
acdbobjectid idtxt = acdbobjectid::knull ;
pbtr->appendacdbentity(idtxt,ptext);
ptext->close();//文本对象
pbtr->close();//块表记录
pbt->close();//块表
ptst->close();//文字样式表
ptstr->close();//文字样式表记录
首先应该看看有没有缺少字体文件,然后考虑文字样式的设置问题
楼上说的对 我的问题解决了,按照上个程序,设置字体如下:
es = ptst->getat("standard",ptstr,acdb::kforwrite );
ptstr->setfilename("hztxt");
然后在cad中输入:style
新建一个字体样式:hztxt
选中大字体,然后选中txt.shx,后面选中:hztxt
运行一下,一切ok!!!(附上字体文件)