public OdfImageRenderFilter(IDictionary<Image, string> userImages, OdfTemplate odfDoc) { Debug.Assert (userImages != null); Debug.Assert (odfDoc != null); this.userImages = userImages; this.resultDocument = odfDoc; }
/// <summary> /// 一部执行模板编译、渲染并返回结果 /// </summary> /// <param name="odfPath"></param> /// <returns></returns> public static OdfTemplate RenderTemplate(string odfPath, IDictionary<string, object> context) { var odf = new OdfTemplate(); odf.Load(odfPath); odf.Compile(); var resultDoc = odf.Render(context); return resultDoc as OdfTemplate; }
public static void Compile(OdfTemplate template) { var xml = new XmlDocument(); template.ReadMainContentXml(xml); var nsmanager = new OdfNamespaceManager(xml.NameTable); nsmanager.LoadOpenDocumentNamespaces(); //第1遍,先处理简单的Tag 替换 PreprocessElements(xml, nsmanager); //第2遍,处理表格循环 ProcessTableRows(xml, nsmanager); template.WriteXmlContent(xml); }
public override object Clone() { var destDoc = new OdfTemplate(); this.CopyTo(destDoc); return destDoc; }
private void ResetTextEngine(IDictionary<Image, string> userImages, OdfTemplate resultDocument) { Debug.Assert(this.engine != null); Debug.Assert(userImages != null); Debug.Assert(resultDocument != null); this.engine.Reset(); this.engine.RegisterFilter(typeof(string), new XmlStringRenderFilter()); this.engine.RegisterFilter(typeof(Image), new OdfImageRenderFilter(userImages, resultDocument)); }
public override IDocument Render(IDictionary<string, object> context) { Debug.Assert(this.engine != null); if (context == null) { throw new ArgumentNullException("context"); } var resultDoc = new OdfTemplate(); this.CopyTo(resultDoc); var userImages = new Dictionary<Image, string>(); this.ResetTextEngine(userImages, resultDoc); using (var inStream = this.GetEntryInputStream(this.MainContentEntryPath)) using (var reader = new StreamReader(inStream, Encoding.UTF8)) using (var ws = resultDoc.GetEntryOutputStream(resultDoc.MainContentEntryPath)) using (var writer = new StreamWriter(ws)) { this.engine.Evaluate(context, reader, writer); } return resultDoc; }