public void ConvertViaHTMLRenderer() { Bitmap bitmap = new Bitmap((Int32)ActualWidth, (Int32)ActualHeight, PixelFormat.Format32bppArgb); CssData d = CssData.Parse("body {font-family:'Times New Roman';font-size: 12pt}"); Graphics g = Graphics.FromImage(bitmap); g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; HtmlRender.Render(g, s, new PointF(), new SizeF(), d); }
public void CanParseRuleWithSingleElementSelector() { const string CSS = @" body { }" ; var adapter = Substitute.For <RAdapter>(); var cssData = CssData.Parse(adapter, CSS, false); Assert.That(cssData.ContainsCssBlock("body"), Is.True); }
public CssData GetCssData(RAdapter adapter) { if (Bytes == null) { return(null); } if (m_cssData == null) { var css = Encoding.UTF8.GetString(Bytes); m_cssData = CssData.Parse(adapter, css); } return(m_cssData); }
public FileResult GeneratePDFHtml(string productname = "", double productquantity = 0) { string html = "<div>"; html += "<p>Ceci est un test</p>"; html += "</div>"; CssData data = CssData.Parse(null, ""); PdfDocument document = PdfGenerator.GeneratePdf(html, PdfSharp.PageSize.A4); MemoryStream stream = new MemoryStream(); document.Save(stream, false); byte[] bytes = stream.ToArray(); return(File(bytes, "application/pdf")); }
public void CanParseAtPageRuleWithoutMarginBoxes() { const string CSS = @" @page { margin: 20mm; }" ; var adapter = Substitute.For <RAdapter>(); var cssData = CssData.Parse(adapter, CSS, false); Assert.That(cssData.ContainsCssBlock("@page"), Is.True, "ContainsCssBlock()"); var cssAtPageBlock = cssData.GetCssBlock("@page").ToArray(); Assert.That(cssAtPageBlock, Has.Length.EqualTo(1), "GetCssBlock()"); Assert.That(cssAtPageBlock[0].Class, Is.EqualTo("@page"), "Class"); Assert.That(cssAtPageBlock[0].Properties.Keys, Is.EquivalentTo(new[] { "margin-left", "margin-top", "margin-right", "margin-bottom" }), "Properties"); }
/// <summary> /// Handle when dependency property value changes to update the underline HtmlContainer with the new value. /// </summary> private static void OnAvaloniaProperty_valueChanged(AvaloniaObject AvaloniaObject, AvaloniaPropertyChangedEventArgs e) { var control = AvaloniaObject as HtmlControl; if (control != null) { var htmlContainer = control._htmlContainer; if (e.Property == AvoidImagesLateLoadingProperty) { htmlContainer.AvoidImagesLateLoading = (bool)e.NewValue; } else if (e.Property == IsSelectionEnabledProperty) { htmlContainer.IsSelectionEnabled = (bool)e.NewValue; } else if (e.Property == IsContextMenuEnabledProperty) { htmlContainer.IsContextMenuEnabled = (bool)e.NewValue; } else if (e.Property == BaseStylesheetProperty) { var baseCssData = CssData.Parse(AvaloniaAdapter.Instance, (string)e.NewValue); control._baseCssData = baseCssData; htmlContainer.SetHtml(control.Text, baseCssData); } else if (e.Property == TextProperty) { htmlContainer.ScrollOffset = new Point(0, 0); htmlContainer.SetHtml((string)e.NewValue, control._baseCssData); control.InvalidateMeasure(); control.InvalidateVisual(); if (control.VisualRoot != null) { control.InvokeMouseMove(); } } } }
public void CanParseAtPageRuleWithMarginBoxes() { const string CSS = @" @page { @bottom-left { margin: 10pt 0 30pt 0; border-top: .25pt solid #666; content: 'My Book'; font-size: 9pt; color: #333; } }" ; var adapter = Substitute.For <RAdapter>(); var cssData = CssData.Parse(adapter, CSS, false); Assert.That(cssData.ContainsCssBlock("@page"), Is.True, "ContainsCssBlock()"); var cssAtPageBlock = cssData.GetCssBlock("@page").ToArray(); Assert.That(cssAtPageBlock, Has.Length.EqualTo(1), "GetCssBlock()"); Assert.That(cssAtPageBlock[0].Class, Is.EqualTo("@page"), "Class"); Assert.That(cssAtPageBlock[0].Properties.Keys, Is.Empty, "Properties"); }
/// <summary> /// Parse the given stylesheet to <see cref="CssData"/> object.<br/> /// If <paramref name="combineWithDefault"/> is true the parsed css blocks are added to the /// default css data (as defined by W3), merged if class name already exists. If false only the data in the given stylesheet is returned. /// </summary> /// <seealso cref="http://www.w3.org/TR/CSS21/sample.html"/> /// <param name="stylesheet">the stylesheet source to parse</param> /// <param name="combineWithDefault">true - combine the parsed css data with default css data, false - return only the parsed css data</param> /// <returns>the parsed css data</returns> public static CssData ParseStyleSheet(string stylesheet, bool combineWithDefault = true) { return(CssData.Parse(PdfSharpAdapter.Instance, stylesheet, combineWithDefault)); }
/// <summary> /// Rendering method /// </summary> /// <param name="g">Graphic to render</param> public override void OnRender(Graphics g) { if (_geo != null) { String imgpath = _daddy.GetResourcesDataPath() + Path.DirectorySeparatorChar + "Img"; String imgpath_clean = imgpath.Replace("\\", "/"); String nameHtml = ""; if (_geo._Available.ToLower() == "true") { nameHtml = _geo._Name.Replace("'", "’"); } else { nameHtml = "<span style=\"text-decoration:line-through;\">" + _geo._Name.Replace("'", " ") + "</span>"; } String stats = ""; OfflineCacheData ocd = _geo._Ocd; if ((ocd != null) && (ocd.HasStats())) { // On a des stats double rating; rating = (_daddy._bUseGCPopularity) ? ocd._dRatingSimple : ocd._dRating; if (rating >= 0) { stats = " <tr><td><img width=16 height=16 src='"+ imgpath_clean + "/Fav.png'>" + ocd._iNbFavs.ToString() + ", " + _daddy.GetTranslator().GetString("LVRating") + ": " + "</td>" + " <td>"+ "<img src='" + imgpath_clean + "/Ratios/" + "ratio_" + ((int)(ocd._dRating * 100.0)).ToString() + ".png'>" + rating.ToString("0.0%").ToString() + "</td></tr>"; } else if (ocd._iNbFavs > 0) { stats = " <tr><td><img width=16 height=16 src='"+ imgpath_clean + "/Fav.png'>" + ocd._iNbFavs.ToString() + "</td>" + " <td> </td></tr>"; } } //String theType = " <img width=16 height=16 src='" + imgpath_clean + "/Type/" + _geo._Type + ".gif'>"; String theType = " <img src='"+ imgpath_clean + "/TypeCat/" + _daddy._geocachingConstants.GetDicoTypeSmallIcon()[_geo._Type] + ".png'>"; if (MyTools.InsensitiveContainsInStringList(GeocachingConstants.GetSupportedCacheTypes(), _geo._Type) == false) { theType = " <img width=16 height=16 src='"+ imgpath_clean + "/Fail.png'>"; } String infpopup = "<body><table border=0>" + " <tr><td><b>"+ theType + " "+ nameHtml + "</b>" + " </td>"+ " <td align='right'><h4>"+ _geo._Code + "</h4></td></tr>" + stats + " <tr><td>"+ _daddy.GetTranslator().GetString("HTMLACacheBy") + ": " + MyTools.RemoveDiacritics(_geo._PlacedBy).Replace("'", " ") + "</td>" + " <td>"+ _daddy.GetTranslator().GetString("HTMLHidden") + ": " + MyTools.CleanDate(_geo._DateCreation) + "</td></tr>" + " <tr><td>"+ _daddy.GetTranslator().GetString("HTMLDifficulty") + ": <img src='" + imgpath_clean + "/Star/" + _geo._D + ".gif'></td>" + " <td>"+ _daddy.GetTranslator().GetString("HTMLTerrain") + ": <img src='" + imgpath_clean + "/Star/" + _geo._T + ".gif'></td></tr>" + " <tr><td>"+ _daddy.GetTranslator().GetString("HTMLSize") + ": <img src='" + imgpath_clean + "/Size/" + _geo._Container + ".gif'></td>"; if ((_geo._Ocd != null) && (_geo._Ocd._dAltiMeters != Double.MaxValue)) { String salti = ""; if (_daddy._bUseKm) { salti = String.Format("{0:0.#}", _geo._Ocd._dAltiMeters) + " m"; } else { salti = String.Format("{0:0.#}", _geo._Ocd._dAltiMeters * 3.2808399) + " ft"; } infpopup += "<td>" + _daddy.GetTranslator().GetString("HTMLAltitude") + ": " + salti + "</td>"; } else { infpopup += "<td> </td>"; } infpopup += "</tr></table></body>"; // A VIRER !!!!!!!!!! //_daddy.Log(infpopup); Image img = null; CssData css = CssData.Parse("body { font:8pt Tahoma } h3 { color: navy; font-weight:normal; }", true); img = HtmlRender.RenderToImage(infpopup, 330, 150, Color.White, css, null, null); System.Drawing.Size st = img.Size; System.Drawing.Rectangle rect = new System.Drawing.Rectangle(Marker.ToolTipPosition.X, Marker.ToolTipPosition.Y - st.Height / 2, st.Width + TextPadding.Width, st.Height + TextPadding.Height); rect.Offset(Offset.X, Offset.Y); g.DrawImage(img, new Point(rect.X, rect.Y)); } }
public async Task <CssData> GetCssDataAsync(string src, Dictionary <string, string> attributes) { return(CssData.Parse(WinFormsAdapter.Instance, DemoUtils.GetStylesheet(src))); }