CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ObjectARX 开发指南

发短信

2022-12-31 15:12| 发布者: admin| 查看: 330| 评论: 0|来自: AutoCAD

本节中的示例显示了类的用法。它围绕一段 AcGi 文本绘制一个矩形,该文本可以定向并位于空间中的任何位置。AcGiTextStyle

文本的法线向量和方向向量必须彼此垂直。如果不确定方向,请考虑在右手坐标系中沿X轴方向和沿Z轴的法线方向。从这些计算Y轴。然后Y轴到Z轴的交叉乘积将为您提供法线平面对方向的解释。确保方向未与法线对齐,否则您将没有相对于法线的方向。

该函数加载字体(如果尚未加载)。(此函数不加载 ACAD 样式。其返回值如下:AcGiTextStyle::loadStyleRec()

0x10

打开另一个文件(不是 FONTALT)代替 -BigFont 文件名

0x08

打开另一个文件(不是 FONTALT)来代替文件名

0x04

无法加载大字体文件名

0x02

文件名加载失败

0x01

根据需要打开的文件

可以通过多种方式缩放文本。用于同时缩放文本的宽度和高度。用于缩放文本的宽度。用于指定特定字体的字符如何彼此相邻放置。如果指定值 1.0,则间距不会更改;如果指定小于 1.0,字符将挤在一起;如果超过 1.0,字符之间的距离会更远。本示例将跟踪百分比设置为值 .80。AcGiTextStyle::setTextSize()setXScale()setTrackingPercent()

该函数返回文本边界框的世界坐标大小。如果参数是,则在用户绘制文本时所做的任何未绘制的笔移动都将包含在边界框中。该选项告诉计算忽略转义代码处理(以便“%%%”不会被解释为单个百分号,而是解释为百分之三)。在调用函数之前,必须调用 loadStyleRec() 以将任何最近的样式更改加载到图形系统中。AcGiTextStyle::extents()penupskTruerawextents()AcGiTextStyle::

下面的示例绘制文本,然后在文本的一部分周围绘制一个边界框。

 Adesk::Boolean 
      AsdkTextStyleSamp::subWorldDraw(AcGiWorldDraw* pW)     
 { 
 AcGePoint3d pos(4.0, 4.0, 0.0); 
 AcGeVector3d norm(0.0, 0.0, 1.0); 
      AcGeVector3d dir(-1.0, -       0.2, 0.0);     
 TCHAR *pStr = _T("This is a percent, '%%%'."); 
 int len = _tcslen(pStr); 
 AcGiTextStyle style; 
  
      AcGeVector3d vec = norm;     
      vec       = vec.crossProduct(dir);     
 dir = vec.crossProduct(norm); 
  
 style.setFileName(_T("txt.shx")); 
      style.setBigFontFileName(_T(""));     
      int       status;     
 if (!((status = style.loadStyleRec()) & 1)) 
 pStr = _T("Font not found."); 
  
      pW->geometry().text(pos, norm, dir, pStr,       len,     
      Adesk::kFalse, style);     
  
 pos.y += 2.0; 
  
 style.setTrackingPercent(0.8); 
 style.setObliquingAngle(0.5); 
  
      // You must call loadStyleRec() again after       changing     
 // the style's properties in order for the current style 
 // settings to be loaded into the graphics system. 
      // Otherwise, the extents       calculation may be incorrect.     
 // 
 style.loadStyleRec(); 
 AcGePoint2d ext = style.extents(pStr, Adesk::kFalse, 
 _tcslen(pStr), Adesk::kFalse); 
  
      pW->geometry       ().text(pos, norm, dir, pStr, len,     
 Adesk::kFalse, style); 
  
 // Draw a rectangle around the last text drawn. 
      // First you have to create a polyline the       size of the     
 // bounding box, then you have to transform it to the 
 // correct orientation, and then to the location of the 
 // text. 
  
      // Compute the       matrix that orients the box.     
 // 
 AcGeMatrix3d textMat; 
 norm.normalize(); 
 dir.normalize(); 
 AcGeVector3d yAxis = norm; 
 yAxis = yAxis.crossProduct(dir); 
      yAxis.normalize();     
 textMat.setCoordSystem(AcGePoint3d(0.0, 0.0, 0.0), dir, 
 yAxis, norm); 
  
 // Create the bounding box and enlarge it somewhat. 
 // 
      double offset =       ext.y / 2.0;     
 AcGePoint3d verts[5]; 
 verts[0] = verts[4] = AcGePoint3d(-offset, -offset, 0.0); 
 verts[1] = AcGePoint3d(ext.x + offset, -offset, 0.0); 
      verts[2] =       AcGePoint3d(ext.x + offset, ext.y + offset, 0.0);     
 verts[3] = AcGePoint3d(-offset, ext.y + offset, 0.0); 
  
      // Orient and then translate each point in       the     
      // bounding box.     
 // 
 for (int i = 0; i < 5; i++) { 
 verts[i].transformBy(textMat); 
 verts[i].x += pos.x; 
 verts[i].y += pos.y; 
      verts[i].z += pos.z;     
      }     
      pW-       >geometry().polyline(5, verts);     
  
 return Adesk::kTrue; 

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-5-19 13:21

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部