diff --git a/IWingRecorder/IWingEngine.cs b/IWingRecorder/IWingEngine.cs index 9517326..dc67326 100644 --- a/IWingRecorder/IWingEngine.cs +++ b/IWingRecorder/IWingEngine.cs @@ -496,8 +496,9 @@ namespace IWingRecorder /// /// 开始录制 /// + /// 录制文件 /// - bool StartRecording(); + bool StartRecording(string filename); /// /// 结束录制 diff --git a/IWingRecorder/Utilities.cs b/IWingRecorder/Utilities.cs index 5e546bc..5cbc239 100644 --- a/IWingRecorder/Utilities.cs +++ b/IWingRecorder/Utilities.cs @@ -1,9 +1,14 @@ -using System.Text; +using System.ComponentModel; +using System.Text; using System.Windows; using System.Windows.Media; namespace IWingRecorder { + /// + /// 羽云录屏插件系统 SDK ,提供宿主与插件通信的编码基础, + /// 并提供简单的函数封装方便插件开发 + /// public partial class Utilities { /// @@ -12,20 +17,38 @@ namespace IWingRecorder /// public const string PluginVersion = "V1B"; + /// + /// 对于 WPF 字体样式枚举 + /// public enum TextDecorationType { + /// + /// 无效果 + /// None, + /// + /// 下划线 + /// Underline, + /// + /// 基线 + /// Baseline, + /// + /// 删除线 + /// Strikethrough, + /// + /// 上划线 + /// OverLine } /// - /// 获取文本效果类型 + /// 通过 WPF 文字样式获取 TextDecorationType 文本效果类型枚举 /// - /// - /// + /// TextDecoration 对象 + /// 返回 TextDecorationType 枚举 public static TextDecorationType TypeOfTextDecorationItem(TextDecoration decoration) { if (decoration == TextDecorations.Underline[0]) @@ -47,6 +70,73 @@ namespace IWingRecorder return TextDecorationType.None; } + /// + /// 判断 TextDecorationCollection 对象是否包含 TextDecorationType 字体样式枚举 + /// + /// TextDecorationCollection 对象 + /// TextDecorationType 字体样式枚举 + /// 如果包含返回 true + public static bool TextDecorationTypeContains(TextDecorationCollection decorations, TextDecorationType type) + { + switch (type) + { + case TextDecorationType.None: + return true; + case TextDecorationType.Underline: + return decorations.Contains(TextDecorations.Underline[0]); + case TextDecorationType.Baseline: + return decorations.Contains(TextDecorations.Baseline[0]); + case TextDecorationType.Strikethrough: + return decorations.Contains(TextDecorations.Strikethrough[0]); + case TextDecorationType.OverLine: + return decorations.Contains(TextDecorations.OverLine[0]); + default: + return false; + } + } + + /// + /// 获取包含最大路径的 StringBuilder 对象 + /// + /// + public static StringBuilder Get_MAX_PATH_BufferStringBuilder() + => new StringBuilder(260); + + /// + /// 将 WPF 的 Color 对象转化为 ARGB 十六进制数字 + /// + /// WPF 的 Color 对象 + /// ARGB 十六进制数字 + public static uint ColorToRGBHex(Color color) + { + return (uint)(color.A << 24 | color.R << 16 | color.G << 8 | color.B); + } + + /// + /// 忽略大小写比较字符串 + /// + /// 字符串 1 + /// 字符串 2 + /// 如果忽略大小写字符串相等返回 true + public static bool StringCompareIgnoreCase(string str1, string str2) + { + return string.Compare(str1, str2, true) == 0; + } + + /// + /// 调用 PropertyChanged 事件函数,通知数据更改 + /// + /// 数据更改事件处理事件 + /// 触发者 + /// 属性名 + public static void OnPropertyChanged(PropertyChangedEventHandler propertyChanged, object sender, string propertyName) + { + propertyChanged?.Invoke(sender, new PropertyChangedEventArgs(propertyName)); + } + + /// + /// 羽云录屏封装的 WPF 字体对象 + /// public class WingFont { public FontFamily FontFamily { get; set; } @@ -69,6 +159,43 @@ namespace IWingRecorder } return $"{FontFamily} | {FontWeight} | {FontStyle} | {sb}"; } + + /// + /// 将 WingFont 字体转为 C++ 使用的 LOGFONT + /// 注意此转换将会损失一些 WPF 字体特性 + /// + /// LOGFONT结构体 + public object ToLogFont() + { + var fontstyle = FontStyle; + System.Drawing.FontStyle fontStyle = System.Drawing.FontStyle.Regular; + if (fontstyle == FontStyles.Oblique || fontstyle== FontStyles.Italic) + fontStyle |= System.Drawing.FontStyle.Italic; + + var textd = TextDecorations; + if (textd != null) + { + if(TextDecorationTypeContains(textd, TextDecorationType.Underline)|| + TextDecorationTypeContains(textd, TextDecorationType.Baseline)) + fontStyle|= System.Drawing.FontStyle.Underline; + if(TextDecorationTypeContains(textd, TextDecorationType.Strikethrough)) + fontStyle |= System.Drawing.FontStyle.Strikeout; + } + + var fontweight = FontWeight; + if (fontweight != null) + { + if (fontweight == FontWeights.Bold || fontweight == FontWeights.SemiBold || + fontweight == FontWeights.DemiBold || fontweight == FontWeights.UltraBold || + fontweight == FontWeights.ExtraBold) + fontStyle |= System.Drawing.FontStyle.Bold; + } + + System.Drawing.Font font = new System.Drawing.Font(FontFamily.Source, (float)FontSize,fontStyle); + object logFont = new object(); + font.ToLogFont(logFont); + return logFont; + } } } } diff --git a/TestAddin/VitualEngine.cs b/TestAddin/VitualEngine.cs index 4a7f731..67c96b0 100644 --- a/TestAddin/VitualEngine.cs +++ b/TestAddin/VitualEngine.cs @@ -226,8 +226,9 @@ namespace TestAddin return true; } - public bool StartRecording() + public bool StartRecording(string filename) { + FormTest.WriteLine($"+ StartRecording : {filename}"); timer.Start(); recordingState = RecordingState.Recording; return true; @@ -305,7 +306,7 @@ namespace TestAddin if (format == null) return false; foreach (var item in SupportRecordingFormats) { - if (string.Compare(item.Name, format, true) == 0) + if (Utilities.StringCompareIgnoreCase(item.Name, format)) { currentRecordingFormat = format; OnPropertyChanged(nameof(CurrentRecordingFormat)); @@ -336,7 +337,7 @@ namespace TestAddin if (format == null) return false; foreach (var item in SupportScreenShotFormat) { - if (string.Compare(item, format, true) == 0) + if (Utilities.StringCompareIgnoreCase(item, format)) { currentScreenShotFormat = format; OnPropertyChanged(nameof(CurrentScreenShotFormat)); diff --git a/WingRecorder/Window/MainWindow.xaml.cs b/WingRecorder/Window/MainWindow.xaml.cs index 8b4ea2d..7460ffa 100644 --- a/WingRecorder/Window/MainWindow.xaml.cs +++ b/WingRecorder/Window/MainWindow.xaml.cs @@ -166,7 +166,7 @@ namespace WingRecorder { new CountDownWindow().ShowDialog(); } - if (engine.StartRecording()) + if (engine.StartRecording(Utilities.GetRandomFileName(Utilities.RandomFileType.Video, engine.CurrentRecordingFormat))) { config.Locked = true; lblStartRecord.Text = PauseTitle;