Table of Contents

Struct OdfLength

Namespace
OdfKit.Styles
Assembly
OdfKit.dll

Provides the OdfLength API. 表示 ODF 長度的結構。

public struct OdfLength : IEquatable<OdfLength>
Implements
Inherited Members

Remarks

以指定的數值與單位建立新的 OdfLength 結構。

Constructors

OdfLength(double, OdfUnit)

Provides the OdfLength API. 表示 ODF 長度的結構。

public OdfLength(double value, OdfUnit unit)

Parameters

value double

長度數值

unit OdfUnit

長度單位

Remarks

以指定的數值與單位建立新的 OdfLength 結構。

Properties

Unit

Gets the Unit value. 取得長度的單位。

public readonly OdfUnit Unit { get; }

Property Value

OdfUnit

Value

Gets the Value value. 取得長度的數值。

public readonly double Value { get; }

Property Value

double

Methods

ConvertTo(OdfUnit)

Converts to. 將長度轉換為指定的目標單位。

public double ConvertTo(OdfUnit targetUnit)

Parameters

targetUnit OdfUnit

目標長度單位

Returns

double

轉換為目標單位的數值

Exceptions

InvalidOperationException

當嘗試直接在相對單位與絕對單位之間轉換時拋出

NotSupportedException

當長度單位轉換不支援時拋出

Equals(OdfLength)

Performs equals. 判斷目前的長度結構是否與另一個長度結構相等。

public bool Equals(OdfLength other)

Parameters

other OdfLength

要比較的另一個長度結構

Returns

bool

如果兩個結構相等則為 true,否則為 false

Equals(object?)

Performs equals. 判斷指定的物件是否與目前的長度結構相等。

public override bool Equals(object? obj)

Parameters

obj object

要比較的物件

Returns

bool

如果指定的物件與目前的結構相等則為 true,否則為 false

FallbackTo(OdfUnit)

Performs fallback to. 如果是 Unspecified 則套用 context 預設的單位進行轉譯。

public OdfLength FallbackTo(OdfUnit defaultUnit)

Parameters

defaultUnit OdfUnit

當單位為未指定時所套用的預設長度單位

Returns

OdfLength

套用預設單位後的 OdfLength 結構

FromCentimeters(double)

Creates from centimeters. 從指定的公分值建立 OdfLength 結構。

public static OdfLength FromCentimeters(double val)

Parameters

val double

長度數值

Returns

OdfLength

表示該公分值的 OdfLength 結構

FromEm(double)

Creates from em. 從指定的 Em 值建立 OdfLength 結構。

public static OdfLength FromEm(double val)

Parameters

val double

長度數值

Returns

OdfLength

表示該 Em 值的 OdfLength 結構

FromEmu(long)

Creates from emu. 從指定的 EMU(OOXML 度量單位)值建立 OdfLength 結構。

public static OdfLength FromEmu(long emu)

Parameters

emu long

EMU 數值

Returns

OdfLength

表示該 EMU 值的 OdfLength 結構

FromInches(double)

Creates from inches. 從指定的英吋值建立 OdfLength 結構。

public static OdfLength FromInches(double val)

Parameters

val double

長度數值

Returns

OdfLength

表示該英吋值的 OdfLength 結構

FromMillimeters(double)

Creates from millimeters. 從指定的公釐值建立 OdfLength 結構。

public static OdfLength FromMillimeters(double val)

Parameters

val double

長度數值

Returns

OdfLength

表示該公釐值的 OdfLength 結構

FromPercentage(double)

Creates from percentage. 從指定的百分比值建立 OdfLength 結構。

public static OdfLength FromPercentage(double val)

Parameters

val double

長度數值

Returns

OdfLength

表示該百分比值的 OdfLength 結構

FromPicas(double)

Creates from picas. 從指定的派卡值建立 OdfLength 結構。

public static OdfLength FromPicas(double val)

Parameters

val double

長度數值

Returns

OdfLength

表示該派卡值的 OdfLength 結構

FromPixels(double)

Creates from pixels. 從指定的像素值建立 OdfLength 結構。

public static OdfLength FromPixels(double val)

Parameters

val double

長度數值

Returns

OdfLength

表示該像素值的 OdfLength 結構

FromPoints(double)

Creates from points. 從指定的點數值建立 OdfLength 結構。

public static OdfLength FromPoints(double val)

Parameters

val double

長度數值

Returns

OdfLength

表示該點數值的 OdfLength 結構

GetHashCode()

Gets hash code. 傳回此長度結構的雜湊碼。

public override int GetHashCode()

Returns

int

一個 32 位元有正負號的整數雜湊碼

Parse(string?)

Performs the Parse operation. 解析長度字串並傳回 OdfLength 結構。

public static OdfLength Parse(string? text)

Parameters

text string

要解析的長度字串

Returns

OdfLength

解析後的 OdfLength 結構

Exceptions

FormatException

當長度格式無效或是不支援的單位時拋出

ToCentimeters()

Converts to centimeters. 將長度轉換為公分。

public double ToCentimeters()

Returns

double

轉換為公分的數值

ToEmu()

Converts to emu. 將長度轉換為 EMU(OOXML 度量單位)。

public long ToEmu()

Returns

long

轉換為 EMU 的數值(四捨五入至最接近的整數,遠離零捨入)

ToInches()

Converts to inches. 將長度轉換為英吋。

public double ToInches()

Returns

double

轉換為英吋的數值

ToMillimeters()

Converts to millimeters. 將長度轉換為公釐。

public double ToMillimeters()

Returns

double

轉換為公釐的數值

ToPoints()

Converts to points. 將長度轉換為點。

public double ToPoints()

Returns

double

轉換為點的數值

ToString()

Converts to string. 將長度結構轉換為其字串表示法。

public override string ToString()

Returns

string

代表目前長度結構的字串

TryParse(string?, out OdfLength)

Performs the TryParse operation. 嘗試解析長度字串。

public static bool TryParse(string? text, out OdfLength result)

Parameters

text string

要解析的長度字串

result OdfLength

當此方法傳回時,若解析成功,則包含解析後的 OdfLength;若解析失敗,則為預設值

Returns

bool

若解析成功則為 true,否則為 false

Operators

operator ==(OdfLength, OdfLength)

Performs equals. 判斷兩個 OdfLength 結構是否相等。

public static bool operator ==(OdfLength left, OdfLength right)

Parameters

left OdfLength

要比較的左側結構

right OdfLength

要比較的右側結構

Returns

bool

如果兩個結構相等則為 true,否則為 false

explicit operator double(OdfLength)

Performs double. 顯式將 OdfLength 結構轉換為 double。

public static explicit operator double(OdfLength len)

Parameters

len OdfLength

長度結構

Returns

double

implicit operator string(OdfLength)

Performs string. 隱式將 OdfLength 結構轉換為字串。

public static implicit operator string(OdfLength len)

Parameters

len OdfLength

長度結構

Returns

string

implicit operator OdfLength(string)

Performs odf length. 隱式將字串轉換為 OdfLength 結構。

public static implicit operator OdfLength(string text)

Parameters

text string

要解析的長度字串

Returns

OdfLength

operator !=(OdfLength, OdfLength)

Performs equals. 判斷兩個 OdfLength 結構是否不相等。

public static bool operator !=(OdfLength left, OdfLength right)

Parameters

left OdfLength

要比較的左側結構

right OdfLength

要比較的右側結構

Returns

bool

如果兩個結構不相等則為 true,否則為 false