From 18c0d3c65563e3cce6b0b526be9e31fd252b559c Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Fri, 11 Sep 2015 22:50:32 +0300 Subject: [PATCH] Various html renderer improvements --- samples/TestApplication/Program.cs | 1 + .../Adapters/ControlAdapter.cs | 21 +- .../Adapters/GraphicsAdapter.cs | 5 +- .../Adapters/ImageAdapter.cs | 2 +- src/Perspex.HtmlRenderer/HtmlControl.cs | 33 +- src/Perspex.HtmlRenderer/HtmlLabel.cs | 7 +- src/Perspex.HtmlRenderer/HtmlRender.cs | 424 ------------------ .../Perspex.HtmlRenderer.csproj | 1 - 8 files changed, 33 insertions(+), 461 deletions(-) delete mode 100644 src/Perspex.HtmlRenderer/HtmlRender.cs diff --git a/samples/TestApplication/Program.cs b/samples/TestApplication/Program.cs index 08adbc8a84..7f1de7cbcd 100644 --- a/samples/TestApplication/Program.cs +++ b/samples/TestApplication/Program.cs @@ -378,6 +378,7 @@ namespace TestApplication Content = new ScrollViewer() { Width = 600, + MaxHeight = 600, HorizontalAlignment = HorizontalAlignment.Center, CanScrollHorizontally = false, VerticalScrollBarVisibility = ScrollBarVisibility.Visible, diff --git a/src/Perspex.HtmlRenderer/Adapters/ControlAdapter.cs b/src/Perspex.HtmlRenderer/Adapters/ControlAdapter.cs index b3908d12e8..be9be611e5 100644 --- a/src/Perspex.HtmlRenderer/Adapters/ControlAdapter.cs +++ b/src/Perspex.HtmlRenderer/Adapters/ControlAdapter.cs @@ -39,6 +39,8 @@ namespace TheArtOfDev.HtmlRenderer.Perspex.Adapters ArgChecker.AssertArgNotNull(control, "control"); _control = control; + _control.PointerPressed += delegate { _leftMouseButton = true; }; + _control.PointerPressed += delegate { _leftMouseButton = false; }; } /// @@ -53,28 +55,19 @@ namespace TheArtOfDev.HtmlRenderer.Perspex.Adapters { get { - //TODO: Implement - //return Utils.Convert(_control.PointFromScreen(Mouse.GetPosition(_control))); - return new RPoint(0, 0); + return Util.Convert(MouseDevice.Instance.GetPosition(_control)); } } - public override bool LeftMouseButton - { - get - { - return false; - //TODO: Implement - //return Mouse.LeftButton == MouseButtonState.Pressed; - } - } + private bool _leftMouseButton; + public override bool LeftMouseButton => _leftMouseButton; public override bool RightMouseButton { get { return false; - //TODO: Implement + //TODO: Implement right mouse click //return Mouse.RightButton == MouseButtonState.Pressed; } } @@ -96,7 +89,7 @@ namespace TheArtOfDev.HtmlRenderer.Perspex.Adapters public override void DoDragDropCopy(object dragDropData) { - //TODO: Implement + //TODO: Implement DragDropCopy //DragDrop.DoDragDrop(_control, dragDropData, DragDropEffects.Copy); } diff --git a/src/Perspex.HtmlRenderer/Adapters/GraphicsAdapter.cs b/src/Perspex.HtmlRenderer/Adapters/GraphicsAdapter.cs index dedb4c9e48..e0da822676 100644 --- a/src/Perspex.HtmlRenderer/Adapters/GraphicsAdapter.cs +++ b/src/Perspex.HtmlRenderer/Adapters/GraphicsAdapter.cs @@ -205,9 +205,8 @@ namespace TheArtOfDev.HtmlRenderer.Perspex.Adapters public override void Dispose() { - //TODO: Do something about Dispose - //if (_releaseGraphics) - // _g.Close(); + if (_releaseGraphics) + _g.Dispose(); } diff --git a/src/Perspex.HtmlRenderer/Adapters/ImageAdapter.cs b/src/Perspex.HtmlRenderer/Adapters/ImageAdapter.cs index c2ef084f4d..ed6a41d20b 100644 --- a/src/Perspex.HtmlRenderer/Adapters/ImageAdapter.cs +++ b/src/Perspex.HtmlRenderer/Adapters/ImageAdapter.cs @@ -44,7 +44,7 @@ namespace TheArtOfDev.HtmlRenderer.Perspex.Adapters public override void Dispose() { - //TODO: Implement + //TODO: Implement image disposal /*if (_image.StreamSource != null) _image.StreamSource.Dispose();*/ } diff --git a/src/Perspex.HtmlRenderer/HtmlControl.cs b/src/Perspex.HtmlRenderer/HtmlControl.cs index 3ac0812a1f..a9f9dc9d9a 100644 --- a/src/Perspex.HtmlRenderer/HtmlControl.cs +++ b/src/Perspex.HtmlRenderer/HtmlControl.cs @@ -19,6 +19,7 @@ using Perspex.Media; using Perspex.Threading; using TheArtOfDev.HtmlRenderer.Core; using TheArtOfDev.HtmlRenderer.Core.Entities; +using TheArtOfDev.HtmlRenderer.Perspex.Adapters; namespace Perspex.Controls { @@ -91,11 +92,14 @@ namespace Perspex.Controls PropertyHelper.Register("Text", null, OnPerspexProperty_valueChanged); public static readonly PerspexProperty BackgroundProperty = - PerspexProperty.Register("Background", Colors.White); + PerspexProperty.Register("Background", Brushes.White); public static readonly PerspexProperty BorderThicknessProperty = PerspexProperty.Register("BorderThickness", new Thickness(0)); + public static readonly PerspexProperty BorderBrushProperty = + PerspexProperty.Register("BorderBrush"); + public static readonly PerspexProperty PaddingProperty = PerspexProperty.Register("Padding", new Thickness(0)); @@ -252,15 +256,21 @@ namespace Perspex.Controls set { SetValue(BorderThicknessProperty, value); } } + public Brush BorderBrush + { + get { return (Brush)GetValue(BorderBrushProperty); } + set { SetValue(BorderThicknessProperty, value); } + } + public Thickness Padding { get { return (Thickness)GetValue(PaddingProperty); } set { SetValue(PaddingProperty, value); } } - public Color Background + public Brush Background { - get { return (Color?) GetValue(BackgroundProperty) ?? Colors.White; } + get { return (Brush) GetValue(BackgroundProperty); } set { SetValue(BackgroundProperty, value);} } @@ -321,15 +331,10 @@ namespace Perspex.Controls public override void Render(IDrawingContext context) { - //TODO: Use actual background - context.FillRectange(new SolidColorBrush(Colors.White), new Rect(RenderSize)); - /*if (Background.Opacity > 0) - context.DrawRectangle(Background, null, new Rect(RenderSize)); - */ + context.FillRectange(Background, new Rect(RenderSize)); - if (BorderThickness != new Thickness(0)) + if (BorderThickness != new Thickness(0) && BorderBrush != null) { - //TODO: Get default border brush from theme or something var brush = new SolidColorBrush(Colors.Black); if (BorderThickness.Top > 0) context.FillRectange(brush, new Rect(0, 0, RenderSize.Width, BorderThickness.Top)); @@ -346,7 +351,7 @@ namespace Perspex.Controls if (_htmlContainer != null && htmlWidth > 0 && htmlHeight > 0) { /* - //TODO: Rever antialiasing fixes + //TODO: Revert antialiasing fixes var windows = Window.GetWindow(this); if (windows != null) { @@ -514,8 +519,8 @@ namespace Perspex.Controls /// protected virtual void InvokeMouseMove() { - - _htmlContainer.HandleMouseMove(this, MouseDevice.Instance.GetPosition(this)); + + _htmlContainer.HandleMouseMove(this, MouseDevice.Instance?.GetPosition(this) ?? default(Point)); } /// @@ -541,7 +546,7 @@ namespace Perspex.Controls } else if (e.Property == BaseStylesheetProperty) { - var baseCssData = HtmlRender.ParseStyleSheet((string)e.NewValue); + var baseCssData = CssData.Parse(PerspexAdapter.Instance, (string)e.NewValue); control._baseCssData = baseCssData; htmlContainer.SetHtml(control.Text, baseCssData); } diff --git a/src/Perspex.HtmlRenderer/HtmlLabel.cs b/src/Perspex.HtmlRenderer/HtmlLabel.cs index f4c90cf05e..1ea40f3684 100644 --- a/src/Perspex.HtmlRenderer/HtmlLabel.cs +++ b/src/Perspex.HtmlRenderer/HtmlLabel.cs @@ -45,7 +45,7 @@ namespace Perspex.Controls /// static HtmlLabel() { - //BackgroundProperty.OverrideDefaultValue(Brushes.Transparent); + BackgroundProperty.OverrideDefaultValue(Brushes.Transparent); } #region Private methods @@ -62,9 +62,8 @@ namespace Perspex.Controls var horizontal = Padding.Left + Padding.Right + BorderThickness.Left + BorderThickness.Right; var vertical = Padding.Top + Padding.Bottom + BorderThickness.Top + BorderThickness.Bottom; - var size = new RSize(constraint.Width < Double.PositiveInfinity ? constraint.Width - horizontal : 0, constraint.Height < Double.PositiveInfinity ? constraint.Height - vertical : 0); - //var minSize = new RSize(MinWidth < Double.PositiveInfinity ? MinWidth - horizontal : 0, MinHeight < Double.PositiveInfinity ? MinHeight - vertical : 0); - var maxSize = new RSize(MaxWidth < Double.PositiveInfinity ? MaxWidth - horizontal : 0, MaxHeight < Double.PositiveInfinity ? MaxHeight - vertical : 0); + var size = new Size(Math.Min(MaxWidth, constraint.Width), Math.Min(MaxHeight, constraint.Height)); + var maxSize = new RSize(size.Width < Double.PositiveInfinity ? size.Width - horizontal : 0, size.Height < Double.PositiveInfinity ? size.Height - vertical : 0); _htmlContainer.HtmlContainerInt.MaxSize = maxSize; _htmlContainer.HtmlContainerInt.PerformLayout(ig); diff --git a/src/Perspex.HtmlRenderer/HtmlRender.cs b/src/Perspex.HtmlRenderer/HtmlRender.cs deleted file mode 100644 index 686116e6bb..0000000000 --- a/src/Perspex.HtmlRenderer/HtmlRender.cs +++ /dev/null @@ -1,424 +0,0 @@ -// "Therefore those skilled at the unorthodox -// are infinite as heaven and earth, -// inexhaustible as the great rivers. -// When they come to an end, -// they begin again, -// like the days and months; -// they die and are reborn, -// like the four seasons." -// -// - Sun Tsu, -// "The Art of War" - -using System; - -using Perspex.Media; -using Perspex.Media.Imaging; -using TheArtOfDev.HtmlRenderer.Core; -using TheArtOfDev.HtmlRenderer.Core.Entities; -using TheArtOfDev.HtmlRenderer.Core.Utils; -using TheArtOfDev.HtmlRenderer.Perspex.Adapters; - -namespace Perspex.Controls -{ - /// - /// Standalone static class for simple and direct HTML rendering.
- /// For Perspex UI prefer using HTML controls: or .
- /// For low-level control and performance consider using .
- ///
- /// - /// - /// Rendering to image
- /// // TODO:a update! - /// See https://htmlrenderer.codeplex.com/wikipage?title=Image%20generation
- /// Because of GDI text rendering issue with alpha channel clear type text rendering rendering to image requires special handling.
- /// Solid color background - generate an image where the background is filled with solid color and all the html is rendered on top - /// of the background color, GDI text rendering will be used. (RenderToImage method where the first argument is html string)
- /// Image background - render html on top of existing image with whatever currently exist but it cannot have transparent pixels, - /// GDI text rendering will be used. (RenderToImage method where the first argument is Image object)
- /// Transparent background - render html to empty image using GDI+ text rendering, the generated image can be transparent. - ///
- /// - /// Overwrite stylesheet resolution
- /// Exposed by optional "stylesheetLoad" delegate argument.
- /// Invoked when a stylesheet is about to be loaded by file path or URL in 'link' element.
- /// Allows to overwrite the loaded stylesheet by providing the stylesheet data manually, or different source (file or URL) to load from.
- /// Example: The stylesheet 'href' can be non-valid URI string that is interpreted in the overwrite delegate by custom logic to pre-loaded stylesheet object
- /// If no alternative data is provided the original source will be used.
- ///
- /// - /// Overwrite image resolution
- /// Exposed by optional "imageLoad" delegate argument.
- /// Invoked when an image is about to be loaded by file path, URL or inline data in 'img' element or background-image CSS style.
- /// Allows to overwrite the loaded image by providing the image object manually, or different source (file or URL) to load from.
- /// Example: image 'src' can be non-valid string that is interpreted in the overwrite delegate by custom logic to resource image object
- /// Example: image 'src' in the html is relative - the overwrite intercepts the load and provide full source URL to load the image from
- /// Example: image download requires authentication - the overwrite intercepts the load, downloads the image to disk using custom code and provide - /// file path to load the image from.
- /// If no alternative data is provided the original source will be used.
- /// Note: Cannot use asynchronous scheme overwrite scheme.
- ///
- ///
- /// - /// - /// Simple rendering
- /// HtmlRender.Render(g, "Hello World]]>");
- /// HtmlRender.Render(g, "Hello World]]>", 10, 10, 500, CssData.Parse("body {font-size: 20px}")");
- ///
- /// - /// Image rendering
- /// HtmlRender.RenderToImage("Hello World]]>", new Size(600,400));
- /// HtmlRender.RenderToImage("Hello World]]>", 600);
- /// HtmlRender.RenderToImage(existingImage, "Hello World]]>");
- ///
- ///
- public static class HtmlRender - { - /// - /// Adds a font family to be used in html rendering.
- /// The added font will be used by all rendering function including and all Perspex controls. - ///
- /// - /// The given font family instance must be remain alive while the renderer is in use.
- /// If loaded from file then the file must not be deleted. - ///
- /// The font family to add. - public static void AddFontFamily(string fontFamily) - { - ArgChecker.AssertArgNotNull(fontFamily, "fontFamily"); - - PerspexAdapter.Instance.AddFontFamily(new FontFamilyAdapter(fontFamily)); - } - - /// - /// Adds a font mapping from to iff the is not found.
- /// When the font is used in rendered html and is not found in existing - /// fonts (installed or added) it will be replaced by .
- ///
- /// - /// This fonts mapping can be used as a fallback in case the requested font is not installed in the client system. - /// - /// the font family to replace - /// the font family to replace with - public static void AddFontFamilyMapping(string fromFamily, string toFamily) - { - ArgChecker.AssertArgNotNullOrEmpty(fromFamily, "fromFamily"); - ArgChecker.AssertArgNotNullOrEmpty(toFamily, "toFamily"); - - PerspexAdapter.Instance.AddFontFamilyMapping(fromFamily, toFamily); - } - - /// - /// Parse the given stylesheet to object.
- /// If 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. - ///
- /// - /// the stylesheet source to parse - /// true - combine the parsed css data with default css data, false - return only the parsed css data - /// the parsed css data - public static CssData ParseStyleSheet(string stylesheet, bool combineWithDefault = true) - { - return CssData.Parse(PerspexAdapter.Instance, stylesheet, combineWithDefault); - } - - /// - /// Measure the size (width and height) required to draw the given html under given max width restriction.
- /// If no max width restriction is given the layout will use the maximum possible width required by the content, - /// it can be the longest text line or full image width.
- ///
- /// HTML source to render - /// optional: bound the width of the html to render in (default - 0, unlimited) - /// optional: the style to use for html rendering (default - use W3 default style) - /// optional: can be used to overwrite stylesheet resolution logic - /// optional: can be used to overwrite image resolution logic - /// the size required for the html - public static Size Measure(string html, double maxWidth = 0, CssData cssData = null, - EventHandler stylesheetLoad = null, EventHandler imageLoad = null) - { - Size actualSize = Size.Empty; - if (!string.IsNullOrEmpty(html)) - { - using (var container = new HtmlContainer()) - { - container.MaxSize = new Size(maxWidth, 0); - container.AvoidAsyncImagesLoading = true; - container.AvoidImagesLateLoading = true; - - if (stylesheetLoad != null) - container.StylesheetLoad += stylesheetLoad; - if (imageLoad != null) - container.ImageLoad += imageLoad; - - container.SetHtml(html, cssData); - container.PerformLayout(); - - actualSize = container.ActualSize; - } - } - return actualSize; - } - /* - /// - /// Renders the specified HTML source on the specified location and max width restriction.
- /// If is zero the html will use all the required width, otherwise it will perform line - /// wrap as specified in the html
- /// Returned is the actual width and height of the rendered html.
- ///
- /// Device to render with - /// HTML source to render - /// optional: the left most location to start render the html at (default - 0) - /// optional: the top most location to start render the html at (default - 0) - /// optional: bound the width of the html to render in (default - 0, unlimited) - /// optional: the style to use for html rendering (default - use W3 default style) - /// optional: can be used to overwrite stylesheet resolution logic - /// optional: can be used to overwrite image resolution logic - /// the actual size of the rendered html - public static Size Render(IDrawingContext g, string html, double left = 0, double top = 0, double maxWidth = 0, CssData cssData = null, - EventHandler stylesheetLoad = null, EventHandler imageLoad = null) - { - ArgChecker.AssertArgNotNull(g, "g"); - return RenderClip(g, html, new Point(left, top), new Size(maxWidth, 0), cssData, stylesheetLoad, imageLoad); - } - - /// - /// Renders the specified HTML source on the specified location and max size restriction.
- /// If .Width is zero the html will use all the required width, otherwise it will perform line - /// wrap as specified in the html
- /// If .Height is zero the html will use all the required height, otherwise it will clip at the - /// given max height not rendering the html below it.
- /// Returned is the actual width and height of the rendered html.
- ///
- /// Device to render with - /// HTML source to render - /// the top-left most location to start render the html at - /// the max size of the rendered html (if height above zero it will be clipped) - /// optional: the style to use for html rendering (default - use W3 default style) - /// optional: can be used to overwrite stylesheet resolution logic - /// optional: can be used to overwrite image resolution logic - /// the actual size of the rendered html - public static Size Render(IDrawingContext g, string html, Point location, Size maxSize, CssData cssData = null, - EventHandler stylesheetLoad = null, EventHandler imageLoad = null) - { - ArgChecker.AssertArgNotNull(g, "g"); - return RenderClip(g, html, location, maxSize, cssData, stylesheetLoad, imageLoad); - } - - /// - /// Renders the specified HTML into a new image of the requested size.
- /// The HTML will be layout by the given size but will be clipped if cannot fit.
- ///
- /// HTML source to render - /// The size of the image to render into, layout html by width and clipped by height - /// optional: the style to use for html rendering (default - use W3 default style) - /// optional: can be used to overwrite stylesheet resolution logic - /// optional: can be used to overwrite image resolution logic - /// the generated image of the html - public static BitmapFrame RenderToImage(string html, Size size, CssData cssData = null, - EventHandler stylesheetLoad = null, EventHandler imageLoad = null) - { - var renderTarget = new RenderTargetBitmap((int)size.Width, (int)size.Height, 96, 96, PixelFormats.Pbgra32); - - if (!string.IsNullOrEmpty(html)) - { - // render HTML into the visual - DrawingVisual drawingVisual = new DrawingVisual(); - using (IDrawingContext g = drawingVisual.RenderOpen()) - { - RenderHtml(g, html, new Point(), size, cssData, stylesheetLoad, imageLoad); - } - - // render visual into target bitmap - renderTarget.Render(drawingVisual); - } - - return BitmapFrame.Create(renderTarget); - } - - /// - /// Renders the specified HTML into a new image of unknown size that will be determined by max width/height and HTML layout.
- /// If is zero the html will use all the required width, otherwise it will perform line - /// wrap as specified in the html
- /// If is zero the html will use all the required height, otherwise it will clip at the - /// given max height not rendering the html below it.
- ///

- /// Limitation: The image cannot have transparent background, by default it will be white.
- /// See "Rendering to image" remarks section on .
- ///

- ///
- /// HTML source to render - /// optional: the max width of the rendered html, if not zero and html cannot be layout within the limit it will be clipped - /// optional: the max height of the rendered html, if not zero and html cannot be layout within the limit it will be clipped - /// optional: the color to fill the image with (default - white) - /// optional: the style to use for html rendering (default - use W3 default style) - /// optional: can be used to overwrite stylesheet resolution logic - /// optional: can be used to overwrite image resolution logic - /// the generated image of the html - public static BitmapFrame RenderToImage(string html, int maxWidth = 0, int maxHeight = 0, Color backgroundColor = new Color(), CssData cssData = null, - EventHandler stylesheetLoad = null, EventHandler imageLoad = null) - { - return RenderToImage(html, Size.Empty, new Size(maxWidth, maxHeight), backgroundColor, cssData, stylesheetLoad, imageLoad); - } - - /// - /// Renders the specified HTML into a new image of unknown size that will be determined by min/max width/height and HTML layout.
- /// If is zero the html will use all the required width, otherwise it will perform line - /// wrap as specified in the html
- /// If is zero the html will use all the required height, otherwise it will clip at the - /// given max height not rendering the html below it.
- /// If (Width/Height) is above zero the rendered image will not be smaller than the given min size.
- ///

- /// Limitation: The image cannot have transparent background, by default it will be white.
- /// See "Rendering to image" remarks section on .
- ///

- ///
- /// HTML source to render - /// optional: the min size of the rendered html (zero - not limit the width/height) - /// optional: the max size of the rendered html, if not zero and html cannot be layout within the limit it will be clipped (zero - not limit the width/height) - /// optional: the color to fill the image with (default - white) - /// optional: the style to use for html rendering (default - use W3 default style) - /// optional: can be used to overwrite stylesheet resolution logic - /// optional: can be used to overwrite image resolution logic - /// the generated image of the html - public static BitmapFrame RenderToImage(string html, Size minSize, Size maxSize, Color backgroundColor = new Color(), CssData cssData = null, - EventHandler stylesheetLoad = null, EventHandler imageLoad = null) - { - RenderTargetBitmap renderTarget; - if (!string.IsNullOrEmpty(html)) - { - using (var container = new HtmlContainer()) - { - container.AvoidAsyncImagesLoading = true; - container.AvoidImagesLateLoading = true; - - if (stylesheetLoad != null) - container.StylesheetLoad += stylesheetLoad; - if (imageLoad != null) - container.ImageLoad += imageLoad; - container.SetHtml(html, cssData); - - var finalSize = MeasureHtmlByRestrictions(container, minSize, maxSize); - container.MaxSize = finalSize; - - renderTarget = new RenderTargetBitmap((int)finalSize.Width, (int)finalSize.Height, 96, 96, PixelFormats.Pbgra32); - - // render HTML into the visual - DrawingVisual drawingVisual = new DrawingVisual(); - using (IDrawingContext g = drawingVisual.RenderOpen()) - { - container.PerformPaint(g, new Rect(new Size(maxSize.Width > 0 ? maxSize.Width : double.MaxValue, maxSize.Height > 0 ? maxSize.Height : double.MaxValue))); - } - - // render visual into target bitmap - renderTarget.Render(drawingVisual); - } - } - else - { - renderTarget = new RenderTargetBitmap(0, 0, 96, 96, PixelFormats.Pbgra32); - } - - return BitmapFrame.Create(renderTarget); - } - - - #region Private methods - - /// - /// Measure the size of the html by performing layout under the given restrictions. - /// - /// the html to calculate the layout for - /// the minimal size of the rendered html (zero - not limit the width/height) - /// the maximum size of the rendered html, if not zero and html cannot be layout within the limit it will be clipped (zero - not limit the width/height) - /// return: the size of the html to be rendered within the min/max limits - private static Size MeasureHtmlByRestrictions(HtmlContainer htmlContainer, Size minSize, Size maxSize) - { - // use desktop created graphics to measure the HTML - using (var mg = new GraphicsAdapter()) - { - var sizeInt = HtmlRendererUtil.MeasureHtmlByRestrictions(mg, htmlContainer.HtmlContainerInt, Util.Convert(minSize), Util.Convert(maxSize)); - if (maxSize.Width < 1 && sizeInt.Width > 4096) - sizeInt.Width = 4096; - return Util.ConvertRound(sizeInt); - } - } - - /// - /// Renders the specified HTML source on the specified location and max size restriction.
- /// If .Width is zero the html will use all the required width, otherwise it will perform line - /// wrap as specified in the html
- /// If .Height is zero the html will use all the required height, otherwise it will clip at the - /// given max height not rendering the html below it.
- /// Clip the graphics so the html will not be rendered outside the max height bound given.
- /// Returned is the actual width and height of the rendered html.
- ///
- /// Device to render with - /// HTML source to render - /// the top-left most location to start render the html at - /// the max size of the rendered html (if height above zero it will be clipped) - /// optional: the style to use for html rendering (default - use W3 default style) - /// optional: can be used to overwrite stylesheet resolution logic - /// optional: can be used to overwrite image resolution logic - /// the actual size of the rendered html - private static Size RenderClip(IDrawingContext g, string html, Point location, Size maxSize, CssData cssData, EventHandler stylesheetLoad, EventHandler imageLoad) - { - if (maxSize.Height > 0) - g.PushClip(new RectangleGeometry(new Rect(location, maxSize))); - - var actualSize = RenderHtml(g, html, location, maxSize, cssData, stylesheetLoad, imageLoad); - - if (maxSize.Height > 0) - g.Pop(); - - return actualSize; - } - - /// - /// Renders the specified HTML source on the specified location and max size restriction.
- /// If .Width is zero the html will use all the required width, otherwise it will perform line - /// wrap as specified in the html
- /// If .Height is zero the html will use all the required height, otherwise it will clip at the - /// given max height not rendering the html below it.
- /// Returned is the actual width and height of the rendered html.
- ///
- /// Device to render with - /// HTML source to render - /// the top-left most location to start render the html at - /// the max size of the rendered html (if height above zero it will be clipped) - /// optional: the style to use for html rendering (default - use W3 default style) - /// optional: can be used to overwrite stylesheet resolution logic - /// optional: can be used to overwrite image resolution logic - /// the actual size of the rendered html - private static Size RenderHtml(IDrawingContext g, string html, Point location, Size maxSize, CssData cssData, EventHandler stylesheetLoad, EventHandler imageLoad) - { - Size actualSize = Size.Empty; - - if (!string.IsNullOrEmpty(html)) - { - using (var container = new HtmlContainer()) - { - container.Location = location; - container.MaxSize = maxSize; - container.AvoidAsyncImagesLoading = true; - container.AvoidImagesLateLoading = true; - - if (stylesheetLoad != null) - container.StylesheetLoad += stylesheetLoad; - if (imageLoad != null) - container.ImageLoad += imageLoad; - - container.SetHtml(html, cssData); - container.PerformLayout(); - container.PerformPaint(g, new Rect(0, 0, double.MaxValue, double.MaxValue)); - - actualSize = container.ActualSize; - } - } - - return actualSize; - } - - #endregion - */ - } -} \ No newline at end of file diff --git a/src/Perspex.HtmlRenderer/Perspex.HtmlRenderer.csproj b/src/Perspex.HtmlRenderer/Perspex.HtmlRenderer.csproj index 2a507821df..47e6491bf0 100644 --- a/src/Perspex.HtmlRenderer/Perspex.HtmlRenderer.csproj +++ b/src/Perspex.HtmlRenderer/Perspex.HtmlRenderer.csproj @@ -129,7 +129,6 @@ -