diff --git a/Source/HtmlRenderer.WinForms/Adapters/WinFormsAdapter.cs b/Source/HtmlRenderer.WinForms/Adapters/WinFormsAdapter.cs
index 16bc83db8..cfde0294f 100644
--- a/Source/HtmlRenderer.WinForms/Adapters/WinFormsAdapter.cs
+++ b/Source/HtmlRenderer.WinForms/Adapters/WinFormsAdapter.cs
@@ -88,7 +88,7 @@ protected override RBrush CreateLinearGradientBrush(RRect rect, RColor color1, R
return new BrushAdapter(new LinearGradientBrush(Utils.Convert(rect), Utils.Convert(color1), Utils.Convert(color2), (float)angle), true);
}
- protected override RImage ConvertImageInt(object image)
+ protected override RImage? ConvertImageInt(object? image)
{
return image != null ? new ImageAdapter((Image)image) : null;
}
diff --git a/Source/HtmlRenderer.WinForms/HtmlContainer.cs b/Source/HtmlRenderer.WinForms/HtmlContainer.cs
index 5bc7c5cd0..ee76bacbd 100644
--- a/Source/HtmlRenderer.WinForms/HtmlContainer.cs
+++ b/Source/HtmlRenderer.WinForms/HtmlContainer.cs
@@ -286,7 +286,7 @@ public SizeF ActualSize
///
/// Get the currently selected text segment in the html.
///
- public string SelectedText
+ public string? SelectedText
{
get { return _htmlContainerInt.SelectedText; }
}
@@ -294,7 +294,7 @@ public string SelectedText
///
/// Copy the currently selected html segment with style.
///
- public string SelectedHtml
+ public string? SelectedHtml
{
get { return _htmlContainerInt.SelectedHtml; }
}
@@ -312,7 +312,7 @@ public void ClearSelection()
///
/// the html to init with, init empty if not given
/// optional: the stylesheet to init with, init default if not given
- public void SetHtml(string htmlSource, CssData baseCssData = null)
+ public void SetHtml(string? htmlSource, CssData? baseCssData = null)
{
_htmlContainerInt.SetHtml(htmlSource, baseCssData);
}
@@ -322,7 +322,7 @@ public void SetHtml(string htmlSource, CssData baseCssData = null)
///
/// Optional: controls the way styles are generated when html is generated (default: )
/// generated html
- public string GetHtml(HtmlGenerationStyle styleGen = HtmlGenerationStyle.Inline)
+ public string? GetHtml(HtmlGenerationStyle styleGen = HtmlGenerationStyle.Inline)
{
return _htmlContainerInt.GetHtml(styleGen);
}
@@ -334,7 +334,7 @@ public string GetHtml(HtmlGenerationStyle styleGen = HtmlGenerationStyle.Inline)
/// the location to find the attribute at
/// the attribute key to get value by
/// found attribute value or null if not found
- public string GetAttributeAt(Point location, string attribute)
+ public string? GetAttributeAt(Point location, string attribute)
{
return _htmlContainerInt.GetAttributeAt(Utils.Convert(location), attribute);
}
@@ -358,7 +358,7 @@ public List> GetLinks()
///
/// the location to find the link at
/// css link href if exists or null
- public string GetLinkAt(Point location)
+ public string? GetLinkAt(Point location)
{
return _htmlContainerInt.GetLinkAt(Utils.Convert(location));
}
diff --git a/Source/HtmlRenderer.WinForms/HtmlLabel.cs b/Source/HtmlRenderer.WinForms/HtmlLabel.cs
index 283ef7360..645d418bc 100644
--- a/Source/HtmlRenderer.WinForms/HtmlLabel.cs
+++ b/Source/HtmlRenderer.WinForms/HtmlLabel.cs
@@ -75,7 +75,7 @@ public class HtmlLabel : Control
///
/// Underline html container instance.
///
- protected HtmlContainer _htmlContainer;
+ protected HtmlContainer? _htmlContainer;
///
/// The current border style of the control
@@ -85,17 +85,17 @@ public class HtmlLabel : Control
///
/// the raw base stylesheet data used in the control
///
- protected string _baseRawCssData;
+ protected string? _baseRawCssData;
///
/// the base stylesheet data used in the panel
///
- protected CssData _baseCssData;
+ protected CssData? _baseCssData;
///
/// the current html text set in the control
///
- protected string _text;
+ protected string? _text;
///
/// is to handle auto size of the control height only
@@ -296,7 +296,7 @@ public virtual bool IsContextMenuEnabled
[Description("Set base stylesheet to be used by html rendered in the control.")]
[Category("Appearance")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
- [Editor("System.ComponentModel.Design.MultilineStringEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
+ [Editor("System.ComponentModel.Design.MultilineStringEditor, System.Windows.Forms.Design, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "System.Drawing.Design.UITypeEditor, System.Windows.Forms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public virtual string BaseStylesheet
{
get { return _baseRawCssData; }
@@ -488,21 +488,17 @@ protected override void OnLayout(LayoutEventArgs levent)
{
if (_htmlContainer != null)
{
- Graphics g = CreateGraphics();
- if (g != null)
+ using (var g = CreateGraphics())
+ using (var ig = new GraphicsAdapter(g, _htmlContainer.UseGdiPlusTextRendering))
{
- using (g)
- using (var ig = new GraphicsAdapter(g, _htmlContainer.UseGdiPlusTextRendering))
- {
- var newSize = HtmlRendererUtils.Layout(ig,
+ var newSize = HtmlRendererUtils.Layout(ig,
_htmlContainer.HtmlContainerInt,
new RSize(ClientSize.Width - Padding.Horizontal, ClientSize.Height - Padding.Vertical),
new RSize(MinimumSize.Width - Padding.Horizontal, MinimumSize.Height - Padding.Vertical),
new RSize(MaximumSize.Width - Padding.Horizontal, MaximumSize.Height - Padding.Vertical),
AutoSize,
AutoSizeHeightOnly);
- ClientSize = Utils.ConvertRound(new RSize(newSize.Width + Padding.Horizontal, newSize.Height + Padding.Vertical));
- }
+ ClientSize = Utils.ConvertRound(new RSize(newSize.Width + Padding.Horizontal, newSize.Height + Padding.Vertical));
}
}
base.OnLayout(levent);
@@ -659,7 +655,7 @@ protected override void WndProc(ref Message m)
try
{
// Replace .NET's hand cursor with the OS cursor
- Win32Utils.SetCursor(Win32Utils.LoadCursor(0, Win32Utils.IdcHand));
+ Win32Utils.SetCursor(Win32Utils.LoadCursor(IntPtr.Zero, Win32Utils.IdcHand));
m.Result = IntPtr.Zero;
return;
}
diff --git a/Source/HtmlRenderer.WinForms/HtmlPanel.cs b/Source/HtmlRenderer.WinForms/HtmlPanel.cs
index a2f061874..a4fafd054 100644
--- a/Source/HtmlRenderer.WinForms/HtmlPanel.cs
+++ b/Source/HtmlRenderer.WinForms/HtmlPanel.cs
@@ -77,17 +77,17 @@ public class HtmlPanel : ScrollableControl
///
/// the raw base stylesheet data used in the control
///
- protected string _baseRawCssData;
+ protected string? _baseRawCssData;
///
/// the base stylesheet data used in the control
///
- protected CssData _baseCssData;
+ protected CssData? _baseCssData;
///
/// the current html text set in the control
///
- protected string _text;
+ protected string? _text;
///
/// If to use cursors defined by the operating system or .NET cursors
@@ -304,7 +304,7 @@ public virtual bool IsContextMenuEnabled
[Category("Appearance")]
[Description("Set base stylesheet to be used by html rendered in the control.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
- [Editor("System.ComponentModel.Design.MultilineStringEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
+ [Editor("System.ComponentModel.Design.MultilineStringEditor, System.Windows.Forms.Design, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "System.Drawing.Design.UITypeEditor, System.Windows.Forms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public virtual string BaseStylesheet
{
get { return _baseRawCssData; }
@@ -471,13 +471,9 @@ protected void PerformHtmlLayout()
{
_htmlContainer.MaxSize = new SizeF(ClientSize.Width - Padding.Horizontal, 0);
- Graphics g = CreateGraphics();
- if (g != null)
+ using (var g = CreateGraphics())
{
- using (g)
- {
- _htmlContainer.PerformLayout(g);
- }
+ _htmlContainer.PerformLayout(g);
}
AutoScrollMinSize = Size.Round(new SizeF(_htmlContainer.ActualSize.Width + Padding.Horizontal, _htmlContainer.ActualSize.Height));
@@ -747,7 +743,7 @@ protected override void WndProc(ref Message m)
try
{
// Replace .NET's hand cursor with the OS cursor
- Win32Utils.SetCursor(Win32Utils.LoadCursor(0, Win32Utils.IdcHand));
+ Win32Utils.SetCursor(Win32Utils.LoadCursor(IntPtr.Zero, Win32Utils.IdcHand));
m.Result = IntPtr.Zero;
return;
}
diff --git a/Source/HtmlRenderer.WinForms/HtmlRenderer.WinForms.csproj b/Source/HtmlRenderer.WinForms/HtmlRenderer.WinForms.csproj
index 51aec7512..d05d042ee 100644
--- a/Source/HtmlRenderer.WinForms/HtmlRenderer.WinForms.csproj
+++ b/Source/HtmlRenderer.WinForms/HtmlRenderer.WinForms.csproj
@@ -1,11 +1,11 @@
- net8.0-windows
+ net10.0-windows
Library
TheArtOfDev.HtmlRenderer.WinForms
true
+ enable
true
- true
diff --git a/Source/HtmlRenderer.WinForms/HtmlToolTip.cs b/Source/HtmlRenderer.WinForms/HtmlToolTip.cs
index 2a82209bd..adb087822 100644
--- a/Source/HtmlRenderer.WinForms/HtmlToolTip.cs
+++ b/Source/HtmlRenderer.WinForms/HtmlToolTip.cs
@@ -31,17 +31,17 @@ public class HtmlToolTip : ToolTip
///
/// the container to render and handle the html shown in the tooltip
///
- protected HtmlContainer _htmlContainer;
+ protected HtmlContainer? _htmlContainer;
///
/// the raw base stylesheet data used in the control
///
- protected string _baseRawCssData;
+ protected string? _baseRawCssData;
///
/// the base stylesheet data used in the panel
///
- protected CssData _baseCssData;
+ protected CssData? _baseCssData;
///
/// The text rendering hint to be used for text rendering.
@@ -57,13 +57,13 @@ public class HtmlToolTip : ToolTip
/// the control that the tooltip is currently showing on.
/// Used for link handling.
///
- private Control _associatedControl;
+ private Control? _associatedControl;
///
/// timer used to handle mouse move events when mouse is over the tooltip.
/// Used for link handling.
///
- private Timer _linkHandlingTimer;
+ private Timer? _linkHandlingTimer;
///
/// the handle of the actual tooltip window used to know when the tooltip is hidden
@@ -175,7 +175,7 @@ public TextRenderingHint TextRenderingHint
[Description("Set base stylesheet to be used by html rendered in the tooltip.")]
[Category("Appearance")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
- [Editor("System.ComponentModel.Design.MultilineStringEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
+ [Editor("System.ComponentModel.Design.MultilineStringEditor, System.Windows.Forms.Design, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "System.Drawing.Design.UITypeEditor, System.Windows.Forms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public virtual string BaseStylesheet
{
get { return _baseRawCssData; }
@@ -238,6 +238,9 @@ public virtual Size MaximumSize
///
protected virtual void OnToolTipPopup(PopupEventArgs e)
{
+ if (e.AssociatedControl == null)
+ return;
+
//Create fragment container
var cssClass = string.IsNullOrEmpty(_tooltipCssClass) ? null : string.Format(" class=\"{0}\"", _tooltipCssClass);
var toolipHtml = string.Format("{1}
", cssClass, GetToolTip(e.AssociatedControl));
@@ -276,7 +279,8 @@ protected virtual void OnToolTipDraw(DrawToolTipEventArgs e)
_tooltipHandle = Win32Utils.WindowFromDC(hdc);
e.Graphics.ReleaseHdc(hdc);
- AdjustTooltipPosition(e.AssociatedControl, e.Bounds.Size);
+ if (e.AssociatedControl != null)
+ AdjustTooltipPosition(e.AssociatedControl, e.Bounds.Size);
}
e.Graphics.Clear(Color.White);
@@ -373,16 +377,19 @@ protected virtual void OnLinkHandlingTimerTick(EventArgs e)
_linkHandlingTimer.Stop();
_tooltipHandle = IntPtr.Zero;
- var mPos = Control.MousePosition;
- var mButtons = Control.MouseButtons;
- var rect = Win32Utils.GetWindowRectangle(handle);
- if (rect.Contains(mPos))
+ if (handle != IntPtr.Zero && _associatedControl != null)
{
- if (mButtons == MouseButtons.Left)
+ var mPos = Control.MousePosition;
+ var mButtons = Control.MouseButtons;
+ var rect = Win32Utils.GetWindowRectangle(handle);
+ if (rect.Contains(mPos))
{
- var args = new MouseEventArgs(mButtons, 1, mPos.X - rect.X, mPos.Y - rect.Y, 0);
- _htmlContainer.HandleMouseDown(_associatedControl, args);
- _htmlContainer.HandleMouseUp(_associatedControl, args);
+ if (mButtons == MouseButtons.Left)
+ {
+ var args = new MouseEventArgs(mButtons, 1, mPos.X - rect.X, mPos.Y - rect.Y, 0);
+ _htmlContainer.HandleMouseDown(_associatedControl, args);
+ _htmlContainer.HandleMouseUp(_associatedControl, args);
+ }
}
}
}
@@ -402,23 +409,22 @@ protected virtual void OnToolTipDisposed(EventArgs e)
Draw -= OnToolTipDraw;
Disposed -= OnToolTipDisposed;
+ if (_linkHandlingTimer != null)
+ {
+ _linkHandlingTimer.Tick -= OnLinkHandlingTimerTick;
+ _linkHandlingTimer.Dispose();
+ _linkHandlingTimer = null;
+ }
+
if (_htmlContainer != null)
{
+ _htmlContainer.LinkClicked -= OnLinkClicked;
_htmlContainer.RenderError -= OnRenderError;
_htmlContainer.StylesheetLoad -= OnStylesheetLoad;
_htmlContainer.ImageLoad -= OnImageLoad;
_htmlContainer.Dispose();
_htmlContainer = null;
}
-
- if (_linkHandlingTimer != null)
- {
- _linkHandlingTimer.Dispose();
- _linkHandlingTimer = null;
-
- if (_htmlContainer != null)
- _htmlContainer.LinkClicked -= OnLinkClicked;
- }
}
diff --git a/Source/HtmlRenderer.WinForms/MetafileExtensions.cs b/Source/HtmlRenderer.WinForms/MetafileExtensions.cs
index 7bc5fad25..73aad459f 100644
--- a/Source/HtmlRenderer.WinForms/MetafileExtensions.cs
+++ b/Source/HtmlRenderer.WinForms/MetafileExtensions.cs
@@ -14,24 +14,25 @@ public static void SaveAsEmf(Metafile me, string fileName)
by : SWAT Team member _1
Date : Friday, February 01, 2008 1:38 PM
*/
- int enfMetafileHandle = me.GetHenhmetafile().ToInt32();
+ IntPtr enfMetafileHandle = me.GetHenhmetafile();
int bufferSize = GetEnhMetaFileBits(enfMetafileHandle, 0, null); // Get required buffer size.
byte[] buffer = new byte[bufferSize]; // Allocate sufficient buffer
if (GetEnhMetaFileBits(enfMetafileHandle, bufferSize, buffer) <= 0) // Get raw metafile data.
throw new SystemException("Fail");
- FileStream ms = File.Open(fileName, FileMode.Create);
- ms.Write(buffer, 0, bufferSize);
- ms.Close();
- ms.Dispose();
+ using (var ms = File.Open(fileName, FileMode.Create))
+ {
+ ms.Write(buffer, 0, bufferSize);
+ }
+
if (!DeleteEnhMetaFile(enfMetafileHandle)) //free handle
throw new SystemException("Fail Free");
}
- [DllImport("gdi32")]
- public static extern int GetEnhMetaFileBits(int hemf, int cbBuffer, byte[] lpbBuffer);
+ [DllImport("gdi32.dll")]
+ public static extern int GetEnhMetaFileBits(IntPtr hemf, int cbBuffer, byte[] lpbBuffer);
- [DllImport("gdi32")]
- public static extern bool DeleteEnhMetaFile(int hemfbitHandle);
+ [DllImport("gdi32.dll")]
+ public static extern bool DeleteEnhMetaFile(IntPtr hemfbitHandle);
}
}
diff --git a/Source/HtmlRenderer.WinForms/Utilities/Utils.cs b/Source/HtmlRenderer.WinForms/Utilities/Utils.cs
index 026102976..61a2ce0f5 100644
--- a/Source/HtmlRenderer.WinForms/Utilities/Utils.cs
+++ b/Source/HtmlRenderer.WinForms/Utilities/Utils.cs
@@ -13,6 +13,7 @@
using System;
using System.Drawing;
using TheArtOfDev.HtmlRenderer.Adapters.Entities;
+using TheArtOfDev.HtmlRenderer.Core.Utils;
namespace TheArtOfDev.HtmlRenderer.WinForms.Utilities
{
@@ -34,6 +35,7 @@ public static RPoint Convert(PointF p)
///
public static PointF[] Convert(RPoint[] points)
{
+ ArgChecker.AssertArgNotNull(points, nameof(points));
PointF[] myPoints = new PointF[points.Length];
for (int i = 0; i < points.Length; i++)
myPoints[i] = Convert(points[i]);
diff --git a/Source/HtmlRenderer.WinForms/Utilities/Win32Utils.cs b/Source/HtmlRenderer.WinForms/Utilities/Win32Utils.cs
index 228e47658..7db9fdbf0 100644
--- a/Source/HtmlRenderer.WinForms/Utilities/Win32Utils.cs
+++ b/Source/HtmlRenderer.WinForms/Utilities/Win32Utils.cs
@@ -47,11 +47,11 @@ internal static class Win32Utils
public const int TextAlignBaselineRtl = 256 + 24;
- [DllImport("user32.dll")]
- public static extern int SetCursor(int hCursor);
+ [DllImport("user32.dll", SetLastError = true)]
+ public static extern IntPtr SetCursor(IntPtr hCursor);
- [DllImport("user32.dll")]
- public static extern int LoadCursor(int hInstance, int lpCursorName);
+ [DllImport("user32.dll", SetLastError = true)]
+ public static extern IntPtr LoadCursor(IntPtr hInstance, int lpCursorName);
///
/// Create a compatible memory HDC from the given HDC.
diff --git a/Source/HtmlRenderer/Adapters/Entities/RColor.cs b/Source/HtmlRenderer/Adapters/Entities/RColor.cs
index 83fb26a12..8330a97f5 100644
--- a/Source/HtmlRenderer/Adapters/Entities/RColor.cs
+++ b/Source/HtmlRenderer/Adapters/Entities/RColor.cs
@@ -211,7 +211,7 @@ public static RColor FromArgb(int red, int green, int blue)
///
/// The object to test.
/// 1
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
{
if (obj is RColor)
{
diff --git a/Source/HtmlRenderer/Adapters/Entities/RPoint.cs b/Source/HtmlRenderer/Adapters/Entities/RPoint.cs
index eb36c8b47..2dedde7dd 100644
--- a/Source/HtmlRenderer/Adapters/Entities/RPoint.cs
+++ b/Source/HtmlRenderer/Adapters/Entities/RPoint.cs
@@ -251,7 +251,7 @@ public static RPoint Subtract(RPoint pt, RSize sz)
/// The to test.
///
/// 1
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
{
if (!(obj is RPoint))
return false;
diff --git a/Source/HtmlRenderer/Adapters/Entities/RRect.cs b/Source/HtmlRenderer/Adapters/Entities/RRect.cs
index 3ae148655..f3bd10f3e 100644
--- a/Source/HtmlRenderer/Adapters/Entities/RRect.cs
+++ b/Source/HtmlRenderer/Adapters/Entities/RRect.cs
@@ -284,7 +284,7 @@ public static RRect FromLTRB(double left, double top, double right, double botto
///
/// The to test.
///
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
{
if (!(obj is RRect))
return false;
diff --git a/Source/HtmlRenderer/Adapters/Entities/RSize.cs b/Source/HtmlRenderer/Adapters/Entities/RSize.cs
index 521bce308..903738492 100644
--- a/Source/HtmlRenderer/Adapters/Entities/RSize.cs
+++ b/Source/HtmlRenderer/Adapters/Entities/RSize.cs
@@ -287,7 +287,7 @@ public static RSize Subtract(RSize sz1, RSize sz2)
/// The to test.
///
/// 1
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
{
if (!(obj is RSize))
return false;
diff --git a/Source/HtmlRenderer/Adapters/RAdapter.cs b/Source/HtmlRenderer/Adapters/RAdapter.cs
index 6b13459c1..85ad72a76 100644
--- a/Source/HtmlRenderer/Adapters/RAdapter.cs
+++ b/Source/HtmlRenderer/Adapters/RAdapter.cs
@@ -365,7 +365,7 @@ internal RFont CreateFont(RFontFamily family, double size, RFontStyle style)
///
/// the image returned from load event
/// converted image or null
- protected abstract RImage ConvertImageInt(object image);
+ protected abstract RImage? ConvertImageInt(object? image);
///
/// Create an object from the given stream.
diff --git a/Source/HtmlRenderer/Core/Entities/CssBlock.cs b/Source/HtmlRenderer/Core/Entities/CssBlock.cs
index 2982b3159..fbcaca88e 100644
--- a/Source/HtmlRenderer/Core/Entities/CssBlock.cs
+++ b/Source/HtmlRenderer/Core/Entities/CssBlock.cs
@@ -196,7 +196,7 @@ public bool EqualsSelector(CssBlock other)
///
/// the other block to compare to
/// true - the two blocks are the same, false - otherwise
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj))
return false;
diff --git a/Source/HtmlRenderer/Core/Handlers/ImageDownloader.cs b/Source/HtmlRenderer/Core/Handlers/ImageDownloader.cs
index 2f8b0f5e6..3d6b97d5b 100644
--- a/Source/HtmlRenderer/Core/Handlers/ImageDownloader.cs
+++ b/Source/HtmlRenderer/Core/Handlers/ImageDownloader.cs
@@ -39,10 +39,15 @@ namespace TheArtOfDev.HtmlRenderer.Core.Handlers
internal sealed class ImageDownloader : IDisposable
{
///
- /// the web client used to download image from URL (to cancel on dispose)
+ /// List of web clients used to download images (to allow cancel on dispose).
///
private readonly List _clients = new List();
+ ///
+ /// Lock object for thread-safe _clients access.
+ ///
+ private readonly object _clientsLock = new object();
+
///
/// dictionary of image cache path to callbacks of download to handle multiple requests to download the same image
///
@@ -111,7 +116,7 @@ private void DownloadImageFromUrl(Uri source, string tempPath, string filePath)
{
using (var client = new WebClient())
{
- _clients.Add(client);
+ lock (_clientsLock) { _clients.Add(client); }
client.DownloadFile(source, tempPath);
OnDownloadImageCompleted(client, source, tempPath, filePath, null, false);
}
@@ -133,7 +138,7 @@ private void DownloadImageFromUrlAsync(object data)
try
{
var client = new WebClient();
- _clients.Add(client);
+ lock (_clientsLock) { _clients.Add(client); }
client.DownloadFileCompleted += OnDownloadImageAsyncCompleted;
client.DownloadFileAsync(downloadData._uri, downloadData._tempPath, downloadData);
}
@@ -226,17 +231,20 @@ private void OnDownloadImageCompleted(WebClient client, Uri source, string tempP
private void ReleaseObjects()
{
_imageDownloadCallbacks.Clear();
- while (_clients.Count > 0)
+ lock (_clientsLock)
{
- try
+ while (_clients.Count > 0)
{
- var client = _clients[0];
- client.CancelAsync();
- client.Dispose();
- _clients.RemoveAt(0);
+ try
+ {
+ var client = _clients[0];
+ client.CancelAsync();
+ client.Dispose();
+ _clients.RemoveAt(0);
+ }
+ catch
+ { }
}
- catch
- { }
}
}
diff --git a/Source/HtmlRenderer/Core/Handlers/ImageLoadHandler.cs b/Source/HtmlRenderer/Core/Handlers/ImageLoadHandler.cs
index eb9ace4fd..5acaa7af8 100644
--- a/Source/HtmlRenderer/Core/Handlers/ImageLoadHandler.cs
+++ b/Source/HtmlRenderer/Core/Handlers/ImageLoadHandler.cs
@@ -54,6 +54,11 @@ internal sealed class ImageLoadHandler : IDisposable
///
private readonly ActionInt _loadCompleteCallback;
+ ///
+ /// Dedicated lock object (instead of locking on the callback delegate).
+ ///
+ private readonly object _syncLock = new object();
+
///
/// Must be open as long as the image is in use
///
@@ -302,7 +307,7 @@ private void LoadImageFromFile(string source)
try
{
var imageFileStream = File.Open(source, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
- lock (_loadCompleteCallback)
+ lock (_syncLock)
{
_imageFileStream = imageFileStream;
if (!_disposed)
diff --git a/Source/HtmlRenderer/Core/HtmlContainerInt.cs b/Source/HtmlRenderer/Core/HtmlContainerInt.cs
index 1d71de9fb..32d3114c0 100644
--- a/Source/HtmlRenderer/Core/HtmlContainerInt.cs
+++ b/Source/HtmlRenderer/Core/HtmlContainerInt.cs
@@ -460,7 +460,7 @@ public void SetMargins(int value)
///
/// Get the currently selected text segment in the html.
///
- public string SelectedText
+ public string? SelectedText
{
get { return _selectionHandler.GetSelectedText(); }
}
@@ -468,7 +468,7 @@ public string SelectedText
///
/// Copy the currently selected html segment with style.
///
- public string SelectedHtml
+ public string? SelectedHtml
{
get { return _selectionHandler.GetSelectedHtml(); }
}
@@ -504,7 +504,7 @@ internal RColor SelectionBackColor
///
/// the html to init with, init empty if not given
/// optional: the stylesheet to init with, init default if not given
- public void SetHtml(string htmlSource, CssData baseCssData = null)
+ public void SetHtml(string? htmlSource, CssData? baseCssData = null)
{
Clear();
if (!string.IsNullOrEmpty(htmlSource))
@@ -561,7 +561,7 @@ public void ClearSelection()
///
/// Optional: controls the way styles are generated when html is generated (default: )
/// generated html
- public string GetHtml(HtmlGenerationStyle styleGen = HtmlGenerationStyle.Inline)
+ public string? GetHtml(HtmlGenerationStyle styleGen = HtmlGenerationStyle.Inline)
{
return DomUtils.GenerateHtml(_root, styleGen);
}
@@ -573,7 +573,7 @@ public string GetHtml(HtmlGenerationStyle styleGen = HtmlGenerationStyle.Inline)
/// the location to find the attribute at
/// the attribute key to get value by
/// found attribute value or null if not found
- public string GetAttributeAt(RPoint location, string attribute)
+ public string? GetAttributeAt(RPoint location, string attribute)
{
ArgChecker.AssertArgNotNullOrEmpty(attribute, "attribute");
@@ -603,7 +603,7 @@ public List> GetLinks()
///
/// the location to find the link at
/// css link href if exists or null
- public string GetLinkAt(RPoint location)
+ public string? GetLinkAt(RPoint location)
{
var link = DomUtils.GetLinkBox(_root, OffsetByScroll(location));
return link != null ? link.HrefLink : null;
diff --git a/Source/HtmlRenderer/HtmlRenderer.csproj b/Source/HtmlRenderer/HtmlRenderer.csproj
index 273dcccf8..9ea109b51 100644
--- a/Source/HtmlRenderer/HtmlRenderer.csproj
+++ b/Source/HtmlRenderer/HtmlRenderer.csproj
@@ -1,10 +1,10 @@
- netstandard2.0;net8.0
+ net10.0
Library
TheArtOfDev.HtmlRenderer
+ enable
true
- true
@@ -26,6 +26,6 @@ For existing implementations see: HtmlRenderer.WinForms, HtmlRenderer.WPF and Ht
-
+
-
\ No newline at end of file
+