/// <summary> /// 输出嵌入在RTF文档中的文档元素对象 /// </summary> /// <param name="element">文档元素对象</param> /// <param name="attributes">属性列表</param> /// <param name="resultImage">表示元素内容的图片对象</param> public void WriteEmbObject( DomElement element, Image resultImage) { bool disposeImage = false; if (resultImage == null) { resultImage = element.CreateContentImage(); disposeImage = true; } Size size = new Size( GraphicsUnitConvert.ToTwips(resultImage.Width, GraphicsUnit.Pixel), GraphicsUnitConvert.ToTwips(resultImage.Height, GraphicsUnit.Pixel)); this.WriteStartGroup(); this.WriteKeyword("object"); this.WriteKeyword("objemb"); this.WriteCustomAttribute("objclass", XWriterObjectPrefix + element.GetType().FullName, true); this.WriteKeyword("objw" + size.Width); this.WriteKeyword("objh" + size.Height); StringWriter writer = new StringWriter(); XmlSerializer ser = Xml.MyXmlSerializeHelper.GetElementXmlSerializer(element.GetType()); ser.Serialize(writer, element); writer.Close(); string xmlText = writer.ToString(); byte[] bs = Encoding.UTF8.GetBytes(xmlText); this.WriteStartGroup(); this.WriteKeyword("objdata", true); this.WriteBytes(bs); this.WriteEndGroup(); this.WriteStartGroup(); this.WriteKeyword("result"); this.WriteImage( resultImage, resultImage.Width, resultImage.Height, null, element.RuntimeStyle); this.WriteEndGroup(); this.WriteEndGroup(); if (disposeImage) { resultImage.Dispose(); } }
// - Element is an ElementFragment protected override DomNode Convert(DomDocument document, DomElement element, IScriptGenerator gen) { // TODO This will not work if expressions are in non-string types var myValues = element.Attributes.Select(t => new KeyValuePair <string, object>(t.Name, t.Value)); // Locate the property handling inner text // TODO Using inner text (but it could contain markup, which would technically require special handling logic) // TODO Memoize this lookup (performance) foreach (PropertyInfo p in Utility.ReflectGetProperties(element.GetType())) { if (p.IsDefined(typeof(ValueAttribute))) { var kvp = new KeyValuePair <string, object>(p.Name, element.InnerText); myValues = Utility.Cons(kvp, myValues); } } Activation.Initialize(element, myValues); return(element); }
protected void ElementProperties(object sender, WriterCommandEventArgs args) { if (args.Mode == WriterCommandEventMode.QueryState) { args.Enabled = args.DocumentControler != null && args.DocumentControler.CanSetStyle; } else if (args.Mode == WriterCommandEventMode.Invoke) { args.Result = false; DomElement element = args.Document.CurrentElement; if (args.Document.Selection.ContentElements.Count == 1) { element = args.Document.Selection.ContentElements[0]; } while (element != null) { ElementEditor editor = (ElementEditor)TypeDescriptor.GetEditor(element, typeof(ElementEditor)); if (editor != null) { if (editor.IsSupportMethod(ElementEditMethod.Edit)) { // 调用指定的编辑器 ElementEditEventArgs ea = new ElementEditEventArgs(); ea.Document = args.Document; ea.Element = element; ea.Host = args.Host; ea.LogUndo = true; ea.Method = ElementEditMethod.Edit; bool changed = false; args.Document.BeginLogUndo(); if (editor.Edit(ea)) { // 更新元素内容版本号 if (element is DomContainerElement) { DomContainerElement c = (DomContainerElement)element; c.EditorInvalidateContent(); } element.UpdateContentVersion(); element.InvalidateView(); changed = true; } args.Document.EndLogUndo(); if (changed) { args.Result = true; args.Document.Modified = true; //args.Document.OnSelectionChanged(); args.Document.OnDocumentContentChanged(); args.RefreshLevel = UIStateRefreshLevel.All; } } return; } element = element.Parent; }//while element = args.Document.CurrentElement; if (args.Document.Selection.ContentElements.Count == 1) { element = args.Document.Selection.ContentElements[0]; } XTextElementProperties properties = null; while (element != null) { properties = args.Host.CreateProperties(element.GetType()); if (properties != null) { break; } element = element.Parent; }//while if (properties != null) { properties.Document = args.Document; if (properties.ReadProperties(element)) { args.SourceElement = element; if (properties.PromptEditProperties(args)) { args.Document.BeginLogUndo(); bool changed = false; if (properties.ApplyToElement(args.Document, element, true)) { // 更新元素内容版本号 if (element is DomContainerElement) { DomContainerElement c = (DomContainerElement)element; c.EditorInvalidateContent(); } element.UpdateContentVersion(); element.InvalidateView(); changed = true; } args.Document.EndLogUndo(); if (changed) { args.Result = true; args.Document.Modified = true; //args.Document.OnSelectionChanged(); args.Document.OnDocumentContentChanged(); args.RefreshLevel = UIStateRefreshLevel.All; } } } } } }