Beispiel #1
0
        protected override HtmlItem renderingHtmlImg(HtmlItem it, ref Paragraph par, HtmlItem parent, DocumentObject renderparent)
        {
            HtmlImg imagen = it as HtmlImg;
            MigraDoc.DocumentObjectModel.Shapes.Image img = null;
            MigraDoc.DocumentObjectModel.Shapes.TextFrame tf = null;
            if (imagen != null)
            {
                string route = AppDomain.CurrentDomain.BaseDirectory;
                string directorytem = Settings1.Default.routetem;
                string filename = RandomString(16, false) + "." + imagen.ImageType.ToString();
                string routecompleted = route + directorytem + "\\" + filename;
                imagen.Image.Save(routecompleted);

                MigraDoc.DocumentObjectModel.Tables.Cell cellparent = renderparent as MigraDoc.DocumentObjectModel.Tables.Cell;
                if (cellparent != null)
                {
                    tf = cellparent.AddTextFrame();
                    tf.WrapFormat.Style = MigraDoc.DocumentObjectModel.Shapes.WrapStyle.Through;
                }

                if (tf != null)
                    img = tf.AddImage(routecompleted);
                else
                    img = par.AddImage(routecompleted);

                RenderStyle.CreateRenderStyle(it, ref img).Render();
                listTempFiles.Add(routecompleted);
                imagen.SizeRenderItem = new RenderSizeItem() { Width = Convert.ToDecimal(img.Width), Height = Convert.ToDecimal(img.Height) };

            }

            return imagen;
        }
Beispiel #2
0
 internal Renderer(XGraphics gfx, RenderInfo renderInfo, FieldInfos fieldInfos)
 {
     this.documentObject = renderInfo.DocumentObject;
     this.gfx = gfx;
     this.renderInfo = renderInfo;
     this.fieldInfos = fieldInfos;
 }
Beispiel #3
0
        protected override HtmlItem renderingHtmltr(HtmlItem it, ref Paragraph par, HtmlItem parent, DocumentObject renderparent)
        {
            Htmltr tr = it as Htmltr;
            MigraDoc.DocumentObjectModel.Tables.Row rw = null;
            if (tr != null)
            {
                HtmlTable tb = parent as HtmlTable;
                if (tb != null)
                {
                    MigraDoc.DocumentObjectModel.Tables.Table tt = renderparent as MigraDoc.DocumentObjectModel.Tables.Table;
                    if (tt != null)
                    {
                        if (tt.Columns.Count > 0)
                            rw = tt.AddRow();

                        tr.SetTableParent(tb);
                    }

                }
                foreach (HtmlItem t in it.ListItem)
                {
                    FormattedText ff = new FormattedText();
                    RenderStyle.CreateRenderStyle(it, ref ff).Render();
                    HtmlItem itemrendered = renderingit(t, ref par, it, rw);
                }
            }
            return tr;
        }
Beispiel #4
0
    /// <summary>
    /// Gets the direct parent of the given document object.
    /// </summary>
    /// <param name="documentObject">The document object the parent is searched for.</param>
    public static DocumentObject GetParent(DocumentObject documentObject)
    {
      if (documentObject == null)
        throw new ArgumentNullException("documentObject");

      return documentObject.Parent;
    }
        public DocumentObject NodeHandler(HtmlNode node, DocumentObject parent, DocumentObject current = null)
        {
            var @class = node.Attributes["class"];

            if (!(parent is Section))
            {
                return parent;
            }

            var sec = (Section)parent;

            if (@class != null && @class.Value == "report")
            {
                var margins = node.Attributes["data-margin"];
                if (margins == null)
                {
                    sec.PageSetup.TopMargin = Unit.FromCentimeter(0.1);
                    sec.PageSetup.BottomMargin = Unit.FromCentimeter(0.1);
                    sec.PageSetup.LeftMargin = Unit.FromCentimeter(0.1);
                    sec.PageSetup.RightMargin = Unit.FromCentimeter(0.1);
                }
                else
                {
                    var marginValues = margins.Value.Split(' ');

                    sec.PageSetup.TopMargin = Unit.FromCentimeter(double.Parse(marginValues[0]));
                    sec.PageSetup.RightMargin = Unit.FromCentimeter(double.Parse(marginValues[1]));
                    sec.PageSetup.BottomMargin = Unit.FromCentimeter(double.Parse(marginValues[2]));
                    sec.PageSetup.LeftMargin = Unit.FromCentimeter(double.Parse(marginValues[3]));
                }
            }

            return parent;
        }
