public RenderStyleTd(HtmlItem it, ref MigraDoc.DocumentObjectModel.Tables.Cell cc) { Cll = cc; It = it; }
protected override HtmlItem renderingHtmlList(HtmlItem it, ref Paragraph par, HtmlItem parent) { HtmlList uol = it as HtmlList; if (uol != null) { foreach (HtmlLi l in uol.ListLi) { if (l.ListItem.Exists(isText)) { ListInfo listinfo = new ListInfo(); listinfo.ContinuePreviousList = true; listinfo.ListType = ListType.BulletList1; // default listinfo.NumberPosition = 25 * uol.Level; // BulletList margin default RenderStyle.CreateRenderStyle(uol, ref listinfo).Render(); // render styles element Paragraph newpar = par.Section.AddParagraph(); RenderStyle.CreateRenderStyle(uol, ref newpar).Render(); // render styles paragraph newpar.Format.ListInfo = listinfo; renderingit(l, ref newpar, uol, null); } else renderingit(l, ref par, uol, null); } } if (!(parent is HtmlLi)) par.Section.AddParagraph().AddLineBreak(); return uol; }
protected override HtmlItem renderingHtmlLi(HtmlItem it, ref Paragraph par, HtmlItem parent) { HtmlLi l = it as HtmlLi; if (l != null) { foreach (HtmlItem i in it.ListItem) { FormattedText ff = new FormattedText(); HtmlItem itemrendered = renderingit(i, ref par, l, null); HtmlText textitem = itemrendered as HtmlText; //RenderStyle.CreateRenderStyle(it, ref ff).Render(); if (textitem != null) { ff.Add(new Text(textitem.Text)); par.Add(ff); it.SizeRenderItem.Width = calculateWithText(textitem.Text.Length, ff.Size); if (it.SizeRenderItem.Width > 210) it.SizeRenderItem.Width = 210; it.SizeRenderItem.Height = calculateHeightText(textitem.Text.Length, ff.Size); } } } return l; }
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; }
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; }
protected override HtmlItem renderingHtmlDiv(HtmlItem it, ref Paragraph par, HtmlItem parent) { HtmlDiv div = it as HtmlDiv; if (div != null) { foreach (HtmlItem t in it.ListItem) { FormattedText ff = new FormattedText(); RenderStyle.CreateRenderStyle(it, ref ff).Render(); //Render styles element HtmlItem itemrendered = renderingit(t, ref par, it, null); HtmlText textitem = itemrendered as HtmlText; if (textitem != null) { ff.Add(new Text(textitem.Text)); it.SizeRenderItem.Width = calculateWithText(textitem.Text.Length, ff.Size); if (it.SizeRenderItem.Width > 210) it.SizeRenderItem.Width = 210; it.SizeRenderItem.Height = calculateHeightText(textitem.Text.Length, ff.Size); } par.Add(ff); } par.AddLineBreak(); } return div; }
protected override HtmlItem renderingHtmlText(HtmlItem it, ref Paragraph par, HtmlItem parent) { HtmlText te = it as HtmlText; if (te != null) { if (parent == null) { par.AddText(te.Text); it.SizeRenderItem.Width =calculateWithText( te.Text.Length ,8); if (it.SizeRenderItem.Width > 210) it.SizeRenderItem.Width = 210; it.SizeRenderItem.Height = calculateHeightText(te.Text.Length, 8); } } return te; }
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; }
protected override HtmlItem renderingHtmlContent(HtmlItem it, ref Paragraph par, HtmlItem parent) { HtmlContent content = it as HtmlContent; if (content != null) { if (parent is HtmlContent) par.AddLineBreak(); foreach (HtmlItem t in it.ListItem) { FormattedText ff = new FormattedText(); if (content.Bold.hasValue()) ff.Bold = content.Bold.Value; if (content.Size.hasValue()) ff.Size = content.Size.Value; RenderStyle.CreateRenderStyle(it, ref ff).Render(); HtmlItem itemrendered = renderingit(t, ref par, it, null); HtmlText textitem = itemrendered as HtmlText; if (textitem != null) { ff.Add(new Text(textitem.Text)); par.Add(ff); it.SizeRenderItem.Width = calculateWithText(textitem.Text.Length, ff.Size); //ff.Section.PageSetup.PageWidth=59 =>>210 mm A4 if (it.SizeRenderItem.Width > 210) it.SizeRenderItem.Width = 210; it.SizeRenderItem.Height = calculateHeightText(textitem.Text.Length, ff.Size); } } par.AddLineBreak(); } return content; }
protected override HtmlItem renderingHtmlSpan(HtmlItem it, ref Paragraph par, HtmlItem parent) { HtmlSpan span = it as HtmlSpan; if (span != null) { foreach (HtmlItem t in it.ListItem) { FormattedText ff = new FormattedText(); if (span.Size.hasValue()) ff.Size = span.Size.Value; if (span.Bold.hasValue()) ff.Bold = span.Bold.Value; if (span.Sub.hasValue()) ff.Subscript = span.Sub.Value; if (span.Super.hasValue()) ff.Superscript = span.Super.Value; RenderStyle.CreateRenderStyle(it, ref ff).Render(); // render styles element HtmlItem itemrendered = renderingit(t, ref par, it, null); HtmlText textitem = itemrendered as HtmlText; if (textitem != null) { ff.Add(new Text(textitem.Text)); it.SizeRenderItem.Width = calculateWithText(textitem.Text.Length, ff.Size); if (it.SizeRenderItem.Width > 210) it.SizeRenderItem.Width = 210; it.SizeRenderItem.Height = calculateHeightText(textitem.Text.Length, ff.Size); } par.Add(ff); } } return span; }
protected RenderStyle(HtmlItem it, ref MigraDoc.DocumentObjectModel.Tables.Cell cl) { }
protected RenderStyle(HtmlItem it, ref FormattedText frmt) { }
protected RenderStyle(HtmlItem it, ref MigraDoc.DocumentObjectModel.Shapes.Image imgt) { }
public static RenderStyle CreateRenderStyle(HtmlItem it, ref MigraDoc.DocumentObjectModel.Paragraph prg) { return new RenderStyleParagraph(it, ref prg); }
public static RenderStyle CreateRenderStyle(HtmlItem it, ref MigraDoc.DocumentObjectModel.ListInfo lst) { return new RenderStyleList(it, ref lst); }
public static RenderStyle CreateRenderStyle(HtmlItem it, ref MigraDoc.DocumentObjectModel.Tables.Cell cl) { return new RenderStyleTd(it, ref cl); }
public RenderStyleImage(HtmlItem it, ref MigraDoc.DocumentObjectModel.Shapes.Image imgt) { Imgt = imgt; It = it; }
public RenderStyleParagraph(HtmlItem it, ref Paragraph prg) { Prg = prg; It = it; }
private HtmlItem preparenode(string node, string text, XmlNodeType type, XmlAttributeCollection attributes, HtmlItem nodeparent,XmlNode parent) { // I only make htmlText if type = Text, the others one will be text containers if (type == XmlNodeType.Text) { if (parent.Name.ToLower().Trim() == "style") // style tag no render return null; HtmlText ht = new HtmlText(); ht.Text = text; if (nodeparent != null) nodeparent.ListItem.Add(ht); else ListItem.Add(ht); return ht; } switch (node) { case "td": Htmltd httd = new Htmltd(); if (attributes.Count > 0) httd.StyleItem = new PrepareStyle(listofstylesheets).Prepare(attributes, node);//apply styles to elemnet if (nodeparent != null) { httd.IndexCell=nodeparent.ListItem.Count(); Htmltr rowparnet = nodeparent as Htmltr; if (rowparnet != null) { rowparnet.Cellsinrow++; HtmlTable tableparnet = rowparnet.GetTableParent(); if (tableparnet != null) if (tableparnet.Cells < rowparnet.Cellsinrow) tableparnet.Cells = rowparnet.Cellsinrow; } nodeparent.ListItem.Add(httd); } return httd; case "tr": Htmltr httr = new Htmltr(); if (attributes.Count > 0) httr.StyleItem = new PrepareStyle(listofstylesheets).Prepare(attributes, node);//apply styles to elemnet if (nodeparent != null) { HtmlTable tableparnet = nodeparent as HtmlTable; if (tableparnet != null) httr.SetTableParent(tableparnet); nodeparent.ListItem.Add(httr); } return httr; case "table": HtmlTable httbl = new HtmlTable(); if (attributes.Count > 0) httbl.StyleItem = new PrepareStyle(listofstylesheets).Prepare(attributes, node);//apply styles to elemnet if (nodeparent != null) nodeparent.ListItem.Add(httbl); else ListItem.Add(httbl); return httbl; case "div": HtmlDiv htdiv = new HtmlDiv(); if (attributes.Count > 0) htdiv.StyleItem = new PrepareStyle(listofstylesheets).Prepare(attributes, node);//apply styles to elemnet if (nodeparent != null) nodeparent.ListItem.Add(htdiv); else ListItem.Add(htdiv); return htdiv; case "p": HtmlDiv ht = new HtmlDiv(); if (attributes.Count > 0) ht.StyleItem = new PrepareStyle(listofstylesheets).Prepare(attributes, node); if (nodeparent != null) nodeparent.ListItem.Add(ht); else ListItem.Add(ht); return ht; case "br": HtmlContent br = new HtmlContent(); if (nodeparent != null) nodeparent.ListItem.Add(br); else ListItem.Add(br); return br; case "b": HtmlSpan htb = new HtmlSpan(); htb.Bold.ChangeValue( true); if (nodeparent != null) nodeparent.ListItem.Add(htb); else ListItem.Add(htb); return htb; case "sub": HtmlSpan hsub = new HtmlSpan(); hsub.Sub.ChangeValue(true); if (nodeparent != null) nodeparent.ListItem.Add(hsub); else ListItem.Add(hsub); return hsub; case "sup": HtmlSpan hsup = new HtmlSpan(); hsup.Super.ChangeValue(true); if (nodeparent != null) nodeparent.ListItem.Add(hsup); else ListItem.Add(hsup); return hsup; case "span": HtmlSpan hspan = new HtmlSpan(); if (attributes.Count > 0) hspan.StyleItem = new PrepareStyle(listofstylesheets).Prepare(attributes, node); if (nodeparent != null) nodeparent.ListItem.Add(hspan); else ListItem.Add(hspan); return hspan; case "h1": HtmlSpan ht1 = new HtmlSpan(); ht1.Size.ChangeValue( 22); ht1.Bold.ChangeValue( true); if (nodeparent != null) nodeparent.ListItem.Add(ht1); else ListItem.Add(ht1); return ht1; case "h2": HtmlSpan ht2 = new HtmlSpan(); ht2.Size.ChangeValue( 18); if (nodeparent != null) nodeparent.ListItem.Add(ht2); else ListItem.Add(ht2); return ht2; case "h3": HtmlSpan ht3 = new HtmlSpan(); ht3.Size.ChangeValue( 16); if (nodeparent != null) nodeparent.ListItem.Add(ht3); else ListItem.Add(ht3); return ht3; case "h4": HtmlSpan ht4 = new HtmlSpan(); ht4.Size.ChangeValue( 14); if (nodeparent != null) nodeparent.ListItem.Add(ht4); else ListItem.Add(ht4); return ht4; case "h5": HtmlSpan ht5 = new HtmlSpan(); ht5.Size.ChangeValue( 12); if (nodeparent != null) nodeparent.ListItem.Add(ht5); else ListItem.Add(ht5); return ht5; case "h6": HtmlSpan ht6 = new HtmlSpan(); ht6.Size.ChangeValue( 10); if (nodeparent != null) nodeparent.ListItem.Add(ht6); else ListItem.Add(ht6); return ht6; case "img": HtmlImg im = new HtmlImg(attributes); if (attributes.Count > 0) im.StyleItem = new PrepareStyle(listofstylesheets).Prepare(attributes, node); if (nodeparent != null) nodeparent.ListItem.Add(im); else ListItem.Add(im); break; case "ol": HtmlList ol = new HtmlList(); if (attributes.Count > 0) ol.StyleItem = new PrepareStyle(listofstylesheets).Prepare(attributes, node); ol.HtmlListType = typeHtmlList.ol; if (nodeparent is HtmlLi) { HtmlLi parentLi = nodeparent as HtmlLi; if (parentLi != null) if (parentLi.ParentList != null) ol.Level = parentLi.ParentList.Level + 1; } if (nodeparent != null) nodeparent.ListItem.Add(ol); else ListItem.Add(ol); return ol; case "ul": HtmlList ul = new HtmlList(); if (attributes.Count > 0) ul.StyleItem = new PrepareStyle(listofstylesheets).Prepare(attributes, node); ul.HtmlListType = typeHtmlList.ul; if (nodeparent is HtmlLi) { HtmlLi parentLi = nodeparent as HtmlLi; if (parentLi != null) if (parentLi.ParentList != null) ul.Level = parentLi.ParentList.Level + 1; } if (nodeparent != null) nodeparent.ListItem.Add(ul); else ListItem.Add(ul); return ul; case "li": HtmlLi li = new HtmlLi(); //if (attributes.Count > 0) // im.StyleItem = new PrepareStyle(listofstylesheets).Prepare(attributes, node); if (nodeparent != null) nodeparent.ListItem.Add(li); HtmlList parentli = nodeparent as HtmlList; if (parentli != null) { li.ParentList = parentli; parentli.ListLi.Add(li); } return li; case "link": if (attributes.Count > 0) { PrepareHtmlClass newClass = new PrepareHtmlClass(attributes, ref listofstylesheets, listAlreadyStyleSheets); } break; case "style": if (attributes.Count > 0) { PrepareHtmlClass newClass = new PrepareHtmlClass(text, ref listofstylesheets); } break; case "pre": HtmlCode htcode = new HtmlCode(); if (nodeparent != null) nodeparent.ListItem.Add(htcode); else ListItem.Add(htcode); return htcode; default: return null; } return null; }
protected virtual HtmlItem renderingHtmltr(HtmlItem it, ref Paragraph par, HtmlItem parent, DocumentObject renderparent) { return null; }
protected virtual HtmlItem renderingHtmlText(HtmlItem it, ref Paragraph par, HtmlItem parent) { return null; }
protected override HtmlItem renderingHtmlCode(HtmlItem it, ref Paragraph par, HtmlItem parent) { return null; }
public RenderStyleTable(HtmlItem it, ref MigraDoc.DocumentObjectModel.Tables.Table tt) { Tt = tt; It = it; }
protected override HtmlItem renderingHtmltd(HtmlItem it, ref Paragraph par, HtmlItem parent, DocumentObject renderparent) { MigraDoc.DocumentObjectModel.Tables.Row rw = renderparent as MigraDoc.DocumentObjectModel.Tables.Row; Htmltd tb = it as Htmltd; if (tb != null) { if (rw != null) { Htmltr tr = parent as Htmltr; if (tr != null)// properties of tr { tb.SetTrParent(tr); HtmlTable tbl = tr.GetTableParent(); if (tbl != null)// properties of table { tr.SetTableParent(tbl); } } //add paragraph to the cell Paragraph paragrcell = rw[tb.IndexCell].AddParagraph(); //render style cell content // RenderStyle.CreateRenderStyle(it, ref paragrcell).Render(); MigraDoc.DocumentObjectModel.Tables.Cell cc = rw[tb.IndexCell]; RenderStyle.CreateRenderStyle(it, ref cc).Render(); //reder elements in cell decimal minWidthCell = 0; decimal minWidthCellpar = 0; decimal minHeightCell = 0; decimal minHeightCellpar = 0; foreach (HtmlItem t in it.ListItem) { FormattedText ff = new FormattedText(); RenderStyle.CreateRenderStyle(it, ref ff).Render(); if (rw.Table.Columns.Count > tb.IndexCell) { renderingit(t, ref paragrcell, null, rw[tb.IndexCell]); Iheight hh = t as Iheight; if (hh != null) { if (minWidthCell < minWidthCellpar) minWidthCell = minWidthCellpar; if (minHeightCell < minHeightCellpar) minHeightCell = minHeightCellpar; minWidthCellpar = 0; } if (t.StyleItem != null)// width of style if (t.StyleItem.Width != null) if (t.StyleItem.Width.Measure.HasValue) if (t.StyleItem.Width.Measure.Value > t.SizeRenderItem.Width) t.SizeRenderItem.Width = t.StyleItem.Width.Measure.Value; minWidthCellpar += t.SizeRenderItem.Width; if (t.StyleItem != null)// height of style if (t.StyleItem.Width != null) if (t.StyleItem.High.Measure.HasValue) if (t.StyleItem.High.Measure.Value > t.SizeRenderItem.Height) t.SizeRenderItem.Height = t.StyleItem.High.Measure.Value; minHeightCellpar += t.SizeRenderItem.Height; if (t is HtmlTable) //Always insert a margin Migradoc when table is in a cell minHeightCellpar += 25; } } if (minWidthCellpar > minWidthCell) minWidthCell = minWidthCellpar; if (minHeightCellpar > minHeightCell) minHeightCell = minHeightCellpar; if (rw[tb.IndexCell].Column.Width < (Unit)minWidthCell) { rw[tb.IndexCell].Column.Width = (Unit)minWidthCell; tb.SetWidth(minWidthCell); } if (rw[tb.IndexCell].Row.Height < (Unit)minHeightCell) { rw[tb.IndexCell].Row.Height = (Unit)minHeightCell; tb.SetHeight(minHeightCell); } } } return tb; }
public static RenderStyle CreateRenderStyle(HtmlItem it, ref FormattedText frmt) { return new RenderStyleFormattedText(it, ref frmt); }
private void getnodes(XmlNodeList nodelist,XmlNode parent,HtmlItem nodeparent) { foreach (XmlNode node in nodelist) { string valor = node.InnerText; string nombre = node.Name; XmlAttributeCollection attributes = node.Attributes; HtmlItem nodeprepared = preparenode(node.Name, node.InnerText, node.NodeType, attributes, nodeparent, node.ParentNode); if (node.HasChildNodes) getnodes(node.ChildNodes, node, nodeprepared); } }
public static RenderStyle CreateRenderStyle(HtmlItem it, ref MigraDoc.DocumentObjectModel.Tables.Table tt) { return new RenderStyleTable(it, ref tt); }
public static RenderStyle CreateRenderStyle(HtmlItem it,ref MigraDoc.DocumentObjectModel.Shapes.Image imgt) { return new RenderStyleImage(it, ref imgt); }
public RenderStyleList(HtmlItem it, ref MigraDoc.DocumentObjectModel.ListInfo lst) { Lst = lst; It = it; }
protected HtmlItem renderingit(HtmlItem it, ref Paragraph par, HtmlItem parent, DocumentObject renderparent) { switch (it.GetType().Name) { case "HtmlText": return new RenderHtmlText(listTempFiles).renderingHtmlText(it, ref par, parent); case "HtmlDiv": return new RenderHtmlDiv(listTempFiles).renderingHtmlDiv(it, ref par, parent); case "HtmlSpan": return new RenderHtmlSpan(listTempFiles).renderingHtmlSpan(it, ref par, parent); case "HtmlContent": return new RenderHtmlContent(listTempFiles).renderingHtmlContent(it, ref par, parent); case "HtmlImg": return new RenderHtmlImg(listTempFiles).renderingHtmlImg(it, ref par, parent, renderparent); case "HtmlTable": return new RenderHtmlTable(listTempFiles).renderingHtmlTable(it, ref par, parent, renderparent); case "Htmltr": return new RenderHtmltr(listTempFiles).renderingHtmltr(it, ref par, parent, renderparent); case "Htmltd": return new RenderHtmltd(listTempFiles).renderingHtmltd(it, ref par, parent, renderparent); case "HtmlList": return new RenderHtmlList(listTempFiles).renderingHtmlList(it, ref par, parent); case "HtmlLi": return new RenderHtmlLi(listTempFiles).renderingHtmlLi(it, ref par, parent); case "HtmlCode": return new RenderHtmlCode(listTempFiles).renderingHtmlCode(it, ref par, parent); default: return null; } }