improve:墨迹渲染

This commit is contained in:
2026-04-04 23:06:16 +08:00
parent 66afe271c5
commit c33ac03255
@@ -900,41 +900,28 @@ namespace Ink_Canvas
bool InkToShapeProcess() bool InkToShapeProcess()
{ {
var engineMode = ShapeRecognitionRouter.FromSettingsInt(Settings.InkToShape.ShapeRecognitionEngine); // WinRT 与非 WinRT 均延后到 Dispatcher 上异步执行:在 StrokeCollected 内对
if (ShapeRecognitionRouter.ResolveUseWinRt(engineMode)) // InkToShapeProcessCoreAsync 同步 GetResult() 会长时间阻塞 UI 线程(抬笔卡顿);
// WinRT 路径若同步等待还可能与贴回 UI 的延续死锁(见类注释 InkToShapeSerial)。
var strokeHw = strokeForHandwritingBeautify;
var preBrushHwPts = preBrushHandwritingPoints;
var wsTail = wasStraightened;
// ApplicationIdle:在更高优先级(布局/输入/本帧渲染)之后执行,减轻抬笔瞬间主线程“顶死”感。
Dispatcher.BeginInvoke(new Action(async () =>
{ {
var strokeHw = strokeForHandwritingBeautify; try
var preBrushHwPts = preBrushHandwritingPoints;
var wsTail = wasStraightened;
Dispatcher.BeginInvoke(new Action(async () =>
{ {
try await InkToShapeProcessCoreAsync();
{ if (Settings.InkToShape.EnableWinRtHandwritingStrokeBeautify)
await InkToShapeProcessCoreAsync(); ScheduleHandwritingGlyphReplaceAfterStrokeCollected(strokeHw, isBoardBrushStroke, preBrushHwPts);
if (Settings.InkToShape.EnableWinRtHandwritingStrokeBeautify) RunStrokeCollectedPostShapeRecognitionTail(e, wsTail);
ScheduleHandwritingGlyphReplaceAfterStrokeCollected(strokeHw, isBoardBrushStroke, preBrushHwPts); }
RunStrokeCollectedPostShapeRecognitionTail(e, wsTail); catch (Exception ex)
} {
catch (Exception ex) System.Diagnostics.Debug.WriteLine(ex);
{ }
System.Diagnostics.Debug.WriteLine(ex); }), DispatcherPriority.ApplicationIdle);
} return true;
}), DispatcherPriority.Normal);
return true;
}
try
{
InkToShapeProcessCoreAsync().GetAwaiter().GetResult();
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex);
}
if (Settings.InkToShape.EnableWinRtHandwritingStrokeBeautify)
ScheduleHandwritingGlyphReplaceAfterStrokeCollected(strokeForHandwritingBeautify, isBoardBrushStroke, preBrushHandwritingPoints);
return false;
} }
if (InkToShapeProcess()) if (InkToShapeProcess())