Struct FontVariation
A position on one axis of a variable font, in the axis's own units, such as weight 650.
public readonly record struct FontVariation : IEquatable<FontVariation>
- Implements
- Inherited Members
Examples
// A variable font's axes and named instances, and the face at any position on them.
Typeface flex = Typeface.FromFile(VariableFile);
foreach (VariationAxis axis in flex.VariationAxes)
{
Console.WriteLine($"{axis.Tag} {axis.Name}: {axis.Min} to {axis.Max}, default {axis.Default}");
}
Typeface semiBold = flex.WithVariations(FontVariation.Weight(600), FontVariation.Width(90));
Typeface black = flex.WithNamedInstance(flex.NamedInstances.Count - 1);
// The optical size follows the font size unless the face sets it (OpticalSizing.None turns that off).
var caption = new Font(semiBold, 11);
Typeface drawn = caption.EffectiveTypeface;
// For a PDF, the subset is a static font at the face's position, which every viewer draws as it is.
FontSubset subset = FontSubsetter.Subset(semiBold, caption.Shape("Static at 600").Glyphs.ToArray());
Constructors
FontVariation(FontTag, float)
A position on one axis of a variable font, in the axis's own units, such as weight 650.
public FontVariation(FontTag Axis, float Value)
Parameters
AxisFontTagThe axis tag, such as
wght.ValuefloatThe value in the axis's user units (wght 1 to 1000, wdth in percent, slnt in degrees, opsz in points).
Examples
// A variable font's axes and named instances, and the face at any position on them.
Typeface flex = Typeface.FromFile(VariableFile);
foreach (VariationAxis axis in flex.VariationAxes)
{
Console.WriteLine($"{axis.Tag} {axis.Name}: {axis.Min} to {axis.Max}, default {axis.Default}");
}
Typeface semiBold = flex.WithVariations(FontVariation.Weight(600), FontVariation.Width(90));
Typeface black = flex.WithNamedInstance(flex.NamedInstances.Count - 1);
// The optical size follows the font size unless the face sets it (OpticalSizing.None turns that off).
var caption = new Font(semiBold, 11);
Typeface drawn = caption.EffectiveTypeface;
// For a PDF, the subset is a static font at the face's position, which every viewer draws as it is.
FontSubset subset = FontSubsetter.Subset(semiBold, caption.Shape("Static at 600").Glyphs.ToArray());
FontVariation(string, float)
Initializes a position from the axis tag's text, such as new FontVariation("wght", 650).
public FontVariation(string axis, float value)
Parameters
Properties
Axis
The axis tag, such as wght.
public FontTag Axis { get; init; }
Property Value
ItalicAxis
Gets the tag of the registered italic axis, ital (0 upright, 1 italic).
public static FontTag ItalicAxis { get; }
Property Value
OpticalSizeAxis
Gets the tag of the registered optical size axis, opsz (the text size in points the design is for).
public static FontTag OpticalSizeAxis { get; }
Property Value
SlantAxis
Gets the tag of the registered slant axis, slnt (degrees counter-clockwise, negative for text leaning right).
public static FontTag SlantAxis { get; }
Property Value
Value
The value in the axis's user units (wght 1 to 1000, wdth in percent, slnt in degrees, opsz in points).
public float Value { get; init; }
Property Value
WeightAxis
Gets the tag of the registered weight axis, wght (1 to 1000).
public static FontTag WeightAxis { get; }
Property Value
WidthAxis
Gets the tag of the registered width axis, wdth (percent of normal).
public static FontTag WidthAxis { get; }
Property Value
Methods
Italic(float)
Returns an italic position.
public static FontVariation Italic(float value)
Parameters
valuefloat0 for upright, 1 for italic.
Returns
- FontVariation
The position.
OpticalSize(float)
Returns an optical size position.
public static FontVariation OpticalSize(float points)
Parameters
pointsfloatThe text size the design is for.
Returns
- FontVariation
The position.
Slant(float)
Returns a slant position.
public static FontVariation Slant(float degrees)
Parameters
degreesfloatThe slant in degrees counter-clockwise from upright; negative values lean right.
Returns
- FontVariation
The position.
Weight(float)
Returns a weight position.
public static FontVariation Weight(float value)
Parameters
valuefloatThe weight, 1 to 1000; 400 is normal and 700 bold.
Returns
- FontVariation
The position.
Width(float)
Returns a width position.
public static FontVariation Width(float percent)
Parameters
percentfloatThe width in percent of normal: 100 normal, 75 condensed, 125 expanded.
Returns
- FontVariation
The position.