using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Threading; using FastReport.Utils; namespace FastReport.Export.Html { /// /// Represents the HTML export format enum /// public enum HTMLExportFormat { /// /// Represents the message-HTML type /// MessageHTML, /// /// Represents the HTML type /// HTML } /// /// Specifies the image format in HTML export. /// public enum ImageFormat { /// /// Specifies the .bmp format. /// Bmp, /// /// Specifies the .png format. /// Png, /// /// Specifies the .jpg format. /// Jpeg, /// /// Specifies the .gif format. /// Gif } /// /// Specifies the units of HTML sizes. /// public enum HtmlSizeUnits { /// /// Specifies the pixel units. /// Pixel, /// /// Specifies the percent units. /// Percent } public partial class HTMLExport : ExportBase { private static string Px(double pixel) { return String.Join(String.Empty, new String[] { ExportUtils.FloatToString(pixel), "px;" }); } private string SizeValue(double value, double maxvalue, HtmlSizeUnits units) { FastString sb = new FastString(6); if (units == HtmlSizeUnits.Pixel) sb.Append(Px(value)); else if (units == HtmlSizeUnits.Percent) sb.Append(((int)Math.Round((value * 100 / maxvalue))).ToString()).Append("%"); else sb.Append(value.ToString()); return sb.ToString(); } private void WriteMimePart(Stream stream, string mimetype, string charset, string filename) { FastString sb = new FastString(); sb.Append("--").AppendLine(boundary); sb.Append("Content-Type: ").Append(mimetype).Append(";"); if (charset != String.Empty) sb.Append(" charset=\"").Append(charset).AppendLine("\""); else sb.AppendLine(); string body; byte[] buff = new byte[stream.Length]; stream.Position = 0; stream.Read(buff, 0, buff.Length); if (mimetype == "text/html") { sb.AppendLine("Content-Transfer-Encoding: quoted-printable"); body = ExportUtils.QuotedPrintable(buff); } else { sb.AppendLine("Content-Transfer-Encoding: base64"); body = System.Convert.ToBase64String(buff, Base64FormattingOptions.InsertLineBreaks); } sb.Append("Content-Location: ").AppendLine(ExportUtils.HtmlURL(filename)); sb.AppendLine(); sb.AppendLine(body); sb.AppendLine(); Stream.Write(Encoding.ASCII.GetBytes(sb.ToString()), 0, sb.Length); sb.Clear(); } private void WriteMHTHeader(Stream Stream, string FileName) { FastString sb = new FastString(256); string s = "=?utf-8?B?" + System.Convert.ToBase64String(Encoding.UTF8.GetBytes(FileName)) + "?="; sb.Append("From: ").AppendLine(s); sb.Append("Subject: ").AppendLine(s); sb.Append("Date: ").AppendLine(ExportUtils.GetRFCDate(SystemFake.DateTime.Now)); sb.AppendLine("MIME-Version: 1.0"); sb.Append("Content-Type: multipart/related; type=\"text/html\"; boundary=\"").Append(boundary).AppendLine("\""); sb.AppendLine(); sb.AppendLine("This is a multi-part message in MIME format."); sb.AppendLine(); ExportUtils.Write(Stream, sb.ToString()); sb.Clear(); } } /// /// For internal use only. /// public class HTMLPageData { private string cssText; private string pageText; private List pictures; private List guids; private ManualResetEvent pageEvent; private int pageNumber; private float width; private float height; /// /// For internal use only. /// public float Width { get { return width; } set { width = value; } } /// /// For internal use only. /// public float Height { get { return height; } set { height = value; } } /// /// For internal use only. /// public string CSSText { get { return cssText; } set { cssText = value; } } /// /// For internal use only. /// public string PageText { get { return pageText; } set { pageText = value; } } /// /// For internal use only. /// public List Pictures { get { return pictures; } } /// /// For internal use only. /// public List Guids { get { return guids; } } /// /// For internal use only. /// public ManualResetEvent PageEvent { get { return pageEvent; } } /// /// For internal use only. /// public int PageNumber { get { return pageNumber; } set { pageNumber = value; } } /// /// For internal use only. /// public HTMLPageData() { pictures = new List(); guids = new List(); pageEvent = new ManualResetEvent(false); } } }