using ComPDFKitViewer; using ComPDFKitViewer.AnnotEvent; using PDF_Master.Model; using Prism.Commands; using Prism.Mvvm; using Prism.Services.Dialogs; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Media; namespace PDF_Master.ViewModels.Dialog.Redaction { public class MarkSettingDialogViewModel : BindableBase, IDialogAware { public string Title => ""; public event Action RequestClose; private RedactionAnnotArgs annotArgs; public DelegateCommand OkCommand { get; set; } public DelegateCommand CancelCommand { get; set; } public DelegateCommand AlignCommand { get; set; } private Color lineColor; public Color LineColor { get { return lineColor; } set { SetProperty(ref lineColor, value); } } private Color bgColor; public Color BgColor { get { return bgColor; } set { SetProperty(ref bgColor, value); } } private Color fontColor; public Color FontColor { get { return fontColor; } set { SetProperty(ref fontColor, value); } } private bool isUserText; public bool IsUseText { get { return isUserText; } set { SetProperty(ref isUserText, value); } } private bool leftChecked = true; public bool LeftChecked { get { return leftChecked; } set { SetProperty(ref leftChecked, value); } } private bool centerChecked; public bool CenterChecked { get { return centerChecked; } set { SetProperty(ref centerChecked, value); } } private bool rightChecked; public bool RightChecked { get { return rightChecked; } set { SetProperty(ref rightChecked, value); } } private bool strechChecked; public bool StrechChecked { get { return strechChecked; } set { SetProperty(ref strechChecked, value); } } private string overText; public string OvertText { get { return overText; } set { SetProperty(ref overText, value); } } private int fontFamilySelectedIndex; public int FontFamilySelectedIndex { get { return fontFamilySelectedIndex; } set { SetProperty(ref fontFamilySelectedIndex, value); } } private int fontWeightSelectedIndex; public int FontWeightSelectedIndex { get { return fontWeightSelectedIndex; } set { SetProperty(ref fontWeightSelectedIndex, value); if (value > 0) { switch (value) { case 0: fontWeight = FontWeights.Regular; break; case 1: fontWeight = FontWeights.Bold; break; case 2: fontWeight = FontWeights.SemiBold; break; case 3: fontWeight = FontWeights.UltraBold; break; default: break; } } } } private FontWeight fontWeight = FontWeights.Regular; private int fontSize = 12; private int fontSizeSelectedIndex; public int FontSizeSelectedIndex { get { return fontSizeSelectedIndex; } set { SetProperty(ref fontSizeSelectedIndex, value); } } public List FontFamilys { get; set; } public List FontWeight { get; set; } public List FontSizes { get; set; } public TextAlignment textAlignment { get; set; } = TextAlignment.Left; public MarkSettingDialogViewModel() { OkCommand = new DelegateCommand(ok); CancelCommand = new DelegateCommand(cancel); AlignCommand = new DelegateCommand(align); InitFontFamily(); InitFontWeight(); InitFontSize(); } private void InitFontFamily() { FontFamilys = new List(); FontFamilys.Add("Courier New"); FontFamilys.Add("Arial"); FontFamilys.Add("Times New Roman"); } private void InitFontWeight() { FontWeight = new List(); FontWeight.Add("Regular"); FontWeight.Add("Bold"); FontWeight.Add("Italic"); FontWeight.Add("Bold Italic"); } private void InitFontSize() { FontSizes = new List(); FontSizes.Add("Auto"); } private void cancel() { RequestClose.Invoke(new DialogResult(ButtonResult.Cancel)); } private void ok() { AnnotAttribEvent eventargs = AnnotAttribEvent.GetAnnotAttribEvent(annotArgs, annotArgs.GetAnnotAttrib()); eventargs.UpdateAttrib(AnnotAttrib.FillColor,BgColor); eventargs.UpdateAttrib(AnnotAttrib.NoteText, OvertText); eventargs.UpdateAttrib(AnnotAttrib.FontColor,FontColor); eventargs.UpdateAttrib(AnnotAttrib.Color, LineColor); eventargs.UpdateAttrib(AnnotAttrib.FontSize,fontSize); eventargs.UpdateAttrib(AnnotAttrib.TextAlign, textAlignment); eventargs.UpdateAttrib(AnnotAttrib.IsBold, fontWeight==FontWeights.Bold); if (IsUseText) { eventargs.UpdateAttrib(AnnotAttrib.NoteText, string.Empty); } eventargs.UpdateAnnot(); RequestClose.Invoke(new DialogResult(ButtonResult.OK)); } private void align(string tag) { switch (tag) { case "Left": textAlignment = TextAlignment.Left; break; case "Center": textAlignment = TextAlignment.Center; break; case "Right": textAlignment = TextAlignment.Right; break; case "Strech": textAlignment = TextAlignment.Justify; break; default: break; } } public bool CanCloseDialog() { return true; } public void OnDialogClosed() { } public void OnDialogOpened(IDialogParameters parameters) { annotArgs = parameters.GetValue(ParameterNames.DataModel); BgColor = annotArgs.BgColor; LineColor = annotArgs.LineColor; FontColor = annotArgs.FontColor; OvertText = annotArgs.Content; switch (annotArgs.FontName) { case "Helvetica": FontFamilySelectedIndex = 1; break; case "Times Roman": FontFamilySelectedIndex = 2; break; default: case "Courier": FontFamilySelectedIndex = 0; break; } switch (annotArgs.Align) { case TextAlignment.Left: LeftChecked = true; break; case TextAlignment.Right: RightChecked = true; break; case TextAlignment.Center: CenterChecked = true; break; case TextAlignment.Justify: StrechChecked = true; break; default: break; } } } }