123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866 |
- using ComPDFKitViewer;
- using ComPDFKitViewer.PdfViewer;
- using Microsoft.Win32;
- using PDF_Office.CustomControl.CompositeControl;
- using PDF_Office.Model;
- using PDF_Office.Model.PropertyPanel.AnnotPanel;
- using Prism.Commands;
- using Prism.Mvvm;
- using Prism.Regions;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Input;
- using System.Windows.Media;
- namespace PDF_Office.ViewModels.PropertyPanel.PDFEdit
- {
- public class TextEditPropertyViewModel : PDFEditVM, INavigationAware
- {
- private ComboDataItem _fontFamilyData;
- public ComboDataItem FontFamilyData
- {
- get { return _fontFamilyData; }
- set
- {
- SetProperty(ref _fontFamilyData, value);
- if(_fontFamilyData != null && TextEditEvent != null)
- {
- TextEditEvent.FontFamily = new FontFamily(_fontFamilyData.ValueStr);
- TextEditEvent.UpdatePDFEditByEventArgs();
- }
- }
- }
- private ComboDataItem _presetTextData;
- public ComboDataItem PresetTextData
- {
- get { return _presetTextData; }
- set
- {
- SetProperty(ref _presetTextData, value);
- if(_presetTextData != null && FontStyleList != null)
- {
- var item = FontStyleList.FirstOrDefault(temp => temp.mTag == _presetTextData.ValueStr);
- if(item != null && TextEditEvent != null)
- {
- TextEditEvent.FontFamily = item.mFontFamily;
- TextEditEvent.FontSize = item.mFontSize;
- TextEditEvent.FontWeight = item.mFontWeight;
- TextEditEvent.FontStyle = item.mFontStyle;
- TextEditEvent.UpdatePDFEditByEventArgs();
- }
-
- }
- }
- }
- private FontStyle _fontStyle;
- public FontStyle FontStyleItem
- {
- get { return _fontStyle; }
- set {SetProperty(ref _fontStyle, value);}
- }
- private FontWeight _fontWeight;
- public FontWeight FontWeightItem
- {
- get { return _fontWeight; }
- set { SetProperty(ref _fontWeight, value); }
- }
- private ComboDataItem _fontWeightStyleItem;
- public ComboDataItem FontWeightStyleItem
- {
- get { return _fontWeightStyleItem; }
- set
- {
- SetProperty(ref _fontWeightStyleItem, value);
- if (_fontWeightStyleItem.ValueStr != null && string.IsNullOrEmpty((string)_fontWeightStyleItem.ValueStr) == false)
- {
- switch ((string)_fontWeightStyleItem.ValueStr)
- {
- case "Regular":
- FontStyleItem = FontStyles.Normal;
- FontWeightItem = FontWeights.Normal;
- break;
- case "Bold":
- FontStyleItem = FontStyles.Normal;
- FontWeightItem = FontWeights.Bold;
- break;
- case "Italic":
- FontStyleItem = FontStyles.Italic;
- FontWeightItem = FontWeights.Normal;
- break;
- case "Bold Italic":
- FontStyleItem = FontStyles.Italic;
- FontWeightItem = FontWeights.Bold;
- break;
- }
- TextEditEvent.FontWeight = FontWeightItem;
- TextEditEvent.FontStyle = FontStyleItem;
- TextEditEvent.UpdatePDFEditByEventArgs();
- }
- }
- }
- private ComboDataItem _fontSizeData = new ComboDataItem(6);
- public ComboDataItem FontSizeData
- {
- get { return _fontSizeData; }
- set
- {
- SetProperty(ref _fontSizeData, value);
- if (_fontSizeData != null && TextEditEvent != null)
- {
- TextEditEvent.FontSize = _fontSizeData.Value;
- TextEditEvent.UpdatePDFEditByEventArgs();
- }
- }
- }
- public List<ComboDataItem> FontFamilyItems { get; private set; }
- public List<ComboDataItem> FontStyleItems { get; private set; }
- public List<ComboDataItem> PresetTextItems { get; private set; }
- #region 属性
- #region 文本属性
- private double _angle;
- public double Angle{ get { return _angle; }set{ SetProperty(ref _angle, value);}}
- private Brush selectColor = new SolidColorBrush(Colors.Black);
- public Brush SelectColor {
- get { return selectColor; }
- set{
- SetProperty(ref selectColor, value);
- if (TextEditEvent != null)
- {
- bool isok = TextEditEvent.FontColor.A != (SelectColor as SolidColorBrush).Color.A ||TextEditEvent.FontColor.B != (SelectColor as SolidColorBrush).Color.B ||
- TextEditEvent.FontColor.G != (SelectColor as SolidColorBrush).Color.G ||TextEditEvent.FontColor.R != (SelectColor as SolidColorBrush).Color.R;
- if (isok)
- {
- TextEditEvent.FontColor = (SelectColor as SolidColorBrush).Color;
- TextEditEvent.UpdatePDFEditByEventArgs();
- }
- }
- }
- }
- private FontFamily fontFamily = new FontFamily("Courier");
- public FontFamily TextFontFamily
- {
- get { return fontFamily; }
- set
- {
- SetProperty(ref fontFamily, value);
- if (TextEditEvent != null && fontFamily != null)
- {
- TextEditEvent.FontFamily = fontFamily;
- TextEditEvent.UpdatePDFEditByEventArgs();
- }
- }
- }
- private FontWeight fontWeights = FontWeights.Normal;
- public FontWeight TextFontWeights
- {
- get { return fontWeights; }
- set
- {
- SetProperty(ref fontWeights, value);
- if (TextEditEvent != null && fontWeights != null)
- {
- TextEditEvent.FontWeight = fontWeights;
- TextEditEvent.UpdatePDFEditByEventArgs();
- }
- }
- }
- private FontStyle fontStyle = FontStyles.Normal;
- public FontStyle TextFontStyle
- {
- get { return fontStyle; }
- set
- {
- SetProperty(ref fontStyle, value);
- if (TextEditEvent != null && fontStyle != null)
- {
- TextEditEvent.FontStyle = fontStyle;
- TextEditEvent.UpdatePDFEditByEventArgs();
- }
- }
- }
- private int fontSize = 24;
- public int TextFontSize
- {
- get { return fontSize; }
- set
- {
- SetProperty(ref fontSize, value);
- if (TextEditEvent != null)
- {
- TextEditEvent.FontSize = fontSize;
- TextEditEvent.UpdatePDFEditByEventArgs();
- }
- }
- }
- private List<FontStyleItem> fontStyleList = new List<FontStyleItem>();
- public List<FontStyleItem> FontStyleList
- {
- get { return fontStyleList; }
- set
- {
- SetProperty(ref fontStyleList, value);
- }
- }
- #endregion
- #region 图像属性
- private bool _isCrop = false;
- public bool IsCrop
- {
- get { return _isCrop; }
- set
- {
- SetProperty(ref _isCrop, value);
- }
- }
- //选中的图像
- private System.Windows.Media.Imaging.BitmapSource _currentImg;
- public System.Windows.Media.Imaging.BitmapSource CurrentImg
- {
- get { return _currentImg; }
- set
- {
- SetProperty(ref _currentImg, value);
-
- }
- }
- #endregion
- #endregion
- #region Command
-
- #region 文本Command
- public DelegateCommand AddTextCommand { get; set; }
- public DelegateCommand AddImgCommand { get; set; }
- public DelegateCommand<object> SelectedColorCommand { get; set; }
- public DelegateCommand<object> SelectedFontStyleCommand { get; set; }
- public DelegateCommand<object> FontFamilyChangedCommand { get; set; }
- public DelegateCommand<object> FontStyleChangedCommand { get; set; }
- public DelegateCommand<object> FontSizeChangedCommand { get; set; }
- public DelegateCommand<object> TextAlignCheckedCommand { get; set; }
- public DelegateCommand EditTextModeCommand { get; set; }
- #endregion
- #region 图像Command
- public DelegateCommand ReplaceImgCommand { get; set; }
- public DelegateCommand ExportImgCommand { get; set; }
- public DelegateCommand CropImgCommand { get; set; }
- public DelegateCommand<object> ImgAlignCheckedCommand { get; set; }
-
- /// <summary>
- /// 逆时针旋转
- /// </summary>
- public DelegateCommand AntiClockwiseCommand { get; set; }
- /// <summary>
- /// 顺时针旋转
- /// </summary>
- public DelegateCommand ClockwiseCommand { get; set; }
- public DelegateCommand CropModeCommand { get; set; }
- public DelegateCommand CancelCropCommand { get; set; }
- #endregion
- #endregion
- #region 初始化
- public TextEditPropertyViewModel()
- {
- InitVariable();
- InitCommand();
- }
- private void InitVariable()
- {
- InitFontStyles();
- InitFontFamilyComboBox();
- InitFontStyleComboBox();
- InitFontStyles();
- }
- private void InitFontFamilyComboBox()
- {
- FontFamilyItems = TextFont.GetFamily();
- }
- private void InitFontStyleComboBox()
- {
- FontStyleItems = TextFont.GetFontStyle();
- }
- private void InitFontStyles()
- {
- PresetTextItems = new List<ComboDataItem>();
- FontStyleList = TextFont.GetPresetFontStyle();
- foreach(var item in FontStyleList)
- {
- ComboDataItem itemData = new ComboDataItem(item.mTag, item.mTagContent);
- PresetTextItems.Add(itemData);
- }
-
- }
- private void InitCommand()
- {
- AddTextCommand = new DelegateCommand(AddText);
- AddImgCommand = new DelegateCommand(AddImg);
- ReplaceImgCommand = new DelegateCommand(ReplaceImg);
- ExportImgCommand = new DelegateCommand(ExportImg);
- CropImgCommand = new DelegateCommand(CropImg);
- ImgAlignCheckedCommand = new DelegateCommand<object>(ImgAlignChecked);
- SelectedColorCommand = new DelegateCommand<object>(SelectedColor);
- SelectedFontStyleCommand = new DelegateCommand<object>(SelectedFontStyle);
- FontFamilyChangedCommand = new DelegateCommand<object>(FontFamilyChanged);
- FontStyleChangedCommand = new DelegateCommand<object>(FontStyleChanged);
- FontSizeChangedCommand = new DelegateCommand<object>(FontSizeChanged);
- TextAlignCheckedCommand = new DelegateCommand<object>(TextAlignChecked);
- EditTextModeCommand = new DelegateCommand(EditTextMode);
- AntiClockwiseCommand = new DelegateCommand(AntiClockwise);
- ClockwiseCommand = new DelegateCommand(Clockwise);
- CropModeCommand = new DelegateCommand(CropMode);
- CancelCropCommand = new DelegateCommand(CancelCropImg);
- }
- #endregion
- #region 文本处理
- private void AddText()
- {
- PDFViewer.SetPDFEditCreateType(ComPDFKit.PDFPage.CPDFEditType.EditText);
- }
- private void EditTextMode()
- {
- }
- private void TextAlignChecked(object obj)
- {
- if ((string)obj != null && TextEditEvent != null)
- {
- switch ((string)obj)
- {
- case "AlignLeft":
- TextEditEvent.TextAlign = ComPDFKit.PDFPage.Edit.TextAlignType.AlignLeft;
- break;
- case "AlignCenter":
- TextEditEvent.TextAlign = ComPDFKit.PDFPage.Edit.TextAlignType.AlignMiddle;
- break;
- case "AlignRight":
- TextEditEvent.TextAlign = ComPDFKit.PDFPage.Edit.TextAlignType.AlignRight;
- break;
- case "Align":
- TextEditEvent.TextAlign = ComPDFKit.PDFPage.Edit.TextAlignType.AlignNone;
- break;
- }
- TextEditEvent.UpdatePDFEditByEventArgs();
- }
- }
- private void Clockwise()
- {
- Angle = TextEditEvent.Rotate = TextEditEvent.Rotate + 90;
- TextEditEvent.UpdatePDFEditByEventArgs();
- }
- private void AntiClockwise()
- {
- if ( TextEditEvent != null)
- {
- Angle = TextEditEvent.Rotate = TextEditEvent.Rotate - 90;
- TextEditEvent.UpdatePDFEditByEventArgs();
- }
-
- }
- private void SelectedColor(object obj)
- {
- if (obj != null)
- {
- var colorValue = (Color)obj;
- if (colorValue != null)
- {
- SelectColor = new SolidColorBrush(colorValue);
- }
- }
- }
- private void SelectedFontStyle(object obj)
- {
- if (obj != null && (FontStyleItem)obj != null)
- {
- var item = (FontStyleItem)obj;
- }
- }
- private void FontFamilyChanged(object obj)
- {
- if (obj != null && (int)obj > -1)
- {
- switch ((int)obj)
- {
- case 0: TextFontFamily = new FontFamily("Courier"); break;
- case 1: TextFontFamily = new FontFamily("Helvetica"); break;
- case 2: TextFontFamily = new FontFamily("Times"); break;
- }
- }
- }
- private void FontStyleChanged(object obj)
- {
- if (obj != null && (ComboBoxItem)obj != null)
- {
- var item = (ComboBoxItem)obj;
- var content = (string)item.Content;
- if (content != null)
- {
- switch (content)
- {
- case "Regular":
- TextFontWeights = FontWeights.Normal;
- TextFontStyle = FontStyles.Normal;
- break;
- case "Bold":
- TextFontWeights = FontWeights.Bold;
- TextFontStyle = FontStyles.Normal;
- break;
- case "Italic":
- TextFontWeights = FontWeights.Normal;
- TextFontStyle = FontStyles.Italic;
- break;
- case "Bold Italic":
- TextFontWeights = FontWeights.Bold;
- TextFontStyle = FontStyles.Italic;
- break;
- }
- }
- }
- }
- private void FontSizeChanged(object obj)
- {
- if (obj != null)
- {
- var item = (ComboBoxItem)obj;
- var content = (string)item.Content;
- if (content != null)
- {
- var intData = int.Parse(content);
- TextFontSize = intData;
- }
- }
- }
- #endregion
- #region 图像处理
- private void CancelCropImg()
- {
- if (TextEditEvent != null)
- {
- TextEditEvent.ClipImage = false;
- TextEditEvent.CancelClip();
- TextEditEvent.UpdatePDFEditByEventArgs();
- IsCrop = false;
- }
- }
- private void CropImg()
- {
- if (TextEditEvent != null)
- {
- TextEditEvent.SaveClip();
- TextEditEvent.ClipImage = false;
- TextEditEvent.UpdatePDFEditByEventArgs();
- IsCrop = false;
- }
- }
- private void ExportImg()
- {
- if (PDFViewer == null || TextEditEvent == null || TextEditEvent.EditType != ComPDFKit.PDFPage.CPDFEditType.EditImage) return;
- System.Windows.Forms.FolderBrowserDialog folder = new System.Windows.Forms.FolderBrowserDialog();
- folder.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
- if (folder.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- if (string.IsNullOrEmpty(folder.SelectedPath))
- return;
- var keyValueList = PDFViewer.GetSelectedImages();
- int i = 0;
- foreach (var bitmap in keyValueList)
- {
- foreach (var bitmapItem in bitmap.Value)
- {
- bitmapItem.Save(folder.SelectedPath + "\\" + i + ".png", System.Drawing.Imaging.ImageFormat.Png);
- i++;
- }
- }
- }
- }
- private void AddImg()
- {
- OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.Filter = "png|*.png;|Image|*.gif;*.jpg;*.jpeg;*.bmp;*.jfif;*.png;";
- openFileDialog.Multiselect = true;
- if ((bool)openFileDialog.ShowDialog())
- {
- if (string.IsNullOrEmpty(openFileDialog.FileName) == false)
- {
- PDFViewer.SetPDFEditCreateType(ComPDFKit.PDFPage.CPDFEditType.EditImage);
- PDFViewer.AddPDFEditImage(openFileDialog.FileName);
- }
- }
- }
- private void ReplaceImg()
- {
- if (TextEditEvent == null) return;
- OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.Filter = "png|*.png;|Image|*.gif;*.jpg;*.jpeg;*.bmp;*.jfif;*.png;";
- openFileDialog.Multiselect = true;
- if ((bool)openFileDialog.ShowDialog())
- {
- if (string.IsNullOrEmpty(openFileDialog.FileName) == false)
- {
- PDFViewer.SetPDFEditCreateType(ComPDFKit.PDFPage.CPDFEditType.EditImage);
- TextEditEvent.ReplaceImagePath = openFileDialog.FileName;
- TextEditEvent.UpdatePDFEditByEventArgs();
- }
- }
- }
- private void CropMode()
- {
- IsCrop = true;
- if (TextEditEvent != null)
- {
- TextEditEvent.ClipImage = true;
- TextEditEvent.UpdatePDFEditByEventArgs();
- }
- }
- #endregion
- #region 布局处理
- private void ImgAlignChecked(object obj)
- {
- if (obj != null)
- {
- switch ((string)obj)
- {
- case "AlignLeft":
- PDFViewer.SetPDFEditAligment(AlignModes.AlignLeft);
- break;
- case "AlignHorizonCenter":
- PDFViewer.SetPDFEditAligment(AlignModes.AlignHorizonCenter);
- break;
- case "AlignRight":
- PDFViewer.SetPDFEditAligment(AlignModes.AlignRight);
- break;
- case "DistributeHorizontal":
- PDFViewer.SetPDFEditAligment(AlignModes.DistributeHorizontal);
- break;
- case "AlignTop":
- PDFViewer.SetPDFEditAligment(AlignModes.AlignTop);
- break;
- case "AlignVerticalCenter":
- PDFViewer.SetPDFEditAligment(AlignModes.AlignVerticalCenter);
- break;
- case "AlignBottom":
- PDFViewer.SetPDFEditAligment(AlignModes.AlignBottom);
- break;
- case "DistributeVertical":
- PDFViewer.SetPDFEditAligment(AlignModes.DistributeVertical);
- break;
- }
- }
- }
- private void ReLoadLayoutAlign(int count)
- {
- if (count >= 2)
- IsLayoutAlign = true;
- else
- IsLayoutAlign = false;
- if (count >= 3)
- IsLayoutAvgAlign = true;
- else
- IsLayoutAvgAlign = false;
- }
- #endregion
- #region 右键菜单
- //点击空白处时
- private ContextMenu EmptyStateMenu(object sender)
- {
- var popMenu = App.Current.FindResource("NoneMenu") as ContextMenu;
- if (popMenu != null && popMenu.Items.Count == 3)
- {
- //粘贴
- SetPopMenuItem(popMenu.Items[0] as MenuItem, sender, ApplicationCommands.Paste);
- //添加文本
- SetPopMenuItem(popMenu.Items[1] as MenuItem, sender, AddTextCommand);
- //添加图像
- SetPopMenuItem(popMenu.Items[2] as MenuItem, sender, AddImgCommand);
- }
- return popMenu;
- }
- //选中图像时
- private ContextMenu SelectImgPDFEdit(object sender)
- {
- var popMenu = App.Current.FindResource("SelectImgMenu") as ContextMenu;
- if (popMenu != null && popMenu.Items.Count == 7)
- {
- //复制
- SetPopMenuItem(popMenu.Items[0] as MenuItem, sender, ApplicationCommands.Copy);
- //剪切
- SetPopMenuItem(popMenu.Items[1] as MenuItem, sender, ApplicationCommands.Cut);
- //粘贴
- SetPopMenuItem(popMenu.Items[2] as MenuItem, sender, ApplicationCommands.Paste);
- //删除
- SetPopMenuItem(popMenu.Items[3] as MenuItem, sender, ApplicationCommands.Delete);
- //裁剪
- SetPopMenuItem(popMenu.Items[4] as MenuItem, sender, CropModeCommand);
- //替换
- SetPopMenuItem(popMenu.Items[5] as MenuItem, sender, ReplaceImgCommand);
- //导出
- SetPopMenuItem(popMenu.Items[6] as MenuItem, sender, ExportImgCommand);
- }
- return popMenu;
- }
- //选中文字的框
- private ContextMenu SelectTextBorder(object sender)
- {
- var popMenu = App.Current.FindResource("SelectTextMenu") as ContextMenu;
- if (popMenu != null && popMenu.Items.Count == 5)
- {
- //编辑
- SetPopMenuItem(popMenu.Items[0] as MenuItem, sender, EditTextModeCommand);
- //复制
- SetPopMenuItem(popMenu.Items[1] as MenuItem, sender, ApplicationCommands.Copy);
- //剪切
- SetPopMenuItem(popMenu.Items[2] as MenuItem, sender, ApplicationCommands.Cut);
- //粘贴
- SetPopMenuItem(popMenu.Items[3] as MenuItem, sender, ApplicationCommands.Paste);
- //删除
- SetPopMenuItem(popMenu.Items[4] as MenuItem, sender, ApplicationCommands.Delete);
- }
- return popMenu;
- }
- //选中文字内容
- private ContextMenu SelectTextContent(object sender)
- {
- var popMenu = App.Current.FindResource("SelectContentMenu") as ContextMenu;
- if (popMenu != null && popMenu.Items.Count == 6)
- {
- //复制
- SetPopMenuItem(popMenu.Items[0] as MenuItem, sender, ApplicationCommands.Copy);
- //剪切
- SetPopMenuItem(popMenu.Items[1] as MenuItem, sender, ApplicationCommands.Cut);
- //粘贴
- SetPopMenuItem(popMenu.Items[2] as MenuItem, sender, ApplicationCommands.Paste);
- //粘贴并匹配样式
- SetPopMenuItem(popMenu.Items[3] as MenuItem, sender, ApplicationCommands.Paste);
- //删除
- SetPopMenuItem(popMenu.Items[4] as MenuItem, sender, ApplicationCommands.Delete);
- ////全部选定
- SetPopMenuItem(popMenu.Items[5] as MenuItem, sender, ApplicationCommands.SelectAll);
- }
- return popMenu;
- }
- #endregion
- #region 编辑PDF内容触发的事件
- /// <summary>
- /// 右键菜单的事件
- /// </summary>
- private void PDFViewer_PDFEditCommandHandler(object sender, PDFEditCommand e)
- {
- if (e == null)
- return;
- switch (e.CommandType)
- {
- case CommandType.Context:
- if (e.EditType == ComPDFKit.PDFPage.CPDFEditType.None)
- {
- e.PopupMenu = EmptyStateMenu(sender);
- }
- else if (e.EditType == ComPDFKit.PDFPage.CPDFEditType.EditImage)
- {
- e.PopupMenu = SelectImgPDFEdit(sender);
- }
- else if (e.EditType == ComPDFKit.PDFPage.CPDFEditType.EditText)
- {
- //文字编辑
- if (e.PressOnBorder == true)
- {
- e.PopupMenu = SelectTextBorder(sender);
- }
- if (e.PressOnSelectedText == true)
- {
- e.PopupMenu = SelectTextContent(sender);
- }
- }
- break;
- default:
- e.DoCommand();
- break;
- }
- if (e.PopupMenu != null)
- {
- e.Handle = true;
- }
- }
-
- #region 全局
- public event EventHandler ClearCheckedAglin;
- #endregion
- #endregion
- protected List<PDFEditEvent> TextEditEventList;
- public void OnNavigatedTo(NavigationContext navigationContext)
- {
- navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
- navigationContext.Parameters.TryGetValue<List<PDFEditEvent>>(ParameterNames.AnnotEvent, out TextEditEventList);
- if (PDFViewer != null)
- {
- if (TextEditEventList != null && TextEditEventList.Count > 0)
- {
- TextEditEvent = TextEditEventList[0];
- GetPDFEdit();
- if (TextEditEventList.Count == 2)
- {
- IsLayoutAlign = true;
- IsLayoutAvgAlign = false;
- }
- else if(TextEditEventList.Count >2)
- {
- IsLayoutAlign = true;
- IsLayoutAvgAlign = true;
- }
- else
- {
- IsLayoutAlign = false;
- IsLayoutAvgAlign = false;
- }
- }
- PDFViewer.PDFEditCommandHandler -= PDFViewer_PDFEditCommandHandler;
- PDFViewer.PDFEditCommandHandler += PDFViewer_PDFEditCommandHandler;
- }
- }
- private void GetPDFEdit()
- {
- if(TextEditEvent != null)
- {
- TextFontFamily = TextEditEvent.FontFamily;
- //TextFontSize = (int)TextEditEvent.FontSize;
- TextFontStyle = TextEditEvent.FontStyle;
- TextFontWeights = TextEditEvent.FontWeight;
- SelectColor = new SolidColorBrush(TextEditEvent.FontColor);
- FontSizeData = new ComboDataItem(TextEditEvent.FontSize);
- }
- }
- public bool IsNavigationTarget(NavigationContext navigationContext){ return true; }
-
- public void OnNavigatedFrom(NavigationContext navigationContext)
- {
- TextEditEvent = null;
- ClearCheckedAglin?.Invoke(null, null);
- PDFViewer.PDFEditCommandHandler -= PDFViewer_PDFEditCommandHandler;
- }
- }
- }
|