uusky 发表于 2005-9-7 16:59:00

CAD中的字体乱码问题?>

<P>void addtext(char textString)<BR>{<BR>&nbsp;<BR>&nbsp;AcDbBlockTable *pBlockTablew;<BR>&nbsp;acdbHostApplicationServices()-&gt;workingDatabase()-&gt;getSymbolTable(pBlockTablew, AcDb::kForRead);<BR>&nbsp;AcDbBlockTableRecord *pBlockTableRecordw;<BR>&nbsp;pBlockTablew-&gt;getAt(ACDB_MODEL_SPACE, pBlockTableRecordw, AcDb::kForWrite);<BR>&nbsp;pBlockTablew-&gt;close();</P>
<P><BR>&nbsp;AcGePoint3d textPosition(10.0, 10.0, 0.0);<BR>&nbsp;AcGePoint3d atextPosition(20.0, 10.0, 0.0);<BR>&nbsp;//char textString = "建设项目选址意见书&nbsp;&nbsp;&nbsp; 号红线附图";<BR>&nbsp;double textHeight = 5.5296;<BR>&nbsp;double textWidthFactor = 0.8000;<BR>&nbsp;double textRotation = 0.0;<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;AcDbText *pText=new AcDbText(<FONT color=#1111ee>textPosition, textString, AcDbObjectId::kNull, textHeight, textRotation</FONT>);<BR>&nbsp;pText-&gt;setHorizontalMode(AcDb::kTextMid);<BR>&nbsp;pText-&gt;setAlignmentPoint(atextPosition); <BR><FONT color=#e61a94>&nbsp;&nbsp;&nbsp;//???? pText-&gt;setTextStyle(1);//=HZTXT;</FONT></P>
<P>&nbsp;AcDbObjectId textId;<BR>&nbsp;pBlockTableRecordw-&gt;appendAcDbEntity(textId, pText); <BR>&nbsp;pBlockTableRecordw-&gt;close();<BR>&nbsp;pText-&gt;close();<BR>}</P>
<P>如上 &nbsp; 我在执行文字标注时 用到这个函数</P>
<P>AcDbText *pText=new AcDbText(textPosition, textString, AcDbObjectId::kNull, textHeight, textRotation);</P>
<P>结果文字是乱码,请问是不是AcDbObjectId::kNull这个变量需要改一下,我想字体设置成:HZTXT,怎么改?</P>

zyxc1981 发表于 2005-9-8 08:52:00

我帮你顶

uusky 发表于 2005-9-8 10:49:00

