Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4c70f35714 | |||
| 7b4d13c16f | |||
| 0e561ad24e | |||
| d09d8223c9 | |||
| 6dafde9735 |
@@ -1 +1 @@
|
||||
1.6.2
|
||||
1.6.3
|
||||
@@ -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.6.2.0")]
|
||||
[assembly: AssemblyFileVersion("1.6.2.0")]
|
||||
[assembly: AssemblyVersion("1.6.3.0")]
|
||||
[assembly: AssemblyFileVersion("1.6.3.0")]
|
||||
|
||||
@@ -8,6 +8,7 @@ using System.Windows;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Windows.Controls;
|
||||
using System.IO.Compression;
|
||||
|
||||
namespace Ink_Canvas.Helpers
|
||||
{
|
||||
@@ -19,7 +20,7 @@ namespace Ink_Canvas.Helpers
|
||||
{
|
||||
string localVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
||||
string remoteAddress = proxy;
|
||||
remoteAddress += "https://github.com/CJKmkp/ICC-CE/blob/main/AutomaticUpdateVersionControl.txt";
|
||||
remoteAddress += "https://github.com/awesome-iwb/icc-ce/blob/main/AutomaticUpdateVersionControl.txt";
|
||||
string remoteVersion = await GetRemoteVersion(remoteAddress);
|
||||
|
||||
if (remoteVersion != null)
|
||||
@@ -85,10 +86,11 @@ namespace Ink_Canvas.Helpers
|
||||
return true;
|
||||
}
|
||||
|
||||
string downloadUrl = $"{proxy}https://github.com/ChangSakura/Ink-Canvas/releases/download/v{version}/Ink.Canvas.Annotation.V{version}.Setup.exe";
|
||||
string downloadUrl = $"{proxy}https://github.com/awesome-iwb/icc-ce/releases/download/{version}/InkCanvasForClass.CE.{version}.zip";
|
||||
|
||||
SaveDownloadStatus(false);
|
||||
await DownloadFile(downloadUrl, $"{updatesFolderPath}\\Ink.Canvas.Annotation.V{version}.Setup.exe");
|
||||
string zipFilePath = Path.Combine(updatesFolderPath, $"InkCanvasForClass.CE.{version}.zip");
|
||||
await DownloadFile(downloadUrl, zipFilePath);
|
||||
SaveDownloadStatus(true);
|
||||
|
||||
LogHelper.WriteLogToFile("AutoUpdate | Setup file successfully downloaded.");
|
||||
@@ -96,7 +98,7 @@ namespace Ink_Canvas.Helpers
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"AutoUpdate | Error downloading and installing update: {ex.Message}", LogHelper.LogType.Error);
|
||||
LogHelper.WriteLogToFile($"AutoUpdate | Error downloading update: {ex.Message}", LogHelper.LogType.Error);
|
||||
|
||||
SaveDownloadStatus(false);
|
||||
return false;
|
||||
@@ -155,21 +157,43 @@ namespace Ink_Canvas.Helpers
|
||||
{
|
||||
try
|
||||
{
|
||||
string setupFilePath = Path.Combine(updatesFolderPath, $"Ink.Canvas.Annotation.V{version}.Setup.exe");
|
||||
string zipFilePath = Path.Combine(updatesFolderPath, $"InkCanvasForClass.CE.{version}.zip");
|
||||
|
||||
if (!File.Exists(setupFilePath))
|
||||
if (!File.Exists(zipFilePath))
|
||||
{
|
||||
LogHelper.WriteLogToFile($"AutoUpdate | Setup file not found: {setupFilePath}", LogHelper.LogType.Error);
|
||||
LogHelper.WriteLogToFile($"AutoUpdate | ZIP file not found: {zipFilePath}", LogHelper.LogType.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
string InstallCommand = $"\"{setupFilePath}\" /SILENT";
|
||||
if (isInSilence) InstallCommand += " /VERYSILENT";
|
||||
ExecuteCommandLine(InstallCommand);
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
// 创建临时解压目录
|
||||
string extractPath = Path.Combine(updatesFolderPath, $"Extract_{version}");
|
||||
if (Directory.Exists(extractPath))
|
||||
{
|
||||
Application.Current.Shutdown();
|
||||
});
|
||||
Directory.Delete(extractPath, true);
|
||||
}
|
||||
Directory.CreateDirectory(extractPath);
|
||||
|
||||
// 解压ZIP文件
|
||||
LogHelper.WriteLogToFile($"AutoUpdate | Extracting ZIP file to: {extractPath}");
|
||||
ZipFile.ExtractToDirectory(zipFilePath, extractPath);
|
||||
|
||||
// 获取当前应用程序路径
|
||||
string currentAppDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||
LogHelper.WriteLogToFile($"AutoUpdate | Current application directory: {currentAppDir}");
|
||||
|
||||
// 复制解压的文件到应用程序目录
|
||||
LogHelper.WriteLogToFile($"AutoUpdate | Copying files to application directory");
|
||||
CopyDirectory(extractPath, currentAppDir);
|
||||
|
||||
// 清理临时文件
|
||||
if (Directory.Exists(extractPath))
|
||||
{
|
||||
Directory.Delete(extractPath, true);
|
||||
}
|
||||
|
||||
// 重启应用程序
|
||||
LogHelper.WriteLogToFile($"AutoUpdate | Update completed, restarting application");
|
||||
RestartApplication();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -177,6 +201,49 @@ namespace Ink_Canvas.Helpers
|
||||
}
|
||||
}
|
||||
|
||||
private static void CopyDirectory(string sourceDir, string destinationDir)
|
||||
{
|
||||
// 创建目标目录(如果不存在)
|
||||
Directory.CreateDirectory(destinationDir);
|
||||
|
||||
// 复制所有文件
|
||||
foreach (string filePath in Directory.GetFiles(sourceDir))
|
||||
{
|
||||
string fileName = Path.GetFileName(filePath);
|
||||
string destPath = Path.Combine(destinationDir, fileName);
|
||||
try
|
||||
{
|
||||
// 如果目标文件存在,先删除
|
||||
if (File.Exists(destPath))
|
||||
{
|
||||
File.Delete(destPath);
|
||||
}
|
||||
File.Copy(filePath, destPath);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"AutoUpdate | Error copying file {fileName}: {ex.Message}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
// 递归复制所有子目录
|
||||
foreach (string subDirPath in Directory.GetDirectories(sourceDir))
|
||||
{
|
||||
string subDirName = Path.GetFileName(subDirPath);
|
||||
string destSubDir = Path.Combine(destinationDir, subDirName);
|
||||
CopyDirectory(subDirPath, destSubDir);
|
||||
}
|
||||
}
|
||||
|
||||
private static void RestartApplication()
|
||||
{
|
||||
string appPath = Assembly.GetExecutingAssembly().Location;
|
||||
Process.Start(appPath);
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
Application.Current.Shutdown();
|
||||
});
|
||||
}
|
||||
|
||||
private static void ExecuteCommandLine(string command)
|
||||
{
|
||||
|
||||
@@ -940,7 +940,17 @@
|
||||
<TextBlock Foreground="#fafafa" Text="{Binding ElementName=AutoStraightenLineThresholdSlider, Path=Value, StringFormat={}{0:0}}"
|
||||
VerticalAlignment="Center" FontSize="14" Margin="16,0,0,0" />
|
||||
</ui:SimpleStackPanel>
|
||||
<TextBlock Text="# 开启后,当绘制的直线超过设定长度阈值时,将自动调整为完美直线。" TextWrapping="Wrap" Foreground="#a1a1aa" />
|
||||
<ui:SimpleStackPanel Orientation="Horizontal" HorizontalAlignment="Left"
|
||||
Visibility="{Binding ElementName=ToggleSwitchAutoStraightenLine, Path=IsOn, Converter={StaticResource BooleanToVisibilityConverter}}">
|
||||
<TextBlock Foreground="#fafafa" Text="灵敏度" VerticalAlignment="Center"
|
||||
FontSize="14" Margin="0,0,16,0" />
|
||||
<Slider Name="LineStraightenSensitivitySlider" Width="150" Minimum="0.05" Maximum="0.75"
|
||||
Value="0.10" TickFrequency="0.05" IsSnapToTickEnabled="True"
|
||||
ValueChanged="LineStraightenSensitivitySlider_ValueChanged" />
|
||||
<TextBlock Foreground="#fafafa" Text="{Binding ElementName=LineStraightenSensitivitySlider, Path=Value, StringFormat={}{0:F2}}"
|
||||
VerticalAlignment="Center" FontSize="14" Margin="16,0,0,0" />
|
||||
</ui:SimpleStackPanel>
|
||||
<TextBlock Text="# 开启后,当绘制的直线超过设定长度阈值时,将自动调整为完美直线。灵敏度范围0.05-0.75,越小要求越严格,弯曲的线条越不容易被拉直;值越大越容易识别为直线。" TextWrapping="Wrap" Foreground="#a1a1aa" />
|
||||
<Line HorizontalAlignment="Center" X1="0" Y1="0" X2="400" Y2="0"
|
||||
Stroke="#3f3f46" StrokeThickness="1" Margin="0,4,0,4" />
|
||||
<ui:SimpleStackPanel Orientation="Horizontal" HorizontalAlignment="Left">
|
||||
|
||||
@@ -391,6 +391,13 @@ namespace Ink_Canvas {
|
||||
{
|
||||
// 使用辅助方法设置光标
|
||||
SetCursorBasedOnEditingMode(inkCanvas);
|
||||
|
||||
// 确保光标可见
|
||||
if (Settings.Canvas.IsShowCursor) {
|
||||
inkCanvas.ForceCursor = true;
|
||||
inkCanvas.UseCustomCursor = true;
|
||||
System.Windows.Forms.Cursor.Show();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Definations and Loading
|
||||
|
||||
@@ -750,6 +750,13 @@ namespace Ink_Canvas {
|
||||
SaveSettingsToFile();
|
||||
}
|
||||
|
||||
private void LineStraightenSensitivitySlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) {
|
||||
if (!isLoaded) return;
|
||||
|
||||
Settings.InkToShape.LineStraightenSensitivity = e.NewValue;
|
||||
SaveSettingsToFile();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Canvas
|
||||
|
||||
@@ -578,6 +578,9 @@ namespace Ink_Canvas {
|
||||
ToggleCheckboxEnableInkToShapeRectangle.IsChecked = Settings.InkToShape.IsInkToShapeRectangle;
|
||||
|
||||
ToggleCheckboxEnableInkToShapeRounded.IsChecked = Settings.InkToShape.IsInkToShapeRounded;
|
||||
|
||||
// 初始化直线拉直灵敏度
|
||||
LineStraightenSensitivitySlider.Value = Settings.InkToShape.LineStraightenSensitivity;
|
||||
} else {
|
||||
Settings.InkToShape = new InkToShape();
|
||||
}
|
||||
|
||||
@@ -452,6 +452,7 @@ namespace Ink_Canvas {
|
||||
// 触摸移动时保持自定义光标显示
|
||||
if (Settings.Canvas.IsShowCursor) {
|
||||
inkCanvas.ForceCursor = true;
|
||||
inkCanvas.UseCustomCursor = true; // 确保使用自定义光标
|
||||
System.Windows.Forms.Cursor.Show();
|
||||
}
|
||||
|
||||
@@ -484,6 +485,12 @@ namespace Ink_Canvas {
|
||||
inkCanvas.EraserShape = new EllipseStylusShape(boundsWidth * k * eraserMultiplier,
|
||||
boundsWidth * k * eraserMultiplier);
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.EraseByPoint;
|
||||
|
||||
// 立即应用光标设置
|
||||
if (Settings.Canvas.IsShowCursor) {
|
||||
inkCanvas.Cursor = Cursors.Cross;
|
||||
System.Windows.Forms.Cursor.Show();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (StackPanelPPTControls.Visibility == Visibility.Visible && inkCanvas.Strokes.Count == 0 &&
|
||||
@@ -1669,9 +1676,24 @@ namespace Ink_Canvas {
|
||||
|
||||
private void MainWindow_OnMouseMove(object sender, MouseEventArgs e) {
|
||||
if (e.StylusDevice == null) {
|
||||
// 鼠标移动时保持光标可见
|
||||
System.Windows.Forms.Cursor.Show();
|
||||
|
||||
// 如果用户设置了显示光标,则确保光标显示正确
|
||||
if (Settings.Canvas.IsShowCursor && inkCanvas != null) {
|
||||
inkCanvas.ForceCursor = true;
|
||||
inkCanvas.UseCustomCursor = true;
|
||||
}
|
||||
} else {
|
||||
System.Windows.Forms.Cursor.Hide();
|
||||
// 只有当用户未设置显示光标时才隐藏
|
||||
if (!Settings.Canvas.IsShowCursor) {
|
||||
System.Windows.Forms.Cursor.Hide();
|
||||
} else if (inkCanvas != null) {
|
||||
// 如果用户设置了显示光标,则确保光标显示正确
|
||||
inkCanvas.ForceCursor = true;
|
||||
inkCanvas.UseCustomCursor = true;
|
||||
System.Windows.Forms.Cursor.Show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Ink_Canvas {
|
||||
private StrokeCollection newStrokes = new StrokeCollection();
|
||||
private List<Circle> circles = new List<Circle>();
|
||||
private const double SNAP_THRESHOLD = 15.0; // Distance threshold for endpoint snapping
|
||||
private const double LINE_STRAIGHTEN_THRESHOLD = 0.15; // Threshold for line straightening
|
||||
private const double LINE_STRAIGHTEN_THRESHOLD = 0.10; // 降低阈值,让直线检测更严格
|
||||
|
||||
private void inkCanvas_StrokeCollected(object sender, InkCanvasStrokeCollectedEventArgs e) {
|
||||
if (Settings.Canvas.FitToCurve == true) drawingAttributes.FitToCurve = false;
|
||||
@@ -566,7 +566,7 @@ namespace Ink_Canvas {
|
||||
|
||||
// New method: Checks if a stroke is potentially a straight line
|
||||
private bool IsPotentialStraightLine(Stroke stroke) {
|
||||
// Minimum length for line detection
|
||||
// 确保有足够的点来进行线条分析
|
||||
if (stroke.StylusPoints.Count < 5)
|
||||
return false;
|
||||
|
||||
@@ -574,8 +574,40 @@ namespace Ink_Canvas {
|
||||
Point end = stroke.StylusPoints.Last().ToPoint();
|
||||
double lineLength = GetDistance(start, end);
|
||||
|
||||
// Line should be longer than 30 pixels
|
||||
return lineLength > 30;
|
||||
// 线条必须足够长才考虑拉直,至少30像素
|
||||
if (lineLength < 30)
|
||||
return false;
|
||||
|
||||
// 获取用户设置的灵敏度值
|
||||
double sensitivity = Settings.InkToShape.LineStraightenSensitivity;
|
||||
// 快速检查使用略宽松的阈值
|
||||
double quickThreshold = Math.Min(sensitivity * 1.5, 0.20);
|
||||
|
||||
// 快速检查:计算几个关键点与直线的距离
|
||||
if (stroke.StylusPoints.Count >= 10) {
|
||||
// 取中点和1/4、3/4位置的点,快速检查偏差
|
||||
int quarterIdx = stroke.StylusPoints.Count / 4;
|
||||
int midIdx = stroke.StylusPoints.Count / 2;
|
||||
int threeQuarterIdx = quarterIdx * 3;
|
||||
|
||||
Point quarterPoint = stroke.StylusPoints[quarterIdx].ToPoint();
|
||||
Point midPoint = stroke.StylusPoints[midIdx].ToPoint();
|
||||
Point threeQuarterPoint = stroke.StylusPoints[threeQuarterIdx].ToPoint();
|
||||
|
||||
double quarterDeviation = DistanceFromLineToPoint(start, end, quarterPoint);
|
||||
double midDeviation = DistanceFromLineToPoint(start, end, midPoint);
|
||||
double threeQuarterDeviation = DistanceFromLineToPoint(start, end, threeQuarterPoint);
|
||||
|
||||
// 如果任一点偏离太大,直接排除
|
||||
double quickRelativeThreshold = lineLength * quickThreshold;
|
||||
if (quarterDeviation > quickRelativeThreshold ||
|
||||
midDeviation > quickRelativeThreshold ||
|
||||
threeQuarterDeviation > quickRelativeThreshold) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// New method: Determines if a stroke should be straightened into a line
|
||||
@@ -588,15 +620,62 @@ namespace Ink_Canvas {
|
||||
double maxDeviation = 0;
|
||||
double lineLength = GetDistance(start, end);
|
||||
|
||||
// 如果线条太短,不进行拉直处理
|
||||
if (lineLength < 50) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 获取用户设置的灵敏度值
|
||||
double sensitivity = Settings.InkToShape.LineStraightenSensitivity;
|
||||
|
||||
// 计算点与直线的偏差
|
||||
double totalDeviation = 0;
|
||||
int pointCount = 0;
|
||||
|
||||
// Calculate deviation for each point
|
||||
foreach (StylusPoint sp in stroke.StylusPoints) {
|
||||
Point p = sp.ToPoint();
|
||||
double deviation = DistanceFromLineToPoint(start, end, p);
|
||||
maxDeviation = Math.Max(maxDeviation, deviation);
|
||||
totalDeviation += deviation;
|
||||
pointCount++;
|
||||
}
|
||||
|
||||
// If maximum deviation is less than threshold relative to line length
|
||||
return (maxDeviation / lineLength) < LINE_STRAIGHTEN_THRESHOLD;
|
||||
// 计算平均偏差
|
||||
double avgDeviation = totalDeviation / pointCount;
|
||||
|
||||
// 检查点分布的一致性 - 如果有些点偏离很大而其他点很接近直线,表明线条有明显弯曲
|
||||
double deviationVariance = 0;
|
||||
foreach (StylusPoint sp in stroke.StylusPoints) {
|
||||
Point p = sp.ToPoint();
|
||||
double deviation = DistanceFromLineToPoint(start, end, p);
|
||||
deviationVariance += Math.Pow(deviation - avgDeviation, 2);
|
||||
}
|
||||
deviationVariance /= pointCount;
|
||||
|
||||
// 如果最大偏差超过线长的阈值比例,或者偏差方差较大(表示不均匀弯曲),则不拉直
|
||||
if ((maxDeviation / lineLength) > sensitivity) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 如果偏差方差大,说明线条弯曲不均匀
|
||||
if (deviationVariance > (sensitivity * lineLength * 0.05)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查中点偏离情况 - 针对弧形线条特别有效
|
||||
if (stroke.StylusPoints.Count > 10) {
|
||||
int midIndex = stroke.StylusPoints.Count / 2;
|
||||
Point midPoint = stroke.StylusPoints[midIndex].ToPoint();
|
||||
double midDeviation = DistanceFromLineToPoint(start, end, midPoint);
|
||||
|
||||
// 如果中点偏离过大,不拉直
|
||||
if (midDeviation > (lineLength * sensitivity * 0.8)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// New method: Creates a straight line stroke between two points
|
||||
|
||||
@@ -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("5.0.5.1")]
|
||||
[assembly: AssemblyFileVersion("5.0.5.1")]
|
||||
[assembly: AssemblyVersion("1.6.3.0")]
|
||||
[assembly: AssemblyFileVersion("1.6.3.0")]
|
||||
@@ -409,6 +409,8 @@ namespace Ink_Canvas
|
||||
public bool IsInkToShapeRectangle { get; set; } = true;
|
||||
[JsonProperty("isInkToShapeRounded")]
|
||||
public bool IsInkToShapeRounded { get; set; } = true;
|
||||
[JsonProperty("lineStraightenSensitivity")]
|
||||
public double LineStraightenSensitivity { get; set; } = 0.10; // 直线检测灵敏度,值越小越严格(0.05-0.75)
|
||||
}
|
||||
|
||||
public class RandSettings {
|
||||
|
||||
Binary file not shown.
+1686
-1669
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user