Class Font

GoDiagram®
v10.0.12
by Northwoods Software®

Defines a particular format for text, including font face, size, weight, and style.

Inheritance
Font
Namespace: Northwoods.Go
Assembly: Northwoods.GoDiagram.Avalonia.dll
Syntax
[JsonConverter(typeof(FontJsonConverter))]
public class Font
Remarks

When constructing a font, properties have the following defaults if not provided:

Note that the default size unit is pixels, not points.

To use a custom font file, specify a family ending with '.ttf' when constructing the font.

Constructors

Font()

Constructs a Font with default properties.

Declaration
public Font()

Font(string, float, FontStyle, FontUnit, FontWeight)

Constructs a Font using a specified size, style, unit, and weight.

Declaration
public Font(string family, float size, FontStyle style, FontUnit unit, FontWeight weight)
Parameters
Type Name Description
string family
float size
FontStyle style
FontUnit unit
FontWeight weight

Font(string, float, FontStyle, FontUnit)

Constructs a Font using a specified size, style, and unit.

Declaration
public Font(string family, float size, FontStyle style, FontUnit unit)
Parameters
Type Name Description
string family
float size
FontStyle style
FontUnit unit

Font(string, float, FontStyle, FontWeight)

Constructs a Font using a specified size, style, and weight.

Declaration
public Font(string family, float size, FontStyle style, FontWeight weight)
Parameters
Type Name Description
string family
float size
FontStyle style
FontWeight weight

Font(string, float, FontStyle)

Constructs a Font using a specified size and style.

Declaration
public Font(string family, float size, FontStyle style)
Parameters
Type Name Description
string family
float size
FontStyle style

Font(string, float, FontUnit)

Constructs a Font using a specified size and unit.

Declaration
public Font(string family, float size, FontUnit unit)
Parameters
Type Name Description
string family
float size
FontUnit unit

Font(string, float, FontWeight, FontUnit)

Constructs a Font using a specified size, weight, and unit.

Declaration
public Font(string family, float size, FontWeight weight, FontUnit unit)
Parameters
Type Name Description
string family
float size
FontWeight weight
FontUnit unit

Font(string, float, FontWeight)

Constructs a Font using a specified size and style.

Declaration
public Font(string family, float size, FontWeight weight)
Parameters
Type Name Description
string family
float size
FontWeight weight

Font(string, float)

Constructs a Font using a specified size.

Declaration
public Font(string family, float size)
Parameters
Type Name Description
string family
float size

Properties

Family

This read-only property returns the font's family.

Declaration
public string Family { get; }
Property Value
Type Description
string
Remarks

The default value is "Segoe UI".

IsItalic

This read-only property returns whether this Font is italic.

Declaration
public bool IsItalic { get; }
Property Value
Type Description
bool

Size

This read-only property returns the font's size in units specified by Unit.

Declaration
public float Size { get; }
Property Value
Type Description
float
Remarks

The default value is 13.

Style

This read-only property returns the font's style.

Declaration
public FontStyle Style { get; }
Property Value
Type Description
FontStyle
Remarks

The default value is Regular.

This value allows a bitwise combination of FontStyle values.

Unit

This read-only property returns the font's unit of measure.

Declaration
public FontUnit Unit { get; }
Property Value
Type Description
FontUnit
Remarks

The default value is Pixel.

Weight

This read-only property returns the font's weight.

Declaration
public FontWeight Weight { get; }
Property Value
Type Description
FontWeight
Remarks

The default value is Regular.

Methods

Parse(object)

This is a convenience method for Parse(string) that can be used as a Converter.

Declaration
public static object Parse(object str)
Parameters
Type Name Description
object str
Returns
Type Description
object

Parse(string)

This static method can be used to read in a Font from a string that was produced by Stringify(Font).

Declaration
public static Font Parse(string str)
Parameters
Type Name Description
string str
Returns
Type Description
Font
Remarks

Font.Parse("Segoe UI;13;Pixel;Bold|Italic") produces the Font new Font("Segoe UI", 13, FontWeight.Bold | FontStyle.Italic, FontUnit.Pixel).

Stringify(Font)

This static method can be used to write out a Point as a string that can be read by Parse(string).

Declaration
public static string Stringify(Font val)
Parameters
Type Name Description
Font val
Returns
Type Description
string
Remarks

Font.Stringify(new Font("Segoe UI", 13, FontStyle.Italic, FontUnit.Pixel, FontWeight.Bold)) produces the string "Segoe UI;13;Pixel;Italic;Bold".

Stringify(object)

This is a convenience method for Stringify(Font) that can be used as a BackConverter.

Declaration
public static object Stringify(object pt)
Parameters
Type Name Description
object pt
Returns
Type Description
object

ToString()

Returns a string representation of the Font.

Declaration
public override string ToString()
Returns
Type Description
string

A string representation of the current Font.

Overrides