|
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
namespace System.Drawing.Html
{
public static class HtmlRenderer
{
#region References
/// <summary>
/// List of assembly references
/// </summary>
private static List<Assembly> _references;
/// <summary>
/// Gets a list of Assembly references used to search for external references
/// </summary>
/// <remarks>
/// This references are used when loading images and other content, when
/// rendering a piece of HTML/CSS
/// </remarks>
public static List<Assembly> References
{
get { return _references; }
}
/// <summary>
/// Adds a reference to the References list if not yet listed
/// </summary>
/// <param name="assembly"></param>
internal static void AddReference(Assembly assembly)
{
if (!References.Contains(assembly))
{
References.Add(assembly);
}
}
static HtmlRenderer()
{
//Initialize references list
_references = new List<Assembly>();
//Add this assembly as a reference
References.Add(Assembly.GetExecutingAssembly());
}
#endregion
#region Methods
/// <summary>
/// Draws the HTML on the specified point using the specified width.
/// </summary>
/// <param name="g">Device to draw</param>
/// <param name="html">HTML source</param>
/// <param name="location">Point to start drawing</param>
/// <param name="width">Width to fit HTML drawing</param>
public static void Render(Graphics g, string html, PointF location, float width)
{
Render(g, html, new RectangleF(location, new SizeF(width, 0)), false);
}
/// <summary>
/// Renders the specified HTML source on the specified area clipping if specified
/// </summary>
/// <param name="g">Device to draw</param>
/// <param name="html">HTML source</param>
/// <param name="area">Area where HTML should be drawn</param>
/// <param name="clip">If true, it will only paint on the specified area</param>
public static void Render(Graphics g, string html, RectangleF area, bool clip)
{
InitialContainer container = new InitialContainer(html);
Region prevClip = g.Clip;
if (clip) g.SetClip(area);
container.SetBounds(area);
container.MeasureBounds(g);
container.Paint(g);
if (clip) g.SetClip(prevClip, System.Drawing.Drawing2D.CombineMode.Replace);
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Jose Menendez
- I've been programming Windows and Web apps since 1997.
- My greatest concern nowadays is product, user interface, and usability.
- TypeScript / React expert
Get me to help you debug your code
https://jose.page/fiverr