123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421 |
- using ComPDFKit.PDFDocument;
- using ComPDFKit.PDFWatermark;
- using ComPDFKitViewer.AnnotEvent;
- using ComPDFKitViewer.PdfViewer;
- using PDF_Office.EventAggregators;
- using PDF_Office.Helper;
- using PDF_Office.Model;
- using PDF_Office.Model.EditTools.Background;
- using PDF_Office.Model.EditTools.Watermark;
- using Prism.Commands;
- using Prism.Events;
- using Prism.Mvvm;
- using Prism.Regions;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Windows.Media;
- namespace PDF_Office.ViewModels.EditTools.Watermark
- {
- public class WatermarkCreateTextContentViewModel : BindableBase,INavigationAware
- {
- public WatermarkInfo WatermarkInfo = new WatermarkInfo();
- IEventAggregator eventAggregator;
- private CPDFViewer PDFViewer;
- private List<string> _opacityList = new List<string>();
- public List<string> OpacityList
- {
- get { return _opacityList; }
- set
- {
- SetProperty(ref _opacityList, value);
- }
- }
- private void InitOpacityList()
- {
- OpacityList.Clear();
- for (int temp = 0; temp <= 100; temp += 10)
- {
- OpacityList.Add(temp.ToString() + " %");
- }
- }
- private List<string> _rotationList = new List<string>();
- public List<string> RotationList
- {
- get { return _rotationList; }
- set
- {
- SetProperty(ref _rotationList, value);
- }
- }
- private void InitRotationList()
- {
- RotationList.Clear();
- for (int temp = -45; temp <= 45; temp += 15)
- {
- RotationList.Add(temp.ToString());
- }
- }
- private List<string> _fontNameList = new List<string>();
- public List<string> FontNameList
- {
- get { return _fontNameList; }
- set
- {
- SetProperty(ref _fontNameList, value);
- }
- }
- private void InitFontNameList()
- {
- FontNameList.Clear();
- FontNameList.Add("Courier");
- FontNameList.Add("Courier-Bold");
- FontNameList.Add("Courier-Oblique");
- FontNameList.Add("Courier-BoldOblique");
- FontNameList.Add("Helvetica");
- FontNameList.Add("Helvetica-Bold");
- FontNameList.Add("Helvetica-Oblique");
- FontNameList.Add("Helvetica-BoldOblique");
- FontNameList.Add("Times-Roman");
- FontNameList.Add("Times-Bold");
- FontNameList.Add("Times-Italic");
- FontNameList.Add("Times-BoldItalic");
- }
- private List<string> _fontSizeList = new List<string>();
- public List<string> FontSizeList
- {
- get { return _fontSizeList; }
- set
- {
- SetProperty(ref _fontSizeList, value);
- }
- }
- private void InitFontSizeList()
- {
- FontSizeList.Clear();
- FontSizeList.Add("自动");
- for (int temp = 8; temp <= 15; temp += 1)
- {
- FontSizeList.Add(temp.ToString() + "pt");
- }
- }
- private List<string> _scaleList = new List<string>();
- public List<string> ScaleList
- {
- get { return _scaleList; }
- set
- {
- SetProperty(ref _scaleList, value);
- }
- }
- private void InitScaleList()
- {
- ScaleList.Clear();
- for (int temp = 0; temp <= 100; temp += 10)
- {
- ScaleList.Add(temp.ToString() + " %");
- }
- }
- private List<string> _isFrontList = new List<string>();
- public List<string> IsFrontList
- {
- get { return _isFrontList; }
- set
- {
- SetProperty(ref _isFrontList, value);
- }
- }
- private void InitIsFrontList()
- {
- IsFrontList.Clear();
- IsFrontList.Add("位于页面上方");
- IsFrontList.Add("位于页面下方");
- }
- private string _textValue = "一个水印";
- public string TextValue
- {
- get { return _textValue; }
- set
- {
- SetProperty(ref _textValue, value);
- WatermarkInfo.Text = TextValue;
- }
- }
- private int _rotationValue = 0;
- public int RotationValue
- {
- get { return _rotationValue; }
- set
- {
- SetProperty(ref _rotationValue, value);
- WatermarkInfo.Rotation = (float)RotationValue;
- }
- }
- private int _opacityValue = 100;
- public int OpacityValue
- {
- get { return _opacityValue; }
- set
- {
- SetProperty(ref _opacityValue, value);
- WatermarkInfo.Opacity = (byte)(((float)OpacityValue/100)*225);
- }
- }
- private int _relativeScaleValue = 50;
- public int RelativeScaleValue
- {
- get { return _relativeScaleValue; }
- set
- {
- SetProperty(ref _relativeScaleValue, value);
- }
- }
- private string _vertOffsetValue = "0";
- public string VertOffsetValue
- {
- get { return _vertOffsetValue; }
- set
- {
- SetProperty(ref _vertOffsetValue, value);
- WatermarkInfo.VertOffset = float.Parse(VertOffsetValue);
- }
- }
- private string _horizOffsetValue = "0";
- public string HorizOffsetValue
- {
- get { return _horizOffsetValue; }
- set
- {
- SetProperty(ref _horizOffsetValue, value);
- WatermarkInfo.HorizOffset = float.Parse(HorizOffsetValue);
- }
- }
- private string _verticalSpacingValue = "6";
- public string VerticalSpacingValue
- {
- get { return _verticalSpacingValue; }
- set
- {
- SetProperty(ref _verticalSpacingValue, value);
- WatermarkInfo.VerticalSpacing = float.Parse(VerticalSpacingValue);
- }
- }
- private string _horizontalSpacingValue = "6";
- public string HorizontalSpacingValue
- {
- get { return _horizontalSpacingValue; }
- set
- {
- SetProperty(ref _horizontalSpacingValue, value);
- WatermarkInfo.HorizontalSpacing = float.Parse(HorizontalSpacingValue);
- }
- }
- private int _fontSizeSelectedIndex=0;
- public int FontSizeSelectedIndex
- {
- get { return _fontSizeSelectedIndex; }
- set
- {
- SetProperty(ref _fontSizeSelectedIndex, value);
- SetFontSize(FontSizeSelectedIndex);
- }
- }
- private int _fontNameSelectedIndex=0;
- public int FontNameSelectedIndex
- {
- get { return _fontNameSelectedIndex; }
- set
- {
- SetProperty(ref _fontNameSelectedIndex, value);
- SetFontName(FontNameSelectedIndex);
- }
- }
- private int _isFrontSelectedIndex=0;
- public int IsFrontSelectedIndex
- {
- get { return _isFrontSelectedIndex; }
- set
- {
- SetProperty(ref _isFrontSelectedIndex, value);
- SetIsFront(IsFrontSelectedIndex);
- }
- }
- private string _stringColor = "#FF0000";
- public string StringColor
- {
- get
- {
- return _stringColor;
- }
- set
- {
- _stringColor= value;
- WatermarkInfo.TextColor = EditToolsHelper.ConvertColor(value);
- }
- }
- public string PageRangeText { get; set; } = "0";
- private int _pageRangeSelectIndex = 0;
- public int PageRangeSelectIndex
- {
- get { return _pageRangeSelectIndex; }
- set
- {
- SetProperty(ref _pageRangeSelectIndex, value);
- EditToolsHelper.GetPageRange(PageRangeSelectIndex, PDFViewer.Document, ref WatermarkInfo.PageRange, PageRangeText);
- }
- }
- private ObservableDictionary<string, bool> _getLocationFromNumber = new ObservableDictionary<string, bool>();
- public ObservableDictionary<string, bool> GetLocationFromNumber
- {
- get { return _getLocationFromNumber; }
- set { _getLocationFromNumber = value; }
- }
- public DelegateCommand<object> ChangeLocationCommand { get; set; }
- public DelegateCommand<object> SelectedColorChangedCommand { get; set; }
- public WatermarkCreateTextContentViewModel(IEventAggregator eventAggregator)
- {
- this.eventAggregator=eventAggregator;
- WatermarkInfo.WatermarkType = C_Watermark_Type.WATERMARK_TYPE_TEXT;
- StringColor = "#FFFF00";
- ChangeLocationCommand = new DelegateCommand<object>(ChangeLocation);
- SelectedColorChangedCommand = new DelegateCommand<object>(SelectedColorChanged_Click);
- InitList();
- WatermarkInfo.WatermarkHorizalign = C_Watermark_Horizalign.WATERMARK_HORIZALIGN_CENTER;
- WatermarkInfo.WatermarkVertalign = C_Watermark_Vertalign.WATERMARK_VERTALIGN_CENTER;
- InitLocationButtonMatrix();
- eventAggregator.GetEvent<ConfirmEditToolsWatermarkEvent>().Subscribe(ConfirmEditToolsWatermark);
- }
- private void InitLocationButtonMatrix()
- {
- GetLocationFromNumber.Clear();
- for (var temp = 0; temp <= 22; temp++)
- {
- GetLocationFromNumber.Add(temp.ToString(), true);
- if (temp % 10 == 2)
- {
- temp += 7;
- }
- }
- int Num = (int)WatermarkInfo.WatermarkVertalign * 10 + (int)WatermarkInfo.WatermarkHorizalign;
- GetLocationFromNumber[Num.ToString()] = false;
- }
- public void ChangeLocation(object e)
- {
- string args = e as string;
- if (args != null)
- {
- WatermarkInfo.WatermarkVertalign = (C_Watermark_Vertalign)(int.Parse(args) / 10);
- WatermarkInfo.WatermarkHorizalign = (C_Watermark_Horizalign)(int.Parse(args) % 10);
- InitLocationButtonMatrix();
- }
- }
- private void SelectedColorChanged_Click(object obj)
- {
- if (obj != null)
- {
- var colorValue = (Color)obj;
- if (colorValue != null)
- {
- StringColor = colorValue.ToString();
- }
- }
- }
- private void SetFontName(int Index)
- {
- WatermarkInfo.FontName = FontNameList[Index];
- }
- private void SetFontSize(int Index)
- {
- if (Index == 0)
- {
- WatermarkInfo.TextSize = "10";
- }
- else
- {
- WatermarkInfo.TextSize =(Index+7).ToString();
- }
- }
- private void SetIsFront(int Index)
- {
- if (Index == 0)
- {
- WatermarkInfo.IsFront=true;
- }
- if (Index == 1) {
- WatermarkInfo.IsFront = false;
- }
- }
- public void ConfirmEditToolsWatermark(EnumTextOrFile enumTextOrFile)
- {
- if (enumTextOrFile == EnumTextOrFile.StatusText)
- {
- eventAggregator.GetEvent<SetWatermarkEvent>().Publish(WatermarkInfo);
- }
- }
- private void InitList() {
- InitOpacityList();
- InitFontNameList();
- InitFontSizeList();
- InitIsFrontList();
- InitRotationList();
- InitScaleList();
- }
- public bool IsNavigationTarget(NavigationContext navigationContext)
- {
- return true;
- }
- public void OnNavigatedFrom(NavigationContext navigationContext)
- {
- }
- public void OnNavigatedTo(NavigationContext navigationContext)
- {
- navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
- }
- }
- }
|