VegaRise.NET
Back to DOM

DocumentUnitClass

Definition

Namespace
DOM.MeasurementUnits
Assembly
DOM.dll

Represents a document measurement value that can be expressed either as an absolute length stored internally in EMUs (English Metric Units) or as a relative . Percentage

Remarks

is the universal measurement type used throughout the DOM for layout, sizing, spacing, borders, margins, and page geometry. It is a convenience wrapper around a canonical internal representation () stored as EMUs plus a nullable . DocumentUnit _value Percentage Read accessors convert the internal EMU value to the requested unit using the extension methods defined in . Writing any absolute-unit property (Point, Inch, CM, MM, PX, Twips) sets the internal EMU value and clears any percentage; writing sets the relative value and clears the absolute EMU. Vega.Extensions Percentage EMU is the storage unit used by Office Open XML (1 pt = 12700 EMU, 1 inch = 914400 EMU). Storing values as EMUs guarantees lossless conversion between units.

Examples

csharp
1// 1. Create from points (implicit conversion treats a double as points)
2DocumentUnit size = 12.0;
3Console.WriteLine(size.Point); // 12
4Console.WriteLine(size.EMU); // 152400
5
csharp
1// 2. Construct from any unit
2var cm = new DocumentUnit(2.54, Units.cm); // 1 inch
3var twips = new DocumentUnit(1440, Units.Twips); // 72 pt
4var emu = new DocumentUnit(127000L); // 10 pt
5
csharp
1// 3. Read/write different units on the same instance
2var u = new DocumentUnit();
3u.Point = 11.0;
4Console.WriteLine(u.MM); // ~3.88
5Console.WriteLine(u.PX); // ~15
6u.Inch = 0.5; // now 36 pt
7Console.WriteLine(u.Point); // 36
8
csharp
1// 4. Use as a relative value via Percentage
2DocumentUnit relative = new Percentage(150);
3Console.WriteLine(relative.Percentage.Value); // 150
4Console.WriteLine(relative.EMU); // null (absolute cleared)
5

Constructors

DocumentUnit()

Initializes a new empty instance with no value set. DocumentUnit

DocumentUnit(double Value, Units unit)

Initializes a new by converting the specified value from the given unit into the internal EMU representation. DocumentUnit

Properties

CM

Gets or sets the measurement expressed in centimeters.

EMU

Gets or sets the measurement expressed in EMUs (the internal storage unit).

Inch

Gets or sets the measurement expressed in inches.

MM

Gets or sets the measurement expressed in millimeters.

Percentage

Gets or sets the value as a . Setting this property makes the instance represent a relative value and clears any stored absolute EMU. Percentage

Point

Gets or sets the measurement expressed in typographic points.

PX

Gets or sets the measurement expressed in pixels.

The getter converts EMU → points and multiplies by 1.33 to approximate pixels. The setter converts the provided pixel value into EMU by first treating it as points. Pixel conversion is approximate — for precise layout use points or inches.

Twips

Gets or sets the measurement expressed in twips (1/20 of a point).

Methods

Implicit conversion from to . Treats the provided as points and stores the equivalent EMU value. Double, DocumentUnit, Double

Returns a string representation of the unit.

Fields

_percentage

Internal relative measurement when the unit represents a percentage of some reference. When non-null this value is authoritative and will be null. _value

_value

Internal absolute value stored in EMUs. When non-null this value is the authoritative absolute measurement for the instance.

VegaRise.NET

Sign In

Welcome back. Please sign in to your account.

Forgot password?
or

Don't have an account? Create an account

By signing in, you agree to our Terms of Service and Privacy Policy.