Beispiel #6
0
 internal ChartRenderer(DocumentObject domObj, RtfDocumentRenderer docRenderer)
   : base(domObj, docRenderer)
 {
   this.chart = (Chart)domObj;
   this.isInline = DocumentRelations.HasParentOfType(this.chart, typeof(Paragraph)) ||
     RenderInParagraph();
 }
Beispiel #7
0
 /// <summary>
 /// Add formatted text to the MigraDoc object.
 /// </summary>
 /// <param name="parentObject">The MigraDoc object to store the elements in.</param>
 /// <returns>The formatted text object.</returns>
 private static FormattedText AddFormattedText(DocumentObject parentObject)
 {
     FormattedText formattedText = parentObject as FormattedText;
     if (formattedText == null)
         return GetParagraph(parentObject).AddFormattedText();
     else
         return formattedText.AddFormattedText();
 }
Beispiel #8
0
    /// <summary>
    /// Determines whether the specified documentObject has a
    /// parent of the given type somewhere within the document hierarchy.
    /// </summary>
    /// <param name="documentObject">The document object to check.</param>
    /// <param name="type">The parent type to search for.</param>
    public static bool HasParentOfType(DocumentObject documentObject, Type type)
    {
      if (documentObject == null)
        throw new ArgumentNullException("documentObject");

      if (type == null)
        throw new ArgumentNullException("type");

      return GetParentOfType(documentObject, type) != null;
    }
Beispiel #9
0
        internal ImageRenderer(DocumentObject domObj, RtfDocumentRenderer docRenderer)
            : base(domObj, docRenderer)
        {
            this.image = domObj as Image;
              this.filePath = this.image.GetFilePath(this.docRenderer.WorkingDirectory);
              this.isInline = DocumentRelations.HasParentOfType(this.image, typeof(Paragraph)) ||
             RenderInParagraph();

              CalculateImageDimensions();
        }
Beispiel #10
0
 private static DocumentObject AddHyperlink(DocumentObject section, HtmlNode node)
 {
     string href = node.GetAttributeValue("href", "");
     Hyperlink link;
     if (href.StartsWith("#"))
         link = GetParagraph(section).AddHyperlink(href.Substring(1), HyperlinkType.Bookmark);
     else
         link = GetParagraph(section).AddHyperlink(href, HyperlinkType.Web);
     return link;
 }
Beispiel #11
0
        /// <summary>
        /// Initializes a new instance of the RendererBase class.
        /// </summary>
        internal RendererBase(DocumentObject domObj, RtfDocumentRenderer docRenderer)
        {
            if (enumTranslationTable == null)
            CreateEnumTranslationTable();

              this.docObject = domObj;
              this.docRenderer = docRenderer;
              if (docRenderer != null)
            this.rtfWriter = docRenderer.RtfWriter;
              this.useEffectiveValue = false;
        }
Beispiel #12
0
        /// <summary>
        /// Gets a parent of the document object with the given type somewhere within the document hierarchy.
        /// Returns null if none exists.
        /// </summary>
        /// <param name="documentObject">The document object the parent is searched for.</param>
        /// <param name="type">The parent type to search for.</param>
        public static DocumentObject GetParentOfType(DocumentObject documentObject, Type type)
        {
            if (documentObject == null)
                throw new ArgumentNullException("documentObject");

            if (type == null)
                throw new ArgumentNullException("type");

            if (documentObject._parent != null)
            {
                if (documentObject._parent.GetType() == type)
                    return documentObject._parent;
                return GetParentOfType(documentObject._parent, type);
            }
            return null;
        }
        public DocumentObject NodeHandler(HtmlNode node, ExCSS.Stylesheet sheet, DocumentObject parent, DocumentObject current = null)
        {
            if (!(parent is Section))
            {
                return parent;
            }

            var sec = (Section)parent;
            
            Unit margin;
            SetMargin(node, sheet, out margin, "margin-top");
            sec.PageSetup.TopMargin = margin;
            SetMargin(node, sheet, out margin, "margin-bottom");
            sec.PageSetup.BottomMargin = margin;
            SetMargin(node, sheet, out margin, "margin-left");
            sec.PageSetup.LeftMargin = margin;
            SetMargin(node, sheet, out margin, "margin-right");
            sec.PageSetup.LeftMargin = margin;
            return parent;
        }
