Back to Devexpress

BestSizeEstimator.GetFontToFitBounds(String, BrickStyle, RectangleF, ReportUnit) Method

xtrareports-devexpress-dot-xtrareports-dot-ui-dot-bestsizeestimator-dot-getfonttofitbounds-x28-system-dot-string-devexpress-dot-xtraprinting-dot-brickstyle-system-dot-drawing-dot-rectanglef-devexpress-dot-xtrareports-dot-ui-dot-reportunit-x29.md

latest4.2 KB
Original Source

BestSizeEstimator.GetFontToFitBounds(String, BrickStyle, RectangleF, ReportUnit) Method

Gets the font with which the specified text fits the specified boundaries.

Namespace : DevExpress.XtraReports.UI

Assembly : DevExpress.XtraReports.v25.2.dll

NuGet Package : DevExpress.Reporting.Core

Declaration

csharp
public static DXFont GetFontToFitBounds(
    string text,
    BrickStyle style,
    RectangleF bounds,
    ReportUnit reportUnit
)
vb
Public Shared Function GetFontToFitBounds(
    text As String,
    style As BrickStyle,
    bounds As RectangleF,
    reportUnit As ReportUnit
) As DXFont

Parameters

NameTypeDescription
textString

A string that specifies the text used in calculations.

| | style | BrickStyle |

A BrickStyle object that specifies a drawing style.

| | bounds | RectangleF |

A RectangleF structure specifying the initial boundaries which the text should fit.

| | reportUnit | ReportUnit |

A ReportUnit enumeration value that specifies the system of measurement.

|

Returns

TypeDescription
DXFont

An optimal font.

|

Remarks

The GetFontToFitBounds method allows you to calculate an optimal font for the specified text to occupy the entire specified area.

The code snippet below demonstrates how to use this method to draw a LabelBrick with maximum possible text size.

csharp
using DevExpress.XtraReports.UI;
using DevExpress.Drawing;

// Prepare for creating a document.
printingSystem.Begin();
BrickGraphics gr = printingSystem.Graph;
gr.Modifier = BrickModifier.Detail;

// Create a new brick instance and specify its settings.
LabelBrick brick = new LabelBrick();
brick.Text = "Some text";
brick.Rect = new RectangleF(0, 0, 200, 100);
DXFont font = BestSizeEstimator.GetFontToFitBounds(brick.Text, brick.Style, brick.Rect, ReportUnit.Pixels);
brick.Style.Font = font;
gr.DrawBrick(brick);

// Finish creating the document.
printingSystem.End();
vb
Imports DevExpress.XtraReports.UI
Imports DevExpress.Drawing

' Prepare for creating a document.
printingSystem.Begin
Dim gr As BrickGraphics = printingSystem.Graph
gr.Modifier = BrickModifier.Detail

' Create a new brick instance and specify its settings.
Dim brick As LabelBrick = New LabelBrick
brick.Text = "Some text"
brick.Rect = New RectangleF(0, 0, 200, 100)
Dim font As DXFont = BestSizeEstimator.GetFontToFitBounds(brick.Text, brick.Style, brick.Rect, ReportUnit.Pixels)
brick.Style.Font = font
gr.DrawBrick(brick)

' Finish creating the document.
printingSystem.End

To perform the opposite operation (that is get the boundaries to fit the specified text), call the BestSizeEstimator.GetBoundsToFitText method.

See Also

GetBoundsToFitText

BestSizeEstimator Class

BestSizeEstimator Members

DevExpress.XtraReports.UI Namespace