static void DrawZValue( AcGiWorldDraw* mode, double z, const AcGePoint3d& tpt, double angle, double height ) { AcGeVector3d v( AcGeVector3d::kXAxis ); v.rotateBy( angle, AcGeVector3d::kZAxis ); if( v.x < 0 ) { angle += PI; } CString text; text.Format( _T( " %.5f " ), z ); AcDbMText mt; mt.setLocation( tpt ); mt.setTextHeight( height ); mt.setAttachment( AcDbMText::kMiddleCenter ); mt.setRotation( angle ); mt.setBackgroundFill( true ); mt.setUseBackgroundColor( true ); mt.setBackgroundScaleFactor( 1.0 ); mt.setContents( text ); // 经过测试发现,AcDbMText调用worldDraw的同时会修改mode的一些属性 mt.setColorIndex( mode->subEntityTraits().color() ); mt.worldDraw( mode ); }
void DrawMText( AcGiWorldDraw* mode, const AcGePoint3d& pt, double angle, const CString& str, double height, AcDbMText::AttachmentPoint ap, const CString& style ) { //acutPrintf(_T("\n绘制前--文字颜色:%d"), mode->subEntityTraits().color()); AcDbMText mt; // //AcDbObjectId style; // 文字样式 AcDbObjectId fontId = GetTextStyle(style); if(!fontId.isNull()) { acutPrintf(_T("\n设置样式为罗马字体")); mt.setTextStyle(fontId); } mt.setLocation( pt ); mt.setTextHeight( height ); mt.setAttachment( ap ); mt.setRotation( angle ); mt.setContents( str ); // 经过测试发现,AcDbMText调用worldDraw的同时会修改mode的一些属性 mt.setColorIndex( mode->subEntityTraits().color() ); mt.worldDraw( mode ); //acutPrintf(_T("\n绘制后--文字颜色:%d"), mode->subEntityTraits().color()); }
static void GetTextAndWidth( double z, double height, CString& text, double& width ) { AcDbMText mt; mt.setLocation( AcGePoint3d::kOrigin ); mt.setRotation( 0 ); mt.setTextHeight( height ); mt.setAttachment( AcDbMText::kMiddleCenter ); // 默认居中 // 获取文字内容 text.Format( _T( " %.3f " ), z ); mt.setContents( text ); // 获取文字宽度 width = mt.actualWidth(); }