Beispiel #14
0
        protected override HtmlItem renderingHtmlTable(HtmlItem it, ref Paragraph par, HtmlItem parent, DocumentObject renderparent)
        {
            HtmlTable tbl = it as HtmlTable;
            MigraDoc.DocumentObjectModel.Shapes.TextFrame tf = null;
            Paragraph partf = null;
            if (tbl != null)
            {
                MigraDoc.DocumentObjectModel.Tables.Table tt = null;
                MigraDoc.DocumentObjectModel.Tables.Cell cellparent = renderparent as MigraDoc.DocumentObjectModel.Tables.Cell;
                if (cellparent != null)
                {
                    tf = cellparent.AddTextFrame();
                    tt = tf.AddTable();
                    partf = tf.AddParagraph();

                }
                else
                    tt = par.Section.AddTable();

                tbl.SizeRenderItem.Width = 0;
                for (int i = 0; i < tbl.Cells; i++)
                {
                    MigraDoc.DocumentObjectModel.Tables.Column cc = tt.AddColumn();

                }

                foreach (HtmlItem t in it.ListItem)
                {
                    FormattedText ff = new FormattedText();
                    RenderStyle.CreateRenderStyle(it, ref ff).Render();
                    if (partf != null)
                        renderingit(t, ref partf, it, tt);
                    else
                        renderingit(t, ref par, it, tt);
                }
                RenderStyle.CreateRenderStyle(it, ref tt).Render();

            }
            return tbl;
        }
        private void ConvertHtmlNodes(HtmlNodeCollection nodes, ExCSS.Stylesheet sheet, DocumentObject section, DocumentObject current = null)
        {
            foreach (var node in nodes)
            {
                Func<HtmlNode, ExCSS.Stylesheet, DocumentObject, DocumentObject> nodeHandler;

                Type t;
                if (_mapping.TryGetValue(node.Name, out t))
                {
                    var instance = (INodeHandler)Activator.CreateInstance(t);
                    var result = instance.NodeHandler(node, sheet, section);

                    if (node.HasChildNodes)
                    {
                        ConvertHtmlNodes(node.ChildNodes, sheet, section, result);
                    }
                }
                else
                {
                    if (nodeHandlers.TryGetValue(node.Name, out nodeHandler))
                    {
                        // pass the current container or section
                        var result = nodeHandler(node, sheet, current ?? section);

                        if (node.HasChildNodes)
                        {
                            ConvertHtmlNodes(node.ChildNodes, sheet, section, result);
                        }
                    }
                    else
                    {
                        if (node.HasChildNodes)
                        {
                            ConvertHtmlNodes(node.ChildNodes, sheet, section, current);
                        }
                    }
                }
            }
        }
 private void ConvertHtmlNodes(HtmlNodeCollection nodes, DocumentObject section, DocumentObject current = null)
 {
     foreach (var node in nodes)
     {
         Func<HtmlNode, DocumentObject, DocumentObject> nodeHandler;
         if (nodeHandlers.TryGetValue(node.Name, out nodeHandler))
         {
             // pass the current container or section
             var result = nodeHandler(node, current ?? section);
             
             if (node.HasChildNodes)
             {
                 ConvertHtmlNodes(node.ChildNodes, section, result);
             }
         }
         else
         {
             if (node.HasChildNodes)
             {
                 ConvertHtmlNodes(node.ChildNodes, section, current);
             }
         }
     }
 }
Beispiel #17
0
 /// <summary>
 /// Initializes a new instance of the Hyperlink class with the specified parent.
 /// </summary>
 internal Hyperlink(DocumentObject parent) : base(parent)
 {
 }
Beispiel #18
0
 /// <summary>
 /// Initializes a new instance of the ListInfo class with the specified parent.
 /// </summary>
 public ListInfo(DocumentObject parent) : base(parent)
 {
 }
Beispiel #19
0
 /// <summary>
 /// Initializes a new instance of the Character class with the specified parent.
 /// </summary>
 internal Character(DocumentObject parent) : base(parent)
 {
 }
