|
@@ -7,7 +7,10 @@ using ComPDFKitViewer;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.ComponentModel;
|
|
|
+using System.Diagnostics;
|
|
|
+using System.Drawing;
|
|
|
using System.Globalization;
|
|
|
+using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
@@ -20,9 +23,11 @@ using System.Windows.Media;
|
|
|
using System.Windows.Media.Imaging;
|
|
|
using System.Windows.Navigation;
|
|
|
using System.Windows.Shapes;
|
|
|
+using ComPDFKit.PDFPage;
|
|
|
using ComPDFKit.Tool.Help;
|
|
|
using ComPDFKit.Viewer.Annot;
|
|
|
using ComPDFKitViewer.BaseObject;
|
|
|
+using Path = System.IO.Path;
|
|
|
|
|
|
|
|
|
namespace Compdfkit_Tools.Measure
|
|
@@ -80,22 +85,172 @@ namespace Compdfkit_Tools.Measure
|
|
|
PDFGrid.Child = PdfViewControl;
|
|
|
|
|
|
panelState.PropertyChanged -= PanelState_PropertyChanged;
|
|
|
- panelState.PropertyChanged += PanelState_PropertyChanged;
|
|
|
PdfViewControl.MouseLeftButtonDownHandler -= PDFToolManager_MouseLeftButtonDownHandler;
|
|
|
PdfViewControl.MouseLeftButtonUpHandler -= PDFToolManager_MouseLeftButtonUpHandler;
|
|
|
PdfViewControl.MouseMoveHandler -= PDFToolManager_MouseMoveHandler;
|
|
|
+ pdfViewControl.MouseRightButtonDownHandler -= PDFToolManager_MouseRightButtonDownHandler;
|
|
|
|
|
|
PdfViewControl.MouseLeftButtonDownHandler += PDFToolManager_MouseLeftButtonDownHandler;
|
|
|
PdfViewControl.MouseLeftButtonUpHandler += PDFToolManager_MouseLeftButtonUpHandler;
|
|
|
PdfViewControl.MouseMoveHandler += PDFToolManager_MouseMoveHandler;
|
|
|
- //pdfViewControl.PDFView.AnnotActiveHandler -= PDFView_AnnotActiveHandler;
|
|
|
- //pdfViewControl.PDFView.AnnotActiveHandler += PDFView_AnnotActiveHandler;
|
|
|
- //pdfViewControl.PDFView.AnnotCommandHandler -= PDFView_AnnotCommandHandler;
|
|
|
- //pdfViewControl.PDFView.AnnotCommandHandler += PDFView_AnnotCommandHandler;
|
|
|
+ pdfViewControl.MouseRightButtonDownHandler += PDFToolManager_MouseRightButtonDownHandler;
|
|
|
+ panelState.PropertyChanged += PanelState_PropertyChanged;
|
|
|
SetInfoPanelVisble(false, false);
|
|
|
SettingPanel.PdfViewControl= pdfViewControl;
|
|
|
}
|
|
|
|
|
|
+ private void PDFToolManager_MouseRightButtonDownHandler(object sender, MouseEventObject e)
|
|
|
+ {
|
|
|
+ ContextMenu ContextMenu = PdfViewControl.GetRightMenu();
|
|
|
+ if (ContextMenu == null)
|
|
|
+ {
|
|
|
+ ContextMenu = new ContextMenu();
|
|
|
+ }
|
|
|
+ switch (e.hitTestType)
|
|
|
+ {
|
|
|
+ case MouseHitTestType.Annot:
|
|
|
+ case MouseHitTestType.SelectRect:
|
|
|
+ CreateAnnotContextMenu(sender, ref ContextMenu, e.annotType);
|
|
|
+ break;
|
|
|
+ case MouseHitTestType.Text:
|
|
|
+ CreateSelectTextContextMenu(sender, ref ContextMenu);
|
|
|
+ break;
|
|
|
+ case MouseHitTestType.ImageSelect:
|
|
|
+ CreateSelectImageContextMenu(sender, ref ContextMenu);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ ContextMenu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Paste"), Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
|
|
|
+ PdfViewControl.CreateViewerMenu(sender, ref ContextMenu);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ PdfViewControl.SetRightMenu(ContextMenu);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void CreateAnnotContextMenu(object sender, ref ContextMenu menu, C_ANNOTATION_TYPE annotType)
|
|
|
+ {
|
|
|
+ switch (annotType)
|
|
|
+ {
|
|
|
+ case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
|
|
|
+ case C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE:
|
|
|
+ case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
|
|
|
+ CreateMeasureContextMenu(sender, ref menu);
|
|
|
+ break;
|
|
|
+ case C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET:
|
|
|
+ break;
|
|
|
+ case C_ANNOTATION_TYPE.C_ANNOTATION_SOUND:
|
|
|
+ case C_ANNOTATION_TYPE.C_ANNOTATION_MOVIE:
|
|
|
+ case C_ANNOTATION_TYPE.C_ANNOTATION_RICHMEDIA:
|
|
|
+ menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Delete"), Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
|
|
|
+ menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Play"), Command = MediaCommands.Play, CommandTarget = (UIElement)sender, CommandParameter = (sender as CPDFViewerTool).GetCacheHitTestAnnot() });
|
|
|
+ menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Cut"), Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
|
|
|
+ menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Paste"), Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Delete"), Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
|
|
|
+ menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Copy"), Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
|
|
|
+ menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Cut"), Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
|
|
|
+ menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Paste"), Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void CreateMeasureContextMenu(object sender, ref ContextMenu menu)
|
|
|
+ {
|
|
|
+ menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Delete"), Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
|
|
|
+
|
|
|
+ MenuItem menuItem = new MenuItem();
|
|
|
+ menuItem.Header = "Measurement Settings";
|
|
|
+ menuItem.Click += (item, param) =>
|
|
|
+ {
|
|
|
+ if (currentAnnot is CPDFLineAnnotation annotation)
|
|
|
+ {
|
|
|
+ SettingPanel.BindMeasureSetting(annotation.GetDistanceMeasure().MeasureInfo);
|
|
|
+ }
|
|
|
+ SetInfoPanelVisble(false, true);
|
|
|
+ };
|
|
|
+ menu.Items.Add(menuItem);
|
|
|
+
|
|
|
+ MenuItem propertyItem = new MenuItem();
|
|
|
+ propertyItem.Header = "Properties";
|
|
|
+ propertyItem.Click += (item, param) =>
|
|
|
+ {
|
|
|
+ panelState.RightPanel = PanelState.RightPanelState.PropertyPanel;
|
|
|
+ };
|
|
|
+ menu.Items.Add(propertyItem);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void CreateSelectTextContextMenu(object sender, ref ContextMenu menu)
|
|
|
+ {
|
|
|
+ menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Copy"), Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void CreateSelectImageContextMenu(object sender, ref ContextMenu menu)
|
|
|
+ {
|
|
|
+ if (menu == null)
|
|
|
+ {
|
|
|
+ menu = new ContextMenu();
|
|
|
+ }
|
|
|
+ MenuItem copyImage = new MenuItem();
|
|
|
+ copyImage.Header = "Copy Image";
|
|
|
+ copyImage.Click += CopyImage_Click;
|
|
|
+ menu.Items.Add(copyImage);
|
|
|
+
|
|
|
+ MenuItem extractImage = new MenuItem();
|
|
|
+ extractImage.Header = "Extract Image";
|
|
|
+ extractImage.Click += ExtractImage_Click;
|
|
|
+ menu.Items.Add(extractImage);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ExtractImage_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ System.Windows.Forms.FolderBrowserDialog folderDialog = new System.Windows.Forms.FolderBrowserDialog();
|
|
|
+ if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
|
+ {
|
|
|
+ var image = PdfViewControl.FocusPDFViewTool.GetSelectImage();
|
|
|
+ if (image == null)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ CPDFPage page = PdfViewControl.PDFToolManager.GetDocument().PageAtIndex(image.PageIndex);
|
|
|
+ string savePath = System.IO.Path.Combine(folderDialog.SelectedPath, Guid.NewGuid() + ".jpg");
|
|
|
+ string tempPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), Guid.NewGuid() + ".jpg");
|
|
|
+ page.GetImgSelection().GetImgBitmap(image.ImageIndex, tempPath);
|
|
|
+
|
|
|
+ Bitmap bitmap = new Bitmap(tempPath);
|
|
|
+ bitmap.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
|
|
|
+ Process.Start("explorer", "/select,\"" + savePath + "\"");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void CopyImage_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ var image = PdfViewControl.FocusPDFViewTool.GetSelectImage();
|
|
|
+ if (image == null)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ CPDFPage page = PdfViewControl.PDFToolManager.GetDocument().PageAtIndex(image.PageIndex);
|
|
|
+ string tempPath = System.IO.Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".jpg");
|
|
|
+ page.GetImgSelection().GetImgBitmap(image.ImageIndex, tempPath);
|
|
|
+
|
|
|
+ Bitmap bitmap = new Bitmap(tempPath);
|
|
|
+ BitmapImage imageData;
|
|
|
+ using (MemoryStream ms = new MemoryStream())
|
|
|
+ {
|
|
|
+ bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
|
|
|
+ imageData = new BitmapImage();
|
|
|
+ imageData.BeginInit();
|
|
|
+ imageData.StreamSource = ms;
|
|
|
+
|
|
|
+ imageData.CacheOption = BitmapCacheOption.OnLoad;
|
|
|
+ imageData.EndInit();
|
|
|
+ imageData.Freeze();
|
|
|
+ Clipboard.SetImage(imageData);
|
|
|
+ bitmap.Dispose();
|
|
|
+ File.Delete(tempPath);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void PDFToolManager_MouseMoveHandler(object sender, MouseEventObject e)
|
|
|
{
|
|
|
}
|
|
@@ -123,88 +278,6 @@ namespace Compdfkit_Tools.Measure
|
|
|
SetInfoPanelVisble(true, false);
|
|
|
}
|
|
|
|
|
|
- //private void PDFView_AnnotCommandHandler(object sender, AnnotCommandArgs e)
|
|
|
- //{
|
|
|
- // switch (e.CommandType)
|
|
|
- // {
|
|
|
- // case CommandType.Context:
|
|
|
- // if (e.CommandTarget == TargetType.Annot && e.PressOnAnnot)
|
|
|
- // {
|
|
|
- // e.Handle = true;
|
|
|
- // e.PopupMenu = new ContextMenu();
|
|
|
- // e.PopupMenu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Delete"), Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
|
|
|
- // MenuItem menuItem = new MenuItem();
|
|
|
- // menuItem.Header = "Measurement Settings";
|
|
|
- // menuItem.Click += (item, param) =>
|
|
|
- // {
|
|
|
- // SettingPanel.UpdateArgsList = e.AnnotEventArgsList;
|
|
|
- // SettingPanel.BindMeasureSetting();
|
|
|
- // SetInfoPanelVisble(false, true);
|
|
|
- // };
|
|
|
-
|
|
|
- // MenuItem propertyItem = new MenuItem();
|
|
|
- // propertyItem.Header = "Properties";
|
|
|
- // propertyItem.Click += (item, param) =>
|
|
|
- // {
|
|
|
- // ExpandEvent?.Invoke(this, new EventArgs());
|
|
|
- // };
|
|
|
- // e.PopupMenu.Items.Add(menuItem);
|
|
|
- // e.PopupMenu.Items.Add(propertyItem);
|
|
|
- // }
|
|
|
- // break;
|
|
|
-
|
|
|
- // case CommandType.Delete:
|
|
|
- // e.DoCommand();
|
|
|
- // break;
|
|
|
- // default:
|
|
|
- // break;
|
|
|
- // }
|
|
|
- //}
|
|
|
-
|
|
|
- //private void PDFView_AnnotActiveHandler(object sender, AnnotAttribEvent e)
|
|
|
- //{
|
|
|
- // if (e == null || e.IsAnnotCreateReset)
|
|
|
- // {
|
|
|
- // if (e == null)
|
|
|
- // {
|
|
|
- // measurePropertyControl?.ClearMeasurePanel();
|
|
|
- // if(PDFMeasureTool.ToolChecked()==false)
|
|
|
- // {
|
|
|
- // SetInfoPanelVisble(false, false);
|
|
|
- // }
|
|
|
- // }
|
|
|
- // return;
|
|
|
- // }
|
|
|
- // else
|
|
|
- // {
|
|
|
- // switch (e.GetAnnotTypes())
|
|
|
- // {
|
|
|
- // case AnnotArgsType.LineMeasure:
|
|
|
- // LineMeasureArgs LineArgs = e.GetAnnotHandlerEventArgs(AnnotArgsType.LineMeasure).First() as LineMeasureArgs;
|
|
|
- // panelState.RightPanel = PanelState.RightPanelState.PropertyPanel;
|
|
|
- // measurePropertyControl.SetPropertyForMeasureCreate(LineArgs, e);
|
|
|
- // SetInfoPanelVisble(true, false);
|
|
|
- // SetMeasureInfoPanel(LineArgs.GetPDFAnnot(), LineArgs);
|
|
|
- // break;
|
|
|
- // case AnnotArgsType.PolygonMeasure:
|
|
|
- // PolygonMeasureArgs polygonArgs = e.GetAnnotHandlerEventArgs(AnnotArgsType.PolygonMeasure).First() as PolygonMeasureArgs;
|
|
|
- // panelState.RightPanel = PanelState.RightPanelState.PropertyPanel;
|
|
|
- // measurePropertyControl.SetPropertyForMeasureCreate(polygonArgs, e);
|
|
|
- // SetInfoPanelVisble(true, false);
|
|
|
- // SetMeasureInfoPanel(polygonArgs.GetPDFAnnot(),polygonArgs);
|
|
|
- // break;
|
|
|
-
|
|
|
- // case AnnotArgsType.PolyLineMeasure:
|
|
|
- // PolyLineMeasureArgs polyLineArgs = e.GetAnnotHandlerEventArgs(AnnotArgsType.PolyLineMeasure).First() as PolyLineMeasureArgs;
|
|
|
- // panelState.RightPanel = PanelState.RightPanelState.PropertyPanel;
|
|
|
- // measurePropertyControl.SetPropertyForMeasureCreate(polyLineArgs, e);
|
|
|
- // SetInfoPanelVisble(true, false);
|
|
|
- // SetMeasureInfoPanel(polyLineArgs.GetPDFAnnot(),polyLineArgs);
|
|
|
- // break;
|
|
|
- // }
|
|
|
- // }
|
|
|
- //}
|
|
|
-
|
|
|
private void SetMeasureInfoPanel(CPDFAnnotation annot,AnnotParam param = null)
|
|
|
{
|
|
|
if (annot == null)
|
|
@@ -317,7 +390,14 @@ namespace Compdfkit_Tools.Measure
|
|
|
BotaContainer.Child = null;
|
|
|
PropertyContainer.Child = null;
|
|
|
displaySettingsControl = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void UnloadEvent()
|
|
|
+ {
|
|
|
PdfViewControl.MouseLeftButtonDownHandler -= PDFToolManager_MouseLeftButtonDownHandler;
|
|
|
+ PdfViewControl.MouseLeftButtonUpHandler -= PDFToolManager_MouseLeftButtonUpHandler;
|
|
|
+ PdfViewControl.MouseMoveHandler -= PDFToolManager_MouseMoveHandler;
|
|
|
+ panelState.PropertyChanged -= PanelState_PropertyChanged;
|
|
|
}
|
|
|
|
|
|
private void PanelState_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
|
@@ -417,9 +497,12 @@ namespace Compdfkit_Tools.Measure
|
|
|
}
|
|
|
SettingPanel.ReturnToInfoPanel = true;
|
|
|
SetInfoPanelVisble(false, true);
|
|
|
- AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
|
|
|
- PdfViewControl.GetCPDFViewer().GetDocument(), currentAnnot.Page.PageIndex, currentAnnot);
|
|
|
- SettingPanel.BindMeasureSetting(GetMeasureInfoFromParam(annotParam));
|
|
|
+ if(currentAnnot != null)
|
|
|
+ {
|
|
|
+ AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
|
|
|
+ PdfViewControl.GetCPDFViewer().GetDocument(), currentAnnot.Page.PageIndex, currentAnnot);
|
|
|
+ SettingPanel.BindMeasureSetting(GetMeasureInfoFromParam(annotParam));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private CPDFMeasureInfo GetMeasureInfoFromParam(AnnotParam param)
|