123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999 |
- 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<ComboDataItem> 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<object> SelectedFillOpacityCommand { get; set; }
- public DelegateCommand<object> SelectedColorCommand { get; set; }
- public DelegateCommand<object> SelectedFillColorCommand { get; set; }
- public DelegateCommand FontSizeChangedCommand { get; set; }
- public DelegateCommand<object> TextAlignCheckedCommand { get; set; }
- public DelegateCommand<object> LineModeCheckedCommand { get; set; }
- public DelegateCommand<object> 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<object> 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<object>(SelectedColor_Command);
- //填充颜色
- SelectedFillColorCommand = new DelegateCommand<object>(SelectedFillColorChange);
- //填充颜色不透明度
- SelectedFillOpacityCommand = new DelegateCommand<object>(SelectedFillOpacity);
- //大小
- FontSizeChangedCommand = new DelegateCommand(FontSizeChanged);
- //内容对齐
- TextAlignCheckedCommand = new DelegateCommand<object>(TextAlignChecked);
- //填写与签名:日期
- DateFormatChangedCommand = new DelegateCommand(DateFormatChanged);
- ShowTimeCheckedChnagedCommand = new DelegateCommand(ShowTimeCheckedChnaged);
- //MVP不上
- LineModeCheckedCommand = new DelegateCommand<object>(LineMode_Checked);
- SelectedOpacityValueCommand = new DelegateCommand<object>(SelectedOpacityValue);
- InitVariable();
- }
- private void InitVariable()
- {
- DateFormatItems = new List<ComboDataItem>();
- 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();
- }
- }
- //从预设样式设置文本
- /// <summary>
- /// 从预设样式设置文本
- /// </summary>
- 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<AnnotAttrib, object> AnnotAttribDir = new Dictionary<AnnotAttrib, object>();
- 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);
- }
- }
- }
- }
- //设置文本字重、样式
- /// <summary>
- /// 设置文本字重、样式
- /// </summary>
- private void FontStyleWeightChanged()
- {
- if (FontVm.CurrrentFontWeightStyle != null)
- {
- FontVm.UpdateFontWeight_Style();
- Dictionary<AnnotAttrib, object> AnnotAttribDir = new Dictionary<AnnotAttrib, object>();
- 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);
- }
- }
- /// <summary>
- /// 设置颜色透明度
- /// </summary>
- /// <param name="obj"></param>
- 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);
- }
- }
- }
- /// <summary>
- /// 设置更多菜单
- /// </summary>
- 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;
- }
- }
- }
- /// <summary>
- /// 更多菜单
- /// 230606 文本预设,修改参数后,redefine按钮应当只能点一次,后面要置灰
- /// </summary>
- /// <param name="isEnable"></param>
- /// <returns></returns>
- 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<PresetFontItem> FontStyleList = new List<PresetFontItem>();
- /// <summary>
- /// 用所选部分重新定义
- /// </summary>
- 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);
- }
- /// <summary>
- /// 恢复默认预设样式
- /// </summary>
- 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<AnnotTransfer>(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;
- }
- }
- /// <summary>
- /// 多选的注释
- /// </summary>
- private List<FreeTextAnnotArgs> ConvertLists()
- {
- List<FreeTextAnnotArgs> FreeTextLists = new List<FreeTextAnnotArgs>();
- 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<string, bool> isNoEqualsDir = new Dictionary<string, bool>();
- 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;
- }
- }
- }
- }
|