Article | 70002655 |
Type | HowTo |
Product | WebJS |
Version | 1103 |
Date Added | 3/19/2025 12:00:00 AM |
Fixed | 11.4.2 (3/19/2025 12:00:00 AM) |
Submitted by | Brendan Fry |
Summary
How to get the actual height width of a text object in javascript webcontrol
Solution
You can get the box of a text by text property tb , in font's style plane and transform it to the drawing world co-ordinate system by the text object property EcsMatrix
In order to ensure the tb and EcsMatrix you must call the vdcanvas.GetEntityBBox for the text object and after use them
see following example
var txt = vdcanvas.AddText("VectorDraw Text box", 1, [0, 0, 0], vdConst.VdConstHorJust_VdTextHorLeft, vdConst.VdConstVerJust_VdTextVerBaseLine, vdgeo.HALF_PI * 0.5); vdcanvas.GetEntityBBox(txt); //ensure that you get the Bounding box of the text so the .tb (text box in font's style plane will be calculated) //read text box var textbox = txt.tb; var left = textbox[0]; var right = textbox[1]; var bottom = textbox[2]; var top = textbox[3]; //add a rect equal to the text box var rc = vdcanvas.AddRect2([left, bottom, 0], right - left, top - bottom, 0); //transform the rect from font's plane to the drawing world plane vdgeo.matrixtransformEntity(txt.EcsMatrix, rc, vdcanvas); //post a redraw setTimeout(vdcanvas.redraw); //Note if you want to get width and height only with out using AddRect see following var scale = txt.Height / txt.StyleRef.FontFileVDS.Ascent; var width = (right - left) * scale; var height = (top - bottom) * scale;