1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185 |
- using ComPDFKit.Import;
- using ComPDFKit.PDFAnnotation;
- using ComPDFKit.PDFAnnotation.Form;
- using ComPDFKit.PDFDocument;
- using ComPDFKit.PDFPage;
- using ComPDFKit.PDFPage.Edit;
- using ComPDFKit.Tool.DrawTool;
- using ComPDFKit.Tool.Help;
- using ComPDFKit.Tool.UndoManger;
- using ComPDFKit.Viewer.Annot;
- using ComPDFKit.Viewer.Helper;
- using ComPDFKitViewer;
- using ComPDFKitViewer.BaseObject;
- using ComPDFKitViewer.Helper;
- using ComPDFKitViewer.Widget;
- using System;
- using System.Collections.Generic;
- using System.Dynamic;
- using System.Linq;
- using System.Text;
- using System.Windows;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using static ComPDFKit.Tool.Help.ImportWin32;
- namespace ComPDFKit.Tool
- {
- partial class CPDFViewerTool
- {
- public class CommandData
- {
- public ExecutedRoutedEventArgs uIEventArgs { get; set; }
- public bool StartCommand { get; set; }
- public CPDFEditType PDFEditType { get; set; }
- public AnnotParam CurrentParam { get; set; } = null;
- }
- /// <summary>
- /// System provided related command time notification
- /// </summary>
- public event EventHandler<CommandData> CommandExecutedHandler;
- public AnnotParam PasteParam { get; set; }
- internal class PDFEditCommandData
- {
- public string TextContent { get; set; }
- /// <summary>
- /// Original rectangle in PDF (72DPI)
- /// </summary>
- public Rect PDFRect { get; set; }
- public bool EditAreaCopied { get; set; }
- public CPDFEditType EditType { get; set; }
- public CPDFCopyEditArea CopyArea { get; set; }
- public CPDFEditPage EditPage { get; set; }
- }
- internal Point rightPressPoint = new Point(-1, -1);
- internal static List<PDFEditCommandData> lastPDFEditArgsList { get; private set; } = new List<PDFEditCommandData>();
- internal static List<AnnotParam> lastAnnotList { get; private set; } = new List<AnnotParam>();
- internal static string CopyText { get; private set; } = "";
- internal void BindCommand()
- {
- CommandBinding copyBind = new CommandBinding(ApplicationCommands.Copy);
- copyBind.CanExecute += CommandCanExecute;
- copyBind.Executed += CommandBind_Executed;
- CommandBindings.Add(copyBind);
- CommandBinding cutBind = new CommandBinding(ApplicationCommands.Cut);
- cutBind.CanExecute += CommandCanExecute;
- cutBind.Executed += CommandBind_Executed;
- CommandBindings.Add(cutBind);
- CommandBinding pasteBind = new CommandBinding(ApplicationCommands.Paste);
- pasteBind.CanExecute += CommandCanExecute;
- pasteBind.Executed += CommandBind_Executed;
- CommandBindings.Add(pasteBind);
- CommandBinding deleteBind = new CommandBinding(ApplicationCommands.Delete);
- deleteBind.CanExecute += CommandCanExecute;
- deleteBind.Executed += CommandBind_Executed;
- CommandBindings.Add(deleteBind);
- CommandBinding playBind = new CommandBinding(MediaCommands.Play);
- playBind.CanExecute += PlayBind_CanExecute;
- playBind.Executed += PlayBind_Executed;
- CommandBindings.Add(playBind);
- CommandBinding pastWithoutStyle = new CommandBinding(CustomCommands.PasteWithoutStyle);
- pastWithoutStyle.CanExecute += CommandCanExecute;
- pastWithoutStyle.Executed += CommandBind_Executed;
- CommandBindings.Add(pastWithoutStyle);
- CommandBinding selectAllBind = new CommandBinding(ApplicationCommands.SelectAll);
- selectAllBind.CanExecute += CommandCanExecute;
- selectAllBind.Executed += CommandBind_Executed;
- CommandBindings.Add(selectAllBind);
- }
- private void PlayBind_Executed(object sender, ExecutedRoutedEventArgs e)
- {
- BaseAnnot cmdArgs = e.Parameter as BaseAnnot;
- if (cmdArgs != null && cmdArgs.GetAnnotData() != null)
- {
- if (cmdArgs is SoundAnnot)
- {
- (cmdArgs as SoundAnnot).Play();
- }
- if (cmdArgs is MovieAnnot)
- {
- (cmdArgs as MovieAnnot).Play();
- }
- }
- e.Handled = true;
- }
- private void PlayBind_CanExecute(object sender, CanExecuteRoutedEventArgs e)
- {
- e.CanExecute = false;
- BaseAnnot cmdArgs = e.Parameter as BaseAnnot;
- if (cmdArgs != null && cmdArgs.GetAnnotData() != null)
- {
- e.CanExecute = true;
- }
- e.Handled = true;
- e.ContinueRouting = false;
- }
- public void ReBindCommand(List<CommandBinding> commandBindings)
- {
- CommandBindings.Clear();
- foreach (CommandBinding binding in commandBindings)
- {
- CommandBindings.Add(binding);
- }
- }
- private bool IsCanDoCommand = true;
- public void CanDoCommand()
- {
- IsCanDoCommand = true;
- }
- public void NotDoCommand()
- {
- IsCanDoCommand = false;
- }
- private void CommandCanExecute(object sender, CanExecuteRoutedEventArgs e)
- {
- if (e.Command is RoutedUICommand uiCommand)
- {
- switch (currentModel)
- {
- case ToolType.Viewer:
- CheckViewerCommandStatus(uiCommand, e);
- break;
- case ToolType.CreateAnnot:
- case ToolType.Pan:
- CheckAnnotCommandStatus(uiCommand, e);
- break;
- case ToolType.WidgetEdit:
- if (AnnotSelectCommandSupport(uiCommand))
- {
- e.CanExecute = true;
- }
- else
- {
- CheckAnnotCommandStatus(uiCommand, e);
- }
- break;
- case ToolType.Customize:
- break;
- case ToolType.ContentEdit:
- {
- CheckPDFEditCommandStatus(uiCommand, e);
- }
- break;
- default:
- break;
- }
- }
- }
- private void CommandBind_Executed(object sender, ExecutedRoutedEventArgs e)
- {
- RoutedUICommand uiCommand = e.Command as RoutedUICommand;
- if (uiCommand != null)
- {
- try
- {
- PasteParam = null;
- CommandData commandData = new CommandData();
- commandData.uIEventArgs = e;
- commandData.StartCommand = true;
- CPDFEditType editType = CPDFEditType.None;
- CommandExecutedHandler?.Invoke(this, commandData);
- if (e.Handled)
- {
- return;
- }
- if (!IsCanDoCommand)
- {
- CanDoCommand();
- return;
- }
- switch (currentModel)
- {
- case ToolType.Viewer:
- ExecuteViewerCommand(uiCommand);
- break;
- case ToolType.CreateAnnot:
- case ToolType.Pan:
- ExecuteAnnotCommand(uiCommand);
- break;
- case ToolType.WidgetEdit:
- if (AnnotSelectCommandSupport(uiCommand))
- {
- AnnotSelectCommandExecute(uiCommand);
- }
- else
- {
- ExecuteAnnotCommand(uiCommand);
- }
- break;
- case ToolType.ContentEdit:
- {
- ExecutePDFEditCommand(uiCommand, out editType);
- }
- break;
- case ToolType.Customize:
- break;
- default:
- break;
- }
- commandData.StartCommand = false;
- commandData.PDFEditType = editType;
- commandData.CurrentParam = PasteParam;
- CommandExecutedHandler?.Invoke(this, commandData);
- }
- catch (Exception ex)
- {
- }
- }
- }
- public void SetPastePoint(Point point)
- {
- rightPressPoint = point;
- }
- #region ContentEdit
- private void CheckPDFEditCommandStatus(RoutedUICommand uiCommand, CanExecuteRoutedEventArgs e)
- {
- switch (uiCommand.Name)
- {
- case "Copy":
- case "Cut":
- case "Delete":
- case "SelectAll":
- {
- if (currentEditAreaObject != null)
- {
- e.CanExecute = true;
- }
- //Add multi status
- MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(MultiSelectedRectViewTag));
- if (multiSelectedRect != null && multiSelectedRect.Children.Count > 0)
- {
- e.CanExecute = true;
- }
- break;
- }
- case "Paste":
- case "PasteWithoutStyle":
- foreach (PDFEditCommandData checkItem in lastPDFEditArgsList)
- {
- if (checkItem.EditType == CPDFEditType.EditText && string.IsNullOrEmpty(checkItem.TextContent) == false)
- {
- e.CanExecute = true;
- break;
- }
- if (checkItem.EditType == CPDFEditType.EditImage && checkItem.EditAreaCopied)
- {
- e.CanExecute = true;
- break;
- }
- if (checkItem.EditType == CPDFEditType.EditPath && checkItem.EditAreaCopied)
- {
- e.CanExecute = true;
- break;
- }
- }
- try
- {
- if (Clipboard.ContainsText())
- {
- if (!string.IsNullOrEmpty(Clipboard.GetText()))
- {
- e.CanExecute = true;
- }
- }
- if (Clipboard.ContainsImage())
- {
- if (Clipboard.GetImage() != null)
- {
- e.CanExecute = true;
- }
- }
- }
- catch (Exception ex)
- {
- }
- break;
- }
- }
- private void ExecutePDFEditCommand(RoutedUICommand uiCommand, out CPDFEditType editType)
- {
- editType = CPDFEditType.None;
- switch (uiCommand.Name)
- {
- case "Copy":
- CopyPDFEditData(out editType);
- break;
- case "Cut":
- CopyPDFEditData(out editType);
- DelPDFEditData(out editType);
- break;
- case "Delete":
- DelPDFEditData(out editType);
- break;
- case "Paste":
- SetEditCopyData();
- if (lastPDFEditArgsList.Count > 0)
- {
- PastePDFEditData(out editType);
- PDFViewer.UpdateRenderFrame();
- }
- break;
- case "PasteWithoutStyle":
- SetEditCopyData();
- if (lastPDFEditArgsList.Count > 0)
- {
- PastePDFEditData(out editType, false);
- PDFViewer.UpdateRenderFrame();
- }
- break;
- case "SelectAll":
- SelectAllPDFEditData(out editType);
- break;
- }
- }
- private void SetEditCopyData()
- {
- try
- {
- if (Clipboard.ContainsText())
- {
- string copyText = Clipboard.GetText();
- bool findCopy = false;
- if (lastPDFEditArgsList != null && lastPDFEditArgsList.Count > 0)
- {
- foreach (PDFEditCommandData checkItem in lastPDFEditArgsList)
- {
- if (checkItem.EditType == CPDFEditType.EditText && copyText == checkItem.TextContent)
- {
- findCopy = true;
- }
- }
- }
- if (findCopy == false)
- {
- lastPDFEditArgsList?.Clear();
- if (string.IsNullOrEmpty(copyText) == false)
- {
- PDFEditCommandData commandData = new PDFEditCommandData();
- commandData.EditType = CPDFEditType.EditText;
- commandData.TextContent = copyText;
- int PageIndex = PDFViewer.CurrentRenderFrame.PageIndex;
- RenderData render = PDFViewer.GetCurrentRenderPageForIndex(PageIndex);
- Rect rect = render.PaintRect;
- Point centerPoint = new Point(
- rect.Width / PDFViewer.CurrentRenderFrame.ZoomFactor / 2,
- rect.Height / PDFViewer.CurrentRenderFrame.ZoomFactor / 2);
- commandData.PDFRect = DpiHelper.StandardRectToPDFRect(new Rect(centerPoint.X, centerPoint.Y, 0, 0));
- lastPDFEditArgsList.Add(commandData);
- }
- }
- }
- else if (Clipboard.ContainsImage())
- {
- if (Clipboard.GetImage() != null)
- {
- BitmapSource bitmapSource = Clipboard.GetImage();
- PDFEditCommandData commandData = new PDFEditCommandData();
- commandData.EditType = CPDFEditType.EditImage;
- int PageIndex = PDFViewer.CurrentRenderFrame.PageIndex;
- RenderData render = PDFViewer.GetCurrentRenderPageForIndex(PageIndex);
- Rect rect = render.PaintRect;
- Point centerPoint = new Point(
- rect.Width / PDFViewer.CurrentRenderFrame.ZoomFactor / 2,
- rect.Height / PDFViewer.CurrentRenderFrame.ZoomFactor / 2);
- commandData.PDFRect = DpiHelper.StandardRectToPDFRect(new Rect(centerPoint.X, centerPoint.Y, bitmapSource.PixelWidth, bitmapSource.PixelHeight));
- lastPDFEditArgsList.Clear();
- lastPDFEditArgsList.Add(commandData);
- }
- }
- }
- catch (Exception ex)
- {
- }
- }
- private void CopyPDFEditData(out CPDFEditType editType)
- {
- editType = CPDFEditType.None;
- if (CPDFEditPage.CopyPage != null)
- {
- CPDFEditPage.CopyPage.ReleaseCopyEditAreaList();
- }
- try
- {
- lastPDFEditArgsList.Clear();
- Clipboard.Clear();
- if (currentEditAreaObject != null)
- {
- PDFEditCommandData commandData = new PDFEditCommandData();
- if (currentEditAreaObject.cPDFEditArea.Type == CPDFEditType.EditText)
- {
- editType = CPDFEditType.EditText;
- CPDFEditTextArea editTextArea = currentEditAreaObject.cPDFEditArea as CPDFEditTextArea;
- commandData.TextContent = editTextArea.SelectText;
- if (selectAllCharsForLine || string.IsNullOrEmpty(commandData.TextContent))
- {
- CPDFEditPage editPage = currentEditAreaObject.cPDFEditPage;
- commandData.EditType = CPDFEditType.EditText;
- commandData.EditAreaCopied = editPage.CopyEditArea(currentEditAreaObject.cPDFEditArea);
- if (commandData.EditAreaCopied)
- {
- List<CPDFCopyEditArea> copyList = editPage.GetCopyEditAreaList();
- CPDFCopyEditArea CopyArea = copyList[copyList.Count - 1];
- commandData.TextContent = CopyArea.GetCopyTextAreaContent();
- commandData.CopyArea = CopyArea;
- commandData.EditPage = editPage;
- }
- }
- try
- {
- Clipboard.Clear();
- Clipboard.SetText(commandData.TextContent);
- Clipboard.Flush();
- }
- catch (Exception)
- {
- }
- commandData.PDFRect = DataConversionForWPF.CRectConversionForRect(currentEditAreaObject.cPDFEditArea.GetFrame());
- lastPDFEditArgsList.Add(commandData);
- }
- if (currentEditAreaObject.cPDFEditArea.Type == CPDFEditType.EditImage)
- {
- editType = CPDFEditType.EditImage;
- CPDFEditPage editPage = currentEditAreaObject.cPDFEditPage;
- commandData.PDFRect = DataConversionForWPF.CRectConversionForRect(currentEditAreaObject.cPDFEditArea.GetFrame());
- commandData.EditAreaCopied = editPage.CopyEditArea(currentEditAreaObject.cPDFEditArea);
- commandData.EditType = CPDFEditType.EditImage;
- if (commandData.EditAreaCopied)
- {
- List<CPDFCopyEditArea> copyList = editPage.GetCopyEditAreaList();
- commandData.CopyArea = copyList[copyList.Count - 1];
- commandData.EditPage = editPage;
- lastPDFEditArgsList.Add(commandData);
- }
- }
- if (currentEditAreaObject.cPDFEditArea.Type == CPDFEditType.EditPath)
- {
- editType = CPDFEditType.EditPath;
- CPDFEditPage editPage = currentEditAreaObject.cPDFEditPage;
- commandData.PDFRect = DataConversionForWPF.CRectConversionForRect(currentEditAreaObject.cPDFEditArea.GetFrame());
- commandData.EditAreaCopied = editPage.CopyEditArea(currentEditAreaObject.cPDFEditArea);
- commandData.EditType = CPDFEditType.EditPath;
- if (commandData.EditAreaCopied)
- {
- List<CPDFCopyEditArea> copyList = editPage.GetCopyEditAreaList();
- commandData.CopyArea = copyList[copyList.Count - 1];
- commandData.EditPage = editPage;
- lastPDFEditArgsList.Add(commandData);
- }
- }
- }
- else
- {
- //Add multi status
- MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(MultiSelectedRectViewTag));
- if (multiSelectedRect != null && multiSelectedRect.Children.Count > 0)
- {
- foreach (SelectedRect selectedRect in multiSelectedRect.Children)
- {
- EditAreaObject editAreaObject = GetEditAreaObjectListForRect(selectedRect);
- if (editAreaObject != null)
- {
- PDFEditCommandData commandData = new PDFEditCommandData();
- if (editAreaObject.cPDFEditArea.Type == CPDFEditType.EditText)
- {
- editType = CPDFEditType.EditText;
- CPDFEditTextArea editTextArea = editAreaObject.cPDFEditArea as CPDFEditTextArea;
- commandData.TextContent = editTextArea.SelectText;
- if (!string.IsNullOrEmpty(commandData.TextContent))
- {
- CPDFEditPage editPage = editAreaObject.cPDFEditPage;
- commandData.EditType = CPDFEditType.EditText;
- commandData.EditAreaCopied = editPage.CopyEditArea(editAreaObject.cPDFEditArea);
- if (commandData.EditAreaCopied)
- {
- List<CPDFCopyEditArea> copyList = editPage.GetCopyEditAreaList();
- CPDFCopyEditArea CopyArea = copyList[copyList.Count - 1];
- commandData.TextContent = CopyArea.GetCopyTextAreaContent();
- commandData.CopyArea = CopyArea;
- commandData.EditPage = editPage;
- }
- }
- try
- {
- Clipboard.Clear();
- Clipboard.SetText(commandData.TextContent);
- Clipboard.Flush();
- }
- catch (Exception)
- {
- }
- commandData.PDFRect = DataConversionForWPF.CRectConversionForRect(editAreaObject.cPDFEditArea.GetFrame());
- lastPDFEditArgsList.Add(commandData);
- }
- if (editAreaObject.cPDFEditArea.Type == CPDFEditType.EditImage)
- {
- editType = CPDFEditType.EditImage;
- CPDFEditPage editPage = editAreaObject.cPDFEditPage;
- commandData.PDFRect = DataConversionForWPF.CRectConversionForRect(editAreaObject.cPDFEditArea.GetFrame());
- commandData.EditAreaCopied = editPage.CopyEditArea(editAreaObject.cPDFEditArea);
- commandData.EditType = CPDFEditType.EditImage;
- if (commandData.EditAreaCopied)
- {
- List<CPDFCopyEditArea> copyList = editPage.GetCopyEditAreaList();
- commandData.CopyArea = copyList[copyList.Count - 1];
- commandData.EditPage = editPage;
- lastPDFEditArgsList.Add(commandData);
- }
- }
- if (editAreaObject.cPDFEditArea.Type == CPDFEditType.EditPath)
- {
- editType = CPDFEditType.EditPath;
- CPDFEditPage editPage = editAreaObject.cPDFEditPage;
- commandData.PDFRect = DataConversionForWPF.CRectConversionForRect(editAreaObject.cPDFEditArea.GetFrame());
- commandData.EditAreaCopied = editPage.CopyEditArea(editAreaObject.cPDFEditArea);
- commandData.EditType = CPDFEditType.EditPath;
- if (commandData.EditAreaCopied)
- {
- List<CPDFCopyEditArea> copyList = editPage.GetCopyEditAreaList();
- commandData.CopyArea = copyList[copyList.Count - 1];
- commandData.EditPage = editPage;
- lastPDFEditArgsList.Add(commandData);
- }
- }
- }
- }
- }
- }
- }
- catch
- {
- }
- }
- private void DelPDFEditData(out CPDFEditType editType)
- {
- editType = CPDFEditType.None;
- if (currentEditAreaObject != null)
- {
- GroupHistory groupHistory = new GroupHistory();
- PDFEditHistory editHistory = new PDFEditHistory();
- editHistory.EditPage = currentEditAreaObject.cPDFEditPage;
- editHistory.PageIndex = currentEditAreaObject.PageIndex;
- groupHistory.Histories.Add(editHistory);
- if (currentEditAreaObject.cPDFEditArea.Type == CPDFEditType.EditText)
- {
- editType = CPDFEditType.EditText;
- CPDFEditTextArea editTextArea = currentEditAreaObject.cPDFEditArea as CPDFEditTextArea;
- string selectContent = editTextArea.SelectText;
- if (!selectAllCharsForLine)
- {
- DeleteChars();
- }
- else
- {
- RemoveTextBlock();
- }
- }
- if (currentEditAreaObject.cPDFEditArea.Type == CPDFEditType.EditImage)
- {
- editType = CPDFEditType.EditImage;
- RemoveImageBlock();
- }
- if (currentEditAreaObject.cPDFEditArea.Type == CPDFEditType.EditPath)
- {
- editType = CPDFEditType.EditPath;
- RemovePathBlock();
- }
- if (PDFViewer != null && PDFViewer.UndoManager != null)
- {
- PDFViewer.UndoManager.AddHistory(groupHistory);
- //After removing the data, you need to get the data again.
- PDFViewer.UpdateRenderFrame();
- }
- }
- else
- {
- //Add multi status
- MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(MultiSelectedRectViewTag));
- if (multiSelectedRect != null && multiSelectedRect.Children.Count > 0)
- {
- List<EditAreaObject> editAreaObjectList = new List<EditAreaObject>();
- foreach (SelectedRect selectedRect in multiSelectedRect.Children)
- {
- EditAreaObject editAreaObject = GetEditAreaObjectListForRect(selectedRect);
- editAreaObjectList.Add(editAreaObject);
- }
- if (editAreaObjectList != null && editAreaObjectList.Count > 0)
- {
- editAreaObjectList = editAreaObjectList.OrderByDescending(x => x.EditAreaIndex).ToList();
- GroupHistory groupHistory = new GroupHistory();
- foreach (EditAreaObject editareaobject in editAreaObjectList)
- {
- PDFEditHistory editHistory = new PDFEditHistory();
- editHistory.EditPage = editareaobject.cPDFEditPage;
- editHistory.PageIndex = editareaobject.PageIndex;
- groupHistory.Histories.Add(editHistory);
- if (editareaobject.cPDFEditArea.Type == CPDFEditType.EditText)
- {
- editType = CPDFEditType.EditText;
- CPDFEditTextArea editTextArea = editareaobject.cPDFEditArea as CPDFEditTextArea;
- string selectContent = editTextArea.SelectText;
- RemoveTextBlock(editareaobject);
- }
- if (editareaobject.cPDFEditArea.Type == CPDFEditType.EditImage)
- {
- editType = CPDFEditType.EditImage;
- RemoveImageBlock(editareaobject);
- }
- if (editareaobject.cPDFEditArea.Type == CPDFEditType.EditPath)
- {
- editType = CPDFEditType.EditPath;
- RemovePathBlock(editareaobject);
- }
- }
- if (PDFViewer != null && PDFViewer.UndoManager != null)
- {
- PDFViewer.UndoManager.AddHistory(groupHistory);
- //After removing the data, you need to get the data again.
- PDFViewer.UpdateRenderFrame();
- }
- }
- CleanSelectedMultiRect();
- OpenSelectedMulti(false);
- }
- }
- }
- private void PastePDFEditData(out CPDFEditType editType, bool pasteMatchStyle = true)
- {
- editType = CPDFEditType.None;
- double left = 0;
- double right = 0;
- double top = 0;
- double bottom = 0;
- bool initial = false;
- #region Calculate the maximum rectangle
- foreach (PDFEditCommandData commandData in lastPDFEditArgsList)
- {
- if (initial == false)
- {
- left = commandData.PDFRect.Left;
- right = commandData.PDFRect.Right;
- top = commandData.PDFRect.Top;
- bottom = commandData.PDFRect.Bottom;
- initial = true;
- continue;
- }
- left = Math.Min(left, commandData.PDFRect.Left);
- right = Math.Max(right, commandData.PDFRect.Right);
- top = Math.Min(top, commandData.PDFRect.Top);
- bottom = Math.Max(bottom, commandData.PDFRect.Bottom);
- }
- left = DpiHelper.PDFNumToStandardNum(left);
- right = DpiHelper.PDFNumToStandardNum(right);
- top = DpiHelper.PDFNumToStandardNum(top);
- bottom = DpiHelper.PDFNumToStandardNum(bottom);
- int offsetX = 25;
- int offsetY = 25;
- Point hoverPoint = rightPressPoint;
- rightPressPoint = new Point(-1, -1);
- int pageIndex = PDFViewer.CurrentRenderFrame.PageIndex;
- // Judge whether the right-click coordinate is on the page.
- PDFViewer.GetePointToPage(hoverPoint, out RenderData renderData, out Point pagePoint);
- if (renderData != null)
- {
- //Calculate the offset from the upper left corner.
- offsetX = (int)(pagePoint.X / currentZoom - left);
- offsetY = (int)(pagePoint.Y / currentZoom - top);
- if (left + offsetX < 0)
- {
- offsetX = (int)-left;
- }
- if (right + offsetX > renderData.PageBound.Width / currentZoom)
- {
- offsetX = (int)(renderData.PageBound.Width / currentZoom - right);
- }
- if (top + offsetY < 0)
- {
- offsetY = (int)-top;
- }
- if (bottom + offsetY > renderData.PageBound.Height / currentZoom)
- {
- offsetY = (int)(renderData.PageBound.Height / currentZoom - bottom);
- }
- pageIndex = renderData.PageIndex;
- }
- else
- {
- RenderData render = PDFViewer.GetCurrentRenderPageForIndex(pageIndex);
- //Max rectangle (standard DPI).
- Rect maxRect = new Rect((int)left + render.PaintRect.Left / currentZoom, (int)top + render.PaintRect.Top / currentZoom, (int)(right - left), (int)(bottom - top));
- //Center point of the visible range.
- Point centerPoint = new Point(
- render.PaintRect.Left / currentZoom + render.PaintRect.Width / currentZoom / 2,
- render.PaintRect.Top / currentZoom + render.PaintRect.Height / currentZoom / 2);
- //Visible range.
- Rect checkRect = new Rect(
- render.PaintRect.Left / currentZoom,
- render.PaintRect.Top / currentZoom,
- render.PaintRect.Width / currentZoom,
- render.PaintRect.Height / currentZoom);
- if (!checkRect.IntersectsWith(maxRect))
- {
- offsetX = (int)(left - centerPoint.X);
- offsetY = (int)(top - centerPoint.Y);
- }
- if (left + offsetX < 0)
- {
- offsetX = (int)-left;
- }
- if (right + offsetX > render.RenderRect.Width / currentZoom)
- {
- offsetX = (int)(render.RenderRect.Width / currentZoom / 2 - right);
- }
- if (top + offsetY < 0)
- {
- offsetY = (int)-top;
- }
- if (bottom + offsetY > render.RenderRect.Height / currentZoom)
- {
- offsetY = (int)(render.RenderRect.Height / currentZoom / 2 - bottom);
- }
- }
- #endregion
- foreach (PDFEditCommandData commandData in lastPDFEditArgsList)
- {
- GroupHistory groupHistory = new GroupHistory();
- CPDFPage docPage = PDFViewer.GetDocument().PageAtIndex(pageIndex);
- CPDFEditPage editPage = docPage.GetEditPage();
- RenderData render = PDFViewer.GetCurrentRenderPageForIndex(pageIndex);
- Rect offsetRect = AddPasteOffset(commandData.PDFRect, (int)DpiHelper.StandardNumToPDFNum(offsetX), (int)DpiHelper.StandardNumToPDFNum(offsetY), new Size(DpiHelper.StandardNumToPDFNum(render.PageBound.Width / currentZoom), DpiHelper.StandardNumToPDFNum(render.PageBound.Height / currentZoom)));
- commandData.PDFRect = offsetRect;
- if (commandData.EditType == CPDFEditType.EditText)
- {
- editType = CPDFEditType.EditText;
- if (pasteMatchStyle && commandData.EditAreaCopied)
- {
- commandData.CopyArea?.PasteEditArea(editPage, new CPoint((float)offsetRect.Left, (float)offsetRect.Top));
- if (editPage.CanUndo())
- {
- PDFEditHistory editHistory = new PDFEditHistory();
- editHistory.EditPage = editPage;
- editHistory.PageIndex = pageIndex;
- groupHistory.Histories.Add(editHistory);
- CPDFViewer pdfViewer = GetCPDFViewer();
- if (pdfViewer != null && pdfViewer.UndoManager != null)
- {
- pdfViewer.UndoManager.AddHistory(groupHistory);
- }
- }
- SelectedEditAreaForIndex(pageIndex, editPage.GetEditAreaList().Count - 1, false);
- }
- else
- {
- PDFEditHistory editHistory = new PDFEditHistory();
- if (!string.IsNullOrEmpty(commandData.TextContent))
- {
- EditAreaObject editAreaObject = GetHitTestAreaObject(hoverPoint);
- if (editAreaObject != null && editAreaObject.cPDFEditArea is CPDFEditTextArea)
- {
- CPDFEditTextArea TextArea = editAreaObject.cPDFEditArea as CPDFEditTextArea;
- if (TextArea.SelectLineRects.Count > 0)
- {
- TextArea.DeleteChars();
- TextArea.ClearSelectChars();
- PDFEditHistory deleteHistory = new PDFEditHistory();
- deleteHistory.EditPage = editPage;
- deleteHistory.PageIndex = pageIndex;
- groupHistory.Histories.Add(deleteHistory);
- }
- TextArea.InsertText(commandData.TextContent);
- editHistory.EditPage = editPage;
- editHistory.PageIndex = pageIndex;
- groupHistory.Histories.Add(editHistory);
- CPDFViewer pdfViewer = GetCPDFViewer();
- if (pdfViewer != null && pdfViewer.UndoManager != null)
- {
- pdfViewer.UndoManager.AddHistory(groupHistory);
- }
- }
- else
- {
- PDFEditHistory createHistory = new PDFEditHistory();
- CPDFEditTextArea editArea = editPage.CreateNewTextArea(DataConversionForWPF.RectConversionForCRect(offsetRect), "Helvetica", 14, new byte[3] { 0, 0, 0 });
- createHistory.EditPage = editPage;
- createHistory.PageIndex = pageIndex;
- groupHistory.Histories.Add(createHistory);
- if (editArea != null)
- {
- if (editArea.InsertText(commandData.TextContent))
- {
- editHistory.EditPage = editPage;
- editHistory.PageIndex = pageIndex;
- groupHistory.Histories.Add(editHistory);
- }
- SelectedEditAreaForIndex(pageIndex, editPage.GetEditAreaList().Count - 1, false);
- }
- CPDFViewer pdfViewer = GetCPDFViewer();
- if (pdfViewer != null && pdfViewer.UndoManager != null)
- {
- pdfViewer.UndoManager.AddHistory(groupHistory);
- }
- }
- }
- }
- }
- if (commandData.EditType == CPDFEditType.EditImage)
- {
- editType = CPDFEditType.EditImage;
- PDFEditHistory editHistory = new PDFEditHistory();
- if (commandData.EditAreaCopied)
- {
- commandData.CopyArea?.PasteEditArea(editPage, new CPoint((float)offsetRect.Left, (float)offsetRect.Top));
- editHistory.EditPage = editPage;
- editHistory.PageIndex = pageIndex;
- CPDFViewer pdfViewer = GetCPDFViewer();
- if (pdfViewer != null && pdfViewer.UndoManager != null)
- {
- pdfViewer.UndoManager.AddHistory(editHistory);
- }
- SelectedEditAreaForIndex(pageIndex, editPage.GetEditAreaList().Count - 1, false);
- }
- else
- {
- BitmapSource bitmapSource = BinaryStructConverter.ImageFromClipboardDib();
- if (bitmapSource != null)
- {
- PDFEditHistory createHistory = new PDFEditHistory();
- byte[] imageData = new byte[bitmapSource.PixelWidth * bitmapSource.PixelHeight * 4];
- if (bitmapSource.Format != PixelFormats.Bgra32)
- {
- FormatConvertedBitmap covert = new FormatConvertedBitmap(bitmapSource, PixelFormats.Bgra32, bitmapSource.Palette, 0);
- covert.CopyPixels(imageData, bitmapSource.PixelWidth * 4, 0);
- }
- else
- {
- bitmapSource.CopyPixels(imageData, bitmapSource.PixelWidth * 4, 0);
- }
- CPDFEditImageArea editArea = editPage.CreateNewImageArea(DataConversionForWPF.RectConversionForCRect(offsetRect), imageData, bitmapSource.PixelWidth, bitmapSource.PixelHeight);
- createHistory.EditPage = editPage;
- createHistory.PageIndex = pageIndex;
- groupHistory.Histories.Add(createHistory);
- if (editArea != null)
- {
- editHistory.EditPage = editPage;
- editHistory.PageIndex = pageIndex;
- SelectedEditAreaForIndex(pageIndex, editPage.GetEditAreaList().Count - 1, false);
- }
- CPDFViewer pdfViewer = GetCPDFViewer();
- if (pdfViewer != null && pdfViewer.UndoManager != null)
- {
- pdfViewer.UndoManager.AddHistory(groupHistory);
- }
- }
- }
- }
- if (commandData.EditType == CPDFEditType.EditPath)
- {
- editType = CPDFEditType.EditPath;
- PDFEditHistory editHistory = new PDFEditHistory();
- if (commandData.EditAreaCopied)
- {
- commandData.CopyArea?.PasteEditArea(editPage, new CPoint((float)offsetRect.Left, (float)offsetRect.Top));
- editHistory.EditPage = editPage;
- editHistory.PageIndex = pageIndex;
- CPDFViewer pdfViewer = GetCPDFViewer();
- if (pdfViewer != null && pdfViewer.UndoManager != null)
- {
- pdfViewer.UndoManager.AddHistory(editHistory);
- }
- SelectedEditAreaForIndex(pageIndex, editPage.GetEditAreaList().Count - 1, false);
- }
- }
- editPage.EndEdit();
- }
- }
- private void SelectAllPDFEditData(out CPDFEditType editType)
- {
- editType = CPDFEditType.None;
- if (currentEditAreaObject != null && currentEditAreaObject.cPDFEditPage != null)
- {
- CPDFEditTextArea textArea = currentEditAreaObject.cPDFEditArea as CPDFEditTextArea;
- textArea.SelectAllChars();
- editType = CPDFEditType.EditText;
- PDFViewer.UpdateRenderFrame();
- }
- }
- private Rect AddPasteOffset(Rect clientRect, int offsetX, int offsetY, Size pageSize)
- {
- clientRect.X += offsetX;
- clientRect.Y += offsetY;
- if (clientRect.Left < 0)
- {
- clientRect.X = 0;
- }
- if (clientRect.Top < 0)
- {
- clientRect.Y = 0;
- }
- if (clientRect.Right > pageSize.Width)
- {
- clientRect.X = pageSize.Width - Math.Min(clientRect.Width, pageSize.Width);
- }
- if (clientRect.Bottom > pageSize.Height)
- {
- clientRect.Y = pageSize.Height - Math.Min(clientRect.Height, pageSize.Height);
- }
- return clientRect;
- }
- #endregion
- #region Annot
- private bool CheckCacheHitTestAnnot(string cmdName = "")
- {
- if (cacheHitTestAnnot == null)
- {
- return false;
- }
- AnnotData hitData = cacheHitTestAnnot.GetAnnotData();
- if (hitData == null)
- {
- return false;
- }
- if (hitData.Annot == null)
- {
- return false;
- }
- if (cmdName == "Delete" && hitData.Annot is CPDFSignatureWidget)
- {
- CPDFSignatureWidget signAnnot = hitData.Annot as CPDFSignatureWidget;
- if (signAnnot != null && signAnnot.IsSigned())
- {
- return false;
- }
- }
- return true;
- }
- private bool CheckAnnotCanDoCopyCut(bool isCut = false)
- {
- if (!CheckCacheHitTestAnnot(isCut ? "Delete" : ""))
- {
- return false;
- }
- if (cacheHitTestAnnot.GetAnnotData().Annot.GetIsLocked() && isCut)
- {
- return false;
- }
- switch (cacheHitTestAnnot.CurrentType)
- {
- case C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT:
- case C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY:
- case C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE:
- case C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT:
- case C_ANNOTATION_TYPE.C_ANNOTATION_REDACT:
- case C_ANNOTATION_TYPE.C_ANNOTATION_SOUND:
- case C_ANNOTATION_TYPE.C_ANNOTATION_MOVIE:
- case C_ANNOTATION_TYPE.C_ANNOTATION_RICHMEDIA:
- return false;
- default:
- break;
- }
- return true;
- }
- private void CheckViewerCommandStatus(RoutedUICommand uiCommand, CanExecuteRoutedEventArgs e)
- {
- switch (uiCommand.Name)
- {
- case "Copy":
- TextSelectInfo textSelectInfo = GetTextSelectInfo();
- if (!e.CanExecute && textSelectInfo != null)
- {
- foreach (int key in textSelectInfo.PageSelectText.Keys)
- {
- if (textSelectInfo.PageSelectText[key] != string.Empty)
- {
- e.CanExecute = true;
- break;
- }
- }
- }
- break;
- default:
- return;
- }
- }
- private void CheckAnnotCommandStatus(RoutedUICommand uiCommand, CanExecuteRoutedEventArgs e)
- {
- switch (uiCommand.Name)
- {
- case "Copy":
- e.CanExecute = CheckAnnotCanDoCopyCut();
- if (!e.CanExecute)
- {
- AnnotSelector annotSelector = GetAnnotSelectsRect();
- if (annotSelector != null && annotSelector.SelectAnnots.Count > 0)
- {
- e.CanExecute = true;
- }
- }
- TextSelectInfo textSelectInfo = GetTextSelectInfo();
- if (!e.CanExecute && textSelectInfo != null)
- {
- foreach (int key in textSelectInfo.PageSelectText.Keys)
- {
- if (textSelectInfo.PageSelectText[key] != string.Empty)
- {
- e.CanExecute = true;
- break;
- }
- }
- }
- break;
- case "Cut":
- e.CanExecute = CheckAnnotCanDoCopyCut(true);
- if (!e.CanExecute)
- {
- AnnotSelector annotSelector = GetAnnotSelectsRect();
- if (annotSelector != null && annotSelector.SelectAnnots.Count > 0)
- {
- e.CanExecute = true;
- }
- }
- break;
- case "Delete":
- e.CanExecute = CheckCacheHitTestAnnot("Delete");
- if (!e.CanExecute)
- {
- AnnotSelector annotSelector = GetAnnotSelectsRect();
- if (annotSelector != null && annotSelector.SelectAnnots.Count > 0)
- {
- e.CanExecute = true;
- }
- }
- break;
- case "Paste":
- if (lastAnnotList.Count > 0)
- {
- e.CanExecute = true;
- }
- try
- {
- if (Clipboard.ContainsText())
- {
- if (!string.IsNullOrEmpty(Clipboard.GetText()))
- {
- e.CanExecute = true;
- }
- }
- }
- catch (Exception ex)
- {
- }
- break;
- }
- }
- private void ExecuteViewerCommand(RoutedUICommand uiCommand)
- {
- switch (uiCommand.Name)
- {
- case "Copy":
- TextSelectInfo textSelectInfo = GetTextSelectInfo();
- if (textSelectInfo != null)
- {
- StringBuilder copyTextBuilder = new StringBuilder();
- foreach (int key in textSelectInfo.PageSelectText.Keys)
- {
- if (textSelectInfo.PageSelectText[key] != string.Empty)
- {
- copyTextBuilder.Append(textSelectInfo.PageSelectText[key]);
- }
- }
- if (copyTextBuilder.Length > 0)
- {
- try
- {
- Clipboard.Clear();
- Clipboard.SetText(copyTextBuilder.ToString());
- }
- catch (Exception)
- {
- }
- }
- }
- break;
- default:
- return;
- }
- }
- private void ExecuteAnnotCommand(RoutedUICommand uiCommand)
- {
- AnnotSelector mrect = GetAnnotSelectsRect();
- switch (uiCommand.Name)
- {
- case "Copy":
- try
- {
- if (Clipboard.ContainsText())
- {
- Clipboard.SetText("");
- }
- }
- catch (Exception ex)
- {
- }
- if (mrect != null && mrect.SelectAnnots.Count > 0)
- {
- lastAnnotList.Clear();
- foreach (var annotData in mrect.SelectAnnots)
- {
- var annotParam = ParamConverter.AnnotConverter(PDFViewer.GetDocument(), annotData.Annot);
- lastAnnotList.Add(annotParam);
- }
- return;
- }
- if (cacheHitTestAnnot != null)
- {
- lastAnnotList.Clear();
- AnnotParam annotParam = ParamConverter.AnnotConverter(GetCPDFViewer().GetDocument(), cacheHitTestAnnot.GetAnnotData().Annot);
- lastAnnotList.Add(annotParam);
- }
- if (cacheMoveWidget != null)
- {
- lastAnnotList.Clear();
- AnnotParam annotParam = ParamConverter.WidgetConverter(GetCPDFViewer().GetDocument(), cacheMoveWidget.GetAnnotData().Annot);
- lastAnnotList.Add(annotParam);
- }
- else
- {
- TextSelectInfo textSelectInfo = GetTextSelectInfo();
- if (textSelectInfo != null)
- {
- StringBuilder copyTextBuilder = new StringBuilder();
- foreach (int key in textSelectInfo.PageSelectText.Keys)
- {
- if (textSelectInfo.PageSelectText[key] != string.Empty)
- {
- copyTextBuilder.Append(textSelectInfo.PageSelectText[key]);
- }
- }
- if (copyTextBuilder.Length > 0)
- {
- try
- {
- Clipboard.Clear();
- Clipboard.SetText(copyTextBuilder.ToString());
- }
- catch (Exception)
- {
- }
- }
- }
- }
- break;
- case "Cut":
- try
- {
- if (Clipboard.ContainsText())
- {
- Clipboard.SetText("");
- }
- }
- catch (Exception ex)
- {
- }
- if (mrect != null && mrect.SelectAnnots.Count > 0)
- {
- lastAnnotList.Clear();
- foreach (var annotData in mrect.SelectAnnots)
- {
- var annotParam = ParamConverter.AnnotConverter(PDFViewer.GetDocument(), annotData.Annot);
- lastAnnotList.Add(annotParam);
- }
- DeleteAnnotData();
- PDFViewer.UpdateAnnotFrame();
- return;
- }
- if (cacheHitTestAnnot != null)
- {
- lastAnnotList.Clear();
- AnnotParam annotParam;
- if (cacheHitTestAnnot.CurrentType == C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET)
- {
- annotParam = ParamConverter.WidgetConverter(GetCPDFViewer().GetDocument(), cacheHitTestAnnot.GetAnnotData().Annot);
- }
- else
- {
- annotParam = ParamConverter.AnnotConverter(GetCPDFViewer().GetDocument(), cacheHitTestAnnot.GetAnnotData().Annot);
- }
- lastAnnotList.Add(annotParam);
- }
- if (cacheMoveWidget != null)
- {
- lastAnnotList.Clear();
- AnnotParam annotParam = ParamConverter.WidgetConverter(GetCPDFViewer().GetDocument(), cacheMoveWidget.GetAnnotData().Annot);
- lastAnnotList.Add(annotParam);
- }
- DeleteAnnotData();
- PDFViewer.UpdateAnnotFrame();
- break;
- case "Delete":
- DeleteAnnotData();
- PDFViewer.UpdateAnnotFrame();
- break;
- case "Paste":
- PasteAnnotData();
- PDFViewer.UpdateAnnotFrame();
- break;
- }
- }
- private void PasteAnnotData(bool pasteMatchStyle = false)
- {
- GroupHistory groupHistory = new GroupHistory();
- string CopyString = CopyText;
- try
- {
- if (Clipboard.ContainsText())
- {
- if (!string.IsNullOrEmpty(Clipboard.GetText()))
- {
- CopyString = Clipboard.GetText();
- }
- }
- }
- catch (Exception ex)
- {
- }
-
- if (lastAnnotList.Count > 0&& CopyText== CopyString)
- {
- foreach (AnnotParam item in lastAnnotList)
- {
- AnnotHistory annotHistory = null;
- if (item == null)
- {
- continue;
- }
- Point point = rightPressPoint;
- rightPressPoint = new Point(-1, -1);
- switch (item.CurrentType)
- {
- case C_ANNOTATION_TYPE.C_ANNOTATION_TEXT:
- {
- CPDFDocument cPDFDocument = PDFViewer.GetDocument();
- Rect rect;
- annotHistory = new StickyNoteAnnotHistory();
- annotHistory.PDFDoc = cPDFDocument;
- int index = -1;
- if (point.Equals(new Point(-1, -1)))
- {
- index = item.PageIndex;
- rect = new Rect(
- (item.ClientRect.left + 25),
- (item.ClientRect.top + 25),
- item.ClientRect.width(),
- item.ClientRect.height()
- );
- }
- else
- {
- PDFViewer.GetPointPageInfo(point, out index, out Rect paintRect, out var pageBound);
- CRect cRect = item.ClientRect;
- Point zoomPoint = new Point((point.X - pageBound.X) / currentZoom, (point.Y - pageBound.Y) / currentZoom);
- Point pdfPoint = DpiHelper.StandardPointToPDFPoint(zoomPoint);
- rect = new Rect(
- (pdfPoint.X - cRect.width() / 2),
- (pdfPoint.Y - cRect.height() / 2),
- cRect.width(),
- cRect.height()
- );
- }
- CRect setRect = DataConversionForWPF.RectConversionForCRect(rect);
- CPDFPage cPDFPage = cPDFDocument.PageAtIndex(index);
- if (cPDFPage == null)
- return;
- CPDFAnnotation cPDFAnnotation = cPDFPage.CreateAnnot(item.CurrentType);
- CreateDefaultAnnot(cPDFAnnotation, item.CurrentType, item);
- cPDFAnnotation.SetRect(setRect);
- CommonHelper.UpdateStickyAP(cPDFAnnotation as CPDFTextAnnotation);
- AnnotParam annotParam = ParamConverter.AnnotConverter(cPDFDocument, cPDFAnnotation);
- (annotHistory as StickyNoteAnnotHistory).CurrentParam = (StickyNoteParam)annotParam;
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_LINK:
- {
- CPDFDocument cPDFDocument = PDFViewer.GetDocument();
- Rect rect;
- annotHistory = new LinkAnnotHistory();
- annotHistory.PDFDoc = cPDFDocument;
- int index = -1;
- if (point.Equals(new Point(-1, -1)))
- {
- index = item.PageIndex;
- rect = new Rect(
- (item.ClientRect.left + 25),
- (item.ClientRect.top + 25),
- item.ClientRect.width(),
- item.ClientRect.height()
- );
- }
- else
- {
- PDFViewer.GetPointPageInfo(point, out index, out Rect paintRect, out var pageBound);
- CRect cRect = item.ClientRect;
- Point zoomPoint = new Point((point.X - pageBound.X) / currentZoom, (point.Y - pageBound.Y) / currentZoom);
- Point pdfPoint = DpiHelper.StandardPointToPDFPoint(zoomPoint);
- rect = new Rect(
- (pdfPoint.X - cRect.width() / 2),
- (pdfPoint.Y - cRect.height() / 2),
- cRect.width(),
- cRect.height()
- );
- }
- CRect setRect = DataConversionForWPF.RectConversionForCRect(rect);
- CPDFPage cPDFPage = cPDFDocument.PageAtIndex(index);
- if (cPDFPage == null)
- return;
- CPDFAnnotation cPDFAnnotation = cPDFPage.CreateAnnot(item.CurrentType);
- CreateDefaultAnnot(cPDFAnnotation, item.CurrentType, item);
- cPDFAnnotation.SetRect(setRect);
- cPDFAnnotation.UpdateAp();
- AnnotParam annotParam = ParamConverter.AnnotConverter(cPDFDocument, cPDFAnnotation);
- (annotHistory as LinkAnnotHistory).CurrentParam = (LinkParam)annotParam;
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_FREETEXT:
- {
- CPDFDocument cPDFDocument = PDFViewer.GetDocument();
- Rect rect;
- annotHistory = new FreeTextAnnotHistory();
- annotHistory.PDFDoc = cPDFDocument;
- int index = -1;
- if (point.Equals(new Point(-1, -1)))
- {
- index = item.PageIndex;
- rect = new Rect(
- (item.ClientRect.left + 25),
- (item.ClientRect.top + 25),
- item.ClientRect.width(),
- item.ClientRect.height()
- );
- }
- else
- {
- PDFViewer.GetPointPageInfo(point, out index, out Rect paintRect, out var pageBound);
- CRect cRect = item.ClientRect;
- Point zoomPoint = new Point((point.X - pageBound.X) / currentZoom, (point.Y - pageBound.Y) / currentZoom);
- Point pdfPoint = DpiHelper.StandardPointToPDFPoint(zoomPoint);
- rect = new Rect(
- (pdfPoint.X - cRect.width() / 2),
- (pdfPoint.Y - cRect.height() / 2),
- cRect.width(),
- cRect.height()
- );
- }
- CRect setRect = DataConversionForWPF.RectConversionForCRect(rect);
- CPDFPage cPDFPage = cPDFDocument.PageAtIndex(index);
- if (cPDFPage == null)
- return;
- CPDFAnnotation cPDFAnnotation = cPDFPage.CreateAnnot(item.CurrentType);
- CreateDefaultAnnot(cPDFAnnotation, item.CurrentType, item);
- cPDFAnnotation.SetRect(setRect);
- cPDFAnnotation.UpdateAp();
- AnnotParam annotParam = ParamConverter.AnnotConverter(cPDFDocument, cPDFAnnotation);
- (annotHistory as FreeTextAnnotHistory).CurrentParam = (FreeTextParam)annotParam;
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
- {
- CPDFDocument cPDFDocument = PDFViewer.GetDocument();
- Rect rect;
- annotHistory = new LineAnnotHistory();
- annotHistory.PDFDoc = cPDFDocument;
- int index = -1;
- if (point.Equals(new Point(-1, -1)))
- {
- index = item.PageIndex;
- rect = new Rect(
- (item.ClientRect.left + 25),
- (item.ClientRect.top + 25),
- item.ClientRect.width(),
- item.ClientRect.height()
- );
- }
- else
- {
- PDFViewer.GetPointPageInfo(point, out index, out Rect paintRect, out var pageBound);
- CRect cRect = item.ClientRect;
- Point zoomPoint = new Point((point.X - pageBound.X) / currentZoom, (point.Y - pageBound.Y) / currentZoom);
- Point pdfPoint = DpiHelper.StandardPointToPDFPoint(zoomPoint);
- rect = new Rect(
- (pdfPoint.X - cRect.width() / 2),
- (pdfPoint.Y - cRect.height() / 2),
- cRect.width(),
- cRect.height()
- );
- }
- CRect setRect = DataConversionForWPF.RectConversionForCRect(rect);
- LineParam newLineParam = new LineParam();
- item.CopyTo(newLineParam);
- {
- float offsetX = setRect.left - item.ClientRect.left;
- float offsetY = setRect.top - item.ClientRect.top;
- newLineParam.HeadPoint = new CPoint(newLineParam.HeadPoint.x + offsetX, newLineParam.HeadPoint.y + offsetY);
- newLineParam.TailPoint = new CPoint(newLineParam.TailPoint.x + offsetX, newLineParam.TailPoint.y + offsetY);
- }
- CPDFPage cPDFPage = cPDFDocument.PageAtIndex(index);
- if (cPDFPage == null)
- return;
- CPDFAnnotation cPDFAnnotation = cPDFPage.CreateAnnot(item.CurrentType);
- CreateDefaultAnnot(cPDFAnnotation, item.CurrentType, item);
- (cPDFAnnotation as CPDFLineAnnotation)?.SetLinePoints(newLineParam.HeadPoint, newLineParam.TailPoint);
- cPDFAnnotation.SetRect(setRect);
- cPDFAnnotation.UpdateAp();
- AnnotParam annotParam = ParamConverter.AnnotConverter(cPDFDocument, cPDFAnnotation);
- (annotHistory as LineAnnotHistory).CurrentParam = (LineParam)annotParam;
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE:
- {
- CPDFDocument cPDFDocument = PDFViewer.GetDocument();
- Rect rect;
- annotHistory = new SquareAnnotHistory();
- annotHistory.PDFDoc = cPDFDocument;
- int index = -1;
- if (point.Equals(new Point(-1, -1)))
- {
- index = item.PageIndex;
- rect = new Rect(
- (item.ClientRect.left + 25),
- (item.ClientRect.top + 25),
- item.ClientRect.width(),
- item.ClientRect.height()
- );
- }
- else
- {
- PDFViewer.GetPointPageInfo(point, out index, out Rect paintRect, out var pageBound);
- CRect cRect = item.ClientRect;
- Point zoomPoint = new Point((point.X - pageBound.X) / currentZoom, (point.Y - pageBound.Y) / currentZoom);
- Point pdfPoint = DpiHelper.StandardPointToPDFPoint(zoomPoint);
- rect = new Rect(
- (pdfPoint.X - cRect.width() / 2),
- (pdfPoint.Y - cRect.height() / 2),
- cRect.width(),
- cRect.height()
- );
- }
- CRect setRect = DataConversionForWPF.RectConversionForCRect(rect);
- CPDFPage cPDFPage = cPDFDocument.PageAtIndex(index);
- if (cPDFPage == null)
- return;
- CPDFAnnotation cPDFAnnotation = cPDFPage.CreateAnnot(item.CurrentType);
- CreateDefaultAnnot(cPDFAnnotation, item.CurrentType, item);
- cPDFAnnotation.SetRect(setRect);
- CPDFTextPage textPage = cPDFPage.GetTextPage();
- if (textPage != null)
- {
- string newContent = textPage.GetBoundedText(setRect);
- cPDFAnnotation.SetContent(newContent);
- }
- cPDFAnnotation.UpdateAp();
- AnnotParam annotParam = ParamConverter.AnnotConverter(cPDFDocument, cPDFAnnotation);
- (annotHistory as SquareAnnotHistory).CurrentParam = (SquareParam)annotParam;
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE:
- {
- CPDFDocument cPDFDocument = PDFViewer.GetDocument();
- Rect rect;
- annotHistory = new CircleAnnotHistory();
- annotHistory.PDFDoc = cPDFDocument;
- int index = -1;
- if (point.Equals(new Point(-1, -1)))
- {
- index = item.PageIndex;
- rect = new Rect(
- (item.ClientRect.left + 25),
- (item.ClientRect.top + 25),
- item.ClientRect.width(),
- item.ClientRect.height()
- );
- }
- else
- {
- PDFViewer.GetPointPageInfo(point, out index, out Rect paintRect, out var pageBound);
- CRect cRect = item.ClientRect;
- Point zoomPoint = new Point((point.X - pageBound.X) / currentZoom, (point.Y - pageBound.Y) / currentZoom);
- Point pdfPoint = DpiHelper.StandardPointToPDFPoint(zoomPoint);
- rect = new Rect(
- (pdfPoint.X - cRect.width() / 2),
- (pdfPoint.Y - cRect.height() / 2),
- cRect.width(),
- cRect.height()
- );
- }
- CRect setRect = DataConversionForWPF.RectConversionForCRect(rect);
- CPDFPage cPDFPage = cPDFDocument.PageAtIndex(index);
- if (cPDFPage == null)
- return;
- CPDFAnnotation cPDFAnnotation = cPDFPage.CreateAnnot(item.CurrentType);
- CreateDefaultAnnot(cPDFAnnotation, item.CurrentType, item);
- cPDFAnnotation.SetRect(setRect);
- CPDFTextPage textPage = cPDFPage.GetTextPage();
- if (textPage != null)
- {
- string newContent = textPage.GetBoundedText(setRect);
- cPDFAnnotation.SetContent(newContent);
- }
- cPDFAnnotation.UpdateAp();
- AnnotParam annotParam = ParamConverter.AnnotConverter(cPDFDocument, cPDFAnnotation);
- (annotHistory as CircleAnnotHistory).CurrentParam = (CircleParam)annotParam;
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
- {
- CPDFDocument cPDFDocument = PDFViewer.GetDocument();
- Rect rect;
- annotHistory = new PolygonMeasureAnnotHistory();
- annotHistory.PDFDoc = cPDFDocument;
- int index = -1;
- if (point.Equals(new Point(-1, -1)))
- {
- index = item.PageIndex;
- rect = new Rect(
- (item.ClientRect.left + 25),
- (item.ClientRect.top + 25),
- item.ClientRect.width(),
- item.ClientRect.height()
- );
- }
- else
- {
- PDFViewer.GetPointPageInfo(point, out index, out Rect paintRect, out var pageBound);
- CRect cRect = item.ClientRect;
- Point zoomPoint = new Point((point.X - pageBound.X) / currentZoom, (point.Y - pageBound.Y) / currentZoom);
- Point pdfPoint = DpiHelper.StandardPointToPDFPoint(zoomPoint);
- rect = new Rect(
- (pdfPoint.X - cRect.width() / 2),
- (pdfPoint.Y - cRect.height() / 2),
- cRect.width(),
- cRect.height()
- );
- }
- CRect setRect = DataConversionForWPF.RectConversionForCRect(rect);
- PolygonMeasureParam newPolygonParam = new PolygonMeasureParam();
- item.CopyTo(newPolygonParam);
- if (newPolygonParam.SavePoints != null && newPolygonParam.SavePoints.Count > 0)
- {
- float offsetX = setRect.left - item.ClientRect.left;
- float offsetY = setRect.top - item.ClientRect.top;
- List<CPoint> arrangeList = new List<CPoint>();
- foreach (CPoint addPoint in newPolygonParam.SavePoints)
- {
- arrangeList.Add(new CPoint(addPoint.x + offsetX, addPoint.y + offsetY));
- }
- newPolygonParam.SavePoints = arrangeList;
- newPolygonParam.ClientRect = setRect;
- }
- CPDFPage cPDFPage = cPDFDocument.PageAtIndex(index);
- if (cPDFPage == null)
- return;
- CPDFAnnotation cPDFAnnotation = cPDFPage.CreateAnnot(newPolygonParam.CurrentType);
- CreateDefaultAnnot(cPDFAnnotation, newPolygonParam.CurrentType, newPolygonParam);
- cPDFAnnotation.UpdateAp();
- AnnotParam annotParam = ParamConverter.AnnotConverter(cPDFDocument, cPDFAnnotation);
- (annotHistory as PolygonMeasureAnnotHistory).CurrentParam = (PolygonMeasureParam)annotParam;
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE:
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_STAMP:
- {
- CPDFDocument cPDFDocument = PDFViewer.GetDocument();
- Rect rect;
- annotHistory = new StampAnnotHistory();
- annotHistory.PDFDoc = cPDFDocument;
- int index = -1;
- if (point.Equals(new Point(-1, -1)))
- {
- index = item.PageIndex;
- rect = new Rect(
- (item.ClientRect.left + 25),
- (item.ClientRect.top + 25),
- item.ClientRect.width(),
- item.ClientRect.height()
- );
- }
- else
- {
- PDFViewer.GetPointPageInfo(point, out index, out Rect paintRect, out var pageBound);
- CRect cRect = (item as StampParam).SourceRect;
- Point zoomPoint = new Point((point.X - pageBound.X) / currentZoom, (point.Y - pageBound.Y) / currentZoom);
- Point pdfPoint = DpiHelper.StandardPointToPDFPoint(zoomPoint);
- rect = new Rect(
- (pdfPoint.X - cRect.width() / 2),
- (pdfPoint.Y - cRect.height() / 2),
- cRect.width(),
- cRect.height()
- );
- }
- CRect setRect = DataConversionForWPF.RectConversionForCRect(rect);
- CPDFPage cPDFPage = cPDFDocument.PageAtIndex(index);
- if (cPDFPage == null)
- return;
- CPDFAnnotation cPDFAnnotation = cPDFPage.CreateAnnot(item.CurrentType);
- (cPDFAnnotation as CPDFStampAnnotation).SetSourceRect(setRect);
- //cPDFAnnotation.SetRect(setRect);
- CreateDefaultAnnot(cPDFAnnotation, item.CurrentType, item);
- cPDFAnnotation.UpdateAp();
- AnnotParam annotParam = ParamConverter.AnnotConverter(cPDFDocument, cPDFAnnotation);
- (annotHistory as StampAnnotHistory).CurrentParam = (StampParam)annotParam;
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_CARET:
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_INK:
- {
- CPDFDocument cPDFDocument = PDFViewer.GetDocument();
- Rect rect;
- annotHistory = new InkAnnotHistory();
- annotHistory.PDFDoc = cPDFDocument;
- int index = -1;
- if (point.Equals(new Point(-1, -1)))
- {
- index = item.PageIndex;
- rect = new Rect(
- (item.ClientRect.left + 25),
- (item.ClientRect.top + 25),
- item.ClientRect.width(),
- item.ClientRect.height()
- );
- }
- else
- {
- PDFViewer.GetPointPageInfo(point, out index, out Rect paintRect, out var pageBound);
- CRect cRect = item.ClientRect;
- Point zoomPoint = new Point((point.X - pageBound.X) / currentZoom, (point.Y - pageBound.Y) / currentZoom);
- Point pdfPoint = DpiHelper.StandardPointToPDFPoint(zoomPoint);
- rect = new Rect(
- (pdfPoint.X - cRect.width() / 2),
- (pdfPoint.Y - cRect.height() / 2),
- cRect.width(),
- cRect.height()
- );
- }
- CRect setRect = DataConversionForWPF.RectConversionForCRect(rect);
- InkParam newInkParam = new InkParam();
- item.CopyTo(newInkParam);
- if (newInkParam.InkPath != null && newInkParam.InkPath.Count > 0)
- {
- float offsetX = setRect.left - item.ClientRect.left;
- float offsetY = setRect.top - item.ClientRect.top;
- List<List<CPoint>> arrangeList = new List<List<CPoint>>();
- foreach (List<CPoint> inkNode in newInkParam.InkPath)
- {
- List<CPoint> inkPath = new List<CPoint>();
- arrangeList.Add(inkPath);
- foreach (CPoint addPoint in inkNode)
- {
- inkPath.Add(new CPoint(addPoint.x + offsetX, addPoint.y + offsetY));
- }
- }
- newInkParam.InkPath = arrangeList;
- newInkParam.ClientRect = setRect;
- }
- CPDFPage cPDFPage = cPDFDocument.PageAtIndex(index);
- if (cPDFPage == null)
- return;
- CPDFAnnotation cPDFAnnotation = cPDFPage.CreateAnnot(newInkParam.CurrentType);
- CreateDefaultAnnot(cPDFAnnotation, newInkParam.CurrentType, newInkParam);
- cPDFAnnotation.UpdateAp();
- AnnotParam annotParam = ParamConverter.AnnotConverter(cPDFDocument, cPDFAnnotation);
- (annotHistory as InkAnnotHistory).CurrentParam = (InkParam)annotParam;
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_POPUP:
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_FILEATTACHMENT:
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET:
- {
- rightPressPoint = point;
- bool result = PasteWidgetData(ref annotHistory, item as WidgetParm);
- if (!result)
- return;
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_SCREEN:
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_PRINTERMARK:
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_TRAPNET:
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_WATERMARK:
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_3D:
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_RICHMEDIA:
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_INTERCHANGE:
- break;
- default:
- break;
- }
- if (annotHistory != null)
- {
- PasteParam = annotHistory.CurrentParam;
- groupHistory.Histories.Add(annotHistory);
- }
- }
- PDFViewer.UndoManager.AddHistory(groupHistory);
- }
- else
- {
- AnnotHistory annotHistory = null;
-
- if (string.IsNullOrEmpty(CopyString))
- {
- return;
- }
- Point point = rightPressPoint;
- rightPressPoint = new Point(-1, -1);
- CPDFDocument cPDFDocument = PDFViewer.GetDocument();
- Rect rect;
- annotHistory = new FreeTextAnnotHistory();
- annotHistory.PDFDoc = cPDFDocument;
- int index = -1;
- FreeTextParam freeTextParam = new FreeTextParam();
- freeTextParam.Content = CopyString;
- freeTextParam.FontSize = 14;
- freeTextParam.FontColor = new byte[3] { 0, 0, 0 };
- PDFViewer.GetPointPageInfo(point, out index, out Rect paintRect, out var pageBound);
- CPDFPage cPDFPage = cPDFDocument.PageAtIndex(index);
- if (cPDFPage == null)
- return;
- CPDFAnnotation cPDFAnnotation = cPDFPage.CreateAnnot(freeTextParam.CurrentType);
- var freeTextAnnot = cPDFAnnotation as CPDFFreeTextAnnotation;
- freeTextAnnot.SetContent(CopyString);
- freeTextParam.ClientRect = freeTextAnnot.GetTextRect();
- if (point.Equals(new Point(-1, -1)))
- {
- return;
- }
- else
- {
- CRect cRect = freeTextParam.ClientRect;
- Point zoomPoint = new Point((point.X - pageBound.X) / currentZoom, (point.Y - pageBound.Y) / currentZoom);
- Point pdfPoint = DpiHelper.StandardPointToPDFPoint(zoomPoint);
- rect = new Rect(
- (pdfPoint.X - cRect.width() / 2),
- (pdfPoint.Y - cRect.height() / 2),
- cRect.width(),
- cRect.height()
- );
- }
- CRect setRect = DataConversionForWPF.RectConversionForCRect(rect);
- CreateDefaultAnnot(cPDFAnnotation, freeTextParam.CurrentType, freeTextParam);
- cPDFAnnotation.SetRect(setRect);
- cPDFAnnotation.UpdateAp();
- AnnotParam annotParam = ParamConverter.AnnotConverter(cPDFDocument, cPDFAnnotation);
- (annotHistory as FreeTextAnnotHistory).CurrentParam = (FreeTextParam)annotParam;
- PasteParam = annotHistory.CurrentParam;
- PDFViewer.UndoManager.AddHistory(annotHistory);
- }
- }
- private void DeleteAnnotData()
- {
- dynamic notifyData = null;
- AnnotSelector mrect = GetAnnotSelectsRect();
- if (mrect != null && mrect.SelectAnnots.Count > 0)
- {
- GroupHistory historyGroup = new GroupHistory();
- List<AnnotData> annotDatas = new List<AnnotData>();
- foreach (var annotData in mrect.SelectAnnots)
- {
- annotDatas.Add(annotData);
- }
- annotDatas = annotDatas.OrderByDescending(x => x.AnnotIndex).ToList();
- List<AnnotParam> annotParams = new List<AnnotParam>();
- foreach (var annotData in annotDatas)
- {
- annotParams.Add(ParamConverter.AnnotConverter(PDFViewer.GetDocument(), annotData.Annot));
- }
- foreach (var annotData in annotDatas)
- {
- var annotHistory = ParamConverter.CreateHistory(annotData.Annot);
- var annotParam = annotParams[annotDatas.IndexOf(annotData)];
- if (annotParam != null)
- {
- notifyData = new ExpandoObject();
- notifyData.Action = HistoryAction.Remove;
- notifyData.PageIndex = annotParam.PageIndex;
- notifyData.AnnotIndex = annotParam.AnnotIndex;
- notifyData.AnnotType = annotParam.CurrentType;
- notifyData.CurrentParam = annotParam;
- if (annotParam is WidgetParm)
- {
- notifyData.WidgetType = (annotParam as WidgetParm).WidgetType;
- }
- annotHistory.CurrentParam = annotParam;
- annotHistory.PDFDoc = PDFViewer.GetDocument();
- annotHistory.Action = HistoryAction.Remove;
- historyGroup.Histories.Add(annotHistory);
- List<C_ANNOTATION_TYPE> checkEditType = new List<C_ANNOTATION_TYPE>()
- {
- C_ANNOTATION_TYPE.C_ANNOTATION_LINE,
- C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE,
- C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON
- };
- if (checkEditType.Contains(annotData.AnnotType))
- {
- //Need to clear the measurement selected edit box.
- CleanEditAnnot();
- }
- annotData.Annot.RemoveAnnot();
- }
- }
- mrect.ClearItem();
- mrect.CleanDraw();
- mrect = null;
- PDFViewer.UndoManager.AddHistory(historyGroup);
- }
- else
- if (cacheHitTestAnnot != null)
- {
- AnnotHistory annotHistory = ParamConverter.CreateHistory(cacheHitTestAnnot.GetAnnotData().Annot);
- if (annotHistory == null)
- {
- return;
- }
- AnnotParam annotParam = null;
- if (cacheHitTestAnnot is BaseWidget)
- {
- annotParam = ParamConverter.WidgetConverter(PDFViewer.GetDocument(), cacheHitTestAnnot.GetAnnotData().Annot);
- }
- else
- {
- annotParam = ParamConverter.AnnotConverter(PDFViewer.GetDocument(), cacheHitTestAnnot.GetAnnotData().Annot);
- }
- if (annotParam != null)
- {
- notifyData = new ExpandoObject();
- notifyData.Action = HistoryAction.Remove;
- notifyData.PageIndex = annotParam.PageIndex;
- notifyData.AnnotIndex = annotParam.AnnotIndex;
- notifyData.AnnotType = annotParam.CurrentType;
- notifyData.CurrentParam = annotParam;
- if (annotParam is WidgetParm)
- {
- notifyData.WidgetType = (annotParam as WidgetParm).WidgetType;
- }
- annotHistory.CurrentParam = annotParam;
- annotHistory.PDFDoc = PDFViewer.GetDocument();
- annotHistory.Action = HistoryAction.Remove;
- PDFViewer.UndoManager.AddHistory(annotHistory);
- List<C_ANNOTATION_TYPE> checkEditType = new List<C_ANNOTATION_TYPE>()
- {
- C_ANNOTATION_TYPE.C_ANNOTATION_LINE,
- C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE,
- C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON
- };
- if (checkEditType.Contains(cacheHitTestAnnot.CurrentType))
- {
- //Need to clear the measurement selected edit box.
- CleanEditAnnot();
- }
- cacheHitTestAnnot.RemoveClean(true);
- cacheHitTestAnnot.GetAnnotData().Annot.RemoveAnnot();
- cacheHitTestAnnot = null;
- }
- CleanSelectedRect();
- }
- else if (cacheMoveWidget != null)
- {
- AnnotHistory annotHistory = ParamConverter.CreateHistory(cacheMoveWidget.GetAnnotData().Annot);
- if (annotHistory == null)
- {
- return;
- }
- AnnotParam annotParam = ParamConverter.WidgetConverter(PDFViewer.GetDocument(), cacheMoveWidget.GetAnnotData().Annot);
- if (annotParam != null)
- {
- notifyData = new ExpandoObject();
- notifyData.Action = HistoryAction.Remove;
- notifyData.PageIndex = annotParam.PageIndex;
- notifyData.AnnotIndex = annotParam.AnnotIndex;
- notifyData.AnnotType = annotParam.CurrentType;
- notifyData.WidgetType = (annotParam as WidgetParm).WidgetType;
- notifyData.CurrentParam = annotParam;
- annotHistory.CurrentParam = annotParam;
- annotHistory.PDFDoc = PDFViewer.GetDocument();
- annotHistory.Action = HistoryAction.Remove;
- PDFViewer.UndoManager.AddHistory(annotHistory);
- cacheMoveWidget.GetAnnotData().Annot.RemoveAnnot();
- cacheMoveWidget = null;
- }
- CleanSelectedRect();
- }
- if (notifyData != null)
- {
- AnnotChanged?.Invoke(this, notifyData);
- }
- }
- private bool PasteWidgetData(ref AnnotHistory annotHistory, WidgetParm item)
- {
- CPDFDocument cPDFDocument = PDFViewer.GetDocument();
- Point point = rightPressPoint;
- rightPressPoint = new Point(-1, -1);
- Rect rect;
- int index = -1;
- if (point.Equals(new Point(-1, -1)))
- {
- index = item.PageIndex;
- rect = new Rect(
- (item.ClientRect.left + 25),
- (item.ClientRect.top + 25),
- item.ClientRect.width(),
- item.ClientRect.height()
- );
- }
- else
- {
- PDFViewer.GetPointPageInfo(point, out index, out Rect paintRect, out var pageBound);
- CRect cRect = item.ClientRect;
- Point zoomPoint = new Point((point.X - pageBound.X) / currentZoom, (point.Y - pageBound.Y) / currentZoom);
- Point pdfPoint = DpiHelper.StandardPointToPDFPoint(zoomPoint);
- rect = new Rect(
- (pdfPoint.X - cRect.width() / 2),
- (pdfPoint.Y - cRect.height() / 2),
- cRect.width(),
- cRect.height()
- );
- }
- CPDFPage cPDFPage = cPDFDocument.PageAtIndex(index);
- if (cPDFPage == null)
- return false;
- CPDFAnnotation cPDFAnnotation = cPDFPage.CreateWidget(item.WidgetType);
- CreateDefaultWidget(cPDFAnnotation, item.WidgetType, item);
- CRect setRect = DataConversionForWPF.RectConversionForCRect(rect);
- cPDFAnnotation.SetRect(setRect);
- (cPDFAnnotation as CPDFWidget).UpdateFormAp();
- AnnotParam annotParam = ParamConverter.WidgetConverter(cPDFDocument, cPDFAnnotation);
- switch (item.WidgetType)
- {
- case C_WIDGET_TYPE.WIDGET_NONE:
- break;
- case C_WIDGET_TYPE.WIDGET_PUSHBUTTON:
- annotHistory = new PushButtonHistory();
- (annotHistory as PushButtonHistory).CurrentParam = (PushButtonParam)annotParam;
- annotHistory.PDFDoc = cPDFDocument;
- break;
- case C_WIDGET_TYPE.WIDGET_CHECKBOX:
- annotHistory = new CheckBoxHistory();
- (annotHistory as CheckBoxHistory).CurrentParam = (CheckBoxParam)annotParam;
- annotHistory.PDFDoc = cPDFDocument;
- break;
- case C_WIDGET_TYPE.WIDGET_RADIOBUTTON:
- annotHistory = new RadioButtonHistory();
- (annotHistory as RadioButtonHistory).CurrentParam = (RadioButtonParam)annotParam;
- annotHistory.PDFDoc = cPDFDocument;
- break;
- case C_WIDGET_TYPE.WIDGET_TEXTFIELD:
- annotHistory = new TextBoxHistory();
- (annotHistory as TextBoxHistory).CurrentParam = (TextBoxParam)annotParam;
- annotHistory.PDFDoc = cPDFDocument;
- break;
- case C_WIDGET_TYPE.WIDGET_COMBOBOX:
- annotHistory = new ComboBoxHistory();
- (annotHistory as ComboBoxHistory).CurrentParam = (ComboBoxParam)annotParam;
- annotHistory.PDFDoc = cPDFDocument;
- break;
- case C_WIDGET_TYPE.WIDGET_LISTBOX:
- annotHistory = new ListBoxHistory();
- (annotHistory as ListBoxHistory).CurrentParam = (ListBoxParam)annotParam;
- annotHistory.PDFDoc = cPDFDocument;
- break;
- case C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS:
- annotHistory = new SignatureHistory();
- (annotHistory as SignatureHistory).CurrentParam = (SignatureParam)annotParam;
- annotHistory.PDFDoc = cPDFDocument;
- break;
- case C_WIDGET_TYPE.WIDGET_UNKNOWN:
- break;
- default:
- break;
- }
- return true;
- }
- public void RemoveLastAnnotList()
- {
- if (lastAnnotList != null)
- {
- lastAnnotList.Clear();
- }
- }
- public void SetCopyText(string copyText)
- {
- CopyText = copyText;
- }
- #endregion
- }
- }
|