diff --git a/Adapters/AvaloniaAdapter.cs b/Adapters/AvaloniaAdapter.cs index 24870e5..e13accb 100644 --- a/Adapters/AvaloniaAdapter.cs +++ b/Adapters/AvaloniaAdapter.cs @@ -80,7 +80,7 @@ protected override RBrush CreateLinearGradientBrush(RRect rect, RColor color1, R { StartPoint = new RelativePoint(x, y, RelativeUnit.Relative), EndPoint = new RelativePoint(1 - x, 1 - y, RelativeUnit.Relative), - GradientStops = new[] + GradientStops = new GradientStops() { new GradientStop(startColor, 0), new GradientStop(endColor, 1) diff --git a/Adapters/ControlAdapter.cs b/Adapters/ControlAdapter.cs index 9a55768..fcd4257 100644 --- a/Adapters/ControlAdapter.cs +++ b/Adapters/ControlAdapter.cs @@ -56,7 +56,7 @@ public override RPoint MouseLocation { get { - var pos = (_control.GetVisualRoot() as IInputRoot)?.MouseDevice?.Position ?? default(Point); + var pos = (_control.GetVisualRoot() as IInputRoot)?.MouseDevice?.Position ?? default(PixelPoint); return Util.Convert(pos); } } diff --git a/Adapters/GraphicsAdapter.cs b/Adapters/GraphicsAdapter.cs index 2c71700..1a32b0c 100644 --- a/Adapters/GraphicsAdapter.cs +++ b/Adapters/GraphicsAdapter.cs @@ -109,7 +109,7 @@ public override void ReturnPreviousSmoothingMode(Object prevMode) public override RSize MeasureString(string str, RFont font) { var text = GetText(str, font); - var measure = text.Measure(); + var measure = text.Bounds; return new RSize(measure.Width, measure.Height); } @@ -120,14 +120,15 @@ FormattedText GetText(string str, RFont font) return new FormattedText { Text = str, - Typeface = new Typeface(f.Name, font.Size, f.FontStyle, f.Weight), + Typeface = new Typeface(f.Name, f.FontStyle, f.Weight), + FontSize = font.Size }; } public override void MeasureString(string str, RFont font, double maxWidth, out int charFit, out double charFitWidth) { var text = GetText(str, font); - var fullLength = text.Measure().Width; + var fullLength = text.Bounds.Width; if (fullLength < maxWidth) { charFitWidth = fullLength; @@ -140,7 +141,7 @@ public override void MeasureString(string str, RFont font, double maxWidth, out BinarySearch(len => { text = GetText(str.Substring(0, len), font); - var size = text.Measure().Width; + var size = text.Bounds.Width; lastMeasure = size; lastLen = len; if (size <= maxWidth) @@ -151,7 +152,7 @@ public override void MeasureString(string str, RFont font, double maxWidth, out if (lastMeasure > maxWidth) { lastLen--; - lastMeasure = GetText(str.Substring(0, lastLen), font).Measure().Width; + lastMeasure = GetText(str.Substring(0, lastLen), font).Bounds.Width; } charFit = lastLen; charFitWidth = lastMeasure; @@ -253,12 +254,12 @@ public override void DrawRectangle(RBrush brush, double x, double y, double widt public override void DrawImage(RImage image, RRect destRect, RRect srcRect) { - _g.DrawImage(((ImageAdapter) image).Image, 1, Util.Convert(srcRect), Util.Convert(destRect)); + _g.DrawImage(((ImageAdapter) image).Image, /*1, */Util.Convert(srcRect), Util.Convert(destRect)); } public override void DrawImage(RImage image, RRect destRect) { - _g.DrawImage(((ImageAdapter) image).Image, 1, new Rect(0, 0, image.Width, image.Height), + _g.DrawImage(((ImageAdapter) image).Image, /*1, */new Rect(0, 0, image.Width, image.Height), Util.Convert(destRect)); } diff --git a/Adapters/ImageAdapter.cs b/Adapters/ImageAdapter.cs index 3ee0b40..7daa0f1 100644 --- a/Adapters/ImageAdapter.cs +++ b/Adapters/ImageAdapter.cs @@ -38,9 +38,9 @@ public ImageAdapter(Bitmap image) /// public Bitmap Image => _image; - public override double Width => _image.PixelWidth; + public override double Width => _image.PixelSize.Width; - public override double Height => _image.PixelHeight; + public override double Height => _image.PixelSize.Height; public override void Dispose() { diff --git a/Adapters/PenAdapter.cs b/Adapters/PenAdapter.cs index 42025af..31dc713 100644 --- a/Adapters/PenAdapter.cs +++ b/Adapters/PenAdapter.cs @@ -61,10 +61,10 @@ public override RDashStyle DashStyle private static readonly Dictionary DashStyles = new Dictionary { {RDashStyle.Solid,null }, - {RDashStyle.Dash, global::Avalonia.Media.DashStyle.Dash }, - {RDashStyle.DashDot, global::Avalonia.Media.DashStyle.DashDot }, - {RDashStyle.DashDotDot, global::Avalonia.Media.DashStyle.DashDotDot }, - {RDashStyle.Dot, global::Avalonia.Media.DashStyle.Dot } + {RDashStyle.Dash, null/*global::Avalonia.Media.DashStyle.Dash*/ }, + {RDashStyle.DashDot, null/*global::Avalonia.Media.DashStyle.DashDot*/ }, + {RDashStyle.DashDotDot, null/*global::Avalonia.Media.DashStyle.DashDotDot*/ }, + {RDashStyle.Dot, null/*global::Avalonia.Media.DashStyle.Dot*/ } }; /// diff --git a/Avalonia.HtmlRenderer.csproj b/Avalonia.HtmlRenderer.csproj index 15c466d..e58bd07 100644 --- a/Avalonia.HtmlRenderer.csproj +++ b/Avalonia.HtmlRenderer.csproj @@ -111,6 +111,7 @@ - + + - \ No newline at end of file + diff --git a/HtmlControl.cs b/HtmlControl.cs index 49ade7a..31edbd7 100644 --- a/HtmlControl.cs +++ b/HtmlControl.cs @@ -74,17 +74,17 @@ public class HtmlControl : Control protected Point _lastScrollOffset; public static readonly AvaloniaProperty AvoidImagesLateLoadingProperty = - PropertyHelper.Register(nameof(AvoidImagesLateLoading), false, OnAvaloniaProperty_valueChanged); + AvaloniaProperty.Register(nameof(AvoidImagesLateLoading), defaultValue: false); public static readonly AvaloniaProperty IsSelectionEnabledProperty = - PropertyHelper.Register(nameof(IsSelectionEnabled), true, OnAvaloniaProperty_valueChanged); + AvaloniaProperty.Register(nameof(IsSelectionEnabled), defaultValue: true); public static readonly AvaloniaProperty IsContextMenuEnabledProperty = - PropertyHelper.Register(nameof(IsContextMenuEnabled), true, OnAvaloniaProperty_valueChanged); + AvaloniaProperty.Register(nameof(IsContextMenuEnabled), defaultValue: true); public static readonly AvaloniaProperty BaseStylesheetProperty = - PropertyHelper.Register(nameof(BaseStylesheet), null, OnAvaloniaProperty_valueChanged); + AvaloniaProperty.Register(nameof(BaseStylesheet), defaultValue: null); public static readonly AvaloniaProperty TextProperty = - PropertyHelper.Register(nameof(Text), null, OnAvaloniaProperty_valueChanged); + AvaloniaProperty.Register(nameof(Text), defaultValue: null); public static readonly StyledProperty BackgroundProperty = Border.BackgroundProperty.AddOwner(); @@ -117,12 +117,18 @@ static HtmlControl() { FocusableProperty.OverrideDefaultValue(typeof(HtmlControl), true); AffectsRender(TextProperty); + + AvoidImagesLateLoadingProperty.Changed.AddClassHandler(OnAvaloniaProperty_valueChanged); + IsSelectionEnabledProperty.Changed.AddClassHandler(OnAvaloniaProperty_valueChanged); + IsContextMenuEnabledProperty.Changed.AddClassHandler(OnAvaloniaProperty_valueChanged); + BaseStylesheetProperty.Changed.AddClassHandler(OnAvaloniaProperty_valueChanged); + TextProperty.Changed.AddClassHandler(OnAvaloniaProperty_valueChanged); } /// /// Creates a new HtmlPanel and sets a basic css for it's styling. /// - protected HtmlControl() + public HtmlControl() { _htmlContainer = new HtmlContainer(); _htmlContainer.LoadComplete += OnLoadComplete; @@ -521,8 +527,7 @@ protected virtual void InvokeMouseMove() /// /// Handle when dependency property value changes to update the underline HtmlContainer with the new value. /// - private static void OnAvaloniaProperty_valueChanged(AvaloniaObject AvaloniaObject, - AvaloniaPropertyChangedEventArgs e) + private static void OnAvaloniaProperty_valueChanged(IAvaloniaObject AvaloniaObject, AvaloniaPropertyChangedEventArgs e) { var control = AvaloniaObject as HtmlControl; if (control != null) @@ -612,4 +617,4 @@ private void OnRefresh(object sender, HtmlRefreshEventArgs e) Dispatcher.UIThread.InvokeAsync(() => OnRefresh(e)).Wait(); } } -} \ No newline at end of file +} diff --git a/HtmlLabel.cs b/HtmlLabel.cs index 8bb3897..3497782 100644 --- a/HtmlLabel.cs +++ b/HtmlLabel.cs @@ -82,7 +82,7 @@ protected override Size MeasureOverride(Size constraint) /// /// Handle when dependency property value changes to update the underline HtmlContainer with the new value. /// - private static void OnAvaloniaProperty_valueChanged(AvaloniaObject AvaloniaObject, AvaloniaPropertyChangedEventArgs e) + private static Action OnAvaloniaProperty_valueChanged = new Action((AvaloniaObject, e) => { var control = AvaloniaObject as HtmlLabel; if (control != null) @@ -106,7 +106,7 @@ private static void OnAvaloniaProperty_valueChanged(AvaloniaObject AvaloniaObjec } } } - } + }); #endregion } diff --git a/PropertyHelper.cs b/PropertyHelper.cs index 56257ed..5f016d9 100644 --- a/PropertyHelper.cs +++ b/PropertyHelper.cs @@ -9,7 +9,7 @@ namespace Avalonia.HtmlRenderer static class PropertyHelper { - public static AvaloniaProperty Register(string name, T def, Action changed) where TOwner : AvaloniaObject + /*public static AvaloniaProperty Register(string name, T def, Action changed) where TOwner : AvaloniaObject { var pp = AvaloniaProperty.Register(name, def); Action cb = args => @@ -20,5 +20,27 @@ public static AvaloniaProperty Register(string name, T def, Action(string name, T def, Action changed) where TOwner : IAvaloniaObject + { + var pp = AvaloniaProperty.Register(name, def); + + /*IObserver cb = new Observer.Create((args) => + { + changed(args.Sender, args); + });*/ + + pp.Changed.Subscribe(args => + { + changed.Invoke(args.Sender, args); + /*if ((args != null) && (args.Sender != null) && (changed != null)) + changed(args.Sender, args);*/ + }); + + //pp.Changed.Subscribe(changed); + return pp; + } } } diff --git a/Utilities/Util.cs b/Utilities/Util.cs index 3a19eae..7271cd8 100644 --- a/Utilities/Util.cs +++ b/Utilities/Util.cs @@ -29,6 +29,14 @@ public static RPoint Convert(Point p) return new RPoint(p.X, p.Y); } + /// + /// Convert from Avalonia PixelPoint to core point. + /// + public static RPoint Convert(PixelPoint p) + { + return new RPoint(p.X, p.Y); + } + /// /// Convert from WPF point to core point. ///