|
@@ -23,83 +23,41 @@ namespace PDF_Office.ViewModels.PropertyPanel
|
|
|
#region 属性
|
|
|
|
|
|
#region 编辑PDF全局
|
|
|
-
|
|
|
+ //多选时,选中的既是文本也是图像
|
|
|
private bool _isSelectTextAndImg = false;
|
|
|
- public bool IsSelectTextAndImg
|
|
|
- {
|
|
|
- get { return _isSelectTextAndImg; }
|
|
|
- set
|
|
|
- {
|
|
|
- SetProperty(ref _isSelectTextAndImg, value);
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
+ public bool IsSelectTextAndImg{get { return _isSelectTextAndImg; } set {SetProperty(ref _isSelectTextAndImg, value);}}
|
|
|
|
|
|
+ //平均对齐布局
|
|
|
private bool _isLayoutAvgAlign = false;
|
|
|
- public bool IsLayoutAvgAlign
|
|
|
- {
|
|
|
- get { return _isLayoutAvgAlign; }
|
|
|
- set
|
|
|
- {
|
|
|
- SetProperty(ref _isLayoutAvgAlign, value);
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
+ public bool IsLayoutAvgAlign { get { return _isLayoutAvgAlign; }set {SetProperty(ref _isLayoutAvgAlign, value); }}
|
|
|
+ //对齐布局
|
|
|
|
|
|
private bool _isLayoutAlign = false;
|
|
|
- public bool IsLayoutAlign
|
|
|
- {
|
|
|
- get { return _isLayoutAlign; }
|
|
|
- set
|
|
|
- {
|
|
|
- SetProperty(ref _isLayoutAlign, value);
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
+ public bool IsLayoutAlign {get { return _isLayoutAlign; }set{SetProperty(ref _isLayoutAlign, value);}}
|
|
|
+ //是否为文本
|
|
|
|
|
|
private bool _isTextEdit = true;
|
|
|
- public bool IsTextEdit
|
|
|
- {
|
|
|
- get { return _isTextEdit; }
|
|
|
- set
|
|
|
- {
|
|
|
- SetProperty(ref _isTextEdit, value);
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
+ public bool IsTextEdit {get { return _isTextEdit; }set{ SetProperty(ref _isTextEdit, value);} }
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
-
|
|
|
#region 文本属性
|
|
|
|
|
|
private double _angle;
|
|
|
- public double Angle
|
|
|
- {
|
|
|
- get { return _angle; }
|
|
|
- set
|
|
|
- {
|
|
|
- SetProperty(ref _angle, value);
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
+ public double Angle{ get { return _angle; }set{ SetProperty(ref _angle, value);}}
|
|
|
|
|
|
private Brush selectColor = new SolidColorBrush(Colors.Black);
|
|
|
- public Brush SelectColor
|
|
|
- {
|
|
|
+ public Brush SelectColor {
|
|
|
get { return selectColor; }
|
|
|
- set
|
|
|
- {
|
|
|
+ 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;
|
|
|
+ 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)
|
|
|
{
|
|
@@ -109,7 +67,6 @@ namespace PDF_Office.ViewModels.PropertyPanel
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -158,7 +115,6 @@ namespace PDF_Office.ViewModels.PropertyPanel
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
private int fontSize = 24;
|
|
|
public int TextFontSize
|
|
|
{
|
|
@@ -198,7 +154,7 @@ namespace PDF_Office.ViewModels.PropertyPanel
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ //选中的图像
|
|
|
private System.Windows.Media.Imaging.BitmapSource _currentImg;
|
|
|
public System.Windows.Media.Imaging.BitmapSource CurrentImg
|
|
|
{
|
|
@@ -214,9 +170,13 @@ namespace PDF_Office.ViewModels.PropertyPanel
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
-
|
|
|
#region Command
|
|
|
|
|
|
+ #region 全局
|
|
|
+
|
|
|
+ public event EventHandler ClearCheckedAglin;
|
|
|
+ #endregion
|
|
|
+
|
|
|
#region 文本Command
|
|
|
public DelegateCommand AddTextCommand { get; set; }
|
|
|
public DelegateCommand AddImgCommand { get; set; }
|
|
@@ -253,17 +213,19 @@ namespace PDF_Office.ViewModels.PropertyPanel
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
- public event EventHandler ClearCheckedAglin;
|
|
|
+ #endregion
|
|
|
|
|
|
+ #region 变量
|
|
|
+ private PDFEditEvent TextEditEvent;
|
|
|
+ private CPDFViewer PDFViewer;
|
|
|
#endregion
|
|
|
|
|
|
- private ComPDFKitViewer.PDFEditEvent TextEditEvent;
|
|
|
+ #region 初始化
|
|
|
public TextEditPropertyViewModel()
|
|
|
{
|
|
|
InitVariable();
|
|
|
InitCommand();
|
|
|
}
|
|
|
-
|
|
|
private void InitVariable()
|
|
|
{
|
|
|
InitFontStyles();
|
|
@@ -297,137 +259,25 @@ namespace PDF_Office.ViewModels.PropertyPanel
|
|
|
CancelCropCommand = new DelegateCommand(CancelCropImg);
|
|
|
}
|
|
|
|
|
|
- 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 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;
|
|
|
-
|
|
|
- //SaveFileDialog saveFileDialog = new SaveFileDialog();
|
|
|
- //saveFileDialog.Filter = "png|*.png;|Image|*.gif;*.jpg;*.jpeg;*.bmp;*.jfif;*.png;";
|
|
|
- //saveFileDialog.FileName = "编辑PDF导出图片";
|
|
|
-
|
|
|
- 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++;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+ #endregion
|
|
|
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
+ #region 文本处理
|
|
|
|
|
|
- private void AddImg()
|
|
|
+ private void AddText()
|
|
|
{
|
|
|
- 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);
|
|
|
- }
|
|
|
- }
|
|
|
+ PDFViewer.SetPDFEditCreateType(ComPDFKit.PDFPage.CPDFEditType.EditText);
|
|
|
}
|
|
|
|
|
|
- private void ReplaceImg()
|
|
|
+ private void EditTextMode()
|
|
|
{
|
|
|
- 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 AddText()
|
|
|
- {
|
|
|
- PDFViewer.SetPDFEditCreateType(ComPDFKit.PDFPage.CPDFEditType.EditText);
|
|
|
}
|
|
|
|
|
|
private void TextAlignChecked(object obj)
|
|
|
{
|
|
|
- if((string)obj != null && TextEditEvent != null)
|
|
|
+ if ((string)obj != null && TextEditEvent != null)
|
|
|
{
|
|
|
- switch((string)obj)
|
|
|
+ switch ((string)obj)
|
|
|
{
|
|
|
case "AlignLeft":
|
|
|
TextEditEvent.TextAlign = ComPDFKit.PDFPage.Edit.TextAlignType.AlignLeft;
|
|
@@ -440,7 +290,7 @@ namespace PDF_Office.ViewModels.PropertyPanel
|
|
|
case "AlignRight":
|
|
|
TextEditEvent.TextAlign = ComPDFKit.PDFPage.Edit.TextAlignType.AlignRight;
|
|
|
break;
|
|
|
-
|
|
|
+
|
|
|
case "Align":
|
|
|
TextEditEvent.TextAlign = ComPDFKit.PDFPage.Edit.TextAlignType.AlignNone;
|
|
|
break;
|
|
@@ -462,16 +312,6 @@ namespace PDF_Office.ViewModels.PropertyPanel
|
|
|
}
|
|
|
|
|
|
|
|
|
- private void CropMode()
|
|
|
- {
|
|
|
- IsCrop = true;
|
|
|
- if(TextEditEvent != null)
|
|
|
- {
|
|
|
- TextEditEvent.ClipImage = true;
|
|
|
- TextEditEvent.UpdatePDFEditByEventArgs();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
private void SelectedColor(object obj)
|
|
|
{
|
|
|
if (obj != null)
|
|
@@ -494,79 +334,52 @@ namespace PDF_Office.ViewModels.PropertyPanel
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
private void FontFamilyChanged(object obj)
|
|
|
{
|
|
|
- if (obj != null)
|
|
|
+ if (obj != null && (int)obj > -1)
|
|
|
{
|
|
|
- if ((int)obj > -1)
|
|
|
+ switch ((int)obj)
|
|
|
{
|
|
|
- if ((int)obj == 0)
|
|
|
- {
|
|
|
-
|
|
|
- TextFontFamily = new FontFamily("Courier");
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if ((int)obj == 1)
|
|
|
- {
|
|
|
- TextFontFamily = new FontFamily("Helvetica");
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if ((int)obj == 2)
|
|
|
- {
|
|
|
- TextFontFamily = new FontFamily("Times");
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
+ 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)
|
|
|
+ if (obj != null && (ComboBoxItem)obj != null)
|
|
|
{
|
|
|
var item = (ComboBoxItem)obj;
|
|
|
var content = (string)item.Content;
|
|
|
if (content != null)
|
|
|
{
|
|
|
- if (content == "Regular")
|
|
|
- {
|
|
|
- TextFontWeights = FontWeights.Normal;
|
|
|
- TextFontStyle = FontStyles.Normal;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (content == "Bold")
|
|
|
- {
|
|
|
- TextFontWeights = FontWeights.Bold;
|
|
|
- TextFontStyle = FontStyles.Normal;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (content == "Italic")
|
|
|
+ switch (content)
|
|
|
{
|
|
|
- TextFontWeights = FontWeights.Normal;
|
|
|
- TextFontStyle = FontStyles.Italic;
|
|
|
- }
|
|
|
-
|
|
|
- if (content == "Bold Italic")
|
|
|
- {
|
|
|
- TextFontWeights = FontWeights.Bold;
|
|
|
- TextFontStyle = FontStyles.Italic;
|
|
|
+ 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)
|
|
@@ -582,211 +395,307 @@ namespace PDF_Office.ViewModels.PropertyPanel
|
|
|
}
|
|
|
|
|
|
|
|
|
- private CPDFViewer PDFViewer;
|
|
|
+ #endregion
|
|
|
|
|
|
- public void OnNavigatedTo(NavigationContext navigationContext)
|
|
|
- {
|
|
|
+ #region 图像处理
|
|
|
|
|
|
- navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
|
|
|
- if (PDFViewer != null)
|
|
|
+ private void CancelCropImg()
|
|
|
+ {
|
|
|
+ if (TextEditEvent != null)
|
|
|
{
|
|
|
- PDFViewer.PDFEditActiveHandler -= PDFViewer_PDFEditActiveHandler;
|
|
|
- PDFViewer.PDFEditActiveHandler += PDFViewer_PDFEditActiveHandler;
|
|
|
+ TextEditEvent.ClipImage = false;
|
|
|
+ TextEditEvent.CancelClip();
|
|
|
|
|
|
- PDFViewer.PDFEditCommandHandler -= PDFViewer_PDFEditCommandHandler;
|
|
|
- PDFViewer.PDFEditCommandHandler += PDFViewer_PDFEditCommandHandler;
|
|
|
-
|
|
|
+ TextEditEvent.UpdatePDFEditByEventArgs();
|
|
|
+ IsCrop = false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public bool IsNavigationTarget(NavigationContext navigationContext)
|
|
|
- {
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public void OnNavigatedFrom(NavigationContext navigationContext)
|
|
|
+ private void CropImg()
|
|
|
{
|
|
|
+ if (TextEditEvent != null)
|
|
|
+ {
|
|
|
+ TextEditEvent.SaveClip();
|
|
|
+ TextEditEvent.ClipImage = false;
|
|
|
+ TextEditEvent.UpdatePDFEditByEventArgs();
|
|
|
+ IsCrop = false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- private void PDFViewer_PDFEditCommandHandler(object sender, PDFEditCommand e)
|
|
|
+ private void ExportImg()
|
|
|
{
|
|
|
+ if (PDFViewer == null || TextEditEvent == null || TextEditEvent.EditType != ComPDFKit.PDFPage.CPDFEditType.EditImage) return;
|
|
|
|
|
|
- if (e == null)
|
|
|
- return;
|
|
|
+ System.Windows.Forms.FolderBrowserDialog folder = new System.Windows.Forms.FolderBrowserDialog();
|
|
|
+ folder.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
|
|
|
|
|
- switch (e.CommandType)
|
|
|
+ if (folder.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
|
{
|
|
|
- case CommandType.Context:
|
|
|
-
|
|
|
- if (e.EditType == ComPDFKit.PDFPage.CPDFEditType.None)
|
|
|
- {
|
|
|
- e.PopupMenu = EmptyStateMenu(sender);
|
|
|
-
|
|
|
- }
|
|
|
- else if(e.EditType == ComPDFKit.PDFPage.CPDFEditType.EditImage)
|
|
|
+ if (string.IsNullOrEmpty(folder.SelectedPath))
|
|
|
+ return;
|
|
|
+
|
|
|
+ var keyValueList = PDFViewer.GetSelectedImages();
|
|
|
+ int i = 0;
|
|
|
+ foreach (var bitmap in keyValueList)
|
|
|
+ {
|
|
|
+ foreach (var bitmapItem in bitmap.Value)
|
|
|
{
|
|
|
- e.PopupMenu = SelectPDFEdit(sender);
|
|
|
+ bitmapItem.Save(folder.SelectedPath + "\\" + i + ".png", System.Drawing.Imaging.ImageFormat.Png);
|
|
|
+ i++;
|
|
|
}
|
|
|
- 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;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ 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);
|
|
|
+ }
|
|
|
}
|
|
|
- if (e.PopupMenu != null)
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ReplaceImg()
|
|
|
+ {
|
|
|
+ OpenFileDialog openFileDialog = new OpenFileDialog();
|
|
|
+ openFileDialog.Filter = "png|*.png;|Image|*.gif;*.jpg;*.jpeg;*.bmp;*.jfif;*.png;";
|
|
|
+ openFileDialog.Multiselect = true;
|
|
|
+ if ((bool)openFileDialog.ShowDialog())
|
|
|
{
|
|
|
- e.Handle = true;
|
|
|
+ if (string.IsNullOrEmpty(openFileDialog.FileName) == false)
|
|
|
+ {
|
|
|
+ PDFViewer.SetPDFEditCreateType(ComPDFKit.PDFPage.CPDFEditType.EditImage);
|
|
|
+ TextEditEvent.ReplaceImagePath = openFileDialog.FileName;
|
|
|
+ TextEditEvent.UpdatePDFEditByEventArgs();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- private void EditTextMode()
|
|
|
+
|
|
|
+ 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)
|
|
|
{
|
|
|
- //复制
|
|
|
- MenuItem menuItem = popMenu.Items[0] as MenuItem;
|
|
|
- menuItem.CommandTarget = (UIElement)sender;
|
|
|
- menuItem.Command = ApplicationCommands.Paste;
|
|
|
+ //粘贴
|
|
|
+ SetPopMenuItem(popMenu.Items[0] as MenuItem, sender, ApplicationCommands.Paste);
|
|
|
//添加文本
|
|
|
- menuItem = popMenu.Items[1] as MenuItem;
|
|
|
- menuItem.CommandTarget = (UIElement)sender;
|
|
|
- menuItem.Command = AddTextCommand;
|
|
|
+ SetPopMenuItem(popMenu.Items[1] as MenuItem, sender, AddTextCommand);
|
|
|
//添加图像
|
|
|
- menuItem = popMenu.Items[2] as MenuItem;
|
|
|
- menuItem.CommandTarget = (UIElement)sender;
|
|
|
- menuItem.Command = AddImgCommand;
|
|
|
+ SetPopMenuItem(popMenu.Items[2] as MenuItem, sender, AddImgCommand);
|
|
|
}
|
|
|
+
|
|
|
return popMenu;
|
|
|
}
|
|
|
-
|
|
|
- private ContextMenu SelectPDFEdit(object sender)
|
|
|
+ //选中图像时
|
|
|
+ private ContextMenu SelectImgPDFEdit(object sender)
|
|
|
{
|
|
|
var popMenu = App.Current.FindResource("SelectImgMenu") as ContextMenu;
|
|
|
if (popMenu != null && popMenu.Items.Count == 7)
|
|
|
{
|
|
|
//复制
|
|
|
- MenuItem menuItem = popMenu.Items[0] as MenuItem;
|
|
|
- menuItem.CommandTarget = (UIElement)sender;
|
|
|
- menuItem.Command = ApplicationCommands.Copy;
|
|
|
+ SetPopMenuItem(popMenu.Items[0] as MenuItem, sender, ApplicationCommands.Copy);
|
|
|
//剪切
|
|
|
- menuItem = popMenu.Items[1] as MenuItem;
|
|
|
- menuItem.CommandTarget = (UIElement)sender;
|
|
|
- menuItem.Command = ApplicationCommands.Cut;
|
|
|
+ SetPopMenuItem(popMenu.Items[1] as MenuItem, sender, ApplicationCommands.Cut);
|
|
|
//粘贴
|
|
|
- menuItem = popMenu.Items[2] as MenuItem;
|
|
|
- menuItem.CommandTarget = (UIElement)sender;
|
|
|
- menuItem.Command = ApplicationCommands.Paste;
|
|
|
+ SetPopMenuItem(popMenu.Items[2] as MenuItem, sender, ApplicationCommands.Paste);
|
|
|
//删除
|
|
|
- menuItem = popMenu.Items[3] as MenuItem;
|
|
|
- menuItem.CommandTarget = (UIElement)sender;
|
|
|
- menuItem.Command = ApplicationCommands.Delete;
|
|
|
+ SetPopMenuItem(popMenu.Items[3] as MenuItem, sender, ApplicationCommands.Delete);
|
|
|
//裁剪
|
|
|
- menuItem = popMenu.Items[4] as MenuItem;
|
|
|
- menuItem.CommandTarget = (UIElement)sender;
|
|
|
- menuItem.Command = CropModeCommand;
|
|
|
+ SetPopMenuItem(popMenu.Items[4] as MenuItem, sender, CropModeCommand);
|
|
|
//替换
|
|
|
- menuItem = popMenu.Items[5] as MenuItem;
|
|
|
- menuItem.CommandTarget = (UIElement)sender;
|
|
|
- menuItem.Command = ReplaceImgCommand;
|
|
|
+ SetPopMenuItem(popMenu.Items[5] as MenuItem, sender, ReplaceImgCommand);
|
|
|
//导出
|
|
|
- menuItem = popMenu.Items[6] as MenuItem;
|
|
|
- menuItem.CommandTarget = (UIElement)sender;
|
|
|
- menuItem.Command = ExportImgCommand;
|
|
|
-
|
|
|
+ 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)
|
|
|
{
|
|
|
//编辑
|
|
|
- MenuItem menuItem = popMenu.Items[0] as MenuItem;
|
|
|
- menuItem.CommandTarget = (UIElement)sender;
|
|
|
- menuItem.Command = EditTextModeCommand;
|
|
|
+ SetPopMenuItem(popMenu.Items[0] as MenuItem, sender, EditTextModeCommand);
|
|
|
//复制
|
|
|
- menuItem = popMenu.Items[1] as MenuItem;
|
|
|
- menuItem.CommandTarget = (UIElement)sender;
|
|
|
- menuItem.Command = ApplicationCommands.Copy;
|
|
|
+ SetPopMenuItem(popMenu.Items[1] as MenuItem, sender, ApplicationCommands.Copy);
|
|
|
//剪切
|
|
|
- menuItem = popMenu.Items[2] as MenuItem;
|
|
|
- menuItem.CommandTarget = (UIElement)sender;
|
|
|
- menuItem.Command = ApplicationCommands.Cut;
|
|
|
+ SetPopMenuItem(popMenu.Items[2] as MenuItem, sender, ApplicationCommands.Cut);
|
|
|
//粘贴
|
|
|
- menuItem = popMenu.Items[3] as MenuItem;
|
|
|
- menuItem.CommandTarget = (UIElement)sender;
|
|
|
- menuItem.Command = ApplicationCommands.Paste;
|
|
|
+ SetPopMenuItem(popMenu.Items[3] as MenuItem, sender, ApplicationCommands.Paste);
|
|
|
//删除
|
|
|
- menuItem = popMenu.Items[4] as MenuItem;
|
|
|
- menuItem.CommandTarget = (UIElement)sender;
|
|
|
- menuItem.Command = ApplicationCommands.Delete;
|
|
|
+ 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)
|
|
|
{
|
|
|
//复制
|
|
|
- MenuItem menuItem = popMenu.Items[0] as MenuItem;
|
|
|
- menuItem.CommandTarget = (UIElement)sender;
|
|
|
- menuItem.Command = ApplicationCommands.Copy;
|
|
|
+ SetPopMenuItem(popMenu.Items[0] as MenuItem, sender, ApplicationCommands.Copy);
|
|
|
//剪切
|
|
|
- menuItem = popMenu.Items[1] as MenuItem;
|
|
|
- menuItem.CommandTarget = (UIElement)sender;
|
|
|
- menuItem.Command = ApplicationCommands.Cut;
|
|
|
+ SetPopMenuItem(popMenu.Items[1] as MenuItem, sender, ApplicationCommands.Cut);
|
|
|
//粘贴
|
|
|
- menuItem = popMenu.Items[2] as MenuItem;
|
|
|
- menuItem.CommandTarget = (UIElement)sender;
|
|
|
- menuItem.Command = ApplicationCommands.Paste;
|
|
|
+ SetPopMenuItem(popMenu.Items[2] as MenuItem, sender, ApplicationCommands.Paste);
|
|
|
//粘贴并匹配样式
|
|
|
- menuItem = popMenu.Items[3] as MenuItem;
|
|
|
- menuItem.CommandTarget = (UIElement)sender;
|
|
|
- menuItem.Command = ApplicationCommands.Paste;
|
|
|
+ SetPopMenuItem(popMenu.Items[3] as MenuItem, sender, ApplicationCommands.Paste);
|
|
|
//删除
|
|
|
- menuItem = popMenu.Items[4] as MenuItem;
|
|
|
- menuItem.CommandTarget = (UIElement)sender;
|
|
|
- menuItem.Command = ApplicationCommands.Delete;
|
|
|
- //全部选定
|
|
|
- menuItem = popMenu.Items[4] as MenuItem;
|
|
|
- menuItem.CommandTarget = (UIElement)sender;
|
|
|
- menuItem.Command = ApplicationCommands.SelectAll;
|
|
|
+ SetPopMenuItem(popMenu.Items[4] as MenuItem, sender, ApplicationCommands.Delete);
|
|
|
+ ////全部选定
|
|
|
+ SetPopMenuItem(popMenu.Items[5] as MenuItem, sender, ApplicationCommands.SelectAll);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
return popMenu;
|
|
|
}
|
|
|
|
|
|
+ private void SetPopMenuItem(MenuItem menu, object sender, ICommand command)
|
|
|
+ {
|
|
|
+ MenuItem menuItem = menu;
|
|
|
+ menuItem.CommandTarget = (UIElement)sender;
|
|
|
+ menuItem.Command = command;
|
|
|
+ }
|
|
|
+
|
|
|
+ #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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 选中编辑PDF内容的事件
|
|
|
+ /// </summary>
|
|
|
private void PDFViewer_PDFEditActiveHandler(object sender, List<PDFEditEvent> e)
|
|
|
{
|
|
|
- if(e != null && e.Count > 0)
|
|
|
+ if (e != null && e.Count > 0)
|
|
|
{
|
|
|
|
|
|
ReLoadLayoutAlign(e.Count);
|
|
@@ -853,22 +762,34 @@ namespace PDF_Office.ViewModels.PropertyPanel
|
|
|
IsTextEdit = true;
|
|
|
|
|
|
ClearCheckedAglin?.Invoke(null, null);
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void ReLoadLayoutAlign(int count)
|
|
|
+ #endregion
|
|
|
+
|
|
|
+
|
|
|
+ public void OnNavigatedTo(NavigationContext navigationContext)
|
|
|
{
|
|
|
- if (count >= 2)
|
|
|
- IsLayoutAlign = true;
|
|
|
- else
|
|
|
- IsLayoutAlign = false;
|
|
|
|
|
|
- if (count >= 3)
|
|
|
- IsLayoutAvgAlign = true;
|
|
|
- else
|
|
|
- IsLayoutAvgAlign = false;
|
|
|
+ navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
|
|
|
+ if (PDFViewer != null)
|
|
|
+ {
|
|
|
+ PDFViewer.PDFEditActiveHandler -= PDFViewer_PDFEditActiveHandler;
|
|
|
+ PDFViewer.PDFEditActiveHandler += PDFViewer_PDFEditActiveHandler;
|
|
|
+
|
|
|
+ PDFViewer.PDFEditCommandHandler -= PDFViewer_PDFEditCommandHandler;
|
|
|
+ PDFViewer.PDFEditCommandHandler += PDFViewer_PDFEditCommandHandler;
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ public bool IsNavigationTarget(NavigationContext navigationContext){ return true; }
|
|
|
+
|
|
|
+
|
|
|
+ public void OnNavigatedFrom(NavigationContext navigationContext){}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
}
|