using ComPDFKitViewer; using ComPDFKitViewer.AnnotEvent; using PDF_Master.CustomControl.CompositeControl; using PDF_Master.Model; using PDF_Master.Model.AnnotPanel; using PDF_Master.Model.PropertyPanel.AnnotPanel; using PDF_Master.Properties; using PDF_Master.ViewModels.Tools; using PDF_Master.ViewModels.Tools.AnnotManager; using PDFSettings; using Prism.Commands; using Prism.Mvvm; using Prism.Regions; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Media; using static Dropbox.Api.UsersCommon.AccountType; namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel { public class FreetextAnnotPropertyViewModel : BindableBase, INavigationAware { #region 文案 private string T_title; public string T_Title { get { return T_title; } set { SetProperty(ref T_title, value); } } private string T_font; public string T_Font { get { return T_font; } set { SetProperty(ref T_font, value); } } private string T_fill; public string T_Fill { get { return T_fill; } set { SetProperty(ref T_fill, value); } } private void InitString() { T_Title = App.MainPageLoader.GetString("FreeText_Title"); T_Font = App.MainPageLoader.GetString("FreeText_Font"); T_Fill = App.MainPageLoader.GetString("FreeText_Fill"); } #endregion 文案 private string title; public string Title { get { return title; } set { SetProperty(ref title, value); } } private FontBoardVm _fontVm = new FontBoardVm(true); public FontBoardVm FontVm { get { return _fontVm; } set { SetProperty(ref _fontVm, value); } } private AnnotCommon _basicVm = new AnnotCommon(); public AnnotCommon BasicVm { get { return _basicVm; } set => SetProperty(ref _basicVm, value); } private bool _isFillFreeText = false; public bool IsFillFreeTextAnnot { get { return _isFillFreeText; } set => SetProperty(ref _isFillFreeText, value); } private bool _isCheckedTime = false; public bool IsCheckedTime { get { return _isCheckedTime; } set => SetProperty(ref _isCheckedTime, value); } private ComboDataItem _currrentDateFormat = new ComboDataItem("yyyy年M月d日", "format"); public ComboDataItem CurrrentDateFormat { get { return _currrentDateFormat; } set => SetProperty(ref _currrentDateFormat, value); } public List DateFormatItems { get; private set; } public AnnotAttribEvent AnnotEvent { get; set; } private FreeTextAnnotArgs Annot; private AnnotTransfer PropertyPanel; public DelegateCommand SelectedPresetFontCommand { get; set; } public DelegateCommand FontFamilyChangedCommand { get; set; } public DelegateCommand FontStyleWeightChangedCommand { get; set; } public DelegateCommand SelectedFillOpacityCommand { get; set; } public DelegateCommand SelectedColorCommand { get; set; } public DelegateCommand SelectedFillColorCommand { get; set; } public DelegateCommand FontSizeChangedCommand { get; set; } public DelegateCommand TextAlignCheckedCommand { get; set; } public DelegateCommand LineModeCheckedCommand { get; set; } public DelegateCommand SelectedOpacityValueCommand { get; set; } public DelegateCommand CustomFontStyleCommand { get; set; } public DelegateCommand ReDefineFontStyleCommand { get; set; } public DelegateCommand RestoreDefaultStyleCommand { get; set; } public DelegateCommand DateFormatChangedCommand { get; set; } public DelegateCommand ShowTimeCheckedChnagedCommand { get; set; } public event EventHandler LoadPropertyHandler; public FreetextAnnotPropertyViewModel() { InitString(); //文本设置 //预设文本样式 SelectedPresetFontCommand = new DelegateCommand(SelectedPresetFont); //文本字重、字体 FontStyleWeightChangedCommand = new DelegateCommand(FontStyleWeightChanged); //字体 FontFamilyChangedCommand = new DelegateCommand(FontFamilyChanged); //自定义 CustomFontStyleCommand = new DelegateCommand(CustomFontStyle); //重新定义 ReDefineFontStyleCommand = new DelegateCommand(ReDefineFontStyle); //恢复默认 RestoreDefaultStyleCommand = new DelegateCommand(RestoreDefaultStyle); //颜色 SelectedColorCommand = new DelegateCommand(SelectedColor_Command); //填充颜色 SelectedFillColorCommand = new DelegateCommand(SelectedFillColorChange); //填充颜色不透明度 SelectedFillOpacityCommand = new DelegateCommand(SelectedFillOpacity); //大小 FontSizeChangedCommand = new DelegateCommand(FontSizeChanged); //内容对齐 TextAlignCheckedCommand = new DelegateCommand(TextAlignChecked); //填写与签名:日期 DateFormatChangedCommand = new DelegateCommand(DateFormatChanged); ShowTimeCheckedChnagedCommand = new DelegateCommand(ShowTimeCheckedChnaged); //MVP不上 LineModeCheckedCommand = new DelegateCommand(LineMode_Checked); SelectedOpacityValueCommand = new DelegateCommand(SelectedOpacityValue); InitVariable(); } private void InitVariable() { DateFormatItems = new List(); DateFormatItems = TextFont.GetDateFormats(); UpdateDateFormatLists(); InitFillColorItems(); } private void InitFillColorItems() { BasicVm.FillColorItems = AnnotColorList.GetColorList(ColorSelectorType.Fill); } private void UpdateDateFormatLists() { string strTime = " HH:mm:ss"; foreach (var item in DateFormatItems) { if (IsCheckedTime) strTime = item.ValueStr + " HH:mm:ss"; else strTime = item.ValueStr; string stadate = System.DateTime.Now.ToString(strTime); item.SetContent(stadate); if (CurrrentDateFormat != null && item.ValueStr == CurrrentDateFormat.ValueStr) CurrrentDateFormat.SetContent(stadate); } CurrrentDateFormat = new ComboDataItem(CurrrentDateFormat.ValueStr, CurrrentDateFormat.Content); } private void TextAlignChecked(object obj) { if ((string)obj != null) { switch ((string)obj) { case "AlignLeft": GetAnnotAlign(TextAlignment.Left); PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.TextAlign, TextAlignment.Left); break; case "AlignCenter": GetAnnotAlign(TextAlignment.Center); PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.TextAlign, TextAlignment.Center); break; case "AlignRight": GetAnnotAlign(TextAlignment.Right); PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.TextAlign, TextAlignment.Right); break; case "Justify": GetAnnotAlign(TextAlignment.Justify); PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.TextAlign, TextAlignment.Justify); break; } } } private void LineMode_Checked(object obj) { if (obj != null) { var tag = ((string)obj); switch (tag) { case "Dashed": AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, DashStyles.Dash); break; case "Solid": AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, DashStyles.Solid); break; } AnnotEvent?.UpdateAnnot(); } } //从预设样式设置文本 /// /// 从预设样式设置文本 /// private void SelectedPresetFont() { if (FontVm.CurrentPresetFont != null) { var itemComboxItem = FontVm.CurrentPresetFont; var item = FontVm.PresetFontList.FirstOrDefault(temp => temp.mTag == itemComboxItem.ValueStr); if (item != null) { if (item.mTag != "Custom") { FontVm.GetCurrentFontSize(item.mFontSize); if (item.mFontFamily != null) { FontVm.GetCurrentFontFamily(item.mFontFamily.ToString(), item.mFontFamily.ToString()); } FontVm.GetFontWeights_Style(item.mFontStyle, item.mFontWeight); Dictionary AnnotAttribDir = new Dictionary(); AnnotAttribDir.Add(AnnotAttrib.FontSize, item.mFontSize); AnnotAttribDir.Add(AnnotAttrib.FontName, item.mFontFamily.Source); AnnotAttribDir.Add(AnnotAttrib.IsItalic, item.mFontStyle == FontStyles.Italic); AnnotAttribDir.Add(AnnotAttrib.IsBold, item.mFontWeight == FontWeights.Bold); PropertyPanel.UpdateAnnotAllAttribs(AnnotAttribDir); } } } } //设置文本字重、样式 /// /// 设置文本字重、样式 /// private void FontStyleWeightChanged() { if (FontVm.CurrrentFontWeightStyle != null) { FontVm.UpdateFontWeight_Style(); Dictionary AnnotAttribDir = new Dictionary(); AnnotAttribDir.Add(AnnotAttrib.IsItalic, FontVm.FontStyleItem == FontStyles.Italic); AnnotAttribDir.Add(AnnotAttrib.IsBold, FontVm.FontWeightItem == FontWeights.Bold); PropertyPanel.UpdateAnnotAllAttribs(AnnotAttribDir); if (FontVm.CurrentPresetFont != null) { var currentItem = FontVm.PresetFontList.FirstOrDefault(temp => temp.mTag == FontVm.CurrentPresetFont.ValueStr); if (currentItem.mTag != "Custom") { foreach (var item in FontVm.PresetFontList) { if (item.mTag == currentItem.mTag) { if (FontVm.FontWeightItem != item.mFontWeight || FontVm.FontStyleItem != item.mFontStyle) { string txt = string.Format($" * {currentItem.mTagContent}"); if (Title == txt) { Title = ""; } Title = txt; break; } else { if (FontVm.FontWeightItem == item.mFontWeight && FontVm.FontStyleItem == item.mFontStyle && FontVm.CurrentFontSize.Value == item.mFontSize && FontVm.CurrentFontFamily.ValueStr == item.mFontFamily.Source) { string txt = currentItem.mTagContent; if (Title == txt) { Title = ""; } Title = txt; } } } } } else { bool isExist = FontVm.GetCurrentPresetFont(Annot); if (isExist) { } } } } } private void SelectedFillOpacity(object obj) { if (obj != null) { BasicVm.FillOpacity = (double)obj; BasicVm.FillColor.Opacity = BasicVm.FillOpacity; PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Transparency, BasicVm.FillOpacity); } } /// /// 设置颜色透明度 /// /// private void SelectedOpacityValue(object obj) { if (obj != null && obj is double) { if (BasicVm.FillOpacity != (double)obj) { BasicVm.FillOpacity = (double)obj; } if (BasicVm.FontColor.Opacity != BasicVm.FillOpacity) { BasicVm.FontColor.Opacity = BasicVm.FillOpacity; } PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Transparency, BasicVm.FillOpacity); PropertyPanel.InvokeToMyTools(AnnotArgsType.AnnotFreeText, BasicVm.FillOpacity); } } //设置字体大小 private void FontSizeChanged() { if (FontVm.CurrentFontSize != null) { PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.FontSize, FontVm.CurrentFontSize.Value); //if (BasicVm.IsMultiSelected == false) // PropertyPanel.InvokeToMyTools(BasicVm.AnnotType, Annot); } if (FontVm.CurrentPresetFont != null) { var currentItem = FontVm.PresetFontList.FirstOrDefault(temp => temp.mTag == FontVm.CurrentPresetFont.ValueStr); //var comboDataItem = FontVm.PresetFontItems.FirstOrDefault(temp => temp.ValueStr == FontVm.CurrentPresetFont.ValueStr); if (currentItem.mTag != "Custom") { foreach (var item in FontVm.PresetFontList) { if (item.mTag == currentItem.mTag) { if (FontVm.CurrentFontSize.Value != item.mFontSize) { string txt = string.Format($" * {currentItem.mTagContent}"); if (Title == txt) { Title = ""; } Title = txt; break; } else { if (FontVm.FontWeightItem == item.mFontWeight && FontVm.FontStyleItem == item.mFontStyle && FontVm.CurrentFontSize.Value == item.mFontSize && FontVm.CurrentFontFamily.ValueStr == item.mFontFamily.Source) { string txt = currentItem.mTagContent; if (Title == txt) { Title = ""; } Title = txt; } } } } } else { bool isExist = FontVm.GetCurrentPresetFont(Annot); if (isExist) { } } } } //设置字体样式 private void FontFamilyChanged() { if (string.IsNullOrEmpty(FontVm.CurrentFontFamily.ValueStr) == false) { PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.FontName, FontVm.CurrentFontFamily.ValueStr); } if (FontVm.CurrentPresetFont != null) { var currentItem = FontVm.PresetFontList.FirstOrDefault(temp => temp.mTag == FontVm.CurrentPresetFont.ValueStr); //var comboDataItem = FontVm.PresetFontItems.FirstOrDefault(temp => temp.ValueStr == FontVm.CurrentPresetFont.ValueStr); if (currentItem.mTag != "Custom") { foreach (var item in FontVm.PresetFontList) { if (item.mTag == currentItem.mTag) { if (FontVm.CurrentFontFamily.ValueStr != item.mFontFamily.Source) { string txt = string.Format($" * {currentItem.mTagContent}"); if (Title == txt) { Title = ""; } Title = txt; break; } else { if (FontVm.FontWeightItem == item.mFontWeight && FontVm.FontStyleItem == item.mFontStyle && FontVm.CurrentFontSize.Value == item.mFontSize && FontVm.CurrentFontFamily.ValueStr == item.mFontFamily.Source) { string txt = currentItem.mTagContent; if (Title == txt) { Title = ""; } Title = txt; } } } } } else { bool isExist = FontVm.GetCurrentPresetFont(Annot); if (isExist) { } } } } private void SelectedFillColorChange(object obj) { if (obj != null) { var colorValue = (Color)obj; if (colorValue != null) { BasicVm.FillColor = new SolidColorBrush(colorValue); PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.FillColor, colorValue); // BasicVm.FillColor.Opacity = BasicVmFillOpacity; } } } private void SelectedColor_Command(object obj) { if (obj != null) { var colorValue = (Color)obj; if (colorValue != null) { FontVm.FontColor = new SolidColorBrush(colorValue); PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.FontColor, colorValue); } } } /// /// 设置更多菜单 /// private void CustomFontStyle() { if (FontVm.CurrentPresetFont != null) { ContextMenu menu; if (FontVm.CurrentPresetFont.ValueStr == "Custom") { menu = SelectAnnotContextMenu(false, false); } else { menu = SelectAnnotContextMenu(false,false); var currentItem = FontVm.PresetFontList.FirstOrDefault(temp => temp.mTag == FontVm.CurrentPresetFont.ValueStr); if (currentItem.mTag != "Custom") { if (FontVm.FontWeightItem != currentItem.mFontWeight || FontVm.FontStyleItem != currentItem.mFontStyle || FontVm.CurrentFontSize.Value != currentItem.mFontSize || FontVm.CurrentFontFamily.ValueStr != currentItem.mFontFamily.Source) { //重新定义按钮 调整 menu = SelectAnnotContextMenu(true); } else { //更改默认后 ,可以右键恢复 var defaultlists = TextFont.GetPresetFontStyle(); var defaulItem = defaultlists.FirstOrDefault(temp => temp.mTag == FontVm.CurrentPresetFont.ValueStr); if (defaulItem != null && currentItem != null) { if (currentItem.mTagContent == defaulItem.mTagContent) { if (currentItem.mFontStyle != defaulItem.mFontStyle || currentItem.mFontWeight != defaulItem.mFontWeight || currentItem.mFontFamily.Source != defaulItem.mFontFamily.Source || currentItem.mFontSize != defaulItem.mFontSize) { menu = SelectAnnotContextMenu(true, false); } else { menu = SelectAnnotContextMenu(false, false); } } } } } } if (menu != null) { menu.IsOpen = true; } } } /// /// 更多菜单 /// 230606 文本预设,修改参数后,redefine按钮应当只能点一次,后面要置灰 /// /// /// private ContextMenu SelectAnnotContextMenu(bool isEnable,bool isReDefine=true) { var popMenu = App.Current.FindResource("CustomFontStyleFlyoutMenu") as ContextMenu; if (popMenu != null && popMenu.Items.Count == 2) { //用所选部分重新定义 MenuItem menuItem = popMenu.Items[0] as MenuItem; menuItem.IsEnabled = isReDefine; menuItem.Command = ReDefineFontStyleCommand; //恢复默认预设样式 menuItem = popMenu.Items[1] as MenuItem; menuItem.IsEnabled = isEnable; menuItem.Command = RestoreDefaultStyleCommand; } return popMenu; } public List FontStyleList = new List(); /// /// 用所选部分重新定义 /// private void ReDefineFontStyle() { var item = FontVm.PresetFontList.FirstOrDefault(temp => temp.mTag == FontVm.CurrentPresetFont.ValueStr); if (item == null) return; item.mFontFamily = new FontFamily(FontVm.CurrentFontFamily.ValueStr); if (FontVm.CurrrentFontWeightStyle.ValueStr == "Bold") { item.mFontStyle = FontStyles.Normal; item.mFontWeight = FontWeights.Bold; } else if (FontVm.CurrrentFontWeightStyle.ValueStr == "Regular") { item.mFontStyle = FontStyles.Normal; item.mFontWeight = FontWeights.Normal; } else if (FontVm.CurrrentFontWeightStyle.ValueStr == "Italic") { item.mFontStyle = FontStyles.Italic; item.mFontWeight = FontWeights.Normal; } else { item.mFontStyle = FontStyles.Italic; item.mFontWeight = FontWeights.Bold; } item.mFontSize = (int)FontVm.CurrentFontSize.Value; FontVm.CurrentPresetFont = new ComboDataItem(item.mTag, item.mTagContent); SelectedPresetFont(); if (BasicVm.IsMultiSelected == false) PropertyPanel.InvokeToMyTools(BasicVm.AnnotType, Annot); //更改后 保存到本地缓存 TextFont.SavePresetFontList(FontVm.PresetFontList); } /// /// 恢复默认预设样式 /// private void RestoreDefaultStyle() { var defaultlists = TextFont.GetPresetFontStyle(); if (FontVm.CurrentPresetFont.ValueStr != "Custom") { var defaulItem = defaultlists.FirstOrDefault(temp => temp.mTag == FontVm.CurrentPresetFont.ValueStr); if (defaulItem != null) { var currentItem = FontVm.PresetFontList.FirstOrDefault(temp => temp.mTag == FontVm.CurrentPresetFont.ValueStr); if (currentItem != null) { currentItem.mTagContent = defaulItem.mTagContent; currentItem.mFontStyle = defaulItem.mFontStyle; currentItem.mFontWeight = defaulItem.mFontWeight; currentItem.mFontFamily = defaulItem.mFontFamily; currentItem.mFontSize = defaulItem.mFontSize; FontVm.GetCurrentFontFamily(currentItem.mFontFamily.ToString(), currentItem.mFontFamily.ToString()); FontVm.GetCurrentFontSize(currentItem.mFontSize); FontVm.GetFontWeights_Style(currentItem.mFontStyle, currentItem.mFontWeight); FontVm.CurrentPresetFont = new ComboDataItem(defaulItem.mTag, defaulItem.mTagContent); SelectedPresetFont(); //更改后 保存到本地缓存 TextFont.SavePresetFontList(FontVm.PresetFontList); } } } } private void DateFormatChanged() { if (CurrrentDateFormat != null) { if (IsCheckedTime) UpdateDateFormatLists(); PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.NoteText, CurrrentDateFormat.Content); } } private void ShowTimeCheckedChnaged() { if (CurrrentDateFormat != null) { UpdateDateFormatLists(); PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.NoteText, CurrrentDateFormat.Content); } } public bool IsNavigationTarget(NavigationContext navigationContext) { return true; } public void OnNavigatedFrom(NavigationContext navigationContext) { BasicVm.IsMultiSelected = false; // IsCheckedTime = false; } public void OnNavigatedTo(NavigationContext navigationContext) { navigationContext.Parameters.TryGetValue(ParameterNames.PropertyPanelContentViewModel, out PropertyPanel); if (PropertyPanel != null) { AnnotEvent = PropertyPanel.AnnotEvent; Annot = PropertyPanel.annot as FreeTextAnnotArgs; LoadPropertyHandler?.Invoke(this, Annot); BasicVm.AnnotType = PropertyPanel.annot.EventType; BasicVm.AnnotTypeTitle = App.MainPageLoader.GetString("FreeText_Title"); BasicVm.IsMultiSelected = PropertyPanel.IsMultiSelected; IsFillFreeTextAnnot = PropertyPanel.IsTextFill; if (BasicVm.IsMultiSelected) { IsAttributeEquals(); BasicVm.IsSolidLine = BasicVm.IsDashLine = false; } else { GetAnnotProperty(); } IsFillFreeTextAnnot = PropertyPanel.IsTextFill; } } /// /// 多选的注释 /// private List ConvertLists() { List FreeTextLists = new List(); foreach (var item in PropertyPanel.annotlists) { var itemFreeText = item as FreeTextAnnotArgs; if (itemFreeText != null) { FreeTextLists.Add(itemFreeText); } } if (FreeTextLists.Count != PropertyPanel.annotlists.Count) return null; else return FreeTextLists; } private void IsAttributeEquals() { var list = ConvertLists(); if (list != null) { var temp = list[0]; Dictionary isNoEqualsDir = new Dictionary(); isNoEqualsDir.Add("FontFamily", false); isNoEqualsDir.Add("FontSize", false); isNoEqualsDir.Add("FontStyleFontWeight", false); isNoEqualsDir.Add("FontColor", false); isNoEqualsDir.Add("FillColor", false); isNoEqualsDir.Add("TextAglin", false); foreach (var item in list) { //if (item == list[0]) // continue; //if (temp.Align != item.Align) //{ // isNoEqualsDir["TextAglin"] = true; // FontVm.StrTextAlign = "None"; //} //if (temp.FontFamily.ToString() != item.FontFamily.ToString()) //{ // isNoEqualsDir["FontFamily"] = true; // //FontVm.CurrentFontFamily = null; //} //if (temp.FontSize != item.FontSize) //{ // isNoEqualsDir["FontSize"] = true; // FontVm.CurrentFontSize = null; //} //if (temp.FontStyle != item.FontStyle || temp.FontWeight != item.FontWeight) //{ // isNoEqualsDir["FontStyleFontWeight"] = true; // FontVm.CurrrentFontWeightStyle = null; //} //if (isNoEqualsDir["FontFamily"] == true || isNoEqualsDir["FontSize"] == true || isNoEqualsDir["FontStyleFontWeight"] == true) //{ // FontVm.CurrentPresetFont = null; //} if (isNoEqualsDir["FontColor"] == false) { if (temp.FontColor.A != item.FontColor.A || temp.FontColor.R != item.FontColor.R || temp.FontColor.G != item.FontColor.G || temp.FontColor.B != item.FontColor.B) { FontVm.FontColor = new SolidColorBrush(Color.FromArgb(0x01, 0xff, 0xff, 0xff)); isNoEqualsDir["FontColor"] = true; } } if (isNoEqualsDir["FillColor"] == false) { if (temp.BgColor.A != item.BgColor.A || temp.BgColor.R != item.BgColor.R || temp.BgColor.G != item.BgColor.G || temp.BgColor.B != item.BgColor.B) { BasicVm.FillColor = new SolidColorBrush(Color.FromArgb(0x01, 0xff, 0xff, 0xff)); isNoEqualsDir["FillColor"] = true; } } } ////以下是多选注释的属性相等时 //if (isNoEqualsDir["TextAglin"] == false) // { GetAnnotAlign(temp.Align); //} //if (isNoEqualsDir["FontFamily"] == false) //{ FontVm.GetCurrentFontFamily(temp.FontName, temp.FontName); // } // if (isNoEqualsDir["FontSize"] == false) //{ FontVm.GetCurrentFontSize((int)temp.FontSize); //} //if (isNoEqualsDir["FontStyleFontWeight"] == false) //{ FontVm.GetFontWeights_Style(temp.IsItalic ? FontStyles.Italic : FontStyles.Normal, temp.IsBold ? FontWeights.Bold : FontWeights.Normal); //} if (isNoEqualsDir["FontColor"] == false) { FontVm.FontColor = new SolidColorBrush(temp.FontColor); } if (isNoEqualsDir["FillColor"] == false) { FontVm.FontColor = new SolidColorBrush(temp.BgColor); } } } private void GetAnnotProperty() { BasicVm.FillColor = new SolidColorBrush(Annot.BgColor); BasicVm.FillOpacity = Annot.Transparency; FontVm.FontColor = new SolidColorBrush(Annot.FontColor); bool isExist = FontVm.GetCurrentPresetFont(Annot); if (isExist == false) { FontVm.CurrentPresetFont = new ComboDataItem("Custom", "Custom"); FontVm.GetCurrentFontSize((int)Annot.FontSize); FontVm.GetCurrentFontFamily(Annot.FontName, Annot.FontName); FontVm.GetFontWeights_Style(Annot.IsItalic ? FontStyles.Italic : FontStyles.Normal, Annot.IsBold ? FontWeights.Bold : FontWeights.Normal); } else { if (FontVm.CurrentPresetFont != null) { var itemComboxItem = FontVm.CurrentPresetFont; var item = FontVm.PresetFontList.FirstOrDefault(temp => temp.mTag == itemComboxItem.ValueStr); if (item != null) { if (item.mTag != "Custom") { FontVm.GetCurrentFontSize(item.mFontSize); if (item.mFontFamily != null) { FontVm.GetCurrentFontFamily(item.mFontFamily.ToString(), item.mFontFamily.ToString()); } FontVm.GetFontWeights_Style(item.mFontStyle, item.mFontWeight); } } } } GetTimeFormat(); GetAnnotAlign(Annot.Align); } //填写与签名 private void GetTimeFormat() { if (IsFillFreeTextAnnot == false) return; if (string.IsNullOrEmpty(Annot.TextContent)) { if (CurrrentDateFormat != null) { if (IsCheckedTime) UpdateDateFormatLists(); PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.NoteText, CurrrentDateFormat.Content); } return; } DateTime dtDate; bool isTime = false; foreach (var item in DateFormatItems) { var strFormat = ""; var strArr = Annot.TextContent.Split(' '); if (strArr != null && strArr.Count() == 2) { strFormat = item.ValueStr + " HH:mm:ss"; } else { strFormat = item.ValueStr; } if (DateTime.TryParseExact(Annot.TextContent, strFormat, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AdjustToUniversal, out dtDate)) { if (strArr != null && strArr.Count() == 2) { isTime = true; } foreach (var item2 in DateFormatItems) { string stadate = System.DateTime.Now.ToString(strFormat); item.SetContent(stadate); } CurrrentDateFormat = new ComboDataItem(item.ValueStr, item.Content); break; } } IsCheckedTime = isTime; } //文本内容对齐 private void GetAnnotAlign(TextAlignment align) { switch (align) { case TextAlignment.Left: FontVm.StrTextAlign = "Left"; break; case TextAlignment.Center: FontVm.StrTextAlign = "Center"; break; case TextAlignment.Right: FontVm.StrTextAlign = "Right"; break; case TextAlignment.Justify: FontVm.StrTextAlign = "Justify"; break; default: FontVm.StrTextAlign = "None"; break; } } } }