123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334 |
- 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<IDialogResult> RequestClose;
- private RedactionAnnotArgs annotArgs;
- public DelegateCommand OkCommand { get; set; }
- public DelegateCommand CancelCommand { get; set; }
- public DelegateCommand<string> 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<string> FontFamilys { get; set; }
- public List<string> FontWeight { get; set; }
- public List<string> FontSizes { get; set; }
- public TextAlignment textAlignment { get; set; } = TextAlignment.Left;
- public MarkSettingDialogViewModel()
- {
- OkCommand = new DelegateCommand(ok);
- CancelCommand = new DelegateCommand(cancel);
- AlignCommand = new DelegateCommand<string>(align);
- InitFontFamily();
- InitFontWeight();
- InitFontSize();
- }
- private void InitFontFamily()
- {
- FontFamilys = new List<string>();
- FontFamilys.Add("Courier New");
- FontFamilys.Add("Arial");
- FontFamilys.Add("Times New Roman");
- }
- private void InitFontWeight()
- {
- FontWeight = new List<string>();
- FontWeight.Add("Regular");
- FontWeight.Add("Bold");
- FontWeight.Add("Italic");
- FontWeight.Add("Bold Italic");
- }
- private void InitFontSize()
- {
- FontSizes = new List<string>();
- 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<RedactionAnnotArgs>(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;
- }
- }
- }
- }
|