<P>共享一段mm给我的代码&nbsp;&nbsp; &nbsp;一起研究!</P>
<P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 50%"><FONT face=宋体>&nbsp;</P>
<P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%">&nbsp; AcDbDatabase *pDb = acdbHostApplicationServices()-&gt;workingDatabase ();<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></P>
<P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AcDbBlockTable *pBT;<o:p></o:p></P>
<P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AcDbBlockTableRecord *pBTR;<o:p></o:p></P>
<P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Acad::ErrorStatus&nbsp; es; //打开数据库-&gt;块表-&gt;块表记录 <o:p></o:p></P>
<P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 31.5pt; LINE-HEIGHT: 150%">es = pDb-&gt;getBlockTable (pBT,AcDb::kForRead );<o:p></o:p></P>
<P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 31.5pt; LINE-HEIGHT: 150%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // ERROR HANDLE<o:p></o:p></P>
<P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 31.5pt; LINE-HEIGHT: 150%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; es = pBT-&gt;getAt (ACDB_MODEL_SPACE,pBTR,AcDb::kForWrite );<o:p></o:p></P>
<P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 31.5pt; LINE-HEIGHT: 150%"><o:p></o:p></P>
<P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 31.5pt; LINE-HEIGHT: 150%">//get the standard text style<o:p></o:p></P>
<P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 31.5pt; LINE-HEIGHT: 150%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AcDbTextStyleTable *pTST;<o:p></o:p></P>
<P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 31.5pt; LINE-HEIGHT: 150%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AcDbTextStyleTableRecord *pTSTR;<o:p></o:p></P>
<P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 31.5pt; LINE-HEIGHT: 150%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; es = pDb-&gt;getTextStyleTable (pTST,AcDb::kForRead );<o:p></o:p></P>
<P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 31.5pt; LINE-HEIGHT: 150%">//文字样式表-〉文字样式表记录-〉打开记录读取<o:p></o:p></P>
<P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 32.25pt; LINE-HEIGHT: 150%">AcDbObjectId idTextStyle;<o:p></o:p></P>
<P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 32.25pt; LINE-HEIGHT: 150%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; es = pTST-&gt;getAt("Standard",idTextStyle);<o:p></o:p></P>
<P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 32.25pt; LINE-HEIGHT: 150%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; es = pTST-&gt;getAt("Standard",pTSTR,AcDb::kForWrite );<o:p></o:p></P>
<P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 32.25pt; LINE-HEIGHT: 150%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pTSTR-&gt;setFileName("iso");//<o:p>****</o:p>
<P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 32.25pt; LINE-HEIGHT: 150%"><o:p></o:p></P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(es != Acad::eOk){<o:p></o:p>
<P></P>
<P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 32.25pt; LINE-HEIGHT: 150%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; acutPrintf("fail to get the standard text style\n");<o:p></o:p></P>
<P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 32.25pt; LINE-HEIGHT: 150%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<o:p></o:p></P>
<P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 32.25pt; LINE-HEIGHT: 150%"><o:p></o:p></P>
<P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 32.25pt; LINE-HEIGHT: 150%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //es = acdbOpenObject(pEnt,idTextStyle,AcDb::kForRead );<o:p></o:p></P>
<P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 32.25pt; LINE-HEIGHT: 150%"><o:p></o:p></P>
<P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 32.25pt; LINE-HEIGHT: 150%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AcDbMText *pText = new AcDbMText();<o:p></o:p></P>
<P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 32.25pt; LINE-HEIGHT: 150%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pText-&gt;setLocation (AcGePoint3d(10,10,0));<o:p></o:p></P>
<P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 32.25pt; LINE-HEIGHT: 150%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pText-&gt;setTextStyle (idTextStyle);<o:p></o:p></P>
<P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 32.25pt; LINE-HEIGHT: 150%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pText-&gt;setRotation (0.5);<o:p></o:p></P>
<P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 32.25pt; LINE-HEIGHT: 150%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pText-&gt;setContents ("\\T1.2;this is only simple char");<o:p></o:p></P>
<P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 32.25pt; LINE-HEIGHT: 150%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pText-&gt;setColorIndex (1);<o:p></o:p></P>
<P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 32.25pt; LINE-HEIGHT: 150%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AcDbObjectId idTxt = AcDbObjectId::kNull ;<o:p></o:p></P>
<P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 32.25pt; LINE-HEIGHT: 150%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pBTR-&gt;appendAcDbEntity(idTxt,pText);<o:p></o:p></P>
<P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 32.25pt; LINE-HEIGHT: 150%"><o:p></o:p></P>
<P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 32.25pt; LINE-HEIGHT: 150%">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;pText-&gt;close();//文本对象<o:p></o:p></P>
<P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 32.25pt; LINE-HEIGHT: 150%">pBTR-&gt;close();//块表记录<o:p></o:p></P>
<P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 32.25pt; LINE-HEIGHT: 150%">pBT-&gt;close();//块表 &nbsp;&nbsp;&nbsp;&nbsp;<o:p></o:p></P>
<P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 32.25pt; LINE-HEIGHT: 150%">pTST-&gt;close();//文字样式表<o:p></o:p></P>
<P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 32.25pt; LINE-HEIGHT: 150%">pTSTR-&gt;close();//文字样式表记录<o:p></o:p></P>
<P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 50%"></FONT></P>

wuddy 发表于 2005-9-8 10:58:00

<P>首先应该看看有没有缺少字体文件,然后考虑文字样式的设置问题</P>

uusky 发表于 2005-9-8 14:19:00

本帖最后由 作者 于 2005-9-8 14:39:36 编辑 <br /><br /> <P>楼上说的对&nbsp; 我的问题解决了,按照上个程序,设置字体如下:</P>
<P>es = pTST-&gt;getAt("Standard",pTSTR,AcDb::kForWrite );&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;pTSTR-&gt;setFileName("HZTXT");</P>
<P>然后在CAD中输入:style</P>
<P>新建一个字体样式:HZTXT</P>
<P>选中大字体,然后选中txt.shx,后面选中:hztxt </P>
<P>运行一下,一切OK!!!(附上字体文件)</P>
页: [1]
查看完整版本: CAD中的字体乱码问题?>