Table of Contents

Struct XUnit

Namespace
PdfSharp.Drawing
Assembly
PdfSharp.dll

Represents a value and its unit of measure.

public struct XUnit : IFormattable, IComparable<XUnit>, IComparable
Implements
Inherited Members

Constructors

XUnit(double)

Initializes a new instance of the XUnit class with type set to point.

public XUnit(double point)

Parameters

point double

XUnit(double, XGraphicsUnit)

Initializes a new instance of the XUnit class.

public XUnit(double value, XGraphicsUnit type)

Parameters

value double
type XGraphicsUnit

Fields

Zero

Represents a unit with all values zero.

public static readonly XUnit Zero

Field Value

XUnit

Properties

Centimeter

Gets or sets the value in centimeter.

public double Centimeter { get; set; }

Property Value

double

Inch

Gets or sets the value in inch.

public double Inch { get; set; }

Property Value

double

Millimeter

Gets or sets the value in millimeter.

public double Millimeter { get; set; }

Property Value

double

Point

Gets or sets the value in point.

public double Point { get; set; }

Property Value

double

Presentation

Gets or sets the value in presentation units (1/96 inch).

public double Presentation { get; set; }

Property Value

double

Type

Gets the unit of measure.

public readonly XGraphicsUnit Type { get; }

Property Value

XGraphicsUnit

Value

Gets the raw value of the object without any conversion. To determine the XGraphicsUnit use property

Type
. To get the value in point use property
Point
.
public readonly double Value { get; }

Property Value

double

Methods

CompareTo(XUnit)

Compares this XUnit with another XUnit value.

public int CompareTo(XUnit other)

Parameters

other XUnit

Returns

int

CompareTo(object?)

Compares this XUnit with another object.

public int CompareTo(object? obj)

Parameters

obj object

Returns

int

ConvertType(XGraphicsUnit)

Converts an existing object from one unit into another unit type.

public void ConvertType(XGraphicsUnit type)

Parameters

type XGraphicsUnit

Equals(object?)

Calls base class Equals.

public override bool Equals(object? obj)

Parameters

obj object

Returns

bool

FromCentimeter(double)

Returns an XUnit object. Sets type to centimeters.

public static XUnit FromCentimeter(double value)

Parameters

value double

Returns

XUnit

FromInch(double)

Returns an XUnit object. Sets type to inch.

public static XUnit FromInch(double value)

Parameters

value double

Returns

XUnit

FromMillimeter(double)

Returns an XUnit object. Sets type to millimeters.

public static XUnit FromMillimeter(double value)

Parameters

value double

Returns

XUnit

FromPoint(double)

Returns an XUnit object. Sets type to point.

public static XUnit FromPoint(double value)

Parameters

value double

Returns

XUnit

FromPresentation(double)

Returns an XUnit object. Sets type to Presentation.

public static XUnit FromPresentation(double value)

Parameters

value double

Returns

XUnit

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int

IsSameValue(XUnit)

Compares the actual values of this XUnit and another XUnit value tolerating rounding errors.

public bool IsSameValue(XUnit other)

Parameters

other XUnit

Returns

bool

Parse(string)

This member is intended to be used by XmlDomainObjectReader only.

public static XUnit Parse(string value)

Parameters

value string

Returns

XUnit

ToString()

Returns the object as string. The unit of measure is appended to the end of the string.

public override string ToString()

Returns

string

ToString(IFormatProvider?)

Returns the object as string using the format information. The unit of measure is appended to the end of the string.

public string ToString(IFormatProvider? formatProvider)

Parameters

formatProvider IFormatProvider

Returns

string

Operators

operator +(XUnit, XUnit)

Adds an XUnit to an XUnit.

public static XUnit operator +(XUnit l, XUnit r)

Parameters

l XUnit
r XUnit

Returns

XUnit

operator +(XUnit, string)

Adds a string parsed as XUnit to an XUnit.

public static XUnit operator +(XUnit l, string r)

Parameters

l XUnit
r string

Returns

XUnit

operator /(XUnit, double)

Divides an XUnit by a double.

public static XUnit operator /(XUnit l, double r)

Parameters

l XUnit
r double

Returns

XUnit

operator ==(XUnit, XUnit)

Memberwise comparison checking the exact value und unit. To compare by value tolerating rounding errors, use IsSameValue() or code like Math.Abs(a.Pt - b.Pt) < 1e-5.

public static bool operator ==(XUnit l, XUnit r)

Parameters

l XUnit
r XUnit

Returns

bool

operator >(XUnit, XUnit)

Compares two XUnit values.

public static bool operator >(XUnit l, XUnit r)

Parameters

l XUnit
r XUnit

Returns

bool

operator >=(XUnit, XUnit)

Compares two XUnit values.

public static bool operator >=(XUnit l, XUnit r)

Parameters

l XUnit
r XUnit

Returns

bool

implicit operator double(XUnit)

Converts an XUnit object to a double value as point.

[Obsolete("In PDFsharp 6.1 implicit conversion to double is marked obsolete, because it led to misunderstandings and unexpected behavior. Use the XUnit.Point property instead.")]
public static implicit operator double(XUnit value)

Parameters

value XUnit

Returns

double

implicit operator XUnit(double)

Converts a double to an XUnit object with type set to point.

[Obsolete("In PDFsharp 6.1 implicit conversion from double is marked obsolete, because it led to misunderstandings and unexpected behavior. Provide the unit by XUnit.FromPoint() or use the new class XUnitPt instead.")]
public static implicit operator XUnit(double value)

Parameters

value double

Returns

XUnit

implicit operator XUnit(int)

Converts an int to an XUnit object with type set to point.

[Obsolete("In PDFsharp 6.1 implicit conversion from int is marked obsolete, because it led to misunderstandings and unexpected behavior. Provide the unit by XUnit.FromPoint() or use the new class XUnitPt instead.")]
public static implicit operator XUnit(int value)

Parameters

value int

Returns

XUnit

implicit operator XUnit(string)

Converts a string to an XUnit object. If the string contains a suffix like 'cm' or 'in' the object will be converted to the appropriate type, otherwise point is assumed.

public static implicit operator XUnit(string value)

Parameters

value string

Returns

XUnit

operator !=(XUnit, XUnit)

Memberwise comparison checking exact value und unit. To compare by value tolerating rounding errors, use IsSameValue() or code like Math.Abs(a.Pt - b.Pt) < 1e-5.

public static bool operator !=(XUnit l, XUnit r)

Parameters

l XUnit
r XUnit

Returns

bool

operator <(XUnit, XUnit)

Compares two XUnit values.

public static bool operator <(XUnit l, XUnit r)

Parameters

l XUnit
r XUnit

Returns

bool

operator <=(XUnit, XUnit)

Compares two XUnit values.

public static bool operator <=(XUnit l, XUnit r)

Parameters

l XUnit
r XUnit

Returns

bool

operator *(XUnit, double)

Multiplies an XUnit with a double.

public static XUnit operator *(XUnit l, double r)

Parameters

l XUnit
r double

Returns

XUnit

operator -(XUnit, XUnit)

Subtracts an XUnit from an XUnit.

public static XUnit operator -(XUnit l, XUnit r)

Parameters

l XUnit
r XUnit

Returns

XUnit

operator -(XUnit, string)

Subtracts a string parsed as Unit from an XUnit.

public static XUnit operator -(XUnit l, string r)

Parameters

l XUnit
r string

Returns

XUnit

operator -(XUnit)

Returns the negative value of an XUnit.

public static XUnit operator -(XUnit value)

Parameters

value XUnit

Returns

XUnit