Class OdfStyleEngine
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
contentRootOdfNode內容 XML 的根節點
stylesRootOdfNode樣式 XML 的根節點
Exceptions
- ArgumentNullException
當
contentRoot或stylesRoot為 null 時拋出
Fields
OnStyleChanging
Provides the member member. 樣式變更時發生的事件。
public Action<OdfNode, string>? OnStyleChanging
Field Value
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
elementNodeOdfNodeDOM 專案節點
familystring樣式家族
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
styleNamestring樣式名稱
propertyLocalNamestring屬性的區域名稱
propertyNsUristring屬性的命名空間 URI
styleFamilystring樣式家族
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
elementNodeOdfNodefamilystringpropElementLocalNamestringpropAttrLocalNamestringpropAttrNsUristringvaluestring
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
elementNodeOdfNodefamilystringpropElementLocalNamestringpropAttrLocalNamestringpropAttrNsUristringvaluestringpropAttrPrefixstring
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
elementNodeOdfNodeDOM 專案節點
familystring樣式家族
propElementLocalNamestring屬性元素的區域名稱
propAttrLocalNamestring屬性屬性的區域名稱
propAttrNsUristring屬性屬性的命名空間 URI
valuestring要設定的值
propAttrPrefixstring屬性屬性的前綴
deferSavebool是否延遲執行自動樣式去重與存檔
StyleExists(string)
Performs style exists. 判斷指定的樣式是否存在。
public bool StyleExists(string styleName)
Parameters
styleNamestring樣式名稱
Returns
- bool
若存在則為 true,否則為 false