From 5067d3e12caab2520073e5ffbe21e683b4ffa9d6 Mon Sep 17 00:00:00 2001 From: lindexi Date: Sun, 13 Oct 2024 10:26:07 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A9=E6=B8=B2=E6=9F=93=E5=B1=82=E5=88=86?= =?UTF-8?q?=E5=BC=80=EF=BC=8C=E5=9B=A0=E4=B8=BA=E7=9C=8B=E8=B5=B7=E6=9D=A5?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E4=BB=A3=E7=A0=81=E5=BE=88=E5=A4=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LightTextEditorPlus.Avalonia/TextEditor.cs | 7 +++++++ .../API_/ITextEditorSkiaRender.cs | 11 +++++++++++ ...LightTextEditorPlus.Skia.csproj.DotSettings | 2 ++ .../Rendering/RenderManager.cs | 2 +- .../LightTextEditorPlus.Skia/SkiaTextEditor.cs | 18 ++---------------- 5 files changed, 23 insertions(+), 17 deletions(-) create mode 100644 LightTextEditorPlus/LightTextEditorPlus.Skia/API_/ITextEditorSkiaRender.cs create mode 100644 LightTextEditorPlus/LightTextEditorPlus.Skia/LightTextEditorPlus.Skia.csproj.DotSettings diff --git a/LightTextEditorPlus/LightTextEditorPlus.Avalonia/TextEditor.cs b/LightTextEditorPlus/LightTextEditorPlus.Avalonia/TextEditor.cs index acb3b007b..3ae66c269 100644 --- a/LightTextEditorPlus/LightTextEditorPlus.Avalonia/TextEditor.cs +++ b/LightTextEditorPlus/LightTextEditorPlus.Avalonia/TextEditor.cs @@ -26,6 +26,7 @@ public TextEditor() HorizontalAlignment = HorizontalAlignment.Stretch; VerticalAlignment = VerticalAlignment.Stretch; + // 调试代码 TextEditorCore.AppendText("123"); } @@ -35,11 +36,13 @@ public TextEditor() protected override Size MeasureOverride(Size availableSize) { var result = base.MeasureOverride(availableSize); + // 文本库,有多少就要多少 return availableSize; } protected override Size ArrangeOverride(Size finalSize) { + // 实际布局多大就使用多大 TextEditorCore.DocumentManager.DocumentWidth = finalSize.Width; TextEditorCore.DocumentManager.DocumentHeight = finalSize.Height; @@ -86,6 +89,10 @@ public void Render(ImmediateDrawingContext context) using ISkiaSharpApiLease skiaSharpApiLease = skiaSharpApiLeaseFeature.Lease(); _render.Render(skiaSharpApiLease.SkCanvas); } + else + { + // 不支持 Skia 绘制 + } } public Rect Bounds { get; } diff --git a/LightTextEditorPlus/LightTextEditorPlus.Skia/API_/ITextEditorSkiaRender.cs b/LightTextEditorPlus/LightTextEditorPlus.Skia/API_/ITextEditorSkiaRender.cs new file mode 100644 index 000000000..d6d3fab8c --- /dev/null +++ b/LightTextEditorPlus/LightTextEditorPlus.Skia/API_/ITextEditorSkiaRender.cs @@ -0,0 +1,11 @@ +using SkiaSharp; + +namespace LightTextEditorPlus; + +/// +/// 文本的 Skia 渲染器 +/// +public interface ITextEditorSkiaRender +{ + void Render(SKCanvas canvas); +} \ No newline at end of file diff --git a/LightTextEditorPlus/LightTextEditorPlus.Skia/LightTextEditorPlus.Skia.csproj.DotSettings b/LightTextEditorPlus/LightTextEditorPlus.Skia/LightTextEditorPlus.Skia.csproj.DotSettings new file mode 100644 index 000000000..e470ef27c --- /dev/null +++ b/LightTextEditorPlus/LightTextEditorPlus.Skia/LightTextEditorPlus.Skia.csproj.DotSettings @@ -0,0 +1,2 @@ + + True \ No newline at end of file diff --git a/LightTextEditorPlus/LightTextEditorPlus.Skia/Rendering/RenderManager.cs b/LightTextEditorPlus/LightTextEditorPlus.Skia/Rendering/RenderManager.cs index 2a22d6b84..2cf0fb87b 100644 --- a/LightTextEditorPlus/LightTextEditorPlus.Skia/Rendering/RenderManager.cs +++ b/LightTextEditorPlus/LightTextEditorPlus.Skia/Rendering/RenderManager.cs @@ -6,7 +6,7 @@ namespace LightTextEditorPlus.Rendering; -class RenderManager: IRenderManager +class RenderManager: IRenderManager, ITextEditorSkiaRender { record SkiaTextRenderInfo(); diff --git a/LightTextEditorPlus/LightTextEditorPlus.Skia/SkiaTextEditor.cs b/LightTextEditorPlus/LightTextEditorPlus.Skia/SkiaTextEditor.cs index 4d3c467fb..7723ff5a4 100644 --- a/LightTextEditorPlus/LightTextEditorPlus.Skia/SkiaTextEditor.cs +++ b/LightTextEditorPlus/LightTextEditorPlus.Skia/SkiaTextEditor.cs @@ -9,11 +9,10 @@ using LightTextEditorPlus.Core.Platform; using LightTextEditorPlus.Core.Rendering; using LightTextEditorPlus.Rendering; -using SkiaSharp; namespace LightTextEditorPlus; -public partial class SkiaTextEditor : IRenderManager, ITextEditorSkiaRender +public partial class SkiaTextEditor : IRenderManager { public SkiaTextEditor(PlatformProvider? platformProvider = null) { @@ -39,23 +38,10 @@ void IRenderManager.Render(RenderInfoProvider renderInfoProvider) public ITextEditorSkiaRender GetCurrentRender() { - return this; + return RenderManager; } public event EventHandler? RenderRequested; - - public void Render(SKCanvas canvas) - { - RenderManager.Render(canvas); - } -} - -/// -/// 文本的 Skia 渲染器 -/// -public interface ITextEditorSkiaRender -{ - void Render(SKCanvas canvas); } public class SkiaTextEditorPlatformProvider : PlatformProvider