123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437 |
- using ComPDFKit.PDFAnnotation;
- using ComPDFKitViewer.AnnotEvent;
- using Dropbox.Api.Users;
- using DryIoc;
- using ImTools;
- using Microsoft.Office.Interop.Word;
- using PDF_Office.CustomControl.CompositeControl;
- using PDF_Office.Model;
- using PDF_Office.Model.BOTA;
- using Prism.Commands;
- using Prism.Common;
- using Prism.Mvvm;
- using Prism.Services.Dialogs;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Annotations;
- using System.Windows.Media;
- namespace PDF_Office.ViewModels.Dialog.BOTA
- {
- public class AuthorItem : BindableBase
- {
- private string name;
- public string Name
- {
- get { return name; }
- set
- {
- SetProperty(ref name, value);
- }
- }
- public AuthorItem(string name)
- {
- Name = name;
- }
- }
- public class Compare<T, C> : IEqualityComparer<T>
- {
- private Func<T, C> _getField;
- public Compare(Func<T, C> getfield)
- {
- this._getField = getfield;
- }
- public bool Equals(T x, T y)
- {
- return EqualityComparer<C>.Default.Equals(_getField(x), _getField(y));
- }
- public int GetHashCode(T obj)
- {
- return EqualityComparer<C>.Default.GetHashCode(this._getField(obj));
- }
- }
- public static class CommonHelper
- {
- /// <summary>
- /// 自定义Distinct扩展方法
- /// </summary>
- /// <typeparam name="T">要去重的对象类</typeparam>
- /// <typeparam name="C">自定义去重的字段类型</typeparam>
- /// <param name="source">要去重的对象</param>
- /// <param name="getfield">获取自定义去重字段的委托</param>
- /// <returns></returns>
- public static IEnumerable<T> MyDistinct<T, C>(this IEnumerable<T> source, Func<T, C> getfield)
- {
- return source.Distinct(new Compare<T, C>(getfield));
- }
- }
- internal class ScreenAnnotationDialogViewModel : BindableBase, IDialogAware
- {
- public string Title => "";
- public event Action<IDialogResult> RequestClose;
- #region 类型的显示隐藏
- /// <summary>
- /// 高亮字体
- /// </summary>
- private Visibility highlightVisibility = Visibility.Collapsed;
- public Visibility HighlightVisibility
- {
- get { return highlightVisibility; }
- set
- {
- SetProperty(ref highlightVisibility, value);
- }
- }
- /// <summary>
- /// 手绘
- /// </summary>
- private Visibility freeHandVisibility = Visibility.Collapsed;
- public Visibility FreeHandVisibility
- {
- get { return freeHandVisibility; }
- set
- {
- SetProperty(ref freeHandVisibility, value);
- }
- }
- /// <summary>
- /// 便签
- /// </summary>
- private Visibility annotStickyVisibility = Visibility.Collapsed;
- public Visibility AnnotStickyVisibility
- {
- get { return annotStickyVisibility; }
- set
- {
- SetProperty(ref annotStickyVisibility, value);
- }
- }
- /// <summary>
- /// 图章
- /// </summary>
- private Visibility annotStampVisibility = Visibility.Collapsed;
- public Visibility AnnotStampVisibility
- {
- get { return annotStampVisibility; }
- set
- {
- SetProperty(ref annotStampVisibility, value);
- }
- }
- /// <summary>
- /// 线
- /// </summary>
- private Visibility sharpLineVisibility = Visibility.Collapsed;
- public Visibility SharpLineVisibility
- {
- get { return sharpLineVisibility; }
- set
- {
- SetProperty(ref sharpLineVisibility, value);
- }
- }
- /// <summary>
- /// 箭头
- /// </summary>
- private Visibility sharpArrowVisibility = Visibility.Collapsed;
- public Visibility SharpArrowVisibility
- {
- get { return sharpArrowVisibility; }
- set
- {
- SetProperty(ref sharpArrowVisibility, value);
- }
- }
- /// <summary>
- /// 圆
- /// </summary>
- private Visibility annotCircleVisibility = Visibility.Collapsed;
- public Visibility AnnotCircleVisibility
- {
- get { return annotCircleVisibility; }
- set
- {
- SetProperty(ref annotCircleVisibility, value);
- }
- }
- /// <summary>
- /// 矩形
- /// </summary>
- private Visibility annotSquareVisibility = Visibility.Collapsed;
- public Visibility AnnotSquareVisibility
- {
- get { return annotSquareVisibility; }
- set
- {
- SetProperty(ref annotSquareVisibility, value);
- }
- }
- /// <summary>
- /// 文本注释
- /// </summary>
- private Visibility annotFreeTextVisibility = Visibility.Collapsed;
- public Visibility AnnotFreeTextVisibility
- {
- get { return annotFreeTextVisibility; }
- set
- {
- SetProperty(ref annotFreeTextVisibility, value);
- }
- }
- /// <summary>
- /// 删除线
- /// </summary>
- private Visibility annotStrikeoutVisibility = Visibility.Collapsed;
- public Visibility AnnotStrikeoutVisibility
- {
- get { return annotStrikeoutVisibility; }
- set
- {
- SetProperty(ref annotStrikeoutVisibility, value);
- }
- }
- /// <summary>
- /// 下划线
- /// </summary>
- private Visibility underLineVisibility = Visibility.Collapsed;
- public Visibility UnderLineVisibility
- {
- get { return underLineVisibility; }
- set
- {
- SetProperty(ref underLineVisibility, value);
- }
- }
- #endregion 类型的显示隐藏
- public DelegateCommand CancelCommand { get; set; }
- public DelegateCommand CreateCommnad { get; set; }
- public ObservableCollection<AnnotationHandlerEventArgs> AnnotationListItems { get; set; }
- private ObservableCollection<ColorItem> annotationColors = new ObservableCollection<ColorItem>();
- public ObservableCollection<ColorItem> AnnotationColors
- {
- get { return annotationColors; }
- set
- {
- SetProperty(ref annotationColors, value);
- }
- }
- private ObservableCollection<AuthorItem> annotationAuthor = new ObservableCollection<AuthorItem>();
- public ObservableCollection<AuthorItem> AnnotationAuthor
- {
- get { return annotationAuthor; }
- set
- {
- SetProperty(ref annotationAuthor, value);
- }
- }
- //private List<System.Windows.Media.Color> annotationColors = new List<System.Windows.Media.Color>();
- //private List<string> annotationAuthor = new List<string>();
- public ScreenAnnotationDialogViewModel()
- {
- CancelCommand = new DelegateCommand(CancelEvent);
- CreateCommnad = new DelegateCommand(CreateEvent);
- }
- private void CreateEvent()
- {
- DialogParameters valuePairs = new DialogParameters();
- //valuePairs.Add(ParameterNames.Bookmark, Bookmark);
- RequestClose.Invoke(new DialogResult(ButtonResult.OK, valuePairs));
- }
- private void CancelEvent()
- {
- RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
- }
- public bool CanCloseDialog()
- {
- return true;
- }
- public void OnDialogClosed()
- {
- }
- private void SetColor(System.Windows.Media.Color color)
- {
- if (AnnotationColors.Count > 0)
- {
- for (int i = 0; i < AnnotationColors.Count; i++)
- {
- System.Windows.Media.Color color1 = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(AnnotationColors[i].Color.ToString());
- if (color1.R == color.R && color1.G == color.G && color1.B == color.B
- && color1.A == color.A)
- {
- AnnotationColors.Remove(AnnotationColors[i]);
- }
- }
- }
- AnnotationColors.Add(new ColorItem(color));
- //var bFind = AnnotationColors.All<ColorItem>(p => p.Color == new SolidColorBrush(color));
- //if (bFind)
- //{
- // AnnotationColors.Add(new ColorItem(color));
- //}
- }
- public void OnDialogOpened(IDialogParameters parameters)
- {
- ObservableCollection<AnnotationHandlerEventArgs> list;
- parameters.TryGetValue<ObservableCollection<AnnotationHandlerEventArgs>>(ParameterNames.AnnotationList, out list);
- AnnotationListItems = list;
- foreach (var item in AnnotationListItems)
- {
- AnnotationAuthor.Add(new AuthorItem(item.Author));
- AnnotHandlerEventArgs data = item.AnnotHandlerEventArgs;
- switch (item.EventType)
- {
- case AnnotArgsType.AnnotFreeText://文本
- if (data is FreeTextAnnotArgs textAnnotArgs)
- {
- SetColor(textAnnotArgs.FontColor);
- }
- AnnotFreeTextVisibility = Visibility.Visible;
- break;
- case AnnotArgsType.AnnotHighlight://高亮
- if (data is TextHighlightAnnotArgs highlightAnnotArgs)
- {
- SetColor(highlightAnnotArgs.Color);
- }
- HighlightVisibility = Visibility.Visible;
- break;
- case AnnotArgsType.AnnotFreehand://手绘
- if (data is FreehandAnnotArgs freehandAnnotArgs)
- {
- SetColor(freehandAnnotArgs.InkColor);
- }
- FreeHandVisibility = Visibility.Visible;
- break;
- case AnnotArgsType.AnnotSquiggly://波浪线
- break;
- case AnnotArgsType.AnnotStamp://图章
- AnnotStampVisibility = Visibility.Visible;
- break;
- case AnnotArgsType.AnnotStrikeout://删除线
- if (data is TextStrikeoutAnnotArgs textStrikeoutAnnotArgs)
- {
- SetColor(textStrikeoutAnnotArgs.Color);
- }
- AnnotStickyVisibility = Visibility.Visible;
- break;
- case AnnotArgsType.AnnotSticky://便签
- if (data is StickyAnnotArgs stickyAnnotArgs)
- {
- SetColor(stickyAnnotArgs.Color);
- }
- AnnotStickyVisibility = Visibility.Visible;
- break;
- case AnnotArgsType.AnnotUnderline://下划线
- if (data is TextUnderlineAnnotArgs textUnderlineAnnotArgs)
- {
- SetColor(textUnderlineAnnotArgs.Color);
- }
- UnderLineVisibility = Visibility.Visible;
- break;
- case AnnotArgsType.AnnotLine:
- if ((item.AnnotHandlerEventArgs as LineAnnotArgs).HeadLineType >= (C_LINE_TYPE)1 || (item.AnnotHandlerEventArgs as LineAnnotArgs).TailLineType >= (C_LINE_TYPE)1)
- {
- //箭头
- SharpArrowVisibility = Visibility.Visible;
- }
- else
- {
- //线
- SharpLineVisibility = Visibility.Visible;
- }
- SetColor((item.AnnotHandlerEventArgs as LineAnnotArgs).LineColor);
- break;
- case AnnotArgsType.AnnotSquare://矩形
- if (data is SquareAnnotArgs squareAnnotArgs)
- {
- SetColor(squareAnnotArgs.BgColor);
- SetColor(squareAnnotArgs.LineColor);
- }
- AnnotSquareVisibility = Visibility.Visible;
- break;
- case AnnotArgsType.AnnotCircle://圆
- if (data is CircleAnnotArgs circleAnnotArgs)
- {
- SetColor(circleAnnotArgs.BgColor);
- SetColor(circleAnnotArgs.LineColor);
- }
- AnnotCircleVisibility = Visibility.Visible;
- break;
- }
- }
- //AnnotationAuthor = AnnotationAuthor.MyDistinct(s => s.Name) as ObservableCollection<AuthorItem>;
- //AnnotationColors = AnnotationColors.MyDistinct(s => s.Color) as ObservableCollection<ColorItem>;
- AnnotationAuthor = new ObservableCollection<AuthorItem>(AnnotationAuthor.MyDistinct(s => s.Name));
- //AnnotationColors = new ObservableCollection<ColorItem>(AnnotationColors.MyDistinct(s => s.Color));
- }
- }
- }
|