Computes the width and height of the specified string of text.

syntaxSyntax:
DlxTextStyle.GetTextBounds(text)

Parameters

Parameter Description
text The text string.

Return Value

If the operation ends successfully, it returns a DlxRect object with the text bounding rectangle otherwise it returns an empty DlxRect.

Remarks

When this function returns the text extent, it assumes that the text is horizontal.

Example

  Copy codeCopy code
var prj = DlxApp.GetJob().GetProject("Example Sch");
if (!prj.IsValid())
  prj = DlxApp.GetJob().NewProject("Example Sch");
var doc = prj.GetDocument("Examples Sch", DlxApp.DOCTYPE_SCHEMATIC);
if (!doc.IsValid())
{
  doc = prj.NewDocument("Examples Sch", DlxApp.DOCTYPE_SCHEMATIC);
  doc.SetPageFormat("A4", false);
}
if (doc.IsValid() && doc.Activate())
{
  var page = doc.GetActivePage();
  if (page.IsValid())
  {
    var layer = page.GetLayerFromType(DlxApp.LAYERTYPE_DRAWING);
    if (layer.IsValid())
    {
      var fontstyle = new DlxFontStyle("arial", 30, DlxApp.FONTSTYLE_BOLD, DlxApp.FONTUNIT_POINT);
      var textstyle = new DlxTextStyle(fontstyle, "blue");

      var box = textstyle.GetTextBounds("Hello World.");
      box.Offset(50-box.Width()/2, 50-box.Height()/2);
      box.Inflate(5, 5);

      doc.SetStyle(new DlxPenStyle(0.5, "Blue"));
      doc.SetStyle(new DlxBrushStyle("orange"));
      layer.DrawRectangle(box, 0, 30, 30, 30, 30);

      doc.SetStyle(textstyle);
      layer.DrawText(box.CenterPoint(), "Hello World.", 0, DlxApp.TEXTFLAGS_ALIGNMIDDLECENTER);  
    }
  }
}

See also