查看单个帖子
旧 2009-05-06, 02:45 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】how to get the extent of a text string in dwgdirec

how to get the extent of a text string in dwgdirect?
how to get the extent of a text string in dwgdirect?
in arx, we can get the extent of a text string by acgitextstyle::extents function. but in dwgdirect, the odgitextstyle class don't have a similar one;
i tried to calculate the text string extent with the od*gi*fast*ext*calc class,
but cann't create an instance of this class.
the following is the introduction of fuctiong extents in arx;
virtual acgepoint2d extents(const char* pstr, const adesk::boolean penups,
const int len, const adesk::boolean raw,
acgiworlddraw * ctxt = null) const;
pstr input a pointer to a text string for which the extents are to be determined
penups input boolean indicating if leading and trailing spaces are to be included
len input text string length or -1 to indicate null-terminated string
raw input boolean indicating if the autocad escape sequences are to be interpreted
ctxt input pointer to acgiworlddraw; if null, the autocad default regen pipeline is used to calculate extents
this function provides the means to find out the extents of the text string pstr when using the acgitextstyle.
if penups is adesk::ktrue, then any leading and trailing spaces is included in the extents calculation.
a value of -1 for len indicates that the string is null-terminated. any other value is interpreted as the length of the string pointed to by pstr and only that many characters are used. len must not be larger than the length of the string.
if raw is adesk::ktrue, then any autocad escape sequences in the string (such as %%u, %%d, %%p, and %%nnn) are left as is and not interpreted.
note in object dbx, you must create a valid acgiworlddraw and pass it in to this function in the ctxt argument for the extent calculation to work.
the returned acgepoint2d contains the text's extents. the x member is the width of the text, the y is the height.
thanks;
quote:
originally posted by ccli
i tried to calculate the text string extent with the od*gi*fast*ext*calc class,
but cann't create an instance of this class.
try to use next code
code:
odstaticrxobject<odgifastextcalc> drawobj;
odstaticrxobject<odgicontextfordbdatabase> gicontext;
drawobj.setcontext(&gicontext);
drawobj.text(...);
odgeextents3d extents;
drawobj.getextents(extents);
best regards,
sergey z.
thank you very much!
i have got the text extents with your recommended codes;
but there is another question, i cann't set the scale of x axis!
the scale which is setted by the setxscale function, has no effect with
the text extent; the following is the code;
odgitextstyle textstyle;
odgeextents3d textextents;
odstaticrxobject<odgifastextcalc> drawobj;
odstaticrxobject<odgicontextfordbdatabase> gicontext;
drawobj.setcontext(&gicontext);
textstyle.setxscale(textstyle.xscale() * (dwidth / dactwidth));
drawobj.text(ptpos,odgevector3d::kzaxis,odgevector 3d::kxaxis,
lpctstr(stext),-1, false,&textstyle);
drawobj.getextents(textextents);
ptsize.x = textextents.maxpoint().x - textextents.minpoint().x;
ptsize.y = textextents.maxpoint().y - textextents.minpoint().y;
thanks;
quote:
originally posted by ccli
but there is another question, i cann't set the scale of x axis!
the scale which is setted by the setxscale function, has no effect with
the text extent; the following is the code;
are you sure what (dwidth / dactwidth) is not equal 1.0?
i try to call textstyle.setxscale(2.0) and (textextents.maxpoint().x - textextents.minpoint().x) value is changed ( x 2.0 as compared with xscale 1.0 ).
best regards,
sergey z.
quote:
originally posted by sergey z.
are you sure what (dwidth / dactwidth) is not equal 1.0?
i try to call textstyle.setxscale(2.0) and (textextents.maxpoint().x - textextents.minpoint().x) value is changed ( x 2.0 as compared with xscale 1.0 ).
yes,i'm sure. in my aplication, what (dwidth / dactwidth) is less than 1.0;
at last, i solved this problem with:
ptsize.x = textextents.maxpoint().x - textextents.minpoint().x;
ptsize.x = ptsize.x * textstyle.xscale();
thanks.
hello,
you need call drawobj.resetextents() befor second call calculate extents (drawobj.text(..)).
best regards,
sergey z.
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)