Beispiel #20
0
 /// <summary>
 /// Initializes a new instance of the Shading class with the specified parent.
 /// </summary>
 internal Shading(DocumentObject parent) : base(parent)
 {
 }
Beispiel #21
0
 /// <summary>
 ///
 /// </summary>
 public override void Add(DocumentObject docObj)
 {
     base.Add(docObj);
 }
 /// <summary>
 /// Initializes a new instance of the Footnote class with the specified parent.
 /// </summary>
 internal Footnote(DocumentObject parent) : base(parent)
 {
 }
Beispiel #23
0
 /// <summary>
 /// Initializes a new instance of the ParagraphFormat class with the specified parent.
 /// </summary>
 internal ParagraphFormat(DocumentObject parent) : base(parent)
 {
 }
Beispiel #24
0
 public static string ParentAlreadySet(DocumentObject value, DocumentObject docObject)
 {
     return(String.Format("Value of type '{0}' must be cloned before set into '{1}'.",
                          value.GetType(), docObject.GetType()));
 }
Beispiel #25
0
 /// <summary>
 /// Initializes a new instance of the Text class with the specified parent.
 /// </summary>
 internal Text(DocumentObject parent) : base(parent)
 {
 }
Beispiel #26
0
 /// <summary>
 /// Initializes a new instance of the Font class with the specified parent.
 /// </summary>
 internal Font(DocumentObject parent) : base(parent)
 {
 }
Beispiel #27
0
 /// <summary>
 /// Initializes a new instance of the ListInfo class with the specified parent.
 /// </summary>
 internal ListInfo(DocumentObject parent) : base(parent)
 {
 }
Beispiel #28
0
 /// <summary>
 /// Initializes a new instance of the Styles class with the specified parent.
 /// </summary>
 internal Styles(DocumentObject parent)
     : base(parent)
 {
     SetupStyles();
 }
Beispiel #29
0
 /// <summary>
 /// Initializes a new instance of the DocumentObjectCollection class with the specified parent.
 /// </summary>
 public DocumentObjectCollection(DocumentObject parent)
     : base(parent)
 {
     _elements = new List <object>();
 }
Beispiel #30
0
 /// <summary>
 /// Initializes a new instance of the ParagraphFormat class with the specified parent.
 /// </summary>
 public ParagraphFormat(DocumentObject parent) : base(parent)
 {
 }
Beispiel #31
0
 /// <summary>
 /// Initializes a new instance of the TabStops class with the specified parent.
 /// </summary>
 internal TabStops(DocumentObject parent) : base(parent)
 {
 }
 /// <summary>
 /// Initializes a new instance of the HeadersFooters class with the specified parent.
 /// </summary>
 public HeadersFooters(DocumentObject parent) : base(parent)
 {
 }
Beispiel #33
0
 /// <summary>
 /// Initializes a new instance of the Style class with the specified parent.
 /// </summary>
 internal Style(DocumentObject parent) : base(parent)
 {
 }
 internal StyleAndFormatRenderer(DocumentObject domObj, RtfDocumentRenderer docRenderer)
   : base(domObj, docRenderer)
 {
 }
Beispiel #35
0
 /// <summary>
 /// Initializes a new instance of the ParagraphElements class with the specified parent.
 /// </summary>
 internal ParagraphElements(DocumentObject parent) : base(parent)
 {
 }
 internal HeadersFootersRenderer(DocumentObject domObj, RtfDocumentRenderer docRenderer)
     : base(domObj, docRenderer)
 {
     _headersFooters = domObj as HeadersFooters;
 }
Beispiel #37
0
 /// <summary>
 /// Initializes a new instance of the DocumentElements class with the specified parent.
 /// </summary>
 internal DocumentElements(DocumentObject parent) : base(parent)
 {
 }
Beispiel #38
0
 /// <summary>
 /// Initializes a new instance of the TabStop class with the specified parent.
 /// </summary>
 internal TabStop(DocumentObject parent) : base(parent) { }
Beispiel #39
0
 /// <summary>
 /// Initializes a new instance of the FormattedText class with the specified parent.
 /// </summary>
 internal FormattedText(DocumentObject parent) : base(parent)
 {
 }
 /// <summary>
 /// 
 /// </summary>
 public override void Add(DocumentObject docObj)
 {
   base.Add(docObj);
 }
