Computes the width and height of the specified string of text.
![]() |
---|
DlxFontStyle.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
![]() |
|
---|---|
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 font = new DlxFontStyle("arial", 10, DlxApp.FONTSTYLE_BOLD, DlxApp.FONTUNIT_POINT);
var box = font.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);
var style = new DlxTextStyle(font, "blue");
doc.SetStyle(style);
layer.DrawText(box.CenterPoint(), "Hello World.", 0, DlxApp.TEXTFLAGS_ALIGNMIDDLECENTER);
}
}
}
|