Table of Contents

Struct Twips

Namespace
DocWright.Core.Primitives
Assembly
DocWright.Core.dll

A length in twips (twentieths of a typographic point), the integer unit used for all DocWright layout arithmetic. 1 point = 20 twips; 1 inch = 1440 twips.

public readonly struct Twips : IEquatable<Twips>, IComparable<Twips>
Implements
Inherited Members

Remarks

Word's internal layout model is twip-based (ECMA-376 Part 1 §17.18.87 ST_TwipsMeasure, §17.18.105 ST_SignedTwipsMeasure), and DocWright mirrors it so that layout results are bit-identical across frameworks and platforms. Conversions from physical units round half away from zero via FixedPointMath. Arithmetic operators are checked; overflow throws OverflowException.

Constructors

Twips(int)

Initializes a new value from a raw twip count.

Fields

EmusPerTwip

English Metric Units per twip (914400 EMU per inch / 1440 twips per inch).

MaxMeasure

The largest magnitude, in twips, that a measure read out of a document may carry: 2^24 twips, or about 291 feet.

PerInch

Twips per inch.

PerPoint

Twips per typographic point.

Zero

A zero-length value.

Properties

Value

Gets the length in twips.

Methods

ClampMeasure(double)

Clamps a raw measure expressed as a real number to MaxMeasure, rounding half away from zero. Non-finite input clamps to the corresponding bound, or to Zero for NaN.

ClampMeasure(long)

Clamps a raw measure to MaxMeasure, so that downstream checked arithmetic on the result cannot overflow.

CompareTo(Twips)
Equals(Twips)
Equals(object?)
FromCentimeters(double)

Creates a value from centimeters, rounding half away from zero.

FromEighthPoints(int)

Creates a value from eighth-points, the unit Word uses for border widths (ECMA-376 Part 1 §17.18.2 ST_EighthPointMeasure), rounding half away from zero.

FromEmus(Emu)

Creates a value from English Metric Units, rounding half away from zero.

FromFontUnits(int, int, Twips)

Converts a length in font design units to twips for a given em size, using integer arithmetic with round-half-away-from-zero: funits * emSize / unitsPerEm. This is the single sanctioned funit conversion (Microsoft OpenType specification, "Converting FUnits to pixels", adapted to twips).

FromHalfPoints(int)

Creates a value from half-points, the unit Word uses for font sizes (ECMA-376 Part 1 §17.18.42 ST_HpsMeasure).

FromInches(double)

Creates a value from inches, rounding half away from zero.

FromMillimeters(double)

Creates a value from millimeters, rounding half away from zero.

FromPoints(double)

Creates a value from typographic points, rounding half away from zero.

FromPoints(int)

Creates a value from a whole number of typographic points.

GetHashCode()
ToEmus()

Converts this length to English Metric Units (exact; 635 EMU per twip).

ToPoints()

Converts this length to typographic points. This is a renderer-boundary conversion; the result must not feed back into layout arithmetic.

ToString()

Returns the value formatted with the invariant culture, suffixed with "tw" (for example "240tw").

Operators

operator +(Twips, Twips)

Adds two lengths (checked).

operator ==(Twips, Twips)

Determines whether two lengths are equal.

operator >(Twips, Twips)

Determines whether one length is greater than another.

operator >=(Twips, Twips)

Determines whether one length is greater than or equal to another.

operator !=(Twips, Twips)

Determines whether two lengths are not equal.

operator <(Twips, Twips)

Determines whether one length is less than another.

operator <=(Twips, Twips)

Determines whether one length is less than or equal to another.

operator *(Twips, int)

Multiplies a length by an integer factor (checked).

operator *(int, Twips)

Multiplies a length by an integer factor (checked).

operator -(Twips, Twips)

Subtracts one length from another (checked).

operator -(Twips)

Negates a length (checked).