---
title: "Autofit"
canonical: https://www.graphicsmill.com/samples/Text/TextLayout/Autofit_cs
product: "Graphics Mill"
source: "Text/TextLayout/Autofit.cs"
---

# Autofit

Demonstrates how to fit the largest possible text inside a PathBoundedText area.

## Instruction

This code demonstrates how to fit text inside a specified path, in this case, an ellipse, using the GraphicsMill library.
The `ShapeTextFrame` is used to place the text inside the path, ensuring it fills the area as much as possible while maintaining the desired text properties.
The process uses the `CopyfittingMode.Fill` to scale the text accordingly to fit the shape.

## Usings

```csharp
using Aurigma.GraphicsMill.Drawing;
```

## Code Snippet

```csharp
using (var bitmap = new Bitmap(400, 400, PixelFormat.Format24bppRgb, RgbColor.White))
using (var graphics = bitmap.GetGraphics())
{
    var text = new Text();

    text.String = "Since 2001, Aurigma have helped software developers add imaging functionality to their applications in a variety of industries. Our image processing Software Development Kit for .NET, Graphics Mill, is a truly powerful product we are proud to have developed.";
    text.CharStyle.PostScriptName = "Verdana";

    var shapeTextFrame = new ShapeTextFrame();

    shapeTextFrame.Shape = new Path();
    shapeTextFrame.Shape.DrawEllipse(0, 0, graphics.Width, graphics.Height);

    shapeTextFrame.CopyfittingMode = CopyfittingMode.Fill;

    text.Frames.Add(shapeTextFrame);

    graphics.DrawPath(new Pen(RgbColor.Blue), shapeTextFrame.Shape);
    graphics.DrawText(text);

    bitmap.Save("FitTextToArea.png");
}
```

## Explanation

The code:

- Creates a 400x400 pixel bitmap with a white background.
- Defines a `Text` object with a string and applies the "Verdana" font.
- Creates a `ShapeTextFrame` where the text is constrained within an elliptical path.
- The text is fitted to the elliptical area using the `Fill` copyfitting mode.
- A blue pen is used to outline the shape (ellipse) containing the text.
- The final result is saved to "FitTextToArea.png".

## Tags

- [Drawing](<https://www.graphicsmill.com/samples/tags/drawing_md>): Drawing vector shapes and text
- [Text Layout](<https://www.graphicsmill.com/samples/tags/text-layout_md>): Controlling advanced text layout

## Output

- [FitTextToArea.png](<https://www.graphicsmill.com/samples/Text/compiled/Debug/FitTextToArea_png>) (preview)

## Used APIs

- [Aurigma.GraphicsMill.Bitmap.GetGraphics](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Bitmap_GetGraphics.htm.md>)
- [Aurigma.GraphicsMill.Drawing.CharStyle.PostScriptName](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_CharStyle_PostScriptName.htm.md>)
- [Aurigma.GraphicsMill.Drawing.CopyfittingMode](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_CopyfittingMode.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.DrawPath(Pen,Path)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_DrawPath_2_77634c23.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.DrawText(Text)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_DrawText_1_f576d03f.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Path](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_Path.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Path.DrawEllipse(Single,Single,Single,Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Path_DrawEllipse_4_37f6c741.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Pen](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_Pen.htm.md>)
- [Aurigma.GraphicsMill.Drawing.ShapeTextFrame](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_ShapeTextFrame.htm.md>)
- [Aurigma.GraphicsMill.Drawing.ShapeTextFrame.CopyfittingMode](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_ShapeTextFrame_CopyfittingMode.htm.md>)
- [Aurigma.GraphicsMill.Drawing.ShapeTextFrame.Shape](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_ShapeTextFrame_Shape.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Text](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_Text.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Text.CharStyle](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_Text_CharStyle.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Text.Frames](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_Text_Frames.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Text.String](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_Text_String.htm.md>)
