Table of Contents

Class OdfStyleEngine

Namespace
OdfKit.Styles
Assembly
OdfKit.dll

Provides the OdfStyleEngine API. ODF 樣式引擎,負責樣式繼承、解析與去重管理。

public class OdfStyleEngine
Inheritance
OdfStyleEngine
Inherited Members

Remarks

本類別非執行緒安全:內部快取(_automaticStyles_commonStyles_defaultStyles_localStyles_directStyleProperties)皆為一般 Dictionary<TKey, TValue>, 若同一個 OdfStyleEngine 執行個體(或其所屬文件)被多執行緒並行讀寫(例如 RebuildStyleIndex() 與其他讀取方法同時呼叫),可能因集合並行存取而擲出例外或讀到不一致資料。若需並行處理多份文件, 請為每份文件建立獨立的執行個體,而非跨執行緒共用同一個 OdfStyleEngine

Constructors

OdfStyleEngine(OdfNode, OdfNode)

Performs odf style engine. 初始化 OdfStyleEngine 類別的新執行個體。

public OdfStyleEngine(OdfNode contentRoot, OdfNode stylesRoot)

Parameters

contentRoot OdfNode

內容 XML 的根節點

stylesRoot OdfNode

樣式 XML 的根節點

Exceptions

ArgumentNullException

contentRootstylesRoot 為 null 時拋出

Fields

OnStyleChanging

Provides the member member. 樣式變更時發生的事件。

public Action<OdfNode, string>? OnStyleChanging

Field Value

Action<OdfNode, string>

Methods

CollectGarbage()

Collects garbage. 移除未被文件 DOM 或樣式繼承鏈引用的 style:style 樣式定義。

public int CollectGarbage()

Returns

int

移除的樣式數量

DeduplicateAndSaveStyles()

Performs deduplicate and save styles. 執行自動樣式去重,將記憶體中的臨時局部樣式合併寫入 XML 並更新 DOM 節點參照。

public void DeduplicateAndSaveStyles()

GC()

Performs GC. 移除未被文件 DOM 或樣式繼承鏈引用的 style:style 樣式定義。

public int GC()

Returns

int

移除的樣式數量

GetOrCreateLocalStyle(OdfNode, string)

Gets or create local style. 取得或建立特定 DOM 節點在記憶體中的局部編輯樣式節點。

public OdfNode GetOrCreateLocalStyle(OdfNode elementNode, string family)

Parameters

elementNode OdfNode

DOM 專案節點

family string

樣式家族

Returns

OdfNode

建立或取得的局部樣式節點

Exceptions

ArgumentNullException

elementNode 為 null 時拋出

GetStyleProperty(string, string, string, string)

Gets style property. 取得指定的樣式屬性,自動支援層級回溯與循環繼承保護。

public string? GetStyleProperty(string styleName, string propertyLocalName, string propertyNsUri, string styleFamily)

Parameters

styleName string

樣式名稱

propertyLocalName string

屬性的區域名稱

propertyNsUri string

屬性的命名空間 URI

styleFamily string

樣式家族

Returns

string

屬性值,若找不到則為 null

RebuildStyleIndex()

Performs rebuild style index. 重新建構樣式索引。

public void RebuildStyleIndex()

SetLocalStyleProperty(OdfNode, string, string, string, string, string?)

Short overload of SetLocalStyleProperty that accepts elementNode, family, propElementLocalName, propAttrLocalName, propAttrNsUri, and value; remaining optional parameters use defaults and forward to the full overload. 便利多載:提供 elementNode、family、propElementLocalName、propAttrLocalName、propAttrNsUri 與 value;其餘可選參數使用預設值並轉呼叫最長 SetLocalStyleProperty 多載。

public void SetLocalStyleProperty(OdfNode elementNode, string family, string propElementLocalName, string propAttrLocalName, string propAttrNsUri, string? value)

Parameters

elementNode OdfNode
family string
propElementLocalName string
propAttrLocalName string
propAttrNsUri string
value string

SetLocalStyleProperty(OdfNode, string, string, string, string, string?, string?)

Short overload of SetLocalStyleProperty that accepts elementNode, family, propElementLocalName, propAttrLocalName, propAttrNsUri, value, and propAttrPrefix; remaining optional parameters use defaults and forward to the full overload. 便利多載:提供 elementNode、family、propElementLocalName、propAttrLocalName、propAttrNsUri、value 與 propAttrPrefix;其餘可選參數使用預設值並轉呼叫最長 SetLocalStyleProperty 多載。

public void SetLocalStyleProperty(OdfNode elementNode, string family, string propElementLocalName, string propAttrLocalName, string propAttrNsUri, string? value, string? propAttrPrefix)

Parameters

elementNode OdfNode
family string
propElementLocalName string
propAttrLocalName string
propAttrNsUri string
value string
propAttrPrefix string

SetLocalStyleProperty(OdfNode, string, string, string, string, string?, string?, bool)

Sets local style property. 設定局部樣式屬性。

public void SetLocalStyleProperty(OdfNode elementNode, string family, string propElementLocalName, string propAttrLocalName, string propAttrNsUri, string? value, string? propAttrPrefix, bool deferSave)

Parameters

elementNode OdfNode

DOM 專案節點

family string

樣式家族

propElementLocalName string

屬性元素的區域名稱

propAttrLocalName string

屬性屬性的區域名稱

propAttrNsUri string

屬性屬性的命名空間 URI

value string

要設定的值

propAttrPrefix string

屬性屬性的前綴

deferSave bool

是否延遲執行自動樣式去重與存檔

StyleExists(string)

Performs style exists. 判斷指定的樣式是否存在。

public bool StyleExists(string styleName)

Parameters

styleName string

樣式名稱

Returns

bool

若存在則為 true,否則為 false