@@ -1 +1 @@
|
||||
1.7.5.0
|
||||
1.7.6.0
|
||||
|
||||
+5
-14
@@ -423,7 +423,7 @@ namespace Ink_Canvas
|
||||
try
|
||||
{
|
||||
string exePath = Process.GetCurrentProcess().MainModule.FileName;
|
||||
Process.Start(exePath, "-m");
|
||||
Process.Start(exePath);
|
||||
}
|
||||
catch { }
|
||||
Environment.Exit(1);
|
||||
@@ -438,16 +438,7 @@ namespace Ink_Canvas
|
||||
/*if (!StoreHelper.IsStoreApp) */RootPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
|
||||
|
||||
LogHelper.NewLog(string.Format("Ink Canvas Starting (Version: {0})", Assembly.GetExecutingAssembly().GetName().Version));
|
||||
|
||||
// 在应用启动时自动释放IACore相关DLL
|
||||
try
|
||||
{
|
||||
Helpers.IACoreDllExtractor.ExtractIACoreDlls();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"释放IACore DLL时出错: {ex.Message}", LogHelper.LogType.Error);
|
||||
}
|
||||
|
||||
|
||||
// 记录应用启动(设备标识符)
|
||||
DeviceIdentifier.RecordAppLaunch();
|
||||
@@ -456,7 +447,7 @@ namespace Ink_Canvas
|
||||
LogHelper.WriteLogToFile($"App | 更新优先级: {DeviceIdentifier.GetUpdatePriority()}");
|
||||
|
||||
bool ret;
|
||||
mutex = new Mutex(true, "InkCanvasForClass", out ret);
|
||||
mutex = new Mutex(true, "InkCanvasForClass CE", out ret);
|
||||
|
||||
if (!ret && !e.Args.Contains("-m")) //-m multiple
|
||||
{
|
||||
@@ -654,7 +645,7 @@ namespace Ink_Canvas
|
||||
try
|
||||
{
|
||||
string exePath = Process.GetCurrentProcess().MainModule.FileName;
|
||||
Process.Start(exePath, "-m");
|
||||
Process.Start(exePath);
|
||||
}
|
||||
catch { }
|
||||
Environment.Exit(1);
|
||||
@@ -714,7 +705,7 @@ namespace Ink_Canvas
|
||||
Environment.Exit(1);
|
||||
}
|
||||
string exePath = Process.GetCurrentProcess().MainModule.FileName;
|
||||
Process.Start(exePath, "-m");
|
||||
Process.Start(exePath);
|
||||
}
|
||||
// CrashActionType.NoAction 时不重启,直接退出
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ using System.Windows;
|
||||
[assembly: AssemblyTitle("InkCanvasForClass")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Dubi906w")]
|
||||
[assembly: AssemblyCompany("CJK_mkp")]
|
||||
[assembly: AssemblyProduct("InkCanvasForClass")]
|
||||
[assembly: AssemblyCopyright("Copyright © HARKOTEK Studio 2024")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
@@ -49,5 +49,5 @@ using System.Windows;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.7.5.0")]
|
||||
[assembly: AssemblyFileVersion("1.7.5.0")]
|
||||
[assembly: AssemblyVersion("1.76.0")]
|
||||
[assembly: AssemblyFileVersion("1.7.6.0")]
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Ink_Canvas.Helpers
|
||||
|
||||
public double SmoothingStrength { get; set; } = 0.3; // 大幅降低强度
|
||||
public double ResampleInterval { get; set; } = 3.0; // 大幅增加间隔减少点数
|
||||
public int InterpolationSteps { get; set; } = 4; // 极大减少插值步数
|
||||
public int InterpolationSteps { get; set; } = 8; // 从4增加到8,提高插值步数
|
||||
public bool UseHardwareAcceleration { get; set; } = true;
|
||||
public int MaxConcurrentTasks { get; set; } = Environment.ProcessorCount;
|
||||
|
||||
@@ -354,7 +354,7 @@ namespace Ink_Canvas.Helpers
|
||||
{
|
||||
public double SmoothingStrength { get; set; } = 0.3;
|
||||
public double ResampleInterval { get; set; } = 3.0;
|
||||
public int InterpolationSteps { get; set; } = 4;
|
||||
public int InterpolationSteps { get; set; } = 8;
|
||||
|
||||
public Stroke SmoothStroke(Stroke stroke)
|
||||
{
|
||||
@@ -457,7 +457,7 @@ namespace Ink_Canvas.Helpers
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<StylusPoint> SlidingBezierFit(List<StylusPoint> points, int window = 4, int steps = 24)
|
||||
private List<StylusPoint> SlidingBezierFit(List<StylusPoint> points, int window = 4, int steps = 48) // 从24增加到48
|
||||
{
|
||||
var result = new List<StylusPoint>();
|
||||
if (points.Count < window) return points;
|
||||
|
||||
@@ -74,13 +74,13 @@ namespace Ink_Canvas.Helpers
|
||||
|
||||
pathFigure.StartPoint = new Point(points[0].X, points[0].Y);
|
||||
|
||||
// 使用贝塞尔曲线段创建平滑路径
|
||||
for (int i = 0; i < points.Count - 1; i += 3)
|
||||
// 使用贝塞尔曲线段创建平滑路径,增加插点密度
|
||||
for (int i = 0; i < points.Count - 1; i += 2) // 从i+=3改为i+=2,增加插点密度
|
||||
{
|
||||
var p1 = i + 1 < points.Count ? new Point(points[i + 1].X, points[i + 1].Y) : pathFigure.StartPoint;
|
||||
var p2 = i + 2 < points.Count ? new Point(points[i + 2].X, points[i + 2].Y) : p1;
|
||||
var p3 = i + 3 < points.Count ? new Point(points[i + 3].X, points[i + 3].Y) : p2;
|
||||
|
||||
|
||||
var bezierSegment = new BezierSegment(p1, p2, p3, true);
|
||||
pathFigure.Segments.Add(bezierSegment);
|
||||
}
|
||||
@@ -145,7 +145,7 @@ namespace Ink_Canvas.Helpers
|
||||
/// <summary>
|
||||
/// 使用GPU加速的并行贝塞尔计算
|
||||
/// </summary>
|
||||
public static StylusPoint[] ParallelBezierInterpolation(StylusPoint[] controlPoints, int segments = 16)
|
||||
public static StylusPoint[] ParallelBezierInterpolation(StylusPoint[] controlPoints, int segments = 32)
|
||||
{
|
||||
if (controlPoints.Length < 4) return controlPoints;
|
||||
|
||||
@@ -212,13 +212,13 @@ namespace Ink_Canvas.Helpers
|
||||
/// </summary>
|
||||
public class InkSmoothingConfig
|
||||
{
|
||||
public InkSmoothingQuality Quality { get; set; } = InkSmoothingQuality.Balanced;
|
||||
public InkSmoothingQuality Quality { get; set; } = InkSmoothingQuality.HighQuality;
|
||||
public bool UseHardwareAcceleration { get; set; } = true;
|
||||
public bool UseAsyncProcessing { get; set; } = true;
|
||||
public int MaxConcurrentTasks { get; set; } = Environment.ProcessorCount;
|
||||
public double SmoothingStrength { get; set; } = 0.6;
|
||||
public double ResampleInterval { get; set; } = 1.2;
|
||||
public int InterpolationSteps { get; set; } = 16;
|
||||
public double SmoothingStrength { get; set; } = 0.8; // 高质量模式的平滑强度
|
||||
public double ResampleInterval { get; set; } = 0.8; // 高质量模式的重采样间隔
|
||||
public int InterpolationSteps { get; set; } = 64; // 高质量模式的插值步数
|
||||
|
||||
public static InkSmoothingConfig FromSettings()
|
||||
{
|
||||
@@ -239,17 +239,17 @@ namespace Ink_Canvas.Helpers
|
||||
case InkSmoothingQuality.HighPerformance:
|
||||
SmoothingStrength = 0.4;
|
||||
ResampleInterval = 2.0;
|
||||
InterpolationSteps = 8;
|
||||
InterpolationSteps = 16;
|
||||
break;
|
||||
case InkSmoothingQuality.Balanced:
|
||||
SmoothingStrength = 0.6;
|
||||
ResampleInterval = 1.2;
|
||||
InterpolationSteps = 16;
|
||||
InterpolationSteps = 32;
|
||||
break;
|
||||
case InkSmoothingQuality.HighQuality:
|
||||
SmoothingStrength = 0.8;
|
||||
ResampleInterval = 0.8;
|
||||
InterpolationSteps = 32;
|
||||
InterpolationSteps = 64;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,168 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Windows;
|
||||
|
||||
namespace Ink_Canvas.Helpers
|
||||
{
|
||||
/// <summary>
|
||||
/// IACore DLL自动释放器
|
||||
/// 在应用启动时自动释放IACore相关的DLL文件到应用程序目录
|
||||
/// </summary>
|
||||
public static class IACoreDllExtractor
|
||||
{
|
||||
private static readonly string[] RequiredDlls = {
|
||||
"IACore.dll",
|
||||
"IALoader.dll",
|
||||
"IAWinFX.dll"
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// 在应用启动时释放IACore相关DLL
|
||||
/// </summary>
|
||||
public static void ExtractIACoreDlls()
|
||||
{
|
||||
try
|
||||
{
|
||||
string appDirectory = AppDomain.CurrentDomain.BaseDirectory;
|
||||
LogHelper.WriteLogToFile("开始检查并释放IACore相关DLL文件");
|
||||
|
||||
foreach (string dllName in RequiredDlls)
|
||||
{
|
||||
string targetPath = Path.Combine(appDirectory, dllName);
|
||||
|
||||
// 检查文件是否已存在且有效
|
||||
if (File.Exists(targetPath) && IsValidDll(targetPath))
|
||||
{
|
||||
LogHelper.WriteLogToFile($"{dllName} 已存在且有效,跳过释放");
|
||||
continue;
|
||||
}
|
||||
|
||||
// 从嵌入资源中释放DLL
|
||||
if (ExtractDllFromResource(dllName, targetPath))
|
||||
{
|
||||
LogHelper.WriteLogToFile($"成功释放 {dllName} 到 {targetPath}");
|
||||
}
|
||||
else
|
||||
{
|
||||
LogHelper.WriteLogToFile($"警告:无法释放 {dllName},可能影响形状识别功能", LogHelper.LogType.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
LogHelper.WriteLogToFile("IACore DLL释放检查完成");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"释放IACore DLL时出错: {ex.Message}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从嵌入资源中提取DLL文件
|
||||
/// </summary>
|
||||
private static bool ExtractDllFromResource(string dllName, string targetPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||
string resourceName = $"Ink_Canvas.Resources.IACore.{dllName}";
|
||||
|
||||
using (Stream resourceStream = assembly.GetManifestResourceStream(resourceName))
|
||||
{
|
||||
if (resourceStream == null)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"未找到嵌入资源: {resourceName}", LogHelper.LogType.Warning);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 确保目标目录存在
|
||||
string targetDirectory = Path.GetDirectoryName(targetPath);
|
||||
if (!Directory.Exists(targetDirectory))
|
||||
{
|
||||
Directory.CreateDirectory(targetDirectory);
|
||||
}
|
||||
|
||||
// 写入文件
|
||||
using (FileStream fileStream = new FileStream(targetPath, FileMode.Create, FileAccess.Write))
|
||||
{
|
||||
resourceStream.CopyTo(fileStream);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"从资源提取 {dllName} 失败: {ex.Message}", LogHelper.LogType.Error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查DLL文件是否有效
|
||||
/// </summary>
|
||||
private static bool IsValidDll(string filePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!File.Exists(filePath))
|
||||
return false;
|
||||
|
||||
FileInfo fileInfo = new FileInfo(filePath);
|
||||
|
||||
// 检查文件大小(空文件或过小的文件可能无效)
|
||||
if (fileInfo.Length < 1024) // 小于1KB可能无效
|
||||
return false;
|
||||
|
||||
// 简单检查PE头(DLL文件应该以MZ开头)
|
||||
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
byte[] buffer = new byte[2];
|
||||
if (fs.Read(buffer, 0, 2) == 2)
|
||||
{
|
||||
return buffer[0] == 0x4D && buffer[1] == 0x5A; // "MZ"
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理释放的DLL文件(可选,在应用退出时调用)
|
||||
/// </summary>
|
||||
public static void CleanupExtractedDlls()
|
||||
{
|
||||
try
|
||||
{
|
||||
string appDirectory = AppDomain.CurrentDomain.BaseDirectory;
|
||||
|
||||
foreach (string dllName in RequiredDlls)
|
||||
{
|
||||
string filePath = Path.Combine(appDirectory, dllName);
|
||||
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(filePath);
|
||||
LogHelper.WriteLogToFile($"已清理 {dllName}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"清理 {dllName} 失败: {ex.Message}", LogHelper.LogType.Warning);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"清理IACore DLL时出错: {ex.Message}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -194,15 +194,17 @@ namespace Ink_Canvas.Helpers
|
||||
var processorCount = Environment.ProcessorCount;
|
||||
var isHardwareAccelerated = IsHardwareAccelerationSupported();
|
||||
|
||||
if (processorCount >= 8 && isHardwareAccelerated)
|
||||
if (processorCount >= 4 && isHardwareAccelerated)
|
||||
{
|
||||
// 降低高质量模式的门槛,4核以上且支持硬件加速就使用高质量
|
||||
config.Quality = InkSmoothingQuality.HighQuality;
|
||||
config.UseHardwareAcceleration = true;
|
||||
config.UseAsyncProcessing = true;
|
||||
config.MaxConcurrentTasks = Math.Min(processorCount, 8);
|
||||
}
|
||||
else if (processorCount >= 4)
|
||||
else if (processorCount >= 2)
|
||||
{
|
||||
// 2核以上使用平衡模式
|
||||
config.Quality = InkSmoothingQuality.Balanced;
|
||||
config.UseHardwareAcceleration = isHardwareAccelerated;
|
||||
config.UseAsyncProcessing = true;
|
||||
@@ -210,6 +212,7 @@ namespace Ink_Canvas.Helpers
|
||||
}
|
||||
else
|
||||
{
|
||||
// 单核或性能较低的设备使用高性能模式
|
||||
config.Quality = InkSmoothingQuality.HighPerformance;
|
||||
config.UseHardwareAcceleration = false;
|
||||
config.UseAsyncProcessing = false;
|
||||
|
||||
@@ -0,0 +1,397 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Windows.Ink;
|
||||
using System.Windows.Threading;
|
||||
using Microsoft.Office.Interop.PowerPoint;
|
||||
|
||||
namespace Ink_Canvas.Helpers
|
||||
{
|
||||
/// <summary>
|
||||
/// PPT墨迹管理器 - 负责PPT中墨迹的保存、加载和同步
|
||||
/// </summary>
|
||||
public class PPTInkManager : IDisposable
|
||||
{
|
||||
#region Properties
|
||||
public bool IsAutoSaveEnabled { get; set; } = true;
|
||||
public string AutoSaveLocation { get; set; } = "";
|
||||
public StrokeCollection CurrentStrokes { get; private set; } = new StrokeCollection();
|
||||
#endregion
|
||||
|
||||
#region Private Fields
|
||||
private MemoryStream[] _memoryStreams;
|
||||
private int _maxSlides = 100;
|
||||
private string _currentPresentationId = "";
|
||||
private readonly object _lockObject = new object();
|
||||
private bool _disposed = false;
|
||||
|
||||
// 墨迹锁定机制,防止翻页时的墨迹冲突
|
||||
private DateTime _inkLockUntil = DateTime.MinValue;
|
||||
private int _lockedSlideIndex = -1;
|
||||
private const int InkLockMilliseconds = 500;
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
public PPTInkManager()
|
||||
{
|
||||
InitializeMemoryStreams();
|
||||
}
|
||||
|
||||
private void InitializeMemoryStreams()
|
||||
{
|
||||
_memoryStreams = new MemoryStream[_maxSlides + 2];
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
/// <summary>
|
||||
/// 初始化新的演示文稿
|
||||
/// </summary>
|
||||
public void InitializePresentation(Presentation presentation)
|
||||
{
|
||||
if (presentation == null) return;
|
||||
|
||||
lock (_lockObject)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 生成演示文稿唯一标识符
|
||||
_currentPresentationId = GeneratePresentationId(presentation);
|
||||
|
||||
// 重新初始化内存流数组
|
||||
var slideCount = presentation.Slides.Count;
|
||||
_memoryStreams = new MemoryStream[slideCount + 2];
|
||||
|
||||
// 如果启用自动保存,尝试加载已保存的墨迹
|
||||
if (IsAutoSaveEnabled && !string.IsNullOrEmpty(AutoSaveLocation))
|
||||
{
|
||||
LoadSavedStrokes();
|
||||
}
|
||||
|
||||
LogHelper.WriteLogToFile($"已初始化演示文稿墨迹管理: {presentation.Name}, 幻灯片数量: {slideCount}", LogHelper.LogType.Trace);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"初始化演示文稿墨迹管理失败: {ex}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存当前页面的墨迹
|
||||
/// </summary>
|
||||
public void SaveCurrentSlideStrokes(int slideIndex, StrokeCollection strokes)
|
||||
{
|
||||
if (slideIndex <= 0 || strokes == null) return;
|
||||
|
||||
lock (_lockObject)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 检查墨迹锁定
|
||||
if (!CanWriteInk(slideIndex))
|
||||
{
|
||||
LogHelper.WriteLogToFile($"墨迹写入被锁定,当前页:{slideIndex},锁定页:{_lockedSlideIndex}", LogHelper.LogType.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
if (slideIndex < _memoryStreams.Length)
|
||||
{
|
||||
var ms = new MemoryStream();
|
||||
strokes.Save(ms);
|
||||
ms.Position = 0;
|
||||
|
||||
// 释放旧的内存流
|
||||
_memoryStreams[slideIndex]?.Dispose();
|
||||
_memoryStreams[slideIndex] = ms;
|
||||
|
||||
LogHelper.WriteLogToFile($"已保存第{slideIndex}页墨迹,大小: {ms.Length} bytes", LogHelper.LogType.Trace);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"保存第{slideIndex}页墨迹失败: {ex}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载指定页面的墨迹
|
||||
/// </summary>
|
||||
public StrokeCollection LoadSlideStrokes(int slideIndex)
|
||||
{
|
||||
if (slideIndex <= 0) return new StrokeCollection();
|
||||
|
||||
lock (_lockObject)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (slideIndex < _memoryStreams.Length && _memoryStreams[slideIndex] != null && _memoryStreams[slideIndex].Length > 0)
|
||||
{
|
||||
_memoryStreams[slideIndex].Position = 0;
|
||||
var strokes = new StrokeCollection(_memoryStreams[slideIndex]);
|
||||
LogHelper.WriteLogToFile($"已加载第{slideIndex}页墨迹,笔画数量: {strokes.Count}", LogHelper.LogType.Trace);
|
||||
return strokes;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"加载第{slideIndex}页墨迹失败: {ex}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
return new StrokeCollection();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 切换到指定页面并加载墨迹
|
||||
/// </summary>
|
||||
public StrokeCollection SwitchToSlide(int slideIndex, StrokeCollection currentStrokes = null)
|
||||
{
|
||||
lock (_lockObject)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 如果有当前墨迹,先保存
|
||||
if (currentStrokes != null && currentStrokes.Count > 0)
|
||||
{
|
||||
SaveCurrentSlideStrokes(_lockedSlideIndex > 0 ? _lockedSlideIndex : slideIndex, currentStrokes);
|
||||
}
|
||||
|
||||
// 设置墨迹锁定
|
||||
LockInkForSlide(slideIndex);
|
||||
|
||||
// 加载新页面的墨迹
|
||||
return LoadSlideStrokes(slideIndex);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"切换到第{slideIndex}页失败: {ex}", LogHelper.LogType.Error);
|
||||
return new StrokeCollection();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存所有墨迹到文件
|
||||
/// </summary>
|
||||
public void SaveAllStrokesToFile(Presentation presentation)
|
||||
{
|
||||
if (!IsAutoSaveEnabled || string.IsNullOrEmpty(AutoSaveLocation) || presentation == null) return;
|
||||
|
||||
lock (_lockObject)
|
||||
{
|
||||
try
|
||||
{
|
||||
var folderPath = GetPresentationFolderPath();
|
||||
if (!Directory.Exists(folderPath))
|
||||
{
|
||||
Directory.CreateDirectory(folderPath);
|
||||
}
|
||||
|
||||
// 保存位置信息
|
||||
try
|
||||
{
|
||||
File.WriteAllText(Path.Combine(folderPath, "Position"), _lockedSlideIndex.ToString());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"保存位置信息失败: {ex}", LogHelper.LogType.Error);
|
||||
}
|
||||
|
||||
// 保存所有页面的墨迹
|
||||
int savedCount = 0;
|
||||
for (int i = 1; i <= presentation.Slides.Count && i < _memoryStreams.Length; i++)
|
||||
{
|
||||
if (_memoryStreams[i] != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_memoryStreams[i].Length > 8)
|
||||
{
|
||||
var srcBuf = new byte[_memoryStreams[i].Length];
|
||||
_memoryStreams[i].Position = 0;
|
||||
var byteLength = _memoryStreams[i].Read(srcBuf, 0, srcBuf.Length);
|
||||
|
||||
var filePath = Path.Combine(folderPath, i.ToString("0000") + ".icstk");
|
||||
File.WriteAllBytes(filePath, srcBuf);
|
||||
savedCount++;
|
||||
|
||||
LogHelper.WriteLogToFile($"已保存第{i}页墨迹,大小: {byteLength} bytes", LogHelper.LogType.Trace);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 删除空的墨迹文件
|
||||
var filePath = Path.Combine(folderPath, i.ToString("0000") + ".icstk");
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
File.Delete(filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"保存第{i}页墨迹失败: {ex}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LogHelper.WriteLogToFile($"已保存{savedCount}页墨迹到文件", LogHelper.LogType.Event);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"保存墨迹到文件失败: {ex}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从文件加载已保存的墨迹
|
||||
/// </summary>
|
||||
public void LoadSavedStrokes()
|
||||
{
|
||||
if (!IsAutoSaveEnabled || string.IsNullOrEmpty(AutoSaveLocation)) return;
|
||||
|
||||
lock (_lockObject)
|
||||
{
|
||||
try
|
||||
{
|
||||
var folderPath = GetPresentationFolderPath();
|
||||
if (!Directory.Exists(folderPath)) return;
|
||||
|
||||
var files = new DirectoryInfo(folderPath).GetFiles("*.icstk");
|
||||
int loadedCount = 0;
|
||||
|
||||
foreach (var file in files)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (int.TryParse(Path.GetFileNameWithoutExtension(file.Name), out int slideIndex))
|
||||
{
|
||||
if (slideIndex > 0 && slideIndex < _memoryStreams.Length)
|
||||
{
|
||||
var fileBytes = File.ReadAllBytes(file.FullName);
|
||||
_memoryStreams[slideIndex] = new MemoryStream(fileBytes);
|
||||
_memoryStreams[slideIndex].Position = 0;
|
||||
loadedCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"加载墨迹文件{file.Name}失败: {ex}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
LogHelper.WriteLogToFile($"已从文件加载{loadedCount}页墨迹", LogHelper.LogType.Event);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"从文件加载墨迹失败: {ex}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清除所有墨迹
|
||||
/// </summary>
|
||||
public void ClearAllStrokes()
|
||||
{
|
||||
lock (_lockObject)
|
||||
{
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < _memoryStreams.Length; i++)
|
||||
{
|
||||
_memoryStreams[i]?.Dispose();
|
||||
_memoryStreams[i] = null;
|
||||
}
|
||||
|
||||
CurrentStrokes.Clear();
|
||||
LogHelper.WriteLogToFile("已清除所有墨迹", LogHelper.LogType.Trace);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"清除墨迹失败: {ex}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 翻页后锁定墨迹写入
|
||||
/// </summary>
|
||||
public void LockInkForSlide(int slideIndex)
|
||||
{
|
||||
_inkLockUntil = DateTime.Now.AddMilliseconds(InkLockMilliseconds);
|
||||
_lockedSlideIndex = slideIndex;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查是否可以写入墨迹
|
||||
/// </summary>
|
||||
public bool CanWriteInk(int currentSlideIndex)
|
||||
{
|
||||
if (DateTime.Now < _inkLockUntil) return false;
|
||||
if (currentSlideIndex != _lockedSlideIndex && _lockedSlideIndex > 0) return false;
|
||||
return true;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
private string GeneratePresentationId(Presentation presentation)
|
||||
{
|
||||
try
|
||||
{
|
||||
var presentationPath = presentation.FullName;
|
||||
var fileHash = GetFileHash(presentationPath);
|
||||
return $"{presentation.Name}_{presentation.Slides.Count}_{fileHash}";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"生成演示文稿ID失败: {ex}", LogHelper.LogType.Error);
|
||||
return $"unknown_{DateTime.Now.Ticks}";
|
||||
}
|
||||
}
|
||||
|
||||
private string GetFileHash(string filePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(filePath)) return "unknown";
|
||||
|
||||
using (var md5 = MD5.Create())
|
||||
{
|
||||
byte[] hashBytes = md5.ComputeHash(Encoding.UTF8.GetBytes(filePath));
|
||||
return BitConverter.ToString(hashBytes).Replace("-", "").Substring(0, 8);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"计算文件哈希值失败: {ex}", LogHelper.LogType.Error);
|
||||
return "error";
|
||||
}
|
||||
}
|
||||
|
||||
private string GetPresentationFolderPath()
|
||||
{
|
||||
return Path.Combine(AutoSaveLocation, "Auto Saved - Presentations", _currentPresentationId);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Dispose
|
||||
public void Dispose()
|
||||
{
|
||||
if (!_disposed)
|
||||
{
|
||||
lock (_lockObject)
|
||||
{
|
||||
ClearAllStrokes();
|
||||
}
|
||||
_disposed = true;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,435 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Threading;
|
||||
|
||||
namespace Ink_Canvas.Helpers
|
||||
{
|
||||
/// <summary>
|
||||
/// PPT UI管理器 - 统一管理PPT相关的UI更新和样式设置
|
||||
/// </summary>
|
||||
public class PPTUIManager
|
||||
{
|
||||
#region Properties
|
||||
public bool ShowPPTButton { get; set; } = true;
|
||||
public int PPTButtonsDisplayOption { get; set; } = 2222;
|
||||
public int PPTSButtonsOption { get; set; } = 221;
|
||||
public int PPTBButtonsOption { get; set; } = 121;
|
||||
public int PPTLSButtonPosition { get; set; } = 0;
|
||||
public int PPTRSButtonPosition { get; set; } = 0;
|
||||
public bool EnablePPTButtonPageClickable { get; set; } = true;
|
||||
#endregion
|
||||
|
||||
#region Private Fields
|
||||
private readonly MainWindow _mainWindow;
|
||||
private readonly Dispatcher _dispatcher;
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
public PPTUIManager(MainWindow mainWindow)
|
||||
{
|
||||
_mainWindow = mainWindow ?? throw new ArgumentNullException(nameof(mainWindow));
|
||||
_dispatcher = _mainWindow.Dispatcher;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
/// <summary>
|
||||
/// 更新PPT连接状态UI
|
||||
/// </summary>
|
||||
public void UpdateConnectionStatus(bool isConnected)
|
||||
{
|
||||
_dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
if (isConnected)
|
||||
{
|
||||
_mainWindow.StackPanelPPTControls.Visibility = Visibility.Visible;
|
||||
_mainWindow.BtnPPTSlideShow.Visibility = Visibility.Visible;
|
||||
}
|
||||
else
|
||||
{
|
||||
_mainWindow.StackPanelPPTControls.Visibility = Visibility.Collapsed;
|
||||
_mainWindow.BtnPPTSlideShow.Visibility = Visibility.Collapsed;
|
||||
_mainWindow.BtnPPTSlideShowEnd.Visibility = Visibility.Collapsed;
|
||||
HideAllNavigationPanels();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"更新PPT连接状态UI失败: {ex}", LogHelper.LogType.Error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新幻灯片放映状态UI
|
||||
/// </summary>
|
||||
public void UpdateSlideShowStatus(bool isInSlideShow, int currentSlide = 0, int totalSlides = 0)
|
||||
{
|
||||
_dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
if (isInSlideShow)
|
||||
{
|
||||
_mainWindow.BtnPPTSlideShow.Visibility = Visibility.Collapsed;
|
||||
_mainWindow.BtnPPTSlideShowEnd.Visibility = Visibility.Visible;
|
||||
|
||||
if (currentSlide > 0 && totalSlides > 0)
|
||||
{
|
||||
_mainWindow.PPTBtnPageNow.Text = currentSlide.ToString();
|
||||
_mainWindow.PPTBtnPageTotal.Text = $"/ {totalSlides}";
|
||||
}
|
||||
|
||||
UpdateNavigationPanelsVisibility();
|
||||
UpdateNavigationButtonStyles();
|
||||
}
|
||||
else
|
||||
{
|
||||
_mainWindow.BtnPPTSlideShow.Visibility = Visibility.Visible;
|
||||
_mainWindow.BtnPPTSlideShowEnd.Visibility = Visibility.Collapsed;
|
||||
HideAllNavigationPanels();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"更新幻灯片放映状态UI失败: {ex}", LogHelper.LogType.Error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新当前页码显示
|
||||
/// </summary>
|
||||
public void UpdateCurrentSlideNumber(int currentSlide, int totalSlides)
|
||||
{
|
||||
_dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
_mainWindow.PPTBtnPageNow.Text = currentSlide.ToString();
|
||||
_mainWindow.PPTBtnPageTotal.Text = $"/ {totalSlides}";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"更新页码显示失败: {ex}", LogHelper.LogType.Error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新导航面板显示状态
|
||||
/// </summary>
|
||||
public void UpdateNavigationPanelsVisibility()
|
||||
{
|
||||
_dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
// 检查是否应该显示PPT按钮
|
||||
bool shouldShowButtons = ShowPPTButton && _mainWindow.BtnPPTSlideShowEnd.Visibility == Visibility.Visible;
|
||||
|
||||
if (!shouldShowButtons)
|
||||
{
|
||||
HideAllNavigationPanels();
|
||||
return;
|
||||
}
|
||||
|
||||
// 设置侧边按钮位置
|
||||
_mainWindow.LeftSidePanelForPPTNavigation.Margin = new Thickness(0, 0, 0, PPTLSButtonPosition * 2);
|
||||
_mainWindow.RightSidePanelForPPTNavigation.Margin = new Thickness(0, 0, 0, PPTRSButtonPosition * 2);
|
||||
|
||||
// 根据显示选项设置面板可见性
|
||||
var displayOption = PPTButtonsDisplayOption.ToString();
|
||||
if (displayOption.Length >= 4)
|
||||
{
|
||||
var options = displayOption.ToCharArray();
|
||||
|
||||
// 左下角面板
|
||||
if (options[0] == '2')
|
||||
AnimationsHelper.ShowWithFadeIn(_mainWindow.LeftBottomPanelForPPTNavigation);
|
||||
else
|
||||
_mainWindow.LeftBottomPanelForPPTNavigation.Visibility = Visibility.Collapsed;
|
||||
|
||||
// 右下角面板
|
||||
if (options[1] == '2')
|
||||
AnimationsHelper.ShowWithFadeIn(_mainWindow.RightBottomPanelForPPTNavigation);
|
||||
else
|
||||
_mainWindow.RightBottomPanelForPPTNavigation.Visibility = Visibility.Collapsed;
|
||||
|
||||
// 左侧面板
|
||||
if (options[2] == '2')
|
||||
AnimationsHelper.ShowWithFadeIn(_mainWindow.LeftSidePanelForPPTNavigation);
|
||||
else
|
||||
_mainWindow.LeftSidePanelForPPTNavigation.Visibility = Visibility.Collapsed;
|
||||
|
||||
// 右侧面板
|
||||
if (options[3] == '2')
|
||||
AnimationsHelper.ShowWithFadeIn(_mainWindow.RightSidePanelForPPTNavigation);
|
||||
else
|
||||
_mainWindow.RightSidePanelForPPTNavigation.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"更新导航面板显示状态失败: {ex}", LogHelper.LogType.Error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新导航按钮样式
|
||||
/// </summary>
|
||||
public void UpdateNavigationButtonStyles()
|
||||
{
|
||||
_dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
UpdateSideButtonStyles();
|
||||
UpdateBottomButtonStyles();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"更新导航按钮样式失败: {ex}", LogHelper.LogType.Error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 隐藏所有导航面板
|
||||
/// </summary>
|
||||
public void HideAllNavigationPanels()
|
||||
{
|
||||
_dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
_mainWindow.LeftBottomPanelForPPTNavigation.Visibility = Visibility.Collapsed;
|
||||
_mainWindow.RightBottomPanelForPPTNavigation.Visibility = Visibility.Collapsed;
|
||||
_mainWindow.LeftSidePanelForPPTNavigation.Visibility = Visibility.Collapsed;
|
||||
_mainWindow.RightSidePanelForPPTNavigation.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"隐藏导航面板失败: {ex}", LogHelper.LogType.Error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 显示/隐藏侧边栏退出按钮
|
||||
/// </summary>
|
||||
public void UpdateSidebarExitButtons(bool show)
|
||||
{
|
||||
_dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var visibility = show ? Visibility.Visible : Visibility.Collapsed;
|
||||
|
||||
if (_mainWindow.BtnExitPptFromSidebarLeft != null)
|
||||
_mainWindow.BtnExitPptFromSidebarLeft.Visibility = visibility;
|
||||
|
||||
if (_mainWindow.BtnExitPptFromSidebarRight != null)
|
||||
_mainWindow.BtnExitPptFromSidebarRight.Visibility = visibility;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"更新侧边栏退出按钮失败: {ex}", LogHelper.LogType.Error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置浮动栏透明度
|
||||
/// </summary>
|
||||
public void SetFloatingBarOpacity(double opacity)
|
||||
{
|
||||
_dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
_mainWindow.ViewboxFloatingBar.Opacity = opacity;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"设置浮动栏透明度失败: {ex}", LogHelper.LogType.Error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置主面板边距
|
||||
/// </summary>
|
||||
public void SetMainPanelMargin(Thickness margin)
|
||||
{
|
||||
_dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
_mainWindow.ViewBoxStackPanelMain.Margin = margin;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"设置主面板边距失败: {ex}", LogHelper.LogType.Error);
|
||||
}
|
||||
});
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
private void UpdateSideButtonStyles()
|
||||
{
|
||||
try
|
||||
{
|
||||
var sideOption = PPTSButtonsOption.ToString();
|
||||
if (sideOption.Length < 3) return;
|
||||
|
||||
var options = sideOption.ToCharArray();
|
||||
|
||||
// 页码按钮显示
|
||||
var pageButtonVisibility = options[0] == '2' ? Visibility.Visible : Visibility.Collapsed;
|
||||
_mainWindow.PPTLSPageButton.Visibility = pageButtonVisibility;
|
||||
_mainWindow.PPTRSPageButton.Visibility = pageButtonVisibility;
|
||||
|
||||
// 透明度设置
|
||||
var opacity = options[1] == '2' ? 0.5 : 1.0;
|
||||
_mainWindow.PPTBtnLSBorder.Opacity = opacity;
|
||||
_mainWindow.PPTBtnRSBorder.Opacity = opacity;
|
||||
|
||||
// 颜色主题
|
||||
bool isDarkTheme = options[2] == '2';
|
||||
ApplyButtonTheme(_mainWindow.PPTBtnLSBorder, _mainWindow.PPTBtnRSBorder, isDarkTheme, true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"更新侧边按钮样式失败: {ex}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateBottomButtonStyles()
|
||||
{
|
||||
try
|
||||
{
|
||||
var bottomOption = PPTBButtonsOption.ToString();
|
||||
if (bottomOption.Length < 3) return;
|
||||
|
||||
var options = bottomOption.ToCharArray();
|
||||
|
||||
// 页码按钮显示
|
||||
var pageButtonVisibility = options[0] == '2' ? Visibility.Visible : Visibility.Collapsed;
|
||||
_mainWindow.PPTLBPageButton.Visibility = pageButtonVisibility;
|
||||
_mainWindow.PPTRBPageButton.Visibility = pageButtonVisibility;
|
||||
|
||||
// 透明度设置
|
||||
var opacity = options[1] == '2' ? 0.5 : 1.0;
|
||||
_mainWindow.PPTBtnLBBorder.Opacity = opacity;
|
||||
_mainWindow.PPTBtnRBBorder.Opacity = opacity;
|
||||
|
||||
// 颜色主题
|
||||
bool isDarkTheme = options[2] == '2';
|
||||
ApplyButtonTheme(_mainWindow.PPTBtnLBBorder, _mainWindow.PPTBtnRBBorder, isDarkTheme, false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"更新底部按钮样式失败: {ex}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyButtonTheme(Border leftBorder, Border rightBorder, bool isDarkTheme, bool isSideButton)
|
||||
{
|
||||
try
|
||||
{
|
||||
Color backgroundColor, borderColor, foregroundColor, feedbackColor;
|
||||
|
||||
if (isDarkTheme)
|
||||
{
|
||||
backgroundColor = Color.FromRgb(39, 39, 42);
|
||||
borderColor = Color.FromRgb(82, 82, 91);
|
||||
foregroundColor = Colors.White;
|
||||
feedbackColor = Colors.White;
|
||||
}
|
||||
else
|
||||
{
|
||||
backgroundColor = Color.FromRgb(244, 244, 245);
|
||||
borderColor = Color.FromRgb(161, 161, 170);
|
||||
foregroundColor = Color.FromRgb(39, 39, 42);
|
||||
feedbackColor = Color.FromRgb(24, 24, 27);
|
||||
}
|
||||
|
||||
// 应用背景和边框颜色
|
||||
var backgroundBrush = new SolidColorBrush(backgroundColor);
|
||||
var borderBrush = new SolidColorBrush(borderColor);
|
||||
|
||||
leftBorder.Background = backgroundBrush;
|
||||
leftBorder.BorderBrush = borderBrush;
|
||||
rightBorder.Background = backgroundBrush;
|
||||
rightBorder.BorderBrush = borderBrush;
|
||||
|
||||
// 应用图标和文字颜色
|
||||
var foregroundBrush = new SolidColorBrush(foregroundColor);
|
||||
var feedbackBrush = new SolidColorBrush(feedbackColor);
|
||||
|
||||
if (isSideButton)
|
||||
{
|
||||
ApplySideButtonColors(foregroundBrush, feedbackBrush);
|
||||
}
|
||||
else
|
||||
{
|
||||
ApplyBottomButtonColors(foregroundBrush, feedbackBrush);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"应用按钮主题失败: {ex}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplySideButtonColors(SolidColorBrush foregroundBrush, SolidColorBrush feedbackBrush)
|
||||
{
|
||||
// 图标颜色
|
||||
_mainWindow.PPTLSPreviousButtonGeometry.Brush = foregroundBrush;
|
||||
_mainWindow.PPTRSPreviousButtonGeometry.Brush = foregroundBrush;
|
||||
_mainWindow.PPTLSNextButtonGeometry.Brush = foregroundBrush;
|
||||
_mainWindow.PPTRSNextButtonGeometry.Brush = foregroundBrush;
|
||||
|
||||
// 反馈背景颜色
|
||||
_mainWindow.PPTLSPreviousButtonFeedbackBorder.Background = feedbackBrush;
|
||||
_mainWindow.PPTRSPreviousButtonFeedbackBorder.Background = feedbackBrush;
|
||||
_mainWindow.PPTLSPageButtonFeedbackBorder.Background = feedbackBrush;
|
||||
_mainWindow.PPTRSPageButtonFeedbackBorder.Background = feedbackBrush;
|
||||
_mainWindow.PPTLSNextButtonFeedbackBorder.Background = feedbackBrush;
|
||||
_mainWindow.PPTRSNextButtonFeedbackBorder.Background = feedbackBrush;
|
||||
|
||||
// 文字颜色
|
||||
TextBlock.SetForeground(_mainWindow.PPTLSPageButton, foregroundBrush);
|
||||
TextBlock.SetForeground(_mainWindow.PPTRSPageButton, foregroundBrush);
|
||||
}
|
||||
|
||||
private void ApplyBottomButtonColors(SolidColorBrush foregroundBrush, SolidColorBrush feedbackBrush)
|
||||
{
|
||||
// 图标颜色
|
||||
_mainWindow.PPTLBPreviousButtonGeometry.Brush = foregroundBrush;
|
||||
_mainWindow.PPTRBPreviousButtonGeometry.Brush = foregroundBrush;
|
||||
_mainWindow.PPTLBNextButtonGeometry.Brush = foregroundBrush;
|
||||
_mainWindow.PPTRBNextButtonGeometry.Brush = foregroundBrush;
|
||||
|
||||
// 反馈背景颜色
|
||||
_mainWindow.PPTLBPreviousButtonFeedbackBorder.Background = feedbackBrush;
|
||||
_mainWindow.PPTRBPreviousButtonFeedbackBorder.Background = feedbackBrush;
|
||||
_mainWindow.PPTLBPageButtonFeedbackBorder.Background = feedbackBrush;
|
||||
_mainWindow.PPTRBPageButtonFeedbackBorder.Background = feedbackBrush;
|
||||
_mainWindow.PPTLBNextButtonFeedbackBorder.Background = feedbackBrush;
|
||||
_mainWindow.PPTRBNextButtonFeedbackBorder.Background = feedbackBrush;
|
||||
|
||||
// 文字颜色
|
||||
TextBlock.SetForeground(_mainWindow.PPTLBPageButton, foregroundBrush);
|
||||
TextBlock.SetForeground(_mainWindow.PPTRBPageButton, foregroundBrush);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -113,15 +113,15 @@
|
||||
<ItemGroup>
|
||||
<Reference Include="IACore">
|
||||
<HintPath>.\IACore.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="IALoader">
|
||||
<HintPath>.\IALoader.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="IAWinFX">
|
||||
<HintPath>.\IAWinFX.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.VisualBasic" />
|
||||
<Reference Include="netstandard" />
|
||||
@@ -143,10 +143,6 @@
|
||||
<None Include="app.manifest" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Costura.Fody" Version="6.0.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Hardcodet.NotifyIcon.Wpf" Version="1.1.0" />
|
||||
<PackageReference Include="iNKORE.UI.WPF.Modern" Version="0.9.27" />
|
||||
<PackageReference Include="MdXaml" Version="1.27.0" />
|
||||
|
||||
@@ -336,12 +336,21 @@ namespace Ink_Canvas {
|
||||
|
||||
// 加载自定义背景颜色
|
||||
LoadCustomBackgroundColor();
|
||||
|
||||
|
||||
// 注册设置面板滚动事件
|
||||
if (SettingsPanelScrollViewer != null)
|
||||
{
|
||||
SettingsPanelScrollViewer.ScrollChanged += SettingsPanelScrollViewer_ScrollChanged;
|
||||
}
|
||||
|
||||
// 初始化PPT管理器
|
||||
InitializePPTManagers();
|
||||
|
||||
// 如果启用PPT支持,开始监控
|
||||
if (Settings.PowerPointSettings.PowerPointSupport)
|
||||
{
|
||||
StartPPTMonitoring();
|
||||
}
|
||||
|
||||
// HasNewUpdateWindow hasNewUpdateWindow = new HasNewUpdateWindow();
|
||||
if (Environment.Is64BitProcess) GroupBoxInkRecognition.Visibility = Visibility.Collapsed;
|
||||
@@ -500,8 +509,11 @@ namespace Ink_Canvas {
|
||||
private void Window_Closed(object sender, EventArgs e) {
|
||||
SystemEvents.DisplaySettingsChanged -= SystemEventsOnDisplaySettingsChanged;
|
||||
|
||||
// 释放PPT管理器资源
|
||||
DisposePPTManagers();
|
||||
|
||||
LogHelper.WriteLogToFile("Ink Canvas closed", LogHelper.LogType.Event);
|
||||
|
||||
|
||||
// 检查是否有待安装的更新
|
||||
CheckPendingUpdates();
|
||||
}
|
||||
|
||||
@@ -24,14 +24,74 @@ namespace Ink_Canvas {
|
||||
|
||||
// 保存每页白板图片信息
|
||||
private void SaveStrokes(bool isBackupMain = false) {
|
||||
// 确保画布上的所有UI元素都被保存到时间机器历史记录中
|
||||
var currentHistory = timeMachine.ExportTimeMachineHistory();
|
||||
var elementsInHistory = new HashSet<UIElement>();
|
||||
|
||||
// 收集已经在历史记录中的元素
|
||||
if (currentHistory != null) {
|
||||
foreach (var h in currentHistory) {
|
||||
if (h.CommitType == TimeMachineHistoryType.ElementInsert &&
|
||||
h.InsertedElement != null &&
|
||||
!h.StrokeHasBeenCleared) {
|
||||
elementsInHistory.Add(h.InsertedElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 检查画布上的所有UI元素,确保它们都在历史记录中
|
||||
var missingElements = 0;
|
||||
foreach (UIElement child in inkCanvas.Children) {
|
||||
if (child is Image || child is MediaElement) {
|
||||
if (!elementsInHistory.Contains(child)) {
|
||||
timeMachine.CommitElementInsertHistory(child);
|
||||
missingElements++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 确保画布上的所有墨迹都被保存
|
||||
if (inkCanvas.Strokes.Count > 0) {
|
||||
// 检查是否有墨迹没有在时间机器历史记录中
|
||||
var strokesInHistory = new HashSet<Stroke>();
|
||||
if (currentHistory != null) {
|
||||
foreach (var h in currentHistory) {
|
||||
if (h.CommitType == TimeMachineHistoryType.UserInput &&
|
||||
h.CurrentStroke != null &&
|
||||
!h.StrokeHasBeenCleared) {
|
||||
foreach (Stroke stroke in h.CurrentStroke) {
|
||||
strokesInHistory.Add(stroke);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 收集没有在历史记录中的墨迹
|
||||
var missingStrokes = new StrokeCollection();
|
||||
foreach (Stroke stroke in inkCanvas.Strokes) {
|
||||
if (!strokesInHistory.Contains(stroke)) {
|
||||
missingStrokes.Add(stroke);
|
||||
}
|
||||
}
|
||||
|
||||
if (missingStrokes.Count > 0) {
|
||||
timeMachine.CommitStrokeUserInputHistory(missingStrokes);
|
||||
}
|
||||
}
|
||||
|
||||
if (isBackupMain) {
|
||||
var timeMachineHistory = timeMachine.ExportTimeMachineHistory();
|
||||
TimeMachineHistories[0] = timeMachineHistory;
|
||||
timeMachine.ClearStrokeHistory();
|
||||
|
||||
|
||||
} else {
|
||||
var timeMachineHistory = timeMachine.ExportTimeMachineHistory();
|
||||
TimeMachineHistories[CurrentWhiteboardIndex] = timeMachineHistory;
|
||||
timeMachine.ClearStrokeHistory();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,9 +114,11 @@ namespace Ink_Canvas {
|
||||
try {
|
||||
var targetIndex = isBackupMain ? 0 : CurrentWhiteboardIndex;
|
||||
|
||||
// 先清空当前画布的所有内容(墨迹和图片)
|
||||
// 这里必须清除图片,因为页面切换时需要完全重置画布状态
|
||||
// 先清空当前画布的墨迹
|
||||
inkCanvas.Strokes.Clear();
|
||||
|
||||
// 清空当前画布的所有内容(墨迹和图片)
|
||||
// 这里必须清除图片,因为页面切换时需要完全重置画布状态
|
||||
inkCanvas.Children.Clear();
|
||||
|
||||
// 如果历史记录为空,直接返回(新页面或空页面)
|
||||
@@ -73,6 +135,11 @@ namespace Ink_Canvas {
|
||||
// 通过时间机器历史恢复所有内容(墨迹和图片)
|
||||
foreach (var item in TimeMachineHistories[CurrentWhiteboardIndex]) ApplyHistoryToCanvas(item);
|
||||
}
|
||||
|
||||
// 确保选中状态被清除,因为我们切换了页面
|
||||
if (selectedUIElement != null) {
|
||||
DeselectUIElement();
|
||||
}
|
||||
}
|
||||
catch {
|
||||
// ignored
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using Ink_Canvas.Helpers;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace Ink_Canvas
|
||||
@@ -28,17 +29,10 @@ namespace Ink_Canvas
|
||||
string timestamp = "img_" + DateTime.Now.ToString("yyyyMMdd_HH_mm_ss_fff");
|
||||
image.Name = timestamp;
|
||||
|
||||
// 新缩放逻辑:最大宽高为画布一半,并居中
|
||||
double maxWidth = inkCanvas.ActualWidth / 2;
|
||||
double maxHeight = inkCanvas.ActualHeight / 2;
|
||||
double scaleX = maxWidth / image.Width;
|
||||
double scaleY = maxHeight / image.Height;
|
||||
double scale = Math.Min(1, Math.Min(scaleX, scaleY));
|
||||
image.Width = image.Width * scale;
|
||||
image.Height = image.Height * scale;
|
||||
InkCanvas.SetLeft(image, (inkCanvas.ActualWidth - image.Width) / 2);
|
||||
InkCanvas.SetTop(image, (inkCanvas.ActualHeight - image.Height) / 2);
|
||||
CenterAndScaleElement(image);
|
||||
|
||||
InkCanvas.SetLeft(image, 0);
|
||||
InkCanvas.SetTop(image, 0);
|
||||
inkCanvas.Children.Add(image);
|
||||
|
||||
// 添加鼠标事件处理,使图片可以被选择
|
||||
@@ -119,6 +113,8 @@ namespace Ink_Canvas
|
||||
|
||||
if (mediaElement != null)
|
||||
{
|
||||
CenterAndScaleElement(mediaElement);
|
||||
|
||||
InkCanvas.SetLeft(mediaElement, 0);
|
||||
InkCanvas.SetTop(mediaElement, 0);
|
||||
inkCanvas.Children.Add(mediaElement);
|
||||
@@ -256,5 +252,27 @@ namespace Ink_Canvas
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void CenterAndScaleElement(FrameworkElement element)
|
||||
{
|
||||
double maxWidth = SystemParameters.PrimaryScreenWidth / 2;
|
||||
double maxHeight = SystemParameters.PrimaryScreenHeight / 2;
|
||||
|
||||
double scaleX = maxWidth / element.Width;
|
||||
double scaleY = maxHeight / element.Height;
|
||||
double scale = Math.Min(scaleX, scaleY);
|
||||
|
||||
TransformGroup transformGroup = new TransformGroup();
|
||||
transformGroup.Children.Add(new ScaleTransform(scale, scale));
|
||||
|
||||
double canvasWidth = inkCanvas.ActualWidth;
|
||||
double canvasHeight = inkCanvas.ActualHeight;
|
||||
double centerX = (canvasWidth - element.Width * scale) / 2;
|
||||
double centerY = (canvasHeight - element.Height * scale) / 2;
|
||||
|
||||
transformGroup.Children.Add(new TranslateTransform(centerX, centerY));
|
||||
|
||||
element.RenderTransform = transformGroup;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -672,7 +672,11 @@ namespace Ink_Canvas {
|
||||
if (Settings.Automation.IsAutoSaveStrokesAtClear &&
|
||||
inkCanvas.Strokes.Count > Settings.Automation.MinimumAutomationStrokeNumber) {
|
||||
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible)
|
||||
SaveScreenShot(true, $"{pptName}/{previousSlideID}_{DateTime.Now:HH-mm-ss}");
|
||||
{
|
||||
var currentSlide = _pptManager?.GetCurrentSlideNumber() ?? 0;
|
||||
var presentationName = _pptManager?.GetPresentationName() ?? "";
|
||||
SaveScreenShot(true, $"{presentationName}/{currentSlide}_{DateTime.Now:HH-mm-ss}");
|
||||
}
|
||||
else
|
||||
SaveScreenShot(true);
|
||||
}
|
||||
@@ -1287,7 +1291,11 @@ namespace Ink_Canvas {
|
||||
if (inkCanvas.Strokes.Count > 0 &&
|
||||
inkCanvas.Strokes.Count > Settings.Automation.MinimumAutomationStrokeNumber) {
|
||||
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible)
|
||||
SaveScreenShot(true, $"{pptName}/{previousSlideID}_{DateTime.Now:HH-mm-ss}");
|
||||
{
|
||||
var currentSlide = _pptManager?.GetCurrentSlideNumber() ?? 0;
|
||||
var presentationName = _pptManager?.GetPresentationName() ?? "";
|
||||
SaveScreenShot(true, $"{presentationName}/{currentSlide}_{DateTime.Now:HH-mm-ss}");
|
||||
}
|
||||
else SaveScreenShot(true);
|
||||
}
|
||||
|
||||
@@ -1325,14 +1333,10 @@ namespace Ink_Canvas {
|
||||
|
||||
if (currentMode != 0) {
|
||||
SaveStrokes();
|
||||
// 检查是否在PPT放映模式,如果不在则不恢复可能包含PPT墨迹的备份
|
||||
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible) {
|
||||
RestoreStrokes(true);
|
||||
} else {
|
||||
// 不在PPT模式时,清空备份以避免显示已结束PPT的墨迹
|
||||
TimeMachineHistories[0] = null;
|
||||
timeMachine.ClearStrokeHistory();
|
||||
}
|
||||
// 总是恢复备份墨迹,不管是否在PPT模式
|
||||
// PPT墨迹和白板墨迹应该分别管理,不应该互相影响
|
||||
RestoreStrokes(true);
|
||||
LogHelper.WriteLogToFile($"退出白板模式,恢复备份墨迹。当前模式:{(BtnPPTSlideShowEnd.Visibility == Visibility.Visible ? "PPT放映" : "桌面")}", LogHelper.LogType.Trace);
|
||||
}
|
||||
|
||||
if (BtnSwitchTheme.Content.ToString() == "浅色")
|
||||
@@ -1650,14 +1654,10 @@ namespace Ink_Canvas {
|
||||
}
|
||||
|
||||
public void BtnRestart_Click(object sender, RoutedEventArgs e) {
|
||||
try {
|
||||
Process.Start(System.Windows.Forms.Application.ExecutablePath, "-m");
|
||||
App.IsAppExitByUser = true;
|
||||
CloseIsFromButton = true;
|
||||
Application.Current.Shutdown();
|
||||
} catch (Exception ex) {
|
||||
LogHelper.NewLog($"重启程序时出错: {ex.Message}");
|
||||
}
|
||||
Process.Start(System.Windows.Forms.Application.ExecutablePath, "-m");
|
||||
App.IsAppExitByUser = true;
|
||||
CloseIsFromButton = true;
|
||||
Application.Current.Shutdown();
|
||||
}
|
||||
|
||||
private void SettingsOverlayClick(object sender, MouseButtonEventArgs e) {
|
||||
@@ -1780,26 +1780,13 @@ namespace Ink_Canvas {
|
||||
AnimationsHelper.HideWithSlideAndFade(BlackboardLeftSide);
|
||||
AnimationsHelper.HideWithSlideAndFade(BlackboardCenterSide);
|
||||
AnimationsHelper.HideWithSlideAndFade(BlackboardRightSide);
|
||||
|
||||
// 取消任何UI元素的选择
|
||||
|
||||
DeselectUIElement();
|
||||
|
||||
SaveStrokes(true);
|
||||
ClearStrokes(true);
|
||||
|
||||
// 检查是否在PPT放映模式,如果不在则不恢复可能包含PPT墨迹的备份
|
||||
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible) {
|
||||
LogHelper.WriteLogToFile("退出白板:当前在PPT放映模式,恢复备份墨迹", LogHelper.LogType.Trace);
|
||||
RestoreStrokes();
|
||||
} else {
|
||||
// 不在PPT模式时,清空备份以避免显示已结束PPT的墨迹
|
||||
LogHelper.WriteLogToFile("退出白板:当前不在PPT放映模式,清空备份以避免显示已结束PPT的墨迹", LogHelper.LogType.Trace);
|
||||
TimeMachineHistories[0] = null;
|
||||
timeMachine.ClearStrokeHistory();
|
||||
}
|
||||
|
||||
// 退出白板时清空图片
|
||||
inkCanvas.Children.Clear();
|
||||
RestoreStrokes(true);
|
||||
|
||||
|
||||
if (BtnSwitchTheme.Content.ToString() == "浅色") {
|
||||
BtnSwitch.Content = "黑板";
|
||||
@@ -1837,18 +1824,7 @@ namespace Ink_Canvas {
|
||||
|
||||
SaveStrokes();
|
||||
ClearStrokes(true);
|
||||
|
||||
// 检查是否在PPT放映模式,如果不在则不恢复可能包含PPT墨迹的备份
|
||||
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible) {
|
||||
RestoreStrokes(true);
|
||||
} else {
|
||||
// 不在PPT模式时,清空备份以避免显示已结束PPT的墨迹
|
||||
TimeMachineHistories[0] = null;
|
||||
timeMachine.ClearStrokeHistory();
|
||||
}
|
||||
|
||||
// 退出白板时清空图片
|
||||
inkCanvas.Children.Clear();
|
||||
RestoreStrokes(true);
|
||||
|
||||
if (BtnSwitchTheme.Content.ToString() == "浅色") {
|
||||
BtnSwitch.Content = "黑板";
|
||||
@@ -1883,14 +1859,9 @@ namespace Ink_Canvas {
|
||||
SaveStrokes(true);
|
||||
ClearStrokes(true);
|
||||
|
||||
// 检查是否在PPT放映模式,如果不在则不恢复可能包含PPT墨迹的备份
|
||||
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible) {
|
||||
RestoreStrokes();
|
||||
} else {
|
||||
// 不在PPT模式时,清空备份以避免显示已结束PPT的墨迹
|
||||
TimeMachineHistories[0] = null;
|
||||
timeMachine.ClearStrokeHistory();
|
||||
}
|
||||
// 总是恢复备份墨迹,不管是否在PPT模式
|
||||
// PPT墨迹和白板墨迹应该分别管理,不应该互相影响
|
||||
RestoreStrokes();
|
||||
|
||||
BtnSwitch.Content = "屏幕";
|
||||
if (BtnSwitchTheme.Content.ToString() == "浅色") {
|
||||
@@ -2058,17 +2029,10 @@ namespace Ink_Canvas {
|
||||
string timestamp = "img_" + DateTime.Now.ToString("yyyyMMdd_HH_mm_ss_fff");
|
||||
image.Name = timestamp;
|
||||
|
||||
// 新缩放逻辑:最大宽高为画布一半,并居中
|
||||
double maxWidth = inkCanvas.ActualWidth / 2;
|
||||
double maxHeight = inkCanvas.ActualHeight / 2;
|
||||
double scaleX = maxWidth / image.Width;
|
||||
double scaleY = maxHeight / image.Height;
|
||||
double scale = Math.Min(1, Math.Min(scaleX, scaleY));
|
||||
image.Width = image.Width * scale;
|
||||
image.Height = image.Height * scale;
|
||||
InkCanvas.SetLeft(image, (inkCanvas.ActualWidth - image.Width) / 2);
|
||||
InkCanvas.SetTop(image, (inkCanvas.ActualHeight - image.Height) / 2);
|
||||
CenterAndScaleElement(image);
|
||||
|
||||
InkCanvas.SetLeft(image, 0);
|
||||
InkCanvas.SetTop(image, 0);
|
||||
inkCanvas.Children.Add(image);
|
||||
|
||||
timeMachine.CommitElementInsertHistory(image);
|
||||
@@ -2076,6 +2040,5 @@ namespace Ink_Canvas {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+603
-1695
File diff suppressed because it is too large
Load Diff
@@ -57,18 +57,21 @@ namespace Ink_Canvas {
|
||||
List<StrokeCollection> allPageStrokes = new List<StrokeCollection>();
|
||||
|
||||
// 检查PPT放映模式下的多页面墨迹
|
||||
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible && pptApplication != null)
|
||||
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible && _pptManager?.IsConnected == true)
|
||||
{
|
||||
hasMultiplePages = true;
|
||||
// 收集PPT放映模式下的所有页面墨迹
|
||||
for (int i = 1; i <= pptApplication.SlideShowWindows[1].Presentation.Slides.Count; i++)
|
||||
var totalSlides = _pptManager.SlidesCount;
|
||||
var currentSlide = _pptManager.GetCurrentSlideNumber();
|
||||
|
||||
for (int i = 1; i <= totalSlides; i++)
|
||||
{
|
||||
if (memoryStreams[i] != null && memoryStreams[i].Length > 8)
|
||||
var slideStrokes = _pptInkManager?.LoadSlideStrokes(i);
|
||||
if (slideStrokes != null && slideStrokes.Count > 0)
|
||||
{
|
||||
memoryStreams[i].Position = 0;
|
||||
allPageStrokes.Add(new StrokeCollection(memoryStreams[i]));
|
||||
allPageStrokes.Add(slideStrokes);
|
||||
}
|
||||
else if (i == previousSlideID && inkCanvas.Strokes.Count > 0)
|
||||
else if (i == currentSlide && inkCanvas.Strokes.Count > 0)
|
||||
{
|
||||
// 当前页面的墨迹
|
||||
allPageStrokes.Add(inkCanvas.Strokes.Clone());
|
||||
@@ -485,10 +488,8 @@ namespace Ink_Canvas {
|
||||
timeMachine.ClearStrokeHistory();
|
||||
|
||||
// 重置PPT墨迹存储
|
||||
if (memoryStreams == null) {
|
||||
memoryStreams = new MemoryStream[50];
|
||||
}
|
||||
|
||||
_pptInkManager?.ClearAllStrokes();
|
||||
|
||||
// 读取所有页面的墨迹文件
|
||||
var files = Directory.GetFiles(tempDir, "page_*.icstk");
|
||||
foreach (var file in files) {
|
||||
@@ -497,23 +498,19 @@ namespace Ink_Canvas {
|
||||
using (var fs = new FileStream(file, FileMode.Open, FileAccess.Read)) {
|
||||
var strokes = new StrokeCollection(fs);
|
||||
if (strokes.Count > 0) {
|
||||
var ms = new MemoryStream();
|
||||
strokes.Save(ms);
|
||||
ms.Position = 0;
|
||||
memoryStreams[pageNumber] = ms;
|
||||
_pptInkManager?.SaveCurrentSlideStrokes(pageNumber, strokes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 恢复当前页面的墨迹
|
||||
if (pptApplication.SlideShowWindows.Count > 0) {
|
||||
int currentSlide = pptApplication.SlideShowWindows[1].View.CurrentShowPosition;
|
||||
if (memoryStreams[currentSlide] != null && memoryStreams[currentSlide].Length > 0) {
|
||||
memoryStreams[currentSlide].Position = 0;
|
||||
inkCanvas.Strokes.Add(new StrokeCollection(memoryStreams[currentSlide]));
|
||||
if (_pptManager?.IsInSlideShow == true) {
|
||||
int currentSlide = _pptManager.GetCurrentSlideNumber();
|
||||
var currentStrokes = _pptInkManager?.LoadSlideStrokes(currentSlide);
|
||||
if (currentStrokes != null && currentStrokes.Count > 0) {
|
||||
inkCanvas.Strokes.Add(currentStrokes);
|
||||
}
|
||||
previousSlideID = currentSlide;
|
||||
}
|
||||
|
||||
LogHelper.WriteLogToFile($"成功恢复PPT墨迹,共{files.Length}页");
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Windows.Ink;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
using Ink_Canvas.Helpers;
|
||||
using iNKORE.UI.WPF.Modern.Controls;
|
||||
using Point = System.Windows.Point;
|
||||
|
||||
|
||||
@@ -95,10 +95,19 @@ namespace Ink_Canvas {
|
||||
Settings.PowerPointSettings.PowerPointSupport = ToggleSwitchSupportPowerPoint.IsOn;
|
||||
SaveSettingsToFile();
|
||||
|
||||
// 使用新的PPT管理器
|
||||
if (Settings.PowerPointSettings.PowerPointSupport)
|
||||
timerCheckPPT.Start();
|
||||
{
|
||||
if (_pptManager == null)
|
||||
{
|
||||
InitializePPTManagers();
|
||||
}
|
||||
StartPPTMonitoring();
|
||||
}
|
||||
else
|
||||
timerCheckPPT.Stop();
|
||||
{
|
||||
StopPPTMonitoring();
|
||||
}
|
||||
}
|
||||
|
||||
private void ToggleSwitchShowCanvasAtNewSlideShow_Toggled(object sender, RoutedEventArgs e) {
|
||||
@@ -419,7 +428,12 @@ namespace Ink_Canvas {
|
||||
if (!isLoaded) return;
|
||||
Settings.PowerPointSettings.ShowPPTButton = ToggleSwitchShowPPTButton.IsOn;
|
||||
SaveSettingsToFile();
|
||||
UpdatePPTBtnDisplaySettingsStatus();
|
||||
// 更新PPT UI管理器设置
|
||||
if (_pptUIManager != null)
|
||||
{
|
||||
_pptUIManager.ShowPPTButton = Settings.PowerPointSettings.ShowPPTButton;
|
||||
_pptUIManager.UpdateNavigationPanelsVisibility();
|
||||
}
|
||||
UpdatePPTBtnPreview();
|
||||
}
|
||||
|
||||
@@ -436,7 +450,12 @@ namespace Ink_Canvas {
|
||||
c[0] = (bool)((CheckBox)sender).IsChecked ? '2' : '1';
|
||||
Settings.PowerPointSettings.PPTButtonsDisplayOption = int.Parse(new string(c));
|
||||
SaveSettingsToFile();
|
||||
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible) UpdatePPTBtnDisplaySettingsStatus();
|
||||
// 更新PPT UI管理器设置
|
||||
if (_pptUIManager != null && BtnPPTSlideShowEnd.Visibility == Visibility.Visible)
|
||||
{
|
||||
_pptUIManager.PPTButtonsDisplayOption = Settings.PowerPointSettings.PPTButtonsDisplayOption;
|
||||
_pptUIManager.UpdateNavigationPanelsVisibility();
|
||||
}
|
||||
UpdatePPTBtnPreview();
|
||||
}
|
||||
|
||||
@@ -448,7 +467,12 @@ namespace Ink_Canvas {
|
||||
c[1] = (bool)((CheckBox)sender).IsChecked ? '2' : '1';
|
||||
Settings.PowerPointSettings.PPTButtonsDisplayOption = int.Parse(new string(c));
|
||||
SaveSettingsToFile();
|
||||
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible) UpdatePPTBtnDisplaySettingsStatus();
|
||||
// 更新PPT UI管理器设置
|
||||
if (_pptUIManager != null && BtnPPTSlideShowEnd.Visibility == Visibility.Visible)
|
||||
{
|
||||
_pptUIManager.PPTButtonsDisplayOption = Settings.PowerPointSettings.PPTButtonsDisplayOption;
|
||||
_pptUIManager.UpdateNavigationPanelsVisibility();
|
||||
}
|
||||
UpdatePPTBtnPreview();
|
||||
}
|
||||
|
||||
@@ -460,7 +484,12 @@ namespace Ink_Canvas {
|
||||
c[2] = (bool)((CheckBox)sender).IsChecked ? '2' : '1';
|
||||
Settings.PowerPointSettings.PPTButtonsDisplayOption = int.Parse(new string(c));
|
||||
SaveSettingsToFile();
|
||||
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible) UpdatePPTBtnDisplaySettingsStatus();
|
||||
// 更新PPT UI管理器设置
|
||||
if (_pptUIManager != null && BtnPPTSlideShowEnd.Visibility == Visibility.Visible)
|
||||
{
|
||||
_pptUIManager.PPTButtonsDisplayOption = Settings.PowerPointSettings.PPTButtonsDisplayOption;
|
||||
_pptUIManager.UpdateNavigationPanelsVisibility();
|
||||
}
|
||||
UpdatePPTBtnPreview();
|
||||
}
|
||||
|
||||
@@ -472,7 +501,12 @@ namespace Ink_Canvas {
|
||||
c[3] = (bool)((CheckBox)sender).IsChecked ? '2' : '1';
|
||||
Settings.PowerPointSettings.PPTButtonsDisplayOption = int.Parse(new string(c));
|
||||
SaveSettingsToFile();
|
||||
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible) UpdatePPTBtnDisplaySettingsStatus();
|
||||
// 更新PPT UI管理器设置
|
||||
if (_pptUIManager != null && BtnPPTSlideShowEnd.Visibility == Visibility.Visible)
|
||||
{
|
||||
_pptUIManager.PPTButtonsDisplayOption = Settings.PowerPointSettings.PPTButtonsDisplayOption;
|
||||
_pptUIManager.UpdateNavigationPanelsVisibility();
|
||||
}
|
||||
UpdatePPTBtnPreview();
|
||||
}
|
||||
|
||||
@@ -484,7 +518,12 @@ namespace Ink_Canvas {
|
||||
c[0] = (bool)((CheckBox)sender).IsChecked ? '2' : '1';
|
||||
Settings.PowerPointSettings.PPTSButtonsOption = int.Parse(new string(c));
|
||||
SaveSettingsToFile();
|
||||
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible) UpdatePPTBtnStyleSettingsStatus();
|
||||
// 更新PPT UI管理器设置
|
||||
if (_pptUIManager != null && BtnPPTSlideShowEnd.Visibility == Visibility.Visible)
|
||||
{
|
||||
_pptUIManager.PPTSButtonsOption = Settings.PowerPointSettings.PPTSButtonsOption;
|
||||
_pptUIManager.UpdateNavigationButtonStyles();
|
||||
}
|
||||
UpdatePPTBtnPreview();
|
||||
}
|
||||
|
||||
@@ -496,7 +535,12 @@ namespace Ink_Canvas {
|
||||
c[1] = (bool)((CheckBox)sender).IsChecked ? '2' : '1';
|
||||
Settings.PowerPointSettings.PPTSButtonsOption = int.Parse(new string(c));
|
||||
SaveSettingsToFile();
|
||||
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible) UpdatePPTBtnStyleSettingsStatus();
|
||||
// 更新PPT UI管理器设置
|
||||
if (_pptUIManager != null && BtnPPTSlideShowEnd.Visibility == Visibility.Visible)
|
||||
{
|
||||
_pptUIManager.PPTSButtonsOption = Settings.PowerPointSettings.PPTSButtonsOption;
|
||||
_pptUIManager.UpdateNavigationButtonStyles();
|
||||
}
|
||||
UpdatePPTBtnPreview();
|
||||
}
|
||||
|
||||
@@ -508,7 +552,12 @@ namespace Ink_Canvas {
|
||||
c[2] = (bool)((CheckBox)sender).IsChecked ? '2' : '1';
|
||||
Settings.PowerPointSettings.PPTSButtonsOption = int.Parse(new string(c));
|
||||
SaveSettingsToFile();
|
||||
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible) UpdatePPTBtnStyleSettingsStatus();
|
||||
// 更新PPT UI管理器设置
|
||||
if (_pptUIManager != null && BtnPPTSlideShowEnd.Visibility == Visibility.Visible)
|
||||
{
|
||||
_pptUIManager.PPTSButtonsOption = Settings.PowerPointSettings.PPTSButtonsOption;
|
||||
_pptUIManager.UpdateNavigationButtonStyles();
|
||||
}
|
||||
UpdatePPTBtnPreview();
|
||||
}
|
||||
|
||||
@@ -520,7 +569,12 @@ namespace Ink_Canvas {
|
||||
c[0] = (bool)((CheckBox)sender).IsChecked ? '2' : '1';
|
||||
Settings.PowerPointSettings.PPTBButtonsOption = int.Parse(new string(c));
|
||||
SaveSettingsToFile();
|
||||
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible) UpdatePPTBtnStyleSettingsStatus();
|
||||
// 更新PPT UI管理器设置
|
||||
if (_pptUIManager != null && BtnPPTSlideShowEnd.Visibility == Visibility.Visible)
|
||||
{
|
||||
_pptUIManager.PPTBButtonsOption = Settings.PowerPointSettings.PPTBButtonsOption;
|
||||
_pptUIManager.UpdateNavigationButtonStyles();
|
||||
}
|
||||
UpdatePPTBtnPreview();
|
||||
}
|
||||
|
||||
@@ -532,7 +586,7 @@ namespace Ink_Canvas {
|
||||
c[1] = (bool)((CheckBox)sender).IsChecked ? '2' : '1';
|
||||
Settings.PowerPointSettings.PPTBButtonsOption = int.Parse(new string(c));
|
||||
SaveSettingsToFile();
|
||||
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible) UpdatePPTBtnStyleSettingsStatus();
|
||||
UpdatePPTUIManagerSettings();
|
||||
UpdatePPTBtnPreview();
|
||||
}
|
||||
|
||||
@@ -544,7 +598,7 @@ namespace Ink_Canvas {
|
||||
c[2] = (bool)((CheckBox)sender).IsChecked ? '2' : '1';
|
||||
Settings.PowerPointSettings.PPTBButtonsOption = int.Parse(new string(c));
|
||||
SaveSettingsToFile();
|
||||
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible) UpdatePPTBtnStyleSettingsStatus();
|
||||
UpdatePPTUIManagerSettings();
|
||||
UpdatePPTBtnPreview();
|
||||
}
|
||||
|
||||
@@ -552,7 +606,7 @@ namespace Ink_Canvas {
|
||||
if (!isLoaded) return;
|
||||
Settings.PowerPointSettings.PPTLSButtonPosition = (int)PPTButtonLeftPositionValueSlider.Value;
|
||||
UpdatePPTBtnSlidersStatus();
|
||||
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible) UpdatePPTBtnDisplaySettingsStatus();
|
||||
UpdatePPTUIManagerSettings();
|
||||
SliderDelayAction.DebounceAction(2000, null, SaveSettingsToFile);
|
||||
UpdatePPTBtnPreview();
|
||||
}
|
||||
@@ -686,11 +740,28 @@ namespace Ink_Canvas {
|
||||
if (!isLoaded) return;
|
||||
Settings.PowerPointSettings.PPTRSButtonPosition = (int)PPTButtonRightPositionValueSlider.Value;
|
||||
UpdatePPTBtnSlidersStatus();
|
||||
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible) UpdatePPTBtnDisplaySettingsStatus();
|
||||
UpdatePPTUIManagerSettings();
|
||||
SliderDelayAction.DebounceAction(2000,null, SaveSettingsToFile);
|
||||
UpdatePPTBtnPreview();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新PPT UI管理器设置的通用方法
|
||||
/// </summary>
|
||||
private void UpdatePPTUIManagerSettings()
|
||||
{
|
||||
if (_pptUIManager != null && BtnPPTSlideShowEnd.Visibility == Visibility.Visible)
|
||||
{
|
||||
_pptUIManager.PPTButtonsDisplayOption = Settings.PowerPointSettings.PPTButtonsDisplayOption;
|
||||
_pptUIManager.PPTSButtonsOption = Settings.PowerPointSettings.PPTSButtonsOption;
|
||||
_pptUIManager.PPTBButtonsOption = Settings.PowerPointSettings.PPTBButtonsOption;
|
||||
_pptUIManager.PPTLSButtonPosition = Settings.PowerPointSettings.PPTLSButtonPosition;
|
||||
_pptUIManager.PPTRSButtonPosition = Settings.PowerPointSettings.PPTRSButtonPosition;
|
||||
_pptUIManager.UpdateNavigationPanelsVisibility();
|
||||
_pptUIManager.UpdateNavigationButtonStyles();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdatePPTBtnPreview() {
|
||||
//new BitmapImage(new Uri("pack://application:,,,/Resources/new-icons/unfold-chevron.png"));
|
||||
var bopt = Settings.PowerPointSettings.PPTBButtonsOption.ToString();
|
||||
|
||||
@@ -278,10 +278,10 @@ namespace Ink_Canvas {
|
||||
|
||||
if (Settings.PowerPointSettings.PowerPointSupport) {
|
||||
ToggleSwitchSupportPowerPoint.IsOn = true;
|
||||
timerCheckPPT.Start();
|
||||
// PPT监控将在Window_Loaded中启动
|
||||
} else {
|
||||
ToggleSwitchSupportPowerPoint.IsOn = false;
|
||||
timerCheckPPT.Stop();
|
||||
// PPT监控将保持停止状态
|
||||
}
|
||||
|
||||
ToggleSwitchShowCanvasAtNewSlideShow.IsOn = Settings.PowerPointSettings.IsShowCanvasAtNewSlideShow;
|
||||
|
||||
@@ -653,9 +653,9 @@ namespace Ink_Canvas {
|
||||
// New method: Checks if a stroke is potentially a straight line
|
||||
private bool IsPotentialStraightLine(Stroke stroke) {
|
||||
// 确保有足够的点来进行线条分析
|
||||
if (stroke.StylusPoints.Count < 5)
|
||||
if (stroke.StylusPoints.Count < 5)
|
||||
return false;
|
||||
|
||||
|
||||
Point start = stroke.StylusPoints.First().ToPoint();
|
||||
Point end = stroke.StylusPoints.Last().ToPoint();
|
||||
double lineLength = GetDistance(start, end);
|
||||
@@ -664,6 +664,14 @@ namespace Ink_Canvas {
|
||||
// 线条必须足够长才考虑拉直,使用自适应阈值
|
||||
if (lineLength < adaptiveThreshold)
|
||||
return false;
|
||||
|
||||
// 新增:检查墨迹复杂度,避免将复杂图形拉直
|
||||
if (IsComplexShape(stroke))
|
||||
return false;
|
||||
|
||||
// 新增:检查是否为明显的曲线
|
||||
if (IsObviousCurve(stroke))
|
||||
return false;
|
||||
|
||||
// 获取用户设置的灵敏度值,确保使用正确的设置
|
||||
double sensitivity = Settings.InkToShape.LineStraightenSensitivity;
|
||||
@@ -726,7 +734,284 @@ namespace Ink_Canvas {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 检查墨迹是否为复杂形状(如一团墨迹、涂鸦等)
|
||||
/// </summary>
|
||||
private bool IsComplexShape(Stroke stroke)
|
||||
{
|
||||
if (stroke.StylusPoints.Count < 10) return false;
|
||||
|
||||
Point start = stroke.StylusPoints.First().ToPoint();
|
||||
Point end = stroke.StylusPoints.Last().ToPoint();
|
||||
double lineLength = GetDistance(start, end);
|
||||
|
||||
// 计算墨迹的实际路径长度
|
||||
double actualLength = 0;
|
||||
for (int i = 1; i < stroke.StylusPoints.Count; i++)
|
||||
{
|
||||
Point p1 = stroke.StylusPoints[i - 1].ToPoint();
|
||||
Point p2 = stroke.StylusPoints[i].ToPoint();
|
||||
actualLength += GetDistance(p1, p2);
|
||||
}
|
||||
|
||||
// 如果实际路径长度远大于直线距离,说明是复杂形状
|
||||
double complexityRatio = actualLength / Math.Max(lineLength, 1);
|
||||
if (complexityRatio > 2.5) // 实际路径是直线距离的2.5倍以上
|
||||
{
|
||||
Debug.WriteLine($"检测到复杂形状:复杂度比率 = {complexityRatio:F2}");
|
||||
return true;
|
||||
}
|
||||
|
||||
// 检查方向变化次数
|
||||
int directionChanges = CountDirectionChanges(stroke);
|
||||
int maxAllowedChanges = Math.Max(3, stroke.StylusPoints.Count / 20); // 动态阈值
|
||||
if (directionChanges > maxAllowedChanges)
|
||||
{
|
||||
Debug.WriteLine($"检测到复杂形状:方向变化次数 = {directionChanges},阈值 = {maxAllowedChanges}");
|
||||
return true;
|
||||
}
|
||||
|
||||
// 检查是否有明显的回环或重叠
|
||||
if (HasSignificantLoops(stroke))
|
||||
{
|
||||
Debug.WriteLine("检测到复杂形状:存在明显回环");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查是否为明显的曲线(如圆弧、抛物线等)
|
||||
/// </summary>
|
||||
private bool IsObviousCurve(Stroke stroke)
|
||||
{
|
||||
if (stroke.StylusPoints.Count < 10) return false;
|
||||
|
||||
Point start = stroke.StylusPoints.First().ToPoint();
|
||||
Point end = stroke.StylusPoints.Last().ToPoint();
|
||||
double lineLength = GetDistance(start, end);
|
||||
|
||||
// 检查曲率一致性
|
||||
if (HasConsistentCurvature(stroke))
|
||||
{
|
||||
Debug.WriteLine("检测到明显曲线:曲率一致");
|
||||
return true;
|
||||
}
|
||||
|
||||
// 检查中点偏移(对圆弧特别有效)
|
||||
int midIndex = stroke.StylusPoints.Count / 2;
|
||||
Point midPoint = stroke.StylusPoints[midIndex].ToPoint();
|
||||
double midDeviation = DistanceFromLineToPoint(start, end, midPoint);
|
||||
|
||||
// 如果中点偏移超过线长的15%,且偏移方向一致,可能是圆弧
|
||||
if (midDeviation > lineLength * 0.15)
|
||||
{
|
||||
// 检查偏移方向的一致性
|
||||
if (IsConsistentArcDirection(stroke))
|
||||
{
|
||||
Debug.WriteLine($"检测到明显曲线:中点偏移 = {midDeviation:F2},线长 = {lineLength:F2}");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算方向变化次数
|
||||
/// </summary>
|
||||
private int CountDirectionChanges(Stroke stroke)
|
||||
{
|
||||
if (stroke.StylusPoints.Count < 3) return 0;
|
||||
|
||||
int changes = 0;
|
||||
double lastAngle = 0;
|
||||
bool hasLastAngle = false;
|
||||
|
||||
for (int i = 1; i < stroke.StylusPoints.Count - 1; i++)
|
||||
{
|
||||
Point p1 = stroke.StylusPoints[i - 1].ToPoint();
|
||||
Point p2 = stroke.StylusPoints[i].ToPoint();
|
||||
Point p3 = stroke.StylusPoints[i + 1].ToPoint();
|
||||
|
||||
// 计算角度变化
|
||||
double angle1 = Math.Atan2(p2.Y - p1.Y, p2.X - p1.X);
|
||||
double angle2 = Math.Atan2(p3.Y - p2.Y, p3.X - p2.X);
|
||||
double angleDiff = Math.Abs(angle2 - angle1);
|
||||
|
||||
// 处理角度跨越问题
|
||||
if (angleDiff > Math.PI) angleDiff = 2 * Math.PI - angleDiff;
|
||||
|
||||
// 如果角度变化超过30度,认为是方向变化
|
||||
if (angleDiff > Math.PI / 6) // 30度
|
||||
{
|
||||
if (hasLastAngle && Math.Abs(angleDiff - lastAngle) > Math.PI / 12) // 15度
|
||||
{
|
||||
changes++;
|
||||
}
|
||||
lastAngle = angleDiff;
|
||||
hasLastAngle = true;
|
||||
}
|
||||
}
|
||||
|
||||
return changes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查是否有明显的回环
|
||||
/// </summary>
|
||||
private bool HasSignificantLoops(Stroke stroke)
|
||||
{
|
||||
if (stroke.StylusPoints.Count < 20) return false;
|
||||
|
||||
// 检查起点和终点是否接近(可能是闭合图形)
|
||||
Point start = stroke.StylusPoints.First().ToPoint();
|
||||
Point end = stroke.StylusPoints.Last().ToPoint();
|
||||
double startEndDistance = GetDistance(start, end);
|
||||
|
||||
// 计算平均点间距
|
||||
double totalDistance = 0;
|
||||
for (int i = 1; i < stroke.StylusPoints.Count; i++)
|
||||
{
|
||||
Point p1 = stroke.StylusPoints[i - 1].ToPoint();
|
||||
Point p2 = stroke.StylusPoints[i].ToPoint();
|
||||
totalDistance += GetDistance(p1, p2);
|
||||
}
|
||||
double avgPointDistance = totalDistance / (stroke.StylusPoints.Count - 1);
|
||||
|
||||
// 如果起点和终点很接近,可能是闭合图形
|
||||
if (startEndDistance < avgPointDistance * 5)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// 检查是否有点重复经过相似区域
|
||||
int overlapCount = 0;
|
||||
double overlapThreshold = avgPointDistance * 3;
|
||||
|
||||
for (int i = 0; i < stroke.StylusPoints.Count - 10; i += 5)
|
||||
{
|
||||
Point p1 = stroke.StylusPoints[i].ToPoint();
|
||||
for (int j = i + 10; j < stroke.StylusPoints.Count; j += 5)
|
||||
{
|
||||
Point p2 = stroke.StylusPoints[j].ToPoint();
|
||||
if (GetDistance(p1, p2) < overlapThreshold)
|
||||
{
|
||||
overlapCount++;
|
||||
if (overlapCount > 3) return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查曲率是否一致(用于识别圆弧等规则曲线)
|
||||
/// </summary>
|
||||
private bool HasConsistentCurvature(Stroke stroke)
|
||||
{
|
||||
if (stroke.StylusPoints.Count < 15) return false;
|
||||
|
||||
List<double> curvatures = new List<double>();
|
||||
|
||||
// 计算每个点的曲率
|
||||
for (int i = 2; i < stroke.StylusPoints.Count - 2; i++)
|
||||
{
|
||||
Point p1 = stroke.StylusPoints[i - 2].ToPoint();
|
||||
Point p2 = stroke.StylusPoints[i].ToPoint();
|
||||
Point p3 = stroke.StylusPoints[i + 2].ToPoint();
|
||||
|
||||
double curvature = CalculateCurvature(p1, p2, p3);
|
||||
if (!double.IsNaN(curvature) && !double.IsInfinity(curvature))
|
||||
{
|
||||
curvatures.Add(Math.Abs(curvature));
|
||||
}
|
||||
}
|
||||
|
||||
if (curvatures.Count < 5) return false;
|
||||
|
||||
// 计算曲率的标准差
|
||||
double avgCurvature = curvatures.Average();
|
||||
double variance = curvatures.Select(c => Math.Pow(c - avgCurvature, 2)).Average();
|
||||
double stdDev = Math.Sqrt(variance);
|
||||
|
||||
// 如果曲率变化很小且平均曲率不为零,可能是规则曲线
|
||||
return avgCurvature > 0.001 && stdDev / avgCurvature < 0.5;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查圆弧方向是否一致
|
||||
/// </summary>
|
||||
private bool IsConsistentArcDirection(Stroke stroke)
|
||||
{
|
||||
if (stroke.StylusPoints.Count < 10) return false;
|
||||
|
||||
Point start = stroke.StylusPoints.First().ToPoint();
|
||||
Point end = stroke.StylusPoints.Last().ToPoint();
|
||||
|
||||
int positiveDeviations = 0;
|
||||
int negativeDeviations = 0;
|
||||
|
||||
// 检查多个点相对于直线的偏移方向
|
||||
for (int i = 1; i < stroke.StylusPoints.Count - 1; i += Math.Max(1, stroke.StylusPoints.Count / 10))
|
||||
{
|
||||
Point p = stroke.StylusPoints[i].ToPoint();
|
||||
double signedDistance = SignedDistanceFromLineToPoint(start, end, p);
|
||||
|
||||
if (Math.Abs(signedDistance) > 5) // 忽略很小的偏移
|
||||
{
|
||||
if (signedDistance > 0) positiveDeviations++;
|
||||
else negativeDeviations++;
|
||||
}
|
||||
}
|
||||
|
||||
// 如果大部分点都在直线的同一侧,说明是一致的弧形
|
||||
int totalSignificantDeviations = positiveDeviations + negativeDeviations;
|
||||
if (totalSignificantDeviations < 3) return false;
|
||||
|
||||
double consistency = Math.Max(positiveDeviations, negativeDeviations) / (double)totalSignificantDeviations;
|
||||
return consistency > 0.8; // 80%的点在同一侧
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算三点的曲率
|
||||
/// </summary>
|
||||
private double CalculateCurvature(Point p1, Point p2, Point p3)
|
||||
{
|
||||
// 使用三点计算曲率的公式
|
||||
double a = GetDistance(p1, p2);
|
||||
double b = GetDistance(p2, p3);
|
||||
double c = GetDistance(p1, p3);
|
||||
|
||||
if (a == 0 || b == 0 || c == 0) return 0;
|
||||
|
||||
// 使用海伦公式计算面积
|
||||
double s = (a + b + c) / 2;
|
||||
double area = Math.Sqrt(s * (s - a) * (s - b) * (s - c));
|
||||
|
||||
// 曲率 = 4 * 面积 / (a * b * c)
|
||||
return 4 * area / (a * b * c);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算点到直线的有符号距离
|
||||
/// </summary>
|
||||
private double SignedDistanceFromLineToPoint(Point lineStart, Point lineEnd, Point point)
|
||||
{
|
||||
// 使用叉积计算有符号距离
|
||||
double dx = lineEnd.X - lineStart.X;
|
||||
double dy = lineEnd.Y - lineStart.Y;
|
||||
double lineLength = Math.Sqrt(dx * dx + dy * dy);
|
||||
|
||||
if (lineLength == 0) return 0;
|
||||
|
||||
return ((lineEnd.Y - lineStart.Y) * point.X - (lineEnd.X - lineStart.X) * point.Y +
|
||||
lineEnd.X * lineStart.Y - lineEnd.Y * lineStart.X) / lineLength;
|
||||
}
|
||||
|
||||
// New method: Determines if a stroke should be straightened into a line
|
||||
private bool ShouldStraightenLine(Stroke stroke) {
|
||||
Point start = stroke.StylusPoints.First().ToPoint();
|
||||
@@ -737,8 +1022,24 @@ namespace Ink_Canvas {
|
||||
double adaptiveThreshold = Settings.Canvas.AutoStraightenLineThreshold * GetResolutionScale();
|
||||
// 如果线条太短,不进行拉直处理,使用自适应阈值
|
||||
if (lineLength < adaptiveThreshold) {
|
||||
// 显示调试信息 - 线条长度不足
|
||||
// MessageBox.Show($"线条太短: {lineLength} < {Settings.Canvas.AutoStraightenLineThreshold}", "调试信息");
|
||||
Debug.WriteLine($"线条太短: {lineLength} < {adaptiveThreshold}");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 新增:再次检查复杂度(双重保险)
|
||||
if (IsComplexShape(stroke))
|
||||
{
|
||||
Debug.WriteLine("拒绝拉直:检测到复杂形状");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 新增:检查线条的直线度评分
|
||||
double straightnessScore = CalculateStraightnessScore(stroke);
|
||||
double minStraightnessThreshold = 0.7; // 最低直线度要求
|
||||
|
||||
if (straightnessScore < minStraightnessThreshold)
|
||||
{
|
||||
Debug.WriteLine($"拒绝拉直:直线度评分过低 {straightnessScore:F3} < {minStraightnessThreshold}");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -976,9 +1277,111 @@ namespace Ink_Canvas {
|
||||
}
|
||||
}
|
||||
|
||||
Debug.WriteLine("接受拉直");
|
||||
Debug.WriteLine($"接受拉直:直线度评分 = {straightnessScore:F3}");
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算墨迹的直线度评分(0-1,1表示完美直线)
|
||||
/// </summary>
|
||||
private double CalculateStraightnessScore(Stroke stroke)
|
||||
{
|
||||
if (stroke.StylusPoints.Count < 3) return 0;
|
||||
|
||||
Point start = stroke.StylusPoints.First().ToPoint();
|
||||
Point end = stroke.StylusPoints.Last().ToPoint();
|
||||
double lineLength = GetDistance(start, end);
|
||||
|
||||
if (lineLength == 0) return 0;
|
||||
|
||||
// 1. 计算偏差评分(基于点到直线的距离)
|
||||
double totalDeviation = 0;
|
||||
double maxDeviation = 0;
|
||||
int pointCount = 0;
|
||||
|
||||
foreach (StylusPoint sp in stroke.StylusPoints)
|
||||
{
|
||||
Point p = sp.ToPoint();
|
||||
double deviation = DistanceFromLineToPoint(start, end, p);
|
||||
totalDeviation += deviation;
|
||||
maxDeviation = Math.Max(maxDeviation, deviation);
|
||||
pointCount++;
|
||||
}
|
||||
|
||||
double avgDeviation = totalDeviation / pointCount;
|
||||
|
||||
// 偏差评分:基于平均偏差和最大偏差
|
||||
double deviationScore = Math.Max(0, 1 - (avgDeviation / (lineLength * 0.05)) - (maxDeviation / (lineLength * 0.1)));
|
||||
|
||||
// 2. 计算方向一致性评分
|
||||
double directionScore = CalculateDirectionConsistency(stroke);
|
||||
|
||||
// 3. 计算路径效率评分(实际路径长度 vs 直线距离)
|
||||
double actualLength = 0;
|
||||
for (int i = 1; i < stroke.StylusPoints.Count; i++)
|
||||
{
|
||||
Point p1 = stroke.StylusPoints[i - 1].ToPoint();
|
||||
Point p2 = stroke.StylusPoints[i].ToPoint();
|
||||
actualLength += GetDistance(p1, p2);
|
||||
}
|
||||
double efficiencyScore = Math.Max(0, Math.Min(1, lineLength / actualLength));
|
||||
|
||||
// 4. 计算端点连接度评分(起点到终点的直接性)
|
||||
double endpointScore = 1.0; // 默认满分,因为我们已经有了起点和终点
|
||||
|
||||
// 综合评分(加权平均)
|
||||
double finalScore = (deviationScore * 0.4 + directionScore * 0.3 + efficiencyScore * 0.2 + endpointScore * 0.1);
|
||||
|
||||
Debug.WriteLine($"直线度评分详情: 偏差={deviationScore:F3}, 方向={directionScore:F3}, 效率={efficiencyScore:F3}, 综合={finalScore:F3}");
|
||||
|
||||
return Math.Max(0, Math.Min(1, finalScore));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算方向一致性评分
|
||||
/// </summary>
|
||||
private double CalculateDirectionConsistency(Stroke stroke)
|
||||
{
|
||||
if (stroke.StylusPoints.Count < 5) return 1.0;
|
||||
|
||||
Point start = stroke.StylusPoints.First().ToPoint();
|
||||
Point end = stroke.StylusPoints.Last().ToPoint();
|
||||
|
||||
// 目标方向
|
||||
double targetAngle = Math.Atan2(end.Y - start.Y, end.X - start.X);
|
||||
|
||||
double totalAngleDifference = 0;
|
||||
int segmentCount = 0;
|
||||
|
||||
// 计算每个线段与目标方向的角度差
|
||||
for (int i = 1; i < stroke.StylusPoints.Count; i++)
|
||||
{
|
||||
Point p1 = stroke.StylusPoints[i - 1].ToPoint();
|
||||
Point p2 = stroke.StylusPoints[i].ToPoint();
|
||||
|
||||
double segmentLength = GetDistance(p1, p2);
|
||||
if (segmentLength < 2) continue; // 忽略太短的线段
|
||||
|
||||
double segmentAngle = Math.Atan2(p2.Y - p1.Y, p2.X - p1.X);
|
||||
double angleDiff = Math.Abs(segmentAngle - targetAngle);
|
||||
|
||||
// 处理角度跨越问题
|
||||
if (angleDiff > Math.PI) angleDiff = 2 * Math.PI - angleDiff;
|
||||
|
||||
totalAngleDifference += angleDiff;
|
||||
segmentCount++;
|
||||
}
|
||||
|
||||
if (segmentCount == 0) return 1.0;
|
||||
|
||||
double avgAngleDifference = totalAngleDifference / segmentCount;
|
||||
|
||||
// 将角度差转换为评分(0-1)
|
||||
// 0度差 = 1分,90度差 = 0分
|
||||
double directionScore = Math.Max(0, 1 - (avgAngleDifference / (Math.PI / 2)));
|
||||
|
||||
return directionScore;
|
||||
}
|
||||
|
||||
// New method: Creates a straight line stroke between two points
|
||||
private StylusPointCollection CreateStraightLine(Point start, Point end) {
|
||||
|
||||
@@ -139,8 +139,28 @@ namespace Ink_Canvas {
|
||||
targetCanvas.Children.Remove(item.InsertedElement);
|
||||
} else {
|
||||
// Redo: 添加元素
|
||||
if (item.InsertedElement != null && !targetCanvas.Children.Contains(item.InsertedElement))
|
||||
if (item.InsertedElement != null && !targetCanvas.Children.Contains(item.InsertedElement)) {
|
||||
targetCanvas.Children.Add(item.InsertedElement);
|
||||
|
||||
// 重新绑定事件处理器(仅对主画布)
|
||||
if (targetCanvas == inkCanvas) {
|
||||
if (item.InsertedElement is Image img) {
|
||||
img.MouseDown -= UIElement_MouseDown;
|
||||
img.MouseDown += UIElement_MouseDown;
|
||||
img.IsManipulationEnabled = true;
|
||||
|
||||
// 重新应用CenterAndScaleElement变换
|
||||
CenterAndScaleElement(img);
|
||||
} else if (item.InsertedElement is MediaElement media) {
|
||||
media.MouseDown -= UIElement_MouseDown;
|
||||
media.MouseDown += UIElement_MouseDown;
|
||||
media.IsManipulationEnabled = true;
|
||||
|
||||
// 重新应用CenterAndScaleElement变换
|
||||
CenterAndScaleElement(media);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -88,8 +88,9 @@ namespace Ink_Canvas {
|
||||
}
|
||||
|
||||
private void InitTimers() {
|
||||
timerCheckPPT.Elapsed += TimerCheckPPT_Elapsed;
|
||||
timerCheckPPT.Interval = 500;
|
||||
// PPT检查现在由PPTManager处理,不再需要定时器
|
||||
// timerCheckPPT.Elapsed += TimerCheckPPT_Elapsed;
|
||||
// timerCheckPPT.Interval = 500;
|
||||
timerKillProcess.Elapsed += TimerKillProcess_Elapsed;
|
||||
timerKillProcess.Interval = 2000;
|
||||
timerCheckAutoFold.Elapsed += timerCheckAutoFold_Elapsed;
|
||||
|
||||
@@ -62,21 +62,20 @@ namespace Ink_Canvas
|
||||
var mainWin = (MainWindow)Current.MainWindow;
|
||||
if (mainWin.IsLoaded) {
|
||||
IsAppExitByUser = true;
|
||||
|
||||
|
||||
try {
|
||||
// 启动新实例,添加 -m 参数允许多实例启动
|
||||
// 启动新实例
|
||||
string exePath = Process.GetCurrentProcess().MainModule.FileName;
|
||||
ProcessStartInfo startInfo = new ProcessStartInfo();
|
||||
startInfo.FileName = exePath;
|
||||
startInfo.Arguments = "-m";
|
||||
startInfo.UseShellExecute = true;
|
||||
|
||||
|
||||
// 启动进程但不等待
|
||||
Process.Start(startInfo);
|
||||
} catch (Exception ex) {
|
||||
LogHelper.NewLog($"重启程序时出错: {ex.Message}");
|
||||
}
|
||||
|
||||
|
||||
// 退出当前实例
|
||||
Current.Shutdown();
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ using System.Windows;
|
||||
[assembly: AssemblyTitle("InkCanvasForClass")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("HARKOTEK Studio")]
|
||||
[assembly: AssemblyCompany("CJK_mkp")]
|
||||
[assembly: AssemblyProduct("InkCanvasForClass")]
|
||||
[assembly: AssemblyCopyright("© Copyright HARKOTEK Studio 2024-now")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
@@ -49,5 +49,5 @@ using System.Windows;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.7.5.0")]
|
||||
[assembly: AssemblyFileVersion("1.7.5.0")]
|
||||
[assembly: AssemblyVersion("1.7.6.0")]
|
||||
[assembly: AssemblyFileVersion("1.7.6.0")]
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace Ink_Canvas
|
||||
[JsonProperty("useHardwareAcceleration")]
|
||||
public bool UseHardwareAcceleration { get; set; } = true; // 默认启用硬件加速
|
||||
[JsonProperty("inkSmoothingQuality")]
|
||||
public int InkSmoothingQuality { get; set; } = 1; // 0-低质量高性能, 1-平衡, 2-高质量低性能
|
||||
public int InkSmoothingQuality { get; set; } = 2; // 0-低质量高性能, 1-平衡, 2-高质量低性能,默认为高质量
|
||||
[JsonProperty("maxConcurrentSmoothingTasks")]
|
||||
public int MaxConcurrentSmoothingTasks { get; set; } // 0表示自动检测CPU核心数
|
||||
[JsonProperty("clearCanvasAndClearTimeMachine")]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
|
||||
<assemblyIdentity version="1.0.0.0" name="InkCanvasForClass CE.app"/>
|
||||
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
|
||||
<security>
|
||||
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user