Beispiel #41
0
 /// <summary>
 /// Initializes a new instance of the PageBreak class with the specified parent.
 /// </summary>
 internal PageBreak(DocumentObject parent) : base(parent)
 {
 }
        private static DocumentObject AddFormattedText(HtmlNode node, ExCSS.Stylesheet sheet, DocumentObject parent, TextFormat format)
        {
            var formattedText = parent as FormattedText;
            if (formattedText != null)
            {
                return formattedText.Format(format);
            }

            // otherwise parent is paragraph or section
            return GetParagraph(parent).AddFormattedText(format);
        }
Beispiel #43
0
 /// <summary>
 /// Initializes a new instance of the HeaderFooter class with the specified parent.
 /// </summary>
 internal HeaderFooter(DocumentObject parent) : base(parent)
 {
 }
 private static Paragraph GetParagraph(DocumentObject parent)
 {
     return parent as Paragraph ?? ((Section)parent).AddParagraph();
 }
Beispiel #45
0
 internal ShadingRenderer(DocumentObject domObj, RtfDocumentRenderer docRenderer)
   : base(domObj, docRenderer)
 {
   this.shading = domObj as Shading;
   this.isCellShading = !(DocumentRelations.GetParent(shading) is ParagraphFormat);
 }
Beispiel #46
0
 /// <summary>
 /// Initializes a new instance of the Border class with the specified parent.
 /// </summary>
 internal Border(DocumentObject parent) : base(parent)
 {
 }
Beispiel #47
0
 internal BorderRendererBase(DocumentObject domObj, RtfDocumentRenderer docRenderer)
     : base(domObj, docRenderer)
 { }
Beispiel #48
0
 /// <summary>
 /// Initializes a new instance of the Section class with the specified parent.
 /// </summary>
 internal Section(DocumentObject parent) : base(parent)
 {
 }
Beispiel #49
0
 internal FontRenderer(DocumentObject domObj, RtfDocumentRenderer docRenderer)
     : base(domObj, docRenderer)
 {
     _font = domObj as Font;
 }
Beispiel #50
0
 /// <summary>
 /// Initializes a new instance of the DocumentObject class with the specified parent.
 /// </summary>
 internal DocumentObject(DocumentObject parent)
 {
     Debug.Assert(parent != null, "Parent must not be null.");
     _parent = parent;
 }
Beispiel #51
0
 internal BordersRenderer(DocumentObject domObj, RtfDocumentRenderer docRenderer)
   : base(domObj, docRenderer)
 {
   this.borders = domObj as Borders;
 }
Beispiel #52
0
 /// <summary>
 /// Initializes a new instance of the PageSetup class with the specified parent.
 /// </summary>
 internal PageSetup(DocumentObject parent) : base(parent)
 {
 }
 /// <summary>
 /// Initializes a new instance of the ParagraphElements class with the specified parent.
 /// </summary>
 internal ParagraphElements(DocumentObject parent) : base(parent) { }
Beispiel #54
0
 /// <summary>
 /// Initializes a new instance of the ParagraphElements class with the specified parent.
 /// </summary>
 public ParagraphElements(DocumentObject parent) : base(parent)
 {
 }
 private static DocumentObject AddHeading(HtmlNode node, ExCSS.Stylesheet sheet, DocumentObject parent)
 {
     return ((Section)parent).AddParagraph().SetStyle("Heading" + node.Name[1]);
 }
 /// <summary>
 /// Determines the index of a specific item in the collection.
 /// </summary>
 public int IndexOf(DocumentObject val)
 {
     return(((IList)this).IndexOf(val));
 }
 private static Paragraph AddParagraphWithStyle(DocumentObject parent, string style)
 {
     return ((Section)parent).AddParagraph().SetStyle(style);
 }
 /// <summary>
 /// Inserts the object into the collection and sets it's parent.
 /// </summary>
 public virtual void Add(DocumentObject value)
 {
     SetParent(value);
     this.elements.Add(value);
 }
 internal SectionPagesFieldRenderer(DocumentObject domObj, RtfDocumentRenderer docRenderer)
     : base(domObj, docRenderer)
 {
     _sectionPagesField = domObj as SectionPagesField;
 }
 /// <summary>
 /// Initializes a new instance of the DocumentObjectCollection class with the specified parent.
 /// </summary>
 internal DocumentObjectCollection(DocumentObject parent)
     : base(parent)
 {
     this.elements = new ArrayList();
 }