[]
        
(Showing Draft Content)

GrapeCity.Documents.Common.Unit

Struct Unit

Namespace
GrapeCity.Documents.Common
Assembly
GcDocs.Imaging.dll

A utility structure specifying some values related to units of measurement.

public struct Unit
Inherited Members
System.ValueType.Equals(object)
System.ValueType.GetHashCode()
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetType()

Constructors

Unit(float, UnitTypeEnum)

Initializes a new instance of the Unit structure.

public Unit(float value, UnitTypeEnum unitType)

Parameters

value float

The unit value.

unitType UnitTypeEnum

The unit of measurement.

Unit(string)

Initializes a new instance of the Unit structure from a string. String should contain A numeric value qualified with unit of measurement, e.g. "28mm" or "7in".

public Unit(string str)

Parameters

str string

Fields

CmPerInch

Centimeters per inch as double.

public const float CmPerInch = 2.54

Field Value

float

DipPerInch

DIP units per inch as double.

public const float DipPerInch = 96

Field Value

float

DisplayPerInch

Display units per inch as double.

public const float DisplayPerInch = 75

Field Value

float

DocumentUnitsPerInch

Document units per inch as double.

public const float DocumentUnitsPerInch = 300

Field Value

float

MmPerInch

Millimeters per inch as double.

public const float MmPerInch = 25.4

Field Value

float

PicaPerInch

Picas per inch as double.

public const float PicaPerInch = 6

Field Value

float

PointsPerInch

Points per inch as double.

public const float PointsPerInch = 72

Field Value

float

TwipsPerInch

Twips per inch as double.

public const float TwipsPerInch = 1440

Field Value

float

Zero

Represents "0mm" value.

public static readonly Unit Zero

Field Value

Unit

Properties

Units

Gets the unit of measurement of the current unit.

public UnitTypeEnum Units { get; }

Property Value

UnitTypeEnum

Value

Gets the value of the current unit (in Units).

public float Value { get; }

Property Value

float

Methods

Convert(UnitTypeEnum)

Converts value of this Unit structure to value in specified units of measurement.

public float Convert(UnitTypeEnum to)

Parameters

to UnitTypeEnum

The target unit of measurement.

Returns

float

Returns the value in to units.

Convert(float, UnitTypeEnum, UnitTypeEnum)

Converts a value from one unit of measurement to another.

public static float Convert(float value, UnitTypeEnum from, UnitTypeEnum to)

Parameters

value float

The value to convert.

from UnitTypeEnum

The source unit of measurement.

to UnitTypeEnum

The target unit of measurement.

Returns

float

value converted to to units.

Convert(float, UnitTypeEnum, float)

Converts a value from one unit of measurement to pixel.

public static float Convert(float value, UnitTypeEnum from, float toDpi)

Parameters

value float

The value to convert in from units.

from UnitTypeEnum

The source unit of measurement.

toDpi float

The target dpi.

Returns

float

value converted to pixels with specified dpi.

Convert(float, float, UnitTypeEnum)

Converts a value from pixel unit of measurement to another.

public static float Convert(float value, float fromDpi, UnitTypeEnum to)

Parameters

value float

The value to convert in pixels.

fromDpi float

The source dpi.

to UnitTypeEnum

The target unit of measurement.

Returns

float

value converted to to units.

Parse(string)

Parses a string and creates a Unit instance from that string, throws an exception if string is invalid.

public static Unit Parse(string s)

Parameters

s string

The string to parse.

Returns

Unit

A Unit instance.

StringToUnitType(string, ref UnitTypeEnum)

Converts a string to a UnitTypeEnum value. The string can be one of the following: "doc", "in", "mm", "pc", "dsp", "pt", "tw", "inhs", "cm", "dip". This method is case-insensitive.

public static bool StringToUnitType(string s, ref UnitTypeEnum value)

Parameters

s string

The string to convert.

value UnitTypeEnum

OUT: On exit, contains the UnitTypeEnum value.

Returns

bool

true if no error occurred, false otherwise.

ToString()

Converts the current object to a string.

public override string ToString()

Returns

string

The string representing the current Unit object.

TryParse(string, out Unit)

Parses a string and creates Unit structure.

public static bool TryParse(string s, out Unit unit)

Parameters

s string

The string to parse.

unit Unit

OUT: Unit structure.

Returns

bool

True if the conversion was successfull, false otherwise.

TryParse(string, out float, out UnitTypeEnum)

Parses a string and gets Value and Units from that string.

public static bool TryParse(string s, out float value, out UnitTypeEnum units)

Parameters

s string

The string to parse.

value float

OUT: value of Unit structure.

units UnitTypeEnum

OUT: units of Unit structure.

Returns

bool

A true if conversion was successfull.

UnitTypeToString(UnitTypeEnum)

Converts a UnitTypeEnum value to a string representation as in the following table:

  • Document"doc"
  • Inch"in"
  • Millimeter"mm"
  • Pica"pc"
  • Point"pt"
  • Twip"tw"
  • InHs"inhs"
  • Centimeters"cm"
  • Dip"dip"
public static string UnitTypeToString(UnitTypeEnum value)

Parameters

value UnitTypeEnum

A UnitTypeEnum to convert.

Returns

string

The string representing value.

Operators

implicit operator string(Unit)

Converts a unit value to a string.

public static implicit operator string(Unit value)

Parameters

value Unit

The unit to convert.

Returns

string

The string representing the unit value.

implicit operator Unit(string)

Converts a string to a Unit value (see Unit(string).

public static implicit operator Unit(string value)

Parameters

value string

The string to convert.

Returns

Unit

The unit value.