123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- using ComPDFKit.PDFAnnotation;
- using ComPDFKitViewer.PdfViewer;
- using PDF_Office.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.Controls;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
- {
- class CustomCreateDialogViewModel : BindableBase, IDialogAware
- {
- public string Title => ".";
- public event Action<IDialogResult> RequestClose;
- public DelegateCommand CancelCommand { get; set; }
- public DelegateCommand CreateCommnad { get; set; }
- public DelegateCommand UpDataDynamicCommnad { get; set; }
- public DelegateCommand<object> KeyDown { get; set; }
- private BitmapSource imageSource;
- public BitmapSource ImageSource
- {
- get { return imageSource; }
- set
- {
- SetProperty(ref imageSource, value);
- }
- }
- private string stampText = "Stamp Text";
- public string StampText
- {
- get { return stampText; }
- set
- {
- SetProperty(ref stampText, value);
- }
- }
- private bool isCheckedDate;
- public bool IsCheckedDate
- {
- get { return isCheckedDate; }
- set
- {
- SetProperty(ref isCheckedDate, value);
- UpDataStamp();
- }
- }
- private bool isCheckedTime;
- public bool IsCheckedTime
- {
- get { return isCheckedTime; }
- set
- {
- SetProperty(ref isCheckedTime, value);
- UpDataStamp();
- }
- }
- private C_TEXTSTAMP_SHAPE shape = C_TEXTSTAMP_SHAPE.TEXTSTAMP_RECT;
- public C_TEXTSTAMP_SHAPE Shape
- {
- get { return shape; }
- set { shape = value; }
- }
- private C_TEXTSTAMP_COLOR color = C_TEXTSTAMP_COLOR.TEXTSTAMP_RED;
- public C_TEXTSTAMP_COLOR Color
- {
- get { return color; }
- set { color = value; }
- }
- public void SetStampStyle(int index)
- {
- switch (index)
- {
- case 1:
- Color = C_TEXTSTAMP_COLOR.TEXTSTAMP_WHITE;
- Shape = C_TEXTSTAMP_SHAPE.TEXTSTAMP_NONE;
- break;
- case 2:
- Color = C_TEXTSTAMP_COLOR.TEXTSTAMP_WHITE;
- Shape = C_TEXTSTAMP_SHAPE.TEXTSTAMP_RECT;
- break;
- case 3:
- Color = C_TEXTSTAMP_COLOR.TEXTSTAMP_GREEN;
- Shape = C_TEXTSTAMP_SHAPE.TEXTSTAMP_RECT;
- break;
- case 4:
- Color = C_TEXTSTAMP_COLOR.TEXTSTAMP_RED;
- Shape = C_TEXTSTAMP_SHAPE.TEXTSTAMP_RECT;
- break;
- case 5:
- Color = C_TEXTSTAMP_COLOR.TEXTSTAMP_BLUE;
- Shape = C_TEXTSTAMP_SHAPE.TEXTSTAMP_RECT;
- break;
- case 6:
- Color = C_TEXTSTAMP_COLOR.TEXTSTAMP_GREEN;
- Shape = C_TEXTSTAMP_SHAPE.TEXTSTAMP_LEFT_TRIANGLE;
- break;
- case 7:
- Color = C_TEXTSTAMP_COLOR.TEXTSTAMP_RED;
- Shape = C_TEXTSTAMP_SHAPE.TEXTSTAMP_LEFT_TRIANGLE;
- break;
- case 8:
- Color = C_TEXTSTAMP_COLOR.TEXTSTAMP_BLUE;
- Shape = C_TEXTSTAMP_SHAPE.TEXTSTAMP_LEFT_TRIANGLE;
- break;
- case 9:
- Color = C_TEXTSTAMP_COLOR.TEXTSTAMP_GREEN;
- Shape = C_TEXTSTAMP_SHAPE.TEXTSTAMP_RIGHT_TRIANGLE;
- break;
- case 10:
- Color = C_TEXTSTAMP_COLOR.TEXTSTAMP_RED;
- Shape = C_TEXTSTAMP_SHAPE.TEXTSTAMP_RIGHT_TRIANGLE;
- break;
- case 11:
- Color = C_TEXTSTAMP_COLOR.TEXTSTAMP_GREEN;
- Shape = C_TEXTSTAMP_SHAPE.TEXTSTAMP_RIGHT_TRIANGLE;
- break;
- default:
- break;
- }
- UpDataStamp();
- }
- public CustomCreateDialogViewModel()
- {
- CancelCommand = new DelegateCommand(Cancel);
- CreateCommnad = new DelegateCommand(Create);
- UpDataDynamicCommnad = new DelegateCommand(UpDataStamp);
- KeyDown = new DelegateCommand<object>(PreviewKeyDown);
- }
- private void Cancel()
- {
- RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
- }
- private void Create()
- {
- }
- public bool CanCloseDialog()
- {
- return true;
- }
- public void OnDialogClosed()
- {
- return;
- }
- private void PreviewKeyDown(object e)
- {
- var args = e as KeyEventArgs;
- if (args == null)
- {
- return;
- }
- if (args.Key == Key.Enter)
- {
- StampText = (args.OriginalSource as TextBox).Text;
- UpDataStamp();
- }
- }
- private void UpDataStamp()
- {
- string date = "";
- string dateType = "";
- if (IsCheckedDate)
- {
- dateType = "yyyy-MM-dd";
- }
- if (IsCheckedTime)
- {
- dateType= dateType+ " HH:mm:ss";
- }
- if (!String.IsNullOrEmpty(dateType))
- {
- date = DateTime.Now.ToString(dateType);
- }
-
- var bytes = CPDFStampAnnotation.GetTempTextStampImage(StampText, date,
- Shape, Color, out int stampWidth, out int stampHeight, out int width, out int height);
- if (bytes.Length > 0)
- {
- PixelFormat fmt = PixelFormats.Bgra32;
- BitmapSource bps = BitmapSource.Create(width, height, 96, 96, fmt, null, bytes, (width * fmt.BitsPerPixel + 7) / 8);
- ImageSource = bps;
- }
- else
- {
- ImageSource = null;
- }
- }
- public void OnDialogOpened(IDialogParameters parameters)
- {
- UpDataStamp();
- return;
- }
- }
- }
|