private void LoadFrameGraphic(Frame frame, Graphic content) { try { string graphicRealPath = Path.GetFullPath(content.GraphicRealPath); frame.LoadImageFromFile(graphicRealPath); } catch (AODLGraphicException e) { this.OnWarning( new AODLWarning("A couldn't create any content from an an first level node!.", content.Node, e)); } }
/// <summary> /// Creates the frame. /// </summary> /// <param name="frameNode">The framenode.</param> /// <returns>The Frame object.</returns> public Frame CreateFrame(XmlNode frameNode) { try { #region Old code Todo: delete // Frame frame = null; // XmlNode graphicnode = null; // XmlNode graphicproperties = null; // string realgraphicname = ""; // string stylename = ""; // stylename = this.GetStyleName(framenode.OuterXml); // XmlNode stylenode = this.GetAStyleNode("style:style", stylename); // realgraphicname = this.GetAValueFromAnAttribute(framenode, "@draw:name"); // // //Console.WriteLine("frame: {0}", framenode.OuterXml); // // //Up to now, the only sopported, inner content of a frame is a graphic // if(framenode.ChildNodes.Count > 0) // if(framenode.ChildNodes.Item(0).OuterXml.StartsWith("<draw:image")) // graphicnode = framenode.ChildNodes.Item(0).CloneNode(true); // // //If not graphic, it could be text-box, ole or something else // //try to find graphic frame inside // if(graphicnode == null) // { // XmlNode child = framenode.SelectSingleNode("//draw:frame", this._document.NamespaceManager); // if(child != null) // frame = this.CreateFrame(child); // return frame; // } // // string graphicpath = this.GetAValueFromAnAttribute(graphicnode, "@xlink:href"); // // if(stylenode != null) // if(stylenode.ChildNodes.Count > 0) // if(stylenode.ChildNodes.Item(0).OuterXml.StartsWith("<style:graphic-properties")) // graphicproperties = stylenode.ChildNodes.Item(0).CloneNode(true); // // if(stylename.Length > 0 && stylenode != null && realgraphicname.Length > 0 // && graphicnode != null && graphicpath.Length > 0 && graphicproperties != null) // { // graphicpath = graphicpath.Replace("Pictures", ""); // graphicpath = OpenDocumentTextImporter.dirpics+graphicpath.Replace("/", @"\"); // // frame = new Frame(this._document, stylename, // realgraphicname, graphicpath); // // frame.Style.Node = stylenode; // frame.Graphic.Node = graphicnode; // ((FrameStyle)frame.Style).GraphicProperties.Node = graphicproperties; // // XmlNode nodeSize = framenode.SelectSingleNode("@svg:height", // this._document.NamespaceManager); // // if(nodeSize != null) // if(nodeSize.InnerText != null) // frame.GraphicHeight = nodeSize.InnerText; // // nodeSize = framenode.SelectSingleNode("@svg:width", // this._document.NamespaceManager); // // if(nodeSize != null) // if(nodeSize.InnerText != null) // frame.GraphicWidth = nodeSize.InnerText; // } #endregion //Create a new Frame Frame frame = new Frame(this._document, null); frame.Node = frameNode; IContentCollection iColl = new IContentCollection(); //Revieve the FrameStyle IStyle frameStyle = this._document.Styles.GetStyleByName(frame.StyleName); if(frameStyle != null) frame.Style = frameStyle; else { if(this.OnWarning != null) { AODLWarning warning = new AODLWarning("Couldn't recieve a FrameStyle."); warning.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); warning.Node = frameNode; this.OnWarning(warning); } } //Create the frame content foreach(XmlNode nodeChild in frame.Node.ChildNodes) { IContent iContent = this.CreateContent(nodeChild); if(iContent != null) iColl.Add(iContent); else { if(this.OnWarning != null) { AODLWarning warning = new AODLWarning("Couldn't create a IContent object for a frame."); warning.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); warning.Node = nodeChild; this.OnWarning(warning); } } } frame.Node.InnerXml = ""; foreach(IContent iContent in iColl) { frame.Content.Add(iContent); if(iContent is Graphic) { frame.LoadImageFromFile(((Graphic)iContent).GraphicRealPath); } } return frame; } catch(Exception ex) { AODLException exception = new AODLException("Exception while trying to create a Frame."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.Node = frameNode; exception.OriginalException = ex; throw exception; } }