CPDFViewerTool.TextEdit.cs 119 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857
  1. using ComPDFKit.Import;
  2. using ComPDFKit.PDFDocument;
  3. using ComPDFKit.PDFPage;
  4. using ComPDFKit.PDFPage.Edit;
  5. using ComPDFKit.Tool.DrawTool;
  6. using ComPDFKit.Tool.Help;
  7. using ComPDFKit.Tool.SettingParam;
  8. using ComPDFKit.Tool.UndoManger;
  9. using ComPDFKit.Viewer.Helper;
  10. using ComPDFKit.Viewer.Layer;
  11. using ComPDFKitViewer;
  12. using ComPDFKitViewer.Helper;
  13. using ComPDFKitViewer.Layer;
  14. using System;
  15. using System.Collections.Generic;
  16. using System.Diagnostics;
  17. using System.Linq;
  18. using System.Text;
  19. using System.Threading;
  20. using System.Threading.Tasks;
  21. using System.Windows;
  22. using System.Windows.Input;
  23. using System.Windows.Media;
  24. namespace ComPDFKit.Tool
  25. {
  26. /// <summary>
  27. /// Single text block related parameters
  28. /// </summary>
  29. public class EditAreaObject
  30. {
  31. internal CPDFEditArea cPDFEditArea { get; set; }
  32. internal CPDFEditPage cPDFEditPage { get; set; }
  33. /// <summary>
  34. /// Current page number
  35. /// </summary>
  36. internal int PageIndex { get; set; }
  37. /// <summary>
  38. /// EditArea index of the current page
  39. /// </summary>
  40. internal int EditAreaIndex { get; set; }
  41. /// <summary>
  42. /// Draw the rectangle of the complete page
  43. /// </summary>
  44. public Rect PageBound { get; set; }
  45. /// <summary>
  46. /// Draw the rectangle of the visible range
  47. /// </summary>
  48. public Rect PaintRect { get; set; }
  49. /// <summary>
  50. /// State of the current control point
  51. /// </summary>
  52. public PointControlType ControlType { get; set; }
  53. }
  54. public enum CEditingLocation
  55. {
  56. CEditingLocationLineBegin = 0,
  57. CEditingLoadTypeLineEnd,
  58. CEditingLoadTypeSectionBegin,
  59. CEditingLoadTypeSectionEnd,
  60. CEditingLoadTypePreWord,
  61. CEditingLoadTypeNextWord,
  62. CEditingLoadTypePreCharPlace,
  63. CEditingLoadTypeNextCharPlace,
  64. CEditingLoadTypeUpCharPlace,
  65. CEditingLoadTypeDownCharPlace,
  66. }
  67. public enum AlignModes
  68. {
  69. AlignNone,
  70. AlignLeft,
  71. AlignVerticalCenter,
  72. AlignRight,
  73. AlignTop,
  74. AlignHorizonCenter,
  75. AlignBottom,
  76. DistributeVertical,
  77. DistributeHorizontal
  78. }
  79. public partial class CPDFViewerTool
  80. {
  81. /// <summary>
  82. /// Expend the area for taking pictures to avoid the edge of the picture not being completely covered due to accuracy
  83. /// </summary>
  84. private double editPadding = 5;
  85. private Point pointtest;
  86. private int pageindex;
  87. private SelectedRect lastSelectedRect = null;
  88. //start Multiple selection of first data record
  89. private SelectedRect startSelectedRect = null;
  90. private EditAreaObject startSelectedEditAreaObject = null;
  91. private int startSelectedIndex = -1;
  92. private int startSelectedPageIndex = -1;
  93. //end
  94. private SelectedRect lastHoverRect = null;
  95. private int cropIndex = -1;
  96. private int textEditTag = -1;
  97. private double currentZoom;
  98. private EditAreaObject currentEditAreaObject = null;
  99. private int selectedEditPageIndex = -1;
  100. private bool drawCaret = true;
  101. private int selectedEditAreaIndex = -1;
  102. private bool selectAllCharsForLine = false;
  103. private CPoint rawHitPos;
  104. private CPDFEditType contentEditType = CPDFEditType.EditText | CPDFEditType.EditImage;
  105. /// <summary>
  106. /// Save Current Crop Box
  107. /// </summary>
  108. private Thickness ClipThickness = new Thickness(0, 0, 0, 0);
  109. /// <summary>
  110. /// Input variable string
  111. /// </summary>
  112. private StringBuilder delayTextBuilder { get; set; }
  113. private int delayCount = 0;
  114. /// <summary>
  115. /// Node of the object used for drawing when selecting/creating text in the current view tree, for easy removal
  116. /// </summary>
  117. private int operateChildrenIndex = -1;
  118. /// <summary>
  119. /// Pressed point of selected text
  120. /// </summary>
  121. private Point pressPoint;
  122. private Dictionary<SelectedRect, EditAreaObject> editArea = new Dictionary<SelectedRect, EditAreaObject>();
  123. /// <summary>
  124. /// Multiple selection record list
  125. /// </summary>
  126. private Dictionary<SelectedRect, EditAreaObject> editAreaList = new Dictionary<SelectedRect, EditAreaObject>();
  127. /// <summary>
  128. /// Cache the hit test rectangle area when loading the text block each time
  129. /// </summary>
  130. private List<SelectedRect> hitTestRects = new List<SelectedRect>();
  131. private List<SelectedRect> image = new List<SelectedRect>();
  132. private List<SelectedRect> text = new List<SelectedRect>();
  133. protected List<PointControlType> ignoreTextPoints { get; set; } = new List<PointControlType>();
  134. protected List<PointControlType> ignoreImagePoints { get; set; } = new List<PointControlType>();
  135. protected DrawPointType drawEditPointType = DrawPointType.Square;
  136. protected Pen editPen = null;
  137. protected Pen editHoverPen = null;
  138. /// <summary>
  139. /// Cursor movement changes event
  140. /// </summary>
  141. public event EventHandler CaretVisualAreaChanged;
  142. /// <summary>
  143. /// Edit border point style settings
  144. /// </summary>
  145. /// <param name="ignoreTextPoints"></param>
  146. /// <param name="ignoreImagePoints"></param>
  147. /// <param name="drawEditPointType"></param>
  148. public void SetEditIgnorePints(List<PointControlType> ignoreTextPoints, List<PointControlType> ignoreImagePoints, DrawPointType drawEditPointType)
  149. {
  150. this.ignoreTextPoints = ignoreTextPoints;
  151. this.ignoreImagePoints = ignoreImagePoints;
  152. this.drawEditPointType = drawEditPointType;
  153. }
  154. /// <summary>
  155. /// Edit preliminary display of border style status
  156. /// </summary>
  157. /// <param name="editPen"></param>
  158. public void SetEditPen(Pen editPen = null, Pen editHoverPen = null)
  159. {
  160. this.editPen = editPen;
  161. this.editHoverPen = editHoverPen;
  162. }
  163. public Pen GetEditPen()
  164. {
  165. return editPen;
  166. }
  167. /// <summary>
  168. /// Restore Crop Box
  169. /// </summary>
  170. /// <param name="rect"></param>
  171. public void SetClipThickness(Thickness rect = new Thickness())
  172. {
  173. this.ClipThickness = rect;
  174. }
  175. /// <summary>
  176. /// Restore Crop Box
  177. /// </summary>
  178. /// <param name="rect"></param>
  179. public Thickness GetClipThickness()
  180. {
  181. return this.ClipThickness;
  182. }
  183. private void InsertTextEditView()
  184. {
  185. int selectedRectViewIndex = PDFViewer.GetMaxViewIndex();
  186. CustomizeLayer customizeLayer = new CustomizeLayer();
  187. PDFViewer.InsertView(selectedRectViewIndex, customizeLayer);
  188. textEditTag = customizeLayer.GetResTag();
  189. AddHandler(KeyDownEvent, new RoutedEventHandler(KeyInputEventHandler));
  190. }
  191. /// <summary>
  192. /// Set selected
  193. /// </summary>
  194. /// <param name="pageIndex"></param>
  195. /// <param name="editAreaIndex"></param>
  196. public void SelectedEditAreaForIndex(int pageIndex, int editAreaIndex, bool drawCaret = true)
  197. {
  198. selectAllCharsForLine = false;
  199. selectedEditPageIndex = pageIndex;
  200. selectedEditAreaIndex = editAreaIndex;
  201. this.drawCaret = drawCaret;
  202. }
  203. /// <summary>
  204. /// Get the current set edit index
  205. /// </summary>
  206. /// <param name="pageIndex"></param>
  207. /// <param name="editAreaIndex"></param>
  208. public void GetSelectedEditAreaForIndex(out int pageIndex, out int editAreaIndex)
  209. {
  210. pageIndex = selectedEditPageIndex;
  211. editAreaIndex = selectedEditAreaIndex;
  212. }
  213. /// <summary>
  214. /// Refresh the cursor and selected drawing effect
  215. /// </summary>
  216. public void DrawSelectedEditAreaForIndex()
  217. {
  218. if (lastSelectedRect != null)
  219. {
  220. lastSelectedRect.SetIsHover(false);
  221. lastSelectedRect.SetIsSelected(false);
  222. lastSelectedRect.SetIgnorePointsAll();
  223. lastSelectedRect.Draw();
  224. }
  225. foreach (KeyValuePair<SelectedRect, EditAreaObject> item in editArea)
  226. {
  227. if (selectedEditPageIndex == item.Value.PageIndex &&
  228. selectedEditAreaIndex == item.Value.EditAreaIndex)
  229. {
  230. if (currentEditAreaObject != null)
  231. {
  232. PointControlType controlType = currentEditAreaObject.ControlType;
  233. currentEditAreaObject = item.Value;
  234. currentEditAreaObject.ControlType = controlType;
  235. }
  236. else
  237. {
  238. currentEditAreaObject = item.Value;
  239. currentEditAreaObject.ControlType = PointControlType.Body;
  240. }
  241. CaretVisual caretVisual = CommonHelper.FindVisualChild<CaretVisual>(PDFViewer.GetViewForTag(textEditTag));
  242. if (selectAllCharsForLine)
  243. {
  244. caretVisual.SetZoom(0);
  245. }
  246. else
  247. {
  248. caretVisual.SetZoom(currentZoom);
  249. }
  250. caretVisual.SetPaintOffset(item.Key.GetMaxRect());
  251. if (currentEditAreaObject.cPDFEditArea.Type == CPDFEditType.EditText && !selectAllCharsForLine)
  252. {
  253. DrawCaretVisualArea(currentEditAreaObject.cPDFEditArea as CPDFEditTextArea, drawCaret);
  254. }
  255. lastSelectedRect = item.Key;
  256. item.Key.SetIsSelected(true);
  257. List<PointControlType> ignorePoints = new List<PointControlType>();
  258. //Set Box Selection Style
  259. if (selectedEditAreaIndex == cropIndex)
  260. {
  261. item.Key.SetCurrentDrawPointType(DrawPointType.Crop);
  262. if (!ClipThickness.Equals(new Thickness(0, 0, 0, 0)))
  263. {
  264. //Restore Crop Box
  265. item.Key.SetClipThickness(ClipThickness);
  266. }
  267. ignorePoints.Add(PointControlType.Body);
  268. }
  269. else
  270. {
  271. lastSelectedRect.DataChanged -= LastSelectedRect_DataChanged;
  272. lastSelectedRect.DataChanged += LastSelectedRect_DataChanged;
  273. }
  274. if (item.Value.cPDFEditArea is CPDFEditTextArea)
  275. {
  276. item.Key.SetEditIgnorePoints(ignoreTextPoints, ignoreImagePoints, drawEditPointType);
  277. }
  278. else
  279. {
  280. if (selectedEditAreaIndex == cropIndex)
  281. {
  282. item.Key.SetIgnorePoints(ignorePoints);
  283. }
  284. else
  285. {
  286. item.Key.SetEditIgnorePoints(ignoreTextPoints, ignoreImagePoints, drawEditPointType, false);
  287. }
  288. }
  289. item.Key.Draw();
  290. break;
  291. }
  292. }
  293. }
  294. /// <summary>
  295. /// Get the selected box of an annotation according to the index
  296. /// </summary>
  297. public SelectedRect GetEditAreaForIndex(int pageIndex, int editAreaIndex)
  298. {
  299. foreach (KeyValuePair<SelectedRect, EditAreaObject> item in editArea)
  300. {
  301. if (pageIndex == item.Value.PageIndex &&
  302. editAreaIndex == item.Value.EditAreaIndex)
  303. {
  304. return item.Key;
  305. }
  306. }
  307. return null;
  308. }
  309. /// <summary>
  310. /// Index Get List Value
  311. /// </summary>
  312. /// <param name="pageIndex"></param>
  313. /// <param name="editAreaIndex"></param>
  314. /// <returns></returns>
  315. public EditAreaObject GetSelectedForIndex(int pageIndex, int editAreaIndex)
  316. {
  317. foreach (KeyValuePair<SelectedRect, EditAreaObject> item in editArea)
  318. {
  319. if (pageIndex == item.Value.PageIndex &&
  320. editAreaIndex == item.Value.EditAreaIndex)
  321. {
  322. return item.Value;
  323. }
  324. }
  325. return null;
  326. }
  327. public void SetCurrentEditType(CPDFEditType editType)
  328. {
  329. contentEditType = editType;
  330. }
  331. /// <summary>
  332. /// Refresh the current edit data
  333. /// </summary>
  334. /// <param name="currentRenderFrame"></param>
  335. public void SetEditTextRect(RenderFrame currentRenderFrame)
  336. {
  337. lastSelectedRect = null;
  338. editArea.Clear();
  339. hitTestRects.Clear();
  340. image.Clear();
  341. text.Clear();
  342. BaseLayer customizeLayer = PDFViewer.GetViewForTag(textEditTag);
  343. customizeLayer.Children.Clear();
  344. operateChildrenIndex = -1;
  345. CaretVisual caretVisual = new CaretVisual(GetDefaultDrawParam());
  346. customizeLayer.Children.Add(caretVisual);
  347. currentZoom = currentRenderFrame.ZoomFactor;
  348. foreach (RenderData item in currentRenderFrame.GetRenderDatas())
  349. {
  350. if (item.CPDFEditPageObj == null)
  351. {
  352. continue;
  353. }
  354. foreach (CPDFEditArea editArea in item.CPDFEditPageObj.GetEditAreaList().AsEnumerable().Reverse())
  355. {
  356. SelectedRect selectedRect = new SelectedRect(GetDefaultDrawParam(), SelectedType.PDFEdit);
  357. selectedRect.SetEditPen(editPen, editHoverPen);
  358. selectedRect.SetDrawMoveType(DrawMoveType.kReferenceLine);
  359. customizeLayer.Children.Add(selectedRect);
  360. Rect TextBlock = DataConversionForWPF.CRectConversionForRect(editArea.GetFrame());
  361. if (editArea.Type == CPDFEditType.EditImage)
  362. {
  363. if ((contentEditType & CPDFEditType.EditImage) != CPDFEditType.EditImage)
  364. {
  365. continue;
  366. }
  367. TextBlock = DataConversionForWPF.CRectConversionForRect((editArea as CPDFEditImageArea).GetClipRect());
  368. }
  369. else if (editArea.Type == CPDFEditType.EditText)
  370. {
  371. if ((contentEditType & CPDFEditType.EditText) != CPDFEditType.EditText)
  372. {
  373. continue;
  374. }
  375. }
  376. Rect rect = TextBlock;
  377. rect.X = (rect.X) * currentRenderFrame.ZoomFactor;
  378. rect.Y = (rect.Y) * currentRenderFrame.ZoomFactor;
  379. rect.Width *= currentRenderFrame.ZoomFactor;
  380. rect.Height *= currentRenderFrame.ZoomFactor;
  381. rect = DpiHelper.PDFRectToStandardRect(rect);
  382. rect.X += item.PageBound.X;
  383. rect.Y += item.PageBound.Y;
  384. //PDF对象设置界面矩形
  385. selectedRect.SetRectPadding(5);
  386. selectedRect.SetRect(rect, currentZoom);
  387. selectedRect.SetMaxRect(item.PageBound);
  388. selectedRect.SetIgnorePointsAll();
  389. selectedRect.Draw();
  390. EditAreaObject editAreaObject = new EditAreaObject();
  391. editAreaObject.ControlType = PointControlType.None;
  392. editAreaObject.cPDFEditArea = editArea;
  393. editAreaObject.cPDFEditPage = item.CPDFEditPageObj;
  394. editAreaObject.PageIndex = item.PageIndex;
  395. editAreaObject.EditAreaIndex = item.CPDFEditPageObj.GetEditAreaList().IndexOf(editArea);
  396. editAreaObject.PageBound = item.PageBound;
  397. editAreaObject.PaintRect = item.PaintRect;
  398. this.editArea.Add(selectedRect, editAreaObject);
  399. switch (editArea.Type)
  400. {
  401. case CPDFEditType.None:
  402. break;
  403. case CPDFEditType.EditText:
  404. text.Add(selectedRect);
  405. break;
  406. case CPDFEditType.EditImage:
  407. image.Add(selectedRect);
  408. break;
  409. default:
  410. break;
  411. }
  412. }
  413. }
  414. hitTestRects.AddRange(text);
  415. hitTestRects.AddRange(image);
  416. }
  417. public void DrawStartTextEdit(SelectedRect selectedRect, EditAreaObject editAreaObject)
  418. {
  419. Point point = Mouse.GetPosition(this);
  420. if (!GetIsCropMode())
  421. {
  422. if (editAreaObject.cPDFEditArea is CPDFEditTextArea)
  423. {
  424. //Crop judgment point position
  425. selectedRect.SetEditIgnorePoints(ignoreTextPoints, ignoreImagePoints, drawEditPointType);
  426. }
  427. else
  428. {
  429. selectedRect.SetEditIgnorePoints(ignoreTextPoints, ignoreImagePoints, drawEditPointType, false);
  430. }
  431. }
  432. if (selectedRect != null)
  433. {
  434. selectedRect.Draw();
  435. selectedRect.OnMouseLeftButtonDown(point);
  436. isDrawSelectRect = true;
  437. }
  438. }
  439. public void DrawMoveTextEdit(SelectedRect selectedRect, bool selectText)
  440. {
  441. Point point = Mouse.GetPosition(this);
  442. if (selectedRect != null && lastSelectedRect != null)
  443. {
  444. //CleanDraw();
  445. if (selectText)
  446. {
  447. editArea.TryGetValue(lastSelectedRect, out EditAreaObject editAreaObject);
  448. if (editAreaObject.cPDFEditArea is CPDFEditTextArea)
  449. {
  450. Rect checkRect = selectedRect.GetDrawRect();
  451. if (point.X > checkRect.Right)
  452. {
  453. point.X = checkRect.Right;
  454. }
  455. if (point.X < checkRect.Left)
  456. {
  457. point.X = checkRect.Left;
  458. }
  459. if (point.Y > checkRect.Bottom)
  460. {
  461. point.Y = checkRect.Bottom;
  462. }
  463. if (point.Y < checkRect.Top)
  464. {
  465. point.Y = checkRect.Top;
  466. }
  467. Point startPoint = new Point(pressPoint.X - editAreaObject.PageBound.X, pressPoint.Y - editAreaObject.PageBound.Y);
  468. Point endPoint = new Point(point.X - editAreaObject.PageBound.X, point.Y - editAreaObject.PageBound.Y);
  469. SelectText(editAreaObject.cPDFEditArea as CPDFEditTextArea, startPoint, endPoint);
  470. CleanDraw();
  471. }
  472. }
  473. else
  474. {
  475. selectedRect.SetOutSideScaling(isOutSideScaling);
  476. selectedRect.OnMouseMove(point, out bool Tag, PDFViewer.ActualWidth, PDFViewer.ActualHeight);
  477. if (selectedEditAreaIndex == cropIndex)
  478. {
  479. //Refresh ClipRect
  480. ClipThickness = selectedRect.GetClipThickness();
  481. }
  482. else
  483. {
  484. //reduction
  485. ClipThickness = new Thickness(0, 0, 0, 0);
  486. }
  487. selectedRect.Draw();
  488. }
  489. }
  490. }
  491. public void DrawMoveMultiTextEdit(MultiSelectedRect selectedRect)
  492. {
  493. //Point point = Mouse.GetPosition(this);
  494. //if (selectedRect != null)
  495. //{
  496. // selectedRect.OnMouseMove(point, out bool Tag, PDFViewer.ActualWidth, PDFViewer.ActualHeight);
  497. // selectedRect.Draw();
  498. //}
  499. }
  500. /// <summary>
  501. /// Mouse click to select text
  502. /// </summary>
  503. /// <param name="clickPoint">
  504. /// Mouse click position
  505. /// </param>
  506. /// <param name="isWord">
  507. /// If true, select the word; if false, select the line
  508. /// </param>
  509. public void HandleTextSelectClick(SelectedRect selectedRect, bool isWord)
  510. {
  511. Point point = Mouse.GetPosition(this);
  512. if (selectedRect != null && lastSelectedRect != null)
  513. {
  514. editArea.TryGetValue(lastSelectedRect, out EditAreaObject editAreaObject);
  515. if (editAreaObject.cPDFEditArea is CPDFEditTextArea)
  516. {
  517. Rect checkRect = selectedRect.GetDrawRect();
  518. if (point.X > checkRect.Right)
  519. {
  520. point.X = checkRect.Right;
  521. }
  522. if (point.X < checkRect.Left)
  523. {
  524. point.X = checkRect.Left;
  525. }
  526. if (point.Y > checkRect.Bottom)
  527. {
  528. point.Y = checkRect.Bottom;
  529. }
  530. if (point.Y < checkRect.Top)
  531. {
  532. point.Y = checkRect.Top;
  533. }
  534. Point clickPoint = new Point(point.X - editAreaObject.PageBound.X, point.Y - editAreaObject.PageBound.Y);
  535. Point zoomPoint = new Point(clickPoint.X / currentZoom, clickPoint.Y / currentZoom);
  536. Point rawPoint = DpiHelper.StandardPointToPDFPoint(zoomPoint);
  537. CPDFEditTextArea textArea = editAreaObject.cPDFEditArea as CPDFEditTextArea;
  538. List<Rect> selectLineRects = new List<Rect>();
  539. if (isWord)
  540. {
  541. Rect rawRect = DataConversionForWPF.CRectConversionForRect(
  542. textArea.GetRectForWordAtPos(DataConversionForWPF.PointConversionForCPoint(rawPoint))
  543. );
  544. textArea.GetLastSelectChars();
  545. selectLineRects.Add(rawRect);
  546. }
  547. else
  548. {
  549. textArea.GetSectionAtPos(DataConversionForWPF.PointConversionForCPoint(rawPoint));
  550. foreach (CRect item in textArea.SelectLineRects)
  551. {
  552. selectLineRects.Add(DataConversionForWPF.CRectConversionForRect(item));
  553. }
  554. }
  555. CaretVisual caretVisual = CommonHelper.FindVisualChild<CaretVisual>(PDFViewer.GetViewForTag(textEditTag));
  556. caretVisual.SetSelectRect(selectLineRects);
  557. caretVisual.Draw(true, false);
  558. caretVisual.StopCaret();
  559. }
  560. }
  561. }
  562. public void DrawEndTextEdit(SelectedRect selectedRect)
  563. {
  564. Point point = Mouse.GetPosition(this);
  565. if (selectedRect != null)
  566. {
  567. pressPoint = new Point();
  568. selectedRect.OnMouseLeftButtonUp(point);
  569. selectedRect.Draw();
  570. EditAreaObject editAreaObject = GetEditAreaObjectForRect(selectedRect);
  571. if (editAreaObject != null)
  572. {
  573. if (editAreaObject.cPDFEditArea.Type == CPDFEditType.EditText)
  574. {
  575. DrawCaretVisualArea(editAreaObject.cPDFEditArea as CPDFEditTextArea);
  576. }
  577. }
  578. }
  579. }
  580. /// <summary>
  581. /// Get the text editing object of the specified coordinates
  582. /// </summary>
  583. /// <returns>
  584. /// Return the text editing object of the specified coordinates
  585. /// </returns>
  586. public EditAreaObject GetHitTestAreaObject(Point point)
  587. {
  588. SelectedRect selectedRect = null;
  589. foreach (var item in hitTestRects.ToArray())
  590. {
  591. int hitIndex = (int)item.GetHitControlIndex(point);
  592. if (hitIndex != -1)
  593. {
  594. selectedRect = item;
  595. break;
  596. }
  597. }
  598. if (selectedRect == null)
  599. {
  600. return null;
  601. }
  602. if (editArea.TryGetValue(selectedRect, out EditAreaObject editAreaObject))
  603. {
  604. return editAreaObject;
  605. }
  606. else
  607. {
  608. return null;
  609. }
  610. }
  611. /// <summary>
  612. /// Update the background content of a region
  613. /// </summary>
  614. /// <param name="renderData">
  615. /// The key is the page number, and the value is the area to be updated
  616. /// </param>
  617. /// <param name="PaintRect">
  618. /// The area to be updated
  619. /// </param>
  620. private void DrawUpdateText(Dictionary<int, Rect> renderData, Rect PaintRect)
  621. {
  622. int Tag = PDFViewer.GetBackgroundTag();
  623. BaseLayer baseLayer = PDFViewer.GetViewForTag(Tag);
  624. if (baseLayer != null)
  625. {
  626. (baseLayer as BackgroundLayer).ReDrawBackgroundForBuffer(ActualHeight, ActualWidth, PDFViewer.GetDocument(), renderData, PaintRect, currentZoom, PDFViewer.GetDrawModes(), PDFViewer.GetPDFBackground(), true, true);
  627. }
  628. }
  629. public EditAreaObject GetEditAreaObjectForRect(SelectedRect selectedRect)
  630. {
  631. if (selectedRect == null)
  632. {
  633. return null;
  634. }
  635. EditAreaObject editAreaObject;
  636. editArea.TryGetValue(selectedRect, out editAreaObject);
  637. return editAreaObject;
  638. }
  639. public EditAreaObject GetEditAreaObjectListForRect(SelectedRect selectedRect)
  640. {
  641. if (selectedRect == null)
  642. {
  643. return null;
  644. }
  645. EditAreaObject editAreaObject;
  646. editAreaList.TryGetValue(selectedRect, out editAreaObject);
  647. return editAreaObject;
  648. }
  649. public EditAreaObject GetEditAreaObjectListForIndex(int pageIndex, int editIndex)
  650. {
  651. if (editAreaList == null || editAreaList.Count == 0)
  652. {
  653. return null;
  654. }
  655. foreach (EditAreaObject editArea in editAreaList.Values)
  656. {
  657. if (editArea.PageIndex == pageIndex && editArea.EditAreaIndex == editIndex)
  658. {
  659. return editArea;
  660. }
  661. }
  662. return null;
  663. }
  664. public SelectedRect GetSelectedRectForEditAreaObject(CPDFEditArea editAreaObject)
  665. {
  666. if (editAreaObject == null)
  667. {
  668. return null;
  669. }
  670. foreach (var item in editArea)
  671. {
  672. if (item.Value.cPDFEditArea == editAreaObject)
  673. {
  674. return item.Key;
  675. }
  676. }
  677. return null;
  678. }
  679. public SelectedRect GetLastSelectedRect()
  680. {
  681. return lastSelectedRect;
  682. }
  683. public MultiSelectedRect GetMultiSelectedRect()
  684. {
  685. MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(MultiSelectedRectViewTag));
  686. return multiSelectedRect;
  687. }
  688. /// <summary>
  689. /// Select
  690. /// </summary>
  691. /// <returns></returns>
  692. public void DrawTextEditDownEvent(bool drawCaret = true)
  693. {
  694. bool tempSelectAllCharsForLine = selectAllCharsForLine;
  695. TextCompositionManager.RemoveTextInputHandler(this, TextInputEventHandler);
  696. TextCompositionManager.AddTextInputHandler(this, TextInputEventHandler);
  697. RefreshInputMethod();
  698. currentEditAreaObject = null;
  699. SetPastePoint(new Point(-1, -1));
  700. SelectedEditAreaForIndex(-1, -1);
  701. Point point = Mouse.GetPosition(this);
  702. CaretVisual caretVisual = CommonHelper.FindVisualChild<CaretVisual>(PDFViewer.GetViewForTag(textEditTag));
  703. EditAreaObject editAreaObject = null;
  704. if (lastSelectedRect != null)
  705. {
  706. editArea.TryGetValue(lastSelectedRect, out editAreaObject);
  707. if (drawCaret && editAreaObject.cPDFEditArea is CPDFEditTextArea)
  708. {
  709. (editAreaObject.cPDFEditArea as CPDFEditTextArea).ClearSelectChars();
  710. caretVisual.CleanSelectRectDraw();
  711. }
  712. }
  713. //Prioritize the selected status
  714. List<SelectedRect> checkList = new List<SelectedRect>();
  715. if (hitTestRects != null && hitTestRects.Count > 0)
  716. {
  717. List<SelectedRect> checkedList = hitTestRects.AsEnumerable().Where(x => x.GetIsSelected() == true).ToList();
  718. List<SelectedRect> unCheckList = hitTestRects.AsEnumerable().Where(x => x.GetIsSelected() == false).ToList();
  719. checkList.AddRange(checkedList);
  720. checkList.AddRange(unCheckList);
  721. }
  722. foreach (SelectedRect rect in checkList)
  723. {
  724. rect.SetIsHover(false);
  725. rect.SetIsSelected(false);
  726. PointControlType pointControlType = PointControlType.None;
  727. if (GetIsCropMode())
  728. {
  729. pointControlType = rect.GetHitCropControlIndex(point, false);
  730. }
  731. else
  732. {
  733. pointControlType = rect.GetHitControlIndex(point);
  734. }
  735. editArea.TryGetValue(rect, out EditAreaObject editObject);
  736. if (pointControlType != PointControlType.None)
  737. {
  738. if (lastSelectedRect != null)
  739. {
  740. if (!lastSelectedRect.Equals(rect))
  741. {
  742. caretVisual.CleanSelectRectDraw();
  743. lastSelectedRect.SetIgnorePointsAll();
  744. lastSelectedRect.SetIsSelected(false);
  745. lastSelectedRect.Draw();
  746. lastSelectedRect.DataChanged -= LastSelectedRect_DataChanged;
  747. if (editAreaObject.cPDFEditArea is CPDFEditTextArea)
  748. {
  749. string chars = (editAreaObject.cPDFEditArea as CPDFEditTextArea).GetAllChars();
  750. if (string.IsNullOrEmpty(chars))
  751. {
  752. int index = editAreaObject.cPDFEditPage.GetEditAreaList().IndexOf(editAreaObject.cPDFEditArea);
  753. editAreaObject.cPDFEditPage.RemoveEditArea(index);
  754. editAreaObject.cPDFEditPage.EndEdit();
  755. lastSelectedRect.ClearDraw();
  756. // Update the index of the currently selected object
  757. if (editObject.EditAreaIndex > index)
  758. {
  759. editObject.EditAreaIndex--;
  760. }
  761. List<CPDFEditArea> editAreas = editAreaObject.cPDFEditPage.GetEditAreaList(true);
  762. if (editAreas.Count > editObject.EditAreaIndex)
  763. {
  764. editObject.cPDFEditArea = editAreas[editObject.EditAreaIndex];
  765. }
  766. }
  767. }
  768. lastSelectedRect = rect;
  769. lastSelectedRect.DataChanged += LastSelectedRect_DataChanged;
  770. if (!GetIsCropMode())
  771. {
  772. if (editObject.cPDFEditArea is CPDFEditTextArea)
  773. {
  774. rect.SetEditIgnorePoints(ignoreTextPoints, ignoreImagePoints, drawEditPointType);
  775. }
  776. else
  777. {
  778. rect.SetEditIgnorePoints(ignoreTextPoints, ignoreImagePoints, drawEditPointType, false);
  779. }
  780. }
  781. rect.SetIsSelected(true);
  782. rect.Draw();
  783. }
  784. else
  785. {
  786. rect.SetIsSelected(true);
  787. }
  788. }
  789. else
  790. {
  791. lastSelectedRect = rect;
  792. lastSelectedRect.DataChanged += LastSelectedRect_DataChanged;
  793. if (!GetIsCropMode())
  794. {
  795. if (editObject.cPDFEditArea is CPDFEditTextArea)
  796. {
  797. rect.SetEditIgnorePoints(ignoreTextPoints, ignoreImagePoints, drawEditPointType);
  798. }
  799. else
  800. {
  801. rect.SetEditIgnorePoints(ignoreTextPoints, ignoreImagePoints, drawEditPointType, false);
  802. }
  803. }
  804. rect.SetIsSelected(true);
  805. rect.Draw();
  806. }
  807. SelectedEditAreaForIndex(editObject.PageIndex, editObject.EditAreaIndex, drawCaret);
  808. currentEditAreaObject = editObject;
  809. currentEditAreaObject.ControlType = pointControlType;
  810. if (pointControlType == PointControlType.Body)
  811. {
  812. caretVisual.SetCaretVisualArea(editObject.cPDFEditArea, currentZoom, rect.GetMaxRect(), point);
  813. if (tempSelectAllCharsForLine && !drawCaret)
  814. {
  815. caretVisual.SetZoom(0);
  816. selectAllCharsForLine = true;
  817. }
  818. SetPastePoint(point);
  819. caretVisual.StartTimer();
  820. caretVisual.Draw(true, drawCaret);
  821. if (!drawCaret)
  822. {
  823. caretVisual.StopCaret();
  824. }
  825. Point clickPoint = new Point((point.X - editObject.PageBound.X) / currentZoom, (point.Y - editObject.PageBound.Y) / currentZoom);
  826. Point rawPoint = DpiHelper.StandardPointToPDFPoint(clickPoint);
  827. rawHitPos = new CPoint((float)rawPoint.X, (float)rawPoint.Y);
  828. }
  829. else
  830. {
  831. caretVisual.StopTimer();
  832. caretVisual.CleanDraw();
  833. if (pointControlType != PointControlType.None)
  834. {
  835. if (editObject.cPDFEditArea is CPDFEditTextArea)
  836. {
  837. (editObject.cPDFEditArea as CPDFEditTextArea).SelectAllChars();
  838. selectAllCharsForLine = true;
  839. }
  840. }
  841. }
  842. pressPoint = point;
  843. return;
  844. }
  845. }
  846. // No edit box clicked
  847. if (lastSelectedRect != null)
  848. {
  849. if (lastSelectedRect.GetCurrentDrawPointType() == DrawPointType.Crop)
  850. {
  851. // If the clicked point is not in the range of the cropped image
  852. if (!lastSelectedRect.GetDrawRect().Contains(point))
  853. {
  854. lastSelectedRect.SetCurrentDrawPointType(DrawPointType.Square);
  855. cropIndex = -1;
  856. lastSelectedRect.SetIgnorePointsAll();
  857. lastSelectedRect.SetIsSelected(false);
  858. lastSelectedRect.Draw();
  859. }
  860. }
  861. else
  862. {
  863. lastSelectedRect.SetIgnorePointsAll();
  864. lastSelectedRect.SetIsSelected(false);
  865. lastSelectedRect.Draw();
  866. }
  867. if (editAreaObject.cPDFEditArea is CPDFEditTextArea)
  868. {
  869. string chars = (editAreaObject.cPDFEditArea as CPDFEditTextArea).GetAllChars();
  870. if (string.IsNullOrEmpty(chars))
  871. {
  872. int index = editAreaObject.cPDFEditPage.GetEditAreaList().IndexOf(editAreaObject.cPDFEditArea);
  873. editAreaObject.cPDFEditPage.RemoveEditArea(index);
  874. editAreaObject.cPDFEditPage.EndEdit();
  875. lastSelectedRect.ClearDraw();
  876. }
  877. }
  878. lastSelectedRect.DataChanged -= LastSelectedRect_DataChanged;
  879. if (lastSelectedRect.GetCurrentDrawPointType() != DrawPointType.Crop)
  880. {
  881. lastSelectedRect = null;
  882. }
  883. }
  884. caretVisual?.StopTimer();
  885. caretVisual?.CleanDraw();
  886. return;
  887. }
  888. /// <summary>
  889. /// delete multi selectRect
  890. /// </summary>
  891. /// <returns></returns>
  892. public bool DelMultiSelectRect()
  893. {
  894. MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(MultiSelectedRectViewTag));
  895. if (multiSelectedRect != null && multiSelectedRect.Children.Count > 1)
  896. {
  897. Point point = Mouse.GetPosition(this);
  898. SelectedRect selectedRect = multiSelectedRect.GetHitControlRect(point);
  899. if (selectedRect != null)
  900. {
  901. selectedRect = (SelectedRect)multiSelectedRect.Children[multiSelectedRect.GetMulitSelectedRectIndex(selectedRect)];
  902. if (selectedRect != null)
  903. {
  904. EditAreaObject editAreaObject = GetEditAreaObjectListForRect(selectedRect);
  905. if (editAreaObject != null)
  906. {
  907. multiSelectedRect.Children.Remove(selectedRect);
  908. multiSelectedRect.DelMulitSelectedRect(selectedRect);
  909. editAreaMultiIndex.Remove(editAreaObject.EditAreaIndex);
  910. editAreaList.Remove(selectedRect);
  911. multiSelectedRect.Draw();
  912. PDFViewer.UpdateRenderFrame();
  913. return true;
  914. }
  915. }
  916. }
  917. }
  918. return false;
  919. }
  920. public void RightDownEvent()
  921. {
  922. }
  923. private void LastSelectedRect_DataChanged(object sender, SelectedAnnotData e)
  924. {
  925. SelectedRect selectedRect = sender as SelectedRect;
  926. Rect rect = selectedRect.GetRect();
  927. Rect MaxRect = selectedRect.GetMaxRect();
  928. if (editArea.TryGetValue(selectedRect, out EditAreaObject editAreaObject))
  929. {
  930. Rect OldRect = DataConversionForWPF.CRectConversionForRect(editAreaObject.cPDFEditArea.GetFrame());
  931. // Get the moved area and set it to the data layer
  932. Rect PDFRect = new Rect(rect.X - MaxRect.X, rect.Y - MaxRect.Y, rect.Width, rect.Height);
  933. PDFRect = DpiHelper.StandardRectToPDFRect(PDFRect);
  934. PDFRect.X = PDFRect.X / currentZoom;
  935. PDFRect.Y = PDFRect.Y / currentZoom;
  936. PDFRect.Width = PDFRect.Width / currentZoom;
  937. PDFRect.Height = PDFRect.Height / currentZoom;
  938. editAreaObject.cPDFEditArea.SetFrame(DataConversionForWPF.RectConversionForCRect(PDFRect));
  939. PDFEditHistory editHistory = new PDFEditHistory();
  940. editHistory.EditPage = editAreaObject.cPDFEditPage;
  941. editHistory.PageIndex = editAreaObject.PageIndex;
  942. PDFViewer.UndoManager.AddHistory(editHistory);
  943. EndEdit();
  944. // Update the display screen
  945. Dictionary<int, Rect> keyValuePairs = new Dictionary<int, Rect>();
  946. Rect NewRect = DataConversionForWPF.CRectConversionForRect(editAreaObject.cPDFEditArea.GetFrame());
  947. // Calculate the rectangle
  948. OldRect.Union(NewRect);
  949. OldRect.X = OldRect.X - editPadding;
  950. OldRect.Y = OldRect.Y - editPadding;
  951. OldRect.Width = OldRect.Width + editPadding * 2;
  952. OldRect.Height = OldRect.Height + editPadding * 2;
  953. // Calculate the area of the text block that does not need to be displayed completely
  954. Rect paintRect = currentEditAreaObject.PaintRect;
  955. Rect zoomPDFPaintRect = new Rect((paintRect.X - currentEditAreaObject.PageBound.X) / currentZoom, (paintRect.Y - currentEditAreaObject.PageBound.Y) / currentZoom, paintRect.Width / currentZoom, paintRect.Height / currentZoom);
  956. paintRect = DpiHelper.StandardRectToPDFRect(zoomPDFPaintRect);
  957. OldRect.Intersect(paintRect);
  958. keyValuePairs.Add(currentEditAreaObject.PageIndex, OldRect);
  959. DrawUpdateText(keyValuePairs, currentEditAreaObject.PageBound);
  960. UpdateSelectRect(editAreaObject.cPDFEditArea);
  961. // Move the moved selected box to the top layer of the selected logic
  962. switch (editAreaObject.cPDFEditArea.Type)
  963. {
  964. case CPDFEditType.EditText:
  965. text.Remove(selectedRect);
  966. text.Insert(0, selectedRect);
  967. break;
  968. case CPDFEditType.EditImage:
  969. image.Remove(selectedRect);
  970. image.Insert(0, selectedRect);
  971. break;
  972. }
  973. hitTestRects.Clear();
  974. hitTestRects.AddRange(text);
  975. hitTestRects.AddRange(image);
  976. }
  977. }
  978. /// <summary>
  979. /// Reset the window binding and other states of the input method
  980. /// </summary>
  981. private void RefreshInputMethod()
  982. {
  983. if (InputMethod.GetIsInputMethodEnabled(this))
  984. {
  985. InputMethod.SetIsInputMethodEnabled(this, false);
  986. }
  987. if (InputMethod.GetIsInputMethodSuspended(this))
  988. {
  989. InputMethod.SetIsInputMethodSuspended(this, false);
  990. }
  991. InputMethod.SetIsInputMethodEnabled(this, true);
  992. InputMethod.SetIsInputMethodSuspended(this, true);
  993. }
  994. /// <summary>
  995. /// Use to handle keyboard event listening for up, down, left, and right cursor switching, and input method positioning
  996. /// </summary>
  997. private void KeyInputEventHandler(object sender, RoutedEventArgs e)
  998. {
  999. KeyEventArgs ke = e as KeyEventArgs;
  1000. if (currentModel != ToolType.ContentEdit || Keyboard.Modifiers != ModifierKeys.None)
  1001. {
  1002. return;
  1003. }
  1004. switch (ke.Key)
  1005. {
  1006. case Key.Left:
  1007. if (CanMoveCaret())
  1008. {
  1009. (currentEditAreaObject.cPDFEditArea as CPDFEditTextArea)?.GetPrevCharPlace();
  1010. (currentEditAreaObject.cPDFEditArea as CPDFEditTextArea)?.ClearSelectChars();
  1011. DrawCaretVisualArea(currentEditAreaObject.cPDFEditArea as CPDFEditTextArea);
  1012. CaretVisualAreaChanged?.Invoke(null, null);
  1013. ke.Handled = true;
  1014. }
  1015. break;
  1016. case Key.Right:
  1017. if (CanMoveCaret())
  1018. {
  1019. (currentEditAreaObject.cPDFEditArea as CPDFEditTextArea)?.GetNextCharPlace();
  1020. (currentEditAreaObject.cPDFEditArea as CPDFEditTextArea)?.ClearSelectChars();
  1021. DrawCaretVisualArea(currentEditAreaObject.cPDFEditArea as CPDFEditTextArea);
  1022. CaretVisualAreaChanged?.Invoke(null, null);
  1023. ke.Handled = true;
  1024. }
  1025. break;
  1026. case Key.Up:
  1027. if (CanMoveCaret())
  1028. {
  1029. (currentEditAreaObject.cPDFEditArea as CPDFEditTextArea)?.GetUpCharPlace();
  1030. (currentEditAreaObject.cPDFEditArea as CPDFEditTextArea)?.ClearSelectChars();
  1031. DrawCaretVisualArea(currentEditAreaObject.cPDFEditArea as CPDFEditTextArea);
  1032. CaretVisualAreaChanged?.Invoke(null, null);
  1033. ke.Handled = true;
  1034. }
  1035. break;
  1036. case Key.Down:
  1037. if (CanMoveCaret())
  1038. {
  1039. (currentEditAreaObject.cPDFEditArea as CPDFEditTextArea)?.GetDownCharPlace();
  1040. (currentEditAreaObject.cPDFEditArea as CPDFEditTextArea)?.ClearSelectChars();
  1041. DrawCaretVisualArea(currentEditAreaObject.cPDFEditArea as CPDFEditTextArea);
  1042. CaretVisualAreaChanged?.Invoke(null, null);
  1043. ke.Handled = true;
  1044. }
  1045. break;
  1046. default:
  1047. {
  1048. if (lastSelectedRect == null)
  1049. {
  1050. break;
  1051. }
  1052. IntPtr imeWnd = ImportWin32.ImmGetDefaultIMEWnd(IntPtr.Zero);
  1053. IntPtr imeHimc = IntPtr.Zero;
  1054. if (imeWnd != IntPtr.Zero)
  1055. {
  1056. imeHimc = ImportWin32.ImmGetContext(imeWnd);
  1057. }
  1058. if (imeHimc != IntPtr.Zero && currentEditAreaObject != null)
  1059. {
  1060. ImportWin32.CompositionForm showPos = new ImportWin32.CompositionForm();
  1061. Window parentWnd = Window.GetWindow(this);
  1062. if (parentWnd != null)
  1063. {
  1064. CaretVisual caretVisual = CommonHelper.FindVisualChild<CaretVisual>(PDFViewer.GetViewForTag(textEditTag));
  1065. Point HeightPoint = caretVisual.GetCaretHighPoint();
  1066. Point caretPos = new Point(
  1067. HeightPoint.X * currentZoom + lastSelectedRect.GetMaxRect().X,
  1068. HeightPoint.Y * currentZoom + lastSelectedRect.GetMaxRect().Y);
  1069. Point screenPoint = TranslatePoint(caretPos, parentWnd);
  1070. screenPoint = DpiHelper.StandardPointToCurrentPoint(screenPoint);
  1071. showPos.dwStyle = 0x0002;
  1072. showPos.ptCurrentPos.x = (int)screenPoint.X;
  1073. showPos.ptCurrentPos.y = (int)screenPoint.Y;
  1074. ImportWin32.ImmSetCompositionWindow(imeHimc, ref showPos);
  1075. }
  1076. }
  1077. if (imeHimc != IntPtr.Zero)
  1078. {
  1079. ImportWin32.ImmReleaseContext(imeWnd, imeHimc);
  1080. }
  1081. }
  1082. break;
  1083. }
  1084. }
  1085. private bool CanMoveCaret()
  1086. {
  1087. if (currentEditAreaObject == null || currentEditAreaObject.cPDFEditPage == null)
  1088. {
  1089. return false;
  1090. }
  1091. if (currentEditAreaObject.ControlType != PointControlType.Body || currentEditAreaObject.cPDFEditArea == null)
  1092. {
  1093. return false;
  1094. }
  1095. if (currentEditAreaObject.cPDFEditArea.Type != CPDFEditType.EditText)
  1096. {
  1097. return false;
  1098. }
  1099. return true;
  1100. }
  1101. /// <summary>
  1102. /// Text input event
  1103. /// </summary>
  1104. /// <param name="sender"></param>
  1105. /// <param name="e"></param>
  1106. private void TextInputEventHandler(object sender, TextCompositionEventArgs e)
  1107. {
  1108. e.Handled = true;
  1109. if (currentEditAreaObject != null)
  1110. {
  1111. SetText(e.Text);
  1112. }
  1113. }
  1114. /// <summary>
  1115. /// Write the current edit data to the memory PDF
  1116. /// </summary>
  1117. private void EndEdit()
  1118. {
  1119. if (currentEditAreaObject != null && currentEditAreaObject.cPDFEditPage != null)
  1120. {
  1121. currentEditAreaObject.cPDFEditPage.EndEdit();
  1122. }
  1123. }
  1124. private void DeleteChars()
  1125. {
  1126. if (currentEditAreaObject != null)
  1127. {
  1128. CPDFEditTextArea textArea = currentEditAreaObject.cPDFEditArea as CPDFEditTextArea;
  1129. if (textArea.SelectLineRects.Count > 0)
  1130. {
  1131. textArea.DeleteChars();
  1132. }
  1133. else
  1134. {
  1135. textArea.DeleteChar();
  1136. }
  1137. if (textArea.SelectLineRects.Count > 0)
  1138. {
  1139. textArea.ClearSelectChars();
  1140. }
  1141. EndEdit();
  1142. DrawCaretVisualArea(textArea);
  1143. }
  1144. }
  1145. /// <summary>
  1146. /// If it is currently empty, set the TextObject to be deleted
  1147. /// </summary>
  1148. /// <param name="areaObject"></param>
  1149. public void RemoveTextBlock(EditAreaObject areaObject = null)
  1150. {
  1151. if (currentEditAreaObject != null && currentEditAreaObject.cPDFEditPage != null)
  1152. {
  1153. foreach (var Rect in hitTestRects)
  1154. {
  1155. editArea.TryGetValue(Rect, out EditAreaObject editAreaObject);
  1156. if (editAreaObject != currentEditAreaObject)
  1157. {
  1158. continue;
  1159. }
  1160. if (editAreaObject.cPDFEditArea is CPDFEditTextArea)
  1161. {
  1162. CPDFEditPage editPage = editAreaObject.cPDFEditPage;
  1163. CPDFEditTextArea textArea = editAreaObject.cPDFEditArea as CPDFEditTextArea;
  1164. int index = editAreaObject.cPDFEditPage.GetEditAreaList().IndexOf(textArea);
  1165. editPage.RemoveEditArea(index);
  1166. editPage.EndEdit();
  1167. Rect.ClearDraw();
  1168. }
  1169. }
  1170. SelectedEditAreaForIndex(-1, -1);
  1171. }
  1172. else
  1173. {
  1174. if (areaObject != null && areaObject.cPDFEditPage != null)
  1175. {
  1176. if (areaObject.cPDFEditArea is CPDFEditTextArea)
  1177. {
  1178. CPDFEditPage editPage = areaObject.cPDFEditPage;
  1179. CPDFEditTextArea textArea = areaObject.cPDFEditArea as CPDFEditTextArea;
  1180. int index = areaObject.EditAreaIndex;
  1181. editPage.RemoveEditArea(index);
  1182. editPage.EndEdit();
  1183. }
  1184. }
  1185. SelectedEditAreaForIndex(-1, -1);
  1186. }
  1187. }
  1188. /// <summary>
  1189. /// If it is currently empty, set the imageObject to be deleted
  1190. /// </summary>
  1191. /// <param name="areaObject"></param>
  1192. public void RemoveImageBlock(EditAreaObject areaObject = null)
  1193. {
  1194. if (currentEditAreaObject != null && currentEditAreaObject.cPDFEditPage != null)
  1195. {
  1196. foreach (var Rect in hitTestRects)
  1197. {
  1198. editArea.TryGetValue(Rect, out EditAreaObject editAreaObject);
  1199. if (editAreaObject != currentEditAreaObject)
  1200. {
  1201. continue;
  1202. }
  1203. if (editAreaObject.cPDFEditArea is CPDFEditImageArea)
  1204. {
  1205. CPDFEditPage editPage = editAreaObject.cPDFEditPage;
  1206. CPDFEditImageArea textArea = editAreaObject.cPDFEditArea as CPDFEditImageArea;
  1207. int index = editAreaObject.cPDFEditPage.GetEditAreaList().IndexOf(textArea);
  1208. editPage.RemoveEditArea(index);
  1209. editPage.EndEdit();
  1210. Rect.ClearDraw();
  1211. }
  1212. }
  1213. SelectedEditAreaForIndex(-1, -1);
  1214. }
  1215. else
  1216. {
  1217. if (areaObject != null && areaObject.cPDFEditPage != null)
  1218. {
  1219. if (areaObject.cPDFEditArea is CPDFEditImageArea)
  1220. {
  1221. CPDFEditPage editPage = areaObject.cPDFEditPage;
  1222. CPDFEditImageArea textArea = areaObject.cPDFEditArea as CPDFEditImageArea;
  1223. int index = areaObject.EditAreaIndex;
  1224. editPage.RemoveEditArea(index);
  1225. editPage.EndEdit();
  1226. }
  1227. }
  1228. SelectedEditAreaForIndex(-1, -1);
  1229. }
  1230. }
  1231. public void CleanEditView()
  1232. {
  1233. lastSelectedRect = null;
  1234. editArea.Clear();
  1235. hitTestRects.Clear();
  1236. BaseLayer customizeLayer = PDFViewer.GetViewForTag(textEditTag);
  1237. customizeLayer?.Children.Clear();
  1238. operateChildrenIndex = -1;
  1239. }
  1240. public void SetText(string content)
  1241. {
  1242. Interlocked.Increment(ref delayCount);
  1243. if (delayTextBuilder == null || delayTextBuilder.Length == 0)
  1244. {
  1245. delayTextBuilder = new StringBuilder();
  1246. delayTextBuilder.Append(content);
  1247. Task.Factory.StartNew(DelayThread);
  1248. }
  1249. else
  1250. {
  1251. delayTextBuilder.Append(content);
  1252. }
  1253. return;
  1254. }
  1255. /// <summary>
  1256. /// Because the data given by the input method is given one by one, so get all the data in the thread and then pass it to the underlying library
  1257. /// </summary>
  1258. private void DelayThread()
  1259. {
  1260. while (delayCount > 0)
  1261. {
  1262. if (delayCount == 1)
  1263. {
  1264. Thread.Sleep(10);
  1265. }
  1266. else
  1267. {
  1268. Thread.Sleep(1);
  1269. }
  1270. Interlocked.Decrement(ref delayCount);
  1271. }
  1272. if (delayTextBuilder != null && delayTextBuilder.Length > 0)
  1273. {
  1274. Dispatcher.Invoke(() =>
  1275. {
  1276. DelaySetText(delayTextBuilder.ToString());
  1277. });
  1278. delayTextBuilder.Clear();
  1279. }
  1280. }
  1281. /// <summary>
  1282. /// Input text
  1283. /// </summary>
  1284. /// <param name="content"></param>
  1285. private void DelaySetText(string content)
  1286. {
  1287. if (content == string.Empty || currentEditAreaObject == null || currentEditAreaObject.cPDFEditPage == null || content == "\u001b")
  1288. {
  1289. return;
  1290. }
  1291. PDFEditHistory editHistory = new PDFEditHistory();
  1292. editHistory.EditPage = currentEditAreaObject.cPDFEditPage;
  1293. editHistory.PageIndex = currentEditAreaObject.PageIndex;
  1294. CPDFEditTextArea textArea = currentEditAreaObject.cPDFEditArea as CPDFEditTextArea;
  1295. Rect OldRect = DataConversionForWPF.CRectConversionForRect(textArea.GetFrame());
  1296. GroupHistory groupHistory = new GroupHistory();
  1297. if (content == "\b")
  1298. {
  1299. if (textArea.SelectLineRects.Count > 0)
  1300. {
  1301. textArea.DeleteChars();
  1302. groupHistory.Histories.Add(editHistory);
  1303. }
  1304. else
  1305. {
  1306. textArea.BackSpaceChar();
  1307. groupHistory.Histories.Add(editHistory);
  1308. EndEdit();
  1309. }
  1310. }
  1311. else
  1312. {
  1313. if (textArea.SelectLineRects.Count > 0)
  1314. {
  1315. textArea.DeleteChars();
  1316. groupHistory.Histories.Add(editHistory);
  1317. }
  1318. PDFEditHistory InsertHistory = new PDFEditHistory();
  1319. InsertHistory.EditPage = currentEditAreaObject.cPDFEditPage;
  1320. InsertHistory.PageIndex = currentEditAreaObject.PageIndex;
  1321. textArea.InsertText(content);
  1322. groupHistory.Histories.Add(InsertHistory);
  1323. EndEdit();
  1324. }
  1325. if (textArea.SelectLineRects.Count > 0)
  1326. {
  1327. textArea.ClearSelectChars();
  1328. }
  1329. UpdateRender(OldRect, textArea);
  1330. if (PDFViewer != null && PDFViewer.UndoManager != null)
  1331. {
  1332. PDFViewer.UndoManager.AddHistory(groupHistory);
  1333. }
  1334. DrawCaretVisualArea(textArea);
  1335. }
  1336. public void UpdateRender(Rect oldRect, CPDFEditArea newTextArea)
  1337. {
  1338. if (currentEditAreaObject == null)
  1339. {
  1340. return;
  1341. }
  1342. if (newTextArea == null)
  1343. {
  1344. return;
  1345. }
  1346. Dictionary<int, Rect> keyValuePairs = new Dictionary<int, Rect>();
  1347. Rect NewRect = DataConversionForWPF.CRectConversionForRect(newTextArea.GetFrame());
  1348. // Calculate the rectangle
  1349. oldRect.Union(NewRect);
  1350. oldRect.X = oldRect.X - editPadding;
  1351. oldRect.Y = oldRect.Y - editPadding;
  1352. oldRect.Width = oldRect.Width + editPadding * 2;
  1353. oldRect.Height = oldRect.Height + editPadding * 2;
  1354. var e = editArea.GetEnumerator();
  1355. while (e.MoveNext())
  1356. {
  1357. if (e.Current.Value.cPDFEditArea.Equals(newTextArea))
  1358. {
  1359. currentEditAreaObject = e.Current.Value;
  1360. }
  1361. }
  1362. // Calculate the area of the text block that does not need to be displayed completely
  1363. Rect paintRect = currentEditAreaObject.PaintRect;
  1364. Rect zoomPDFPaintRect = new Rect((paintRect.X - currentEditAreaObject.PageBound.X) / currentZoom, (paintRect.Y - currentEditAreaObject.PageBound.Y) / currentZoom, paintRect.Width / currentZoom, paintRect.Height / currentZoom);
  1365. paintRect = DpiHelper.StandardRectToPDFRect(zoomPDFPaintRect);
  1366. oldRect.Intersect(paintRect);
  1367. if (oldRect == Rect.Empty)
  1368. {
  1369. return;
  1370. }
  1371. keyValuePairs.Add(currentEditAreaObject.PageIndex, oldRect);
  1372. DrawUpdateText(keyValuePairs, currentEditAreaObject.PageBound);
  1373. UpdateSelectRect(newTextArea);
  1374. if (newTextArea.Type == CPDFEditType.EditText)
  1375. {
  1376. DrawCaretVisualArea(newTextArea as CPDFEditTextArea);
  1377. }
  1378. }
  1379. public void DrawTest(Rect maxRect, int index)
  1380. {
  1381. SelectedRect selectedRect = new SelectedRect(GetDefaultDrawParam(), SelectedType.PDFEdit);
  1382. selectedRect.SetEditPen(editPen, editHoverPen);
  1383. selectedRect.SetDrawMoveType(DrawMoveType.kReferenceLine);
  1384. BaseLayer customizeLayer = PDFViewer.GetViewForTag(textEditTag);
  1385. customizeLayer.Children.Add(selectedRect);
  1386. operateChildrenIndex = customizeLayer.Children.IndexOf(selectedRect);
  1387. pointtest = Mouse.GetPosition(this);
  1388. selectedRect.SetIgnorePointsAll();
  1389. selectedRect.SetRect(new Rect(pointtest.X, pointtest.Y, 0, 0), currentZoom);
  1390. selectedRect.SetMaxRect(maxRect);
  1391. selectedRect.SetShowCreatTextRect(true);
  1392. selectedRect.Draw();
  1393. pageindex = index;
  1394. }
  1395. public Cursor DrawMoveTest(SelectedRect selectedRect1)
  1396. {
  1397. Cursor cursor = Cursors.Arrow;
  1398. BaseLayer customizeLayer = PDFViewer.GetViewForTag(textEditTag);
  1399. if (operateChildrenIndex > 0 && operateChildrenIndex < customizeLayer.Children.Count)
  1400. {
  1401. SelectedRect selectedRect = (customizeLayer.Children[operateChildrenIndex] as SelectedRect);
  1402. Point point = Mouse.GetPosition(this);
  1403. Rect maxRect = selectedRect.GetMaxRect();
  1404. Rect MoveRect = new Rect(pointtest, point);
  1405. double cLeft = MoveRect.Left;
  1406. double cRight = MoveRect.Right;
  1407. double cUp = MoveRect.Top;
  1408. double cDown = MoveRect.Bottom;
  1409. if (cLeft < maxRect.Left)
  1410. {
  1411. cLeft = maxRect.Left;
  1412. }
  1413. if (cUp < maxRect.Top)
  1414. {
  1415. cUp = maxRect.Top;
  1416. }
  1417. if (cRight > maxRect.Right)
  1418. {
  1419. cRight = maxRect.Right;
  1420. }
  1421. if (cDown > maxRect.Bottom)
  1422. {
  1423. cDown = maxRect.Bottom;
  1424. }
  1425. selectedRect.SetRect(new Rect(cLeft, cUp, cRight - cLeft, cDown - cUp), currentZoom);
  1426. selectedRect.Draw();
  1427. }
  1428. else
  1429. {
  1430. Point point = Mouse.GetPosition(this);
  1431. // No edit box clicked
  1432. if (lastHoverRect != null)
  1433. {
  1434. lastHoverRect.SetIsHover(false);
  1435. lastHoverRect.Draw();
  1436. lastHoverRect = null;
  1437. }
  1438. //Prioritize the selected status
  1439. List<SelectedRect> checkList = new List<SelectedRect>();
  1440. if (hitTestRects != null && hitTestRects.Count > 0)
  1441. {
  1442. List<SelectedRect> checkedList = hitTestRects.AsEnumerable().Where(x => x.GetIsSelected() == true).ToList();
  1443. List<SelectedRect> unCheckList = hitTestRects.AsEnumerable().Where(x => x.GetIsSelected() == false).ToList();
  1444. checkList.AddRange(checkedList);
  1445. checkList.AddRange(unCheckList);
  1446. }
  1447. foreach (SelectedRect rect in checkList)
  1448. {
  1449. PointControlType pointControlType = rect.GetHitControlIndex(point, false);
  1450. MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(MultiSelectedRectViewTag));
  1451. if (GetIsCropMode())
  1452. {
  1453. PointControlType pointCropControlType = rect.GetHitCropControlIndex(point, false);
  1454. if (pointCropControlType != PointControlType.None)
  1455. {
  1456. cursor = GetCursors(pointCropControlType, true);
  1457. break;
  1458. }
  1459. }
  1460. else
  1461. {
  1462. //Multiple selection of mouse styles
  1463. if (multiSelectedRect != null && multiSelectedRect.Children.Count > 0)
  1464. {
  1465. PointControlType pointMultiControlType = multiSelectedRect.GetHitControlIndex(Mouse.GetPosition(this));
  1466. cursor = GetCursors(pointMultiControlType, true);
  1467. }
  1468. if (pointControlType != PointControlType.None)
  1469. {
  1470. EditAreaObject editAreaObject = GetEditAreaObjectForRect(rect);
  1471. if (editAreaObject.cPDFEditArea.Type == CPDFEditType.EditImage)
  1472. {
  1473. //image hover
  1474. if (selectedRect1 == null)
  1475. {
  1476. lastHoverRect = rect;
  1477. rect.SetIsHover(true);
  1478. rect.Draw();
  1479. }
  1480. else
  1481. {
  1482. if (!selectedRect1.Equals(rect))
  1483. {
  1484. lastHoverRect = rect;
  1485. rect.SetIsHover(true);
  1486. rect.Draw();
  1487. }
  1488. }
  1489. cursor = GetCursors(pointControlType, true);
  1490. break;
  1491. }
  1492. else
  1493. {
  1494. cursor = GetCursors(pointControlType, false);
  1495. }
  1496. // Not selected
  1497. if (selectedRect1 == null)
  1498. {
  1499. if (lastHoverRect != null)
  1500. {
  1501. if (!lastHoverRect.Equals(rect))
  1502. {
  1503. lastHoverRect.SetIsHover(false);
  1504. lastHoverRect.Draw();
  1505. lastHoverRect = rect;
  1506. rect.SetIsHover(true);
  1507. rect.Draw();
  1508. }
  1509. }
  1510. else
  1511. {
  1512. lastHoverRect = rect;
  1513. rect.SetIsHover(true);
  1514. rect.Draw();
  1515. }
  1516. }
  1517. else
  1518. {
  1519. // Current selected box is inconsistent with hit test object
  1520. if (!selectedRect1.Equals(rect))
  1521. {
  1522. lastHoverRect = rect;
  1523. rect.SetIsHover(true);
  1524. rect.Draw();
  1525. }
  1526. }
  1527. break;
  1528. }
  1529. }
  1530. }
  1531. }
  1532. return cursor;
  1533. }
  1534. private Cursor GetCursors(PointControlType controlType, bool isImage)
  1535. {
  1536. switch (controlType)
  1537. {
  1538. case PointControlType.LeftTop:
  1539. case PointControlType.RightBottom:
  1540. return Cursors.SizeNWSE;
  1541. case PointControlType.LeftMiddle:
  1542. case PointControlType.RightMiddle:
  1543. return Cursors.SizeWE;
  1544. case PointControlType.LeftBottom:
  1545. case PointControlType.RightTop:
  1546. return Cursors.SizeNESW;
  1547. case PointControlType.MiddlBottom:
  1548. case PointControlType.MiddleTop:
  1549. return Cursors.SizeNS;
  1550. case PointControlType.Body:
  1551. if (isImage)
  1552. {
  1553. return Cursors.SizeAll;
  1554. }
  1555. else
  1556. {
  1557. return Cursors.IBeam;
  1558. }
  1559. case PointControlType.Line:
  1560. return Cursors.SizeAll;
  1561. default:
  1562. return Cursors.Arrow;
  1563. }
  1564. }
  1565. public bool DrawEndTest()
  1566. {
  1567. BaseLayer customizeLayer = PDFViewer.GetViewForTag(textEditTag);
  1568. if (operateChildrenIndex > 0 && operateChildrenIndex < customizeLayer.Children.Count)
  1569. {
  1570. SelectedRect selectedRect = (customizeLayer.Children[operateChildrenIndex] as SelectedRect);
  1571. Rect rect = selectedRect.GetRect();
  1572. Rect MaxRect = selectedRect.GetMaxRect();
  1573. // Get the area and set it to the data layer
  1574. Rect PDFRect = new Rect((rect.X - MaxRect.X) / currentZoom, (rect.Y - MaxRect.Y) / currentZoom, rect.Width / currentZoom, rect.Height / currentZoom);
  1575. PDFRect = DpiHelper.StandardRectToPDFRect(PDFRect);
  1576. CPDFPage docPage = PDFViewer.GetDocument().PageAtIndex(pageindex);
  1577. CPDFEditPage EditPage = docPage.GetEditPage();
  1578. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  1579. TextEditParam textEditParam = defaultSettingParam.TextEditParamDef;
  1580. textEditParam.EditIndex = EditPage.GetEditAreaList().Count;
  1581. if (string.IsNullOrEmpty(textEditParam.FontName))
  1582. {
  1583. textEditParam.FontName = "Helvetica";
  1584. }
  1585. if (textEditParam.FontSize <= 0)
  1586. {
  1587. textEditParam.FontSize = 14;
  1588. }
  1589. if (textEditParam.FontColor == null || textEditParam.FontColor.Length < 3)
  1590. {
  1591. textEditParam.FontColor = new byte[3] { 0, 0, 0 };
  1592. }
  1593. CPDFEditTextArea textArea = EditPage.CreateNewTextArea(
  1594. DataConversionForWPF.RectConversionForCRect(PDFRect),
  1595. textEditParam.FontName,
  1596. (float)textEditParam.FontSize,
  1597. textEditParam.FontColor,
  1598. textEditParam.Transparency,
  1599. textEditParam.IsBold,
  1600. textEditParam.IsItalic,
  1601. textEditParam.TextAlign
  1602. );
  1603. GroupHistory groupHistory = new GroupHistory();
  1604. if (textArea == null)
  1605. {
  1606. textEditParam.FontName = "Helvetica";
  1607. textArea = EditPage.CreateNewTextArea(
  1608. DataConversionForWPF.RectConversionForCRect(PDFRect),
  1609. textEditParam.FontName,
  1610. (float)textEditParam.FontSize,
  1611. textEditParam.FontColor,
  1612. textEditParam.Transparency,
  1613. textEditParam.IsBold,
  1614. textEditParam.IsItalic,
  1615. textEditParam.TextAlign
  1616. );
  1617. }
  1618. // Adjust the size of the creation box for the empty state, so the undo/redo needs to be performed one more time below.
  1619. textArea.InsertText("");
  1620. PDFEditHistory pDFEditHistory = new PDFEditHistory();
  1621. pDFEditHistory.EditPage = EditPage;
  1622. pDFEditHistory.PageIndex = pageindex;
  1623. groupHistory.Histories.Add(pDFEditHistory);
  1624. PDFEditHistory pDFEditHistory1 = new PDFEditHistory();
  1625. pDFEditHistory1.EditPage = EditPage;
  1626. pDFEditHistory1.PageIndex = pageindex;
  1627. groupHistory.Histories.Add(pDFEditHistory1);
  1628. PDFViewer.UndoManager.AddHistory(groupHistory);
  1629. defaultSettingParam.SetPDFEditParamm(textEditParam);
  1630. EditPage.EndEdit();
  1631. customizeLayer.Children.Remove(selectedRect);
  1632. SelectedEditAreaForIndex(pageindex, textEditParam.EditIndex);
  1633. PDFViewer.UpdateRenderFrame();
  1634. return true;
  1635. }
  1636. return false;
  1637. }
  1638. public bool MoveEditArea(Point moveOffset)
  1639. {
  1640. EditAreaObject areaObj = currentEditAreaObject;
  1641. if (PDFViewer == null || GetToolType() != ToolType.ContentEdit)
  1642. {
  1643. return false;
  1644. }
  1645. if (areaObj == null || areaObj.cPDFEditArea == null)
  1646. {
  1647. return false;
  1648. }
  1649. CPDFDocument pdfDoc = PDFViewer.GetDocument();
  1650. if (pdfDoc == null)
  1651. {
  1652. return false;
  1653. }
  1654. CPDFPage pdfPage = pdfDoc.PageAtIndex(areaObj.PageIndex);
  1655. if (pdfPage == null)
  1656. {
  1657. return false;
  1658. }
  1659. CPDFEditArea editArea = areaObj.cPDFEditArea;
  1660. CRect cRect = editArea.GetFrame();
  1661. Rect rect = DataConversionForWPF.CRectConversionForRect(cRect);
  1662. Rect preRect = rect;
  1663. double boundOffset = 5;
  1664. rect.X = Math.Min(pdfPage.PageSize.width - rect.Width - boundOffset, rect.X + moveOffset.X);
  1665. rect.Y = Math.Min(pdfPage.PageSize.height - rect.Height - boundOffset, rect.Y + moveOffset.Y);
  1666. rect.X = Math.Max(rect.X, boundOffset);
  1667. rect.Y = Math.Max(rect.Y, boundOffset);
  1668. editArea.SetFrame(DataConversionForWPF.RectConversionForCRect(rect));
  1669. UpdateSelectRect(editArea);
  1670. if ((int)preRect.Left != (int)rect.Left ||
  1671. (int)preRect.Top != (int)rect.Top ||
  1672. (int)preRect.Width != (int)rect.Width ||
  1673. (int)preRect.Height != (int)rect.Height)
  1674. {
  1675. PDFViewer.UpdateRenderFrame();
  1676. }
  1677. return true;
  1678. }
  1679. public void CropImage(CPDFEditImageArea cPDFEditImageArea)
  1680. {
  1681. SelectedRect selectedRect = null;
  1682. foreach (var item in editArea)
  1683. {
  1684. if (item.Value.cPDFEditArea == cPDFEditImageArea)
  1685. {
  1686. selectedRect = item.Key;
  1687. }
  1688. }
  1689. selectedRect.SetIgnorePointsAll();
  1690. }
  1691. /// <summary>
  1692. /// Update the selected box related to the specified CPDFEditArea
  1693. /// </summary>
  1694. /// <param name="textArea"></param>
  1695. private void UpdateSelectRect(CPDFEditArea editArea)
  1696. {
  1697. SelectedRect selectedRect = null;
  1698. foreach (var item in this.editArea)
  1699. {
  1700. if (item.Value.cPDFEditArea == editArea)
  1701. {
  1702. selectedRect = item.Key;
  1703. }
  1704. }
  1705. if (selectedRect != null)
  1706. {
  1707. Rect maxrect = selectedRect.GetMaxRect();
  1708. Rect rect = DataConversionForWPF.CRectConversionForRect(editArea.GetFrame());
  1709. if (editArea.Type == CPDFEditType.EditImage)
  1710. {
  1711. if ((contentEditType & CPDFEditType.EditImage) == CPDFEditType.EditImage)
  1712. {
  1713. rect = DataConversionForWPF.CRectConversionForRect((editArea as CPDFEditImageArea).GetClipRect());
  1714. }
  1715. }
  1716. rect.X = (rect.X) * currentZoom;
  1717. rect.Y = (rect.Y) * currentZoom;
  1718. rect.Width *= currentZoom;
  1719. rect.Height *= currentZoom;
  1720. rect = DpiHelper.PDFRectToStandardRect(rect);
  1721. rect.X += maxrect.X;
  1722. rect.Y += maxrect.Y;
  1723. selectedRect.SetRect(rect, currentZoom);
  1724. selectedRect.Draw();
  1725. }
  1726. }
  1727. /// <summary>
  1728. /// Select text
  1729. /// </summary>
  1730. private void SelectText(CPDFEditTextArea textArea, Point startPoint, Point endPoint)
  1731. {
  1732. Point zoomStartPoint = new Point(startPoint.X / currentZoom, startPoint.Y / currentZoom);
  1733. Point zoomEndPoint = new Point(endPoint.X / currentZoom, endPoint.Y / currentZoom);
  1734. Point start_point = DpiHelper.StandardPointToPDFPoint(zoomStartPoint);
  1735. Point end_point = DpiHelper.StandardPointToPDFPoint(zoomEndPoint);
  1736. textArea.ClearSelectChars();
  1737. textArea.GetSelectChars(
  1738. DataConversionForWPF.PointConversionForCPoint(start_point),
  1739. DataConversionForWPF.PointConversionForCPoint(end_point)
  1740. );
  1741. CaretVisual caretVisual = CommonHelper.FindVisualChild<CaretVisual>(PDFViewer.GetViewForTag(textEditTag));
  1742. List<Rect> SelectLineRects = new List<Rect>();
  1743. foreach (CRect item in textArea.SelectLineRects)
  1744. {
  1745. SelectLineRects.Add(
  1746. DataConversionForWPF.CRectConversionForRect(item)
  1747. );
  1748. }
  1749. caretVisual.SetSelectRect(SelectLineRects);
  1750. caretVisual.Draw(true);
  1751. }
  1752. /// <summary>
  1753. /// Draw the cursor to the specified text block position immediately
  1754. /// </summary>
  1755. /// <param name="textArea"></param>
  1756. private void DrawCaretVisualArea(CPDFEditTextArea textArea, bool drawCaret = true)
  1757. {
  1758. if (textArea == null)
  1759. {
  1760. return;
  1761. }
  1762. CPoint cursorCPoint = new CPoint(0, 0);
  1763. CPoint highCpoint = new CPoint(0, 0);
  1764. textArea.GetTextCursorPoints(ref cursorCPoint, ref highCpoint);
  1765. rawHitPos = cursorCPoint;
  1766. CaretVisual caretVisual = CommonHelper.FindVisualChild<CaretVisual>(PDFViewer.GetViewForTag(textEditTag));
  1767. Point cursorPoint = DataConversionForWPF.CPointConversionForPoint(cursorCPoint);
  1768. Point pointHigh = DataConversionForWPF.CPointConversionForPoint(highCpoint);
  1769. caretVisual.SetCaretVisualArea(cursorPoint, pointHigh);
  1770. textArea.GetLastSelectChars();
  1771. List<Rect> SelectLineRects = new List<Rect>();
  1772. foreach (CRect item in textArea.SelectLineRects)
  1773. {
  1774. SelectLineRects.Add(DataConversionForWPF.CRectConversionForRect(item));
  1775. }
  1776. caretVisual.SetSelectRect(SelectLineRects);
  1777. if (SelectLineRects.Count > 0)
  1778. {
  1779. if (GetSelectedRectForEditAreaObject(textArea) != null)
  1780. {
  1781. caretVisual.Draw(true, false);
  1782. Point HeightPoint = caretVisual.GetCaretHighPoint();
  1783. Point caretPos = new Point(
  1784. HeightPoint.X * currentZoom + GetSelectedRectForEditAreaObject(textArea).GetMaxRect().X,
  1785. HeightPoint.Y * currentZoom + GetSelectedRectForEditAreaObject(textArea).GetMaxRect().Y);
  1786. SetPastePoint(caretPos);
  1787. }
  1788. caretVisual.StopCaret();
  1789. }
  1790. else
  1791. {
  1792. caretVisual.Draw(true, drawCaret);
  1793. if (drawCaret)
  1794. {
  1795. if (GetSelectedRectForEditAreaObject(textArea) != null)
  1796. {
  1797. Point HeightPoint = caretVisual.GetCaretHighPoint();
  1798. Point caretPos = new Point(
  1799. HeightPoint.X * currentZoom + GetSelectedRectForEditAreaObject(textArea).GetMaxRect().X,
  1800. HeightPoint.Y * currentZoom + GetSelectedRectForEditAreaObject(textArea).GetMaxRect().Y);
  1801. SetPastePoint(caretPos);
  1802. caretVisual.StartTimer();
  1803. }
  1804. else
  1805. {
  1806. caretVisual.StopCaret();
  1807. }
  1808. }
  1809. else
  1810. {
  1811. caretVisual.StopCaret();
  1812. }
  1813. }
  1814. }
  1815. /// <summary>
  1816. /// Stop displaying the cursor, but do not erase the selected effect
  1817. /// </summary>
  1818. private void CleanDraw()
  1819. {
  1820. CaretVisual caretVisual = CommonHelper.FindVisualChild<CaretVisual>(PDFViewer.GetViewForTag(textEditTag));
  1821. caretVisual.Draw(true, false);
  1822. caretVisual.StopCaret();
  1823. }
  1824. /// <summary>
  1825. /// Jump cursor to a specific position in a text area.
  1826. /// </summary>
  1827. /// <param name="editingLocation">Cursor position.</param>
  1828. /// <param name="isSelectRanage"> Whether to select text from the current cursor position till the end of the cursor position.</param>
  1829. public void GoToEditingLoction(CEditingLocation editingLocation, bool isSelectRanage)
  1830. {
  1831. EditAreaObject areaObj = currentEditAreaObject;
  1832. if (areaObj == null || !(areaObj.cPDFEditArea is CPDFEditTextArea))
  1833. {
  1834. return;
  1835. }
  1836. if (PDFViewer == null)
  1837. {
  1838. return;
  1839. }
  1840. CPDFEditTextArea textArea = areaObj.cPDFEditArea as CPDFEditTextArea;
  1841. switch (editingLocation)
  1842. {
  1843. case CEditingLocation.CEditingLocationLineBegin:
  1844. textArea.GetLineBeginCharPlace();
  1845. break;
  1846. case CEditingLocation.CEditingLoadTypeLineEnd:
  1847. textArea.GetLineEndCharPlace();
  1848. break;
  1849. case CEditingLocation.CEditingLoadTypeSectionBegin:
  1850. textArea.GetSectionBeginCharPlace();
  1851. break;
  1852. case CEditingLocation.CEditingLoadTypeSectionEnd:
  1853. textArea.GetSectionEndCharPlace();
  1854. break;
  1855. case CEditingLocation.CEditingLoadTypePreWord:
  1856. textArea.GetPreWordCharPlace();
  1857. break;
  1858. case CEditingLocation.CEditingLoadTypeNextWord:
  1859. textArea.GetNextWordCharPlace();
  1860. break;
  1861. case CEditingLocation.CEditingLoadTypePreCharPlace:
  1862. textArea.GetPrevCharPlace();
  1863. break;
  1864. case CEditingLocation.CEditingLoadTypeNextCharPlace:
  1865. textArea.GetNextCharPlace();
  1866. break;
  1867. case CEditingLocation.CEditingLoadTypeUpCharPlace:
  1868. textArea.GetUpCharPlace();
  1869. break;
  1870. case CEditingLocation.CEditingLoadTypeDownCharPlace:
  1871. textArea.GetDownCharPlace();
  1872. break;
  1873. default:
  1874. return;
  1875. }
  1876. CPoint cursorPoint = new CPoint(-1, -1);
  1877. CPoint pointHigh = new CPoint(0, 0);
  1878. textArea.GetTextCursorPoints(ref cursorPoint, ref pointHigh);
  1879. textArea.ClearSelectChars();
  1880. Rect caretRect = new Rect(new Point(cursorPoint.x, cursorPoint.y), new Point(pointHigh.x, pointHigh.y));
  1881. Point endPoint = DpiHelper.PDFPointToStandardPoint(new Point(caretRect.Left, (caretRect.Top + caretRect.Bottom) / 2));
  1882. Point startPoint = DpiHelper.PDFPointToStandardPoint(new Point(rawHitPos.x, rawHitPos.y));
  1883. startPoint.X = startPoint.X * currentZoom;
  1884. startPoint.Y = startPoint.Y * currentZoom;
  1885. endPoint.X = endPoint.X * currentZoom;
  1886. endPoint.Y = endPoint.Y * currentZoom;
  1887. if (isSelectRanage)
  1888. {
  1889. SelectText(textArea, startPoint, endPoint);
  1890. CleanDraw();
  1891. }
  1892. else
  1893. {
  1894. DrawCaretVisualArea(currentEditAreaObject.cPDFEditArea as CPDFEditTextArea);
  1895. rawHitPos = cursorPoint;
  1896. }
  1897. Point caretPoint = new Point(endPoint.X + areaObj.PageBound.Left, endPoint.Y + areaObj.PageBound.Top);
  1898. int direction = 1;
  1899. if (caretPoint.X < 0 || caretPoint.X > PDFViewer.ViewportWidth)
  1900. {
  1901. if (caretPoint.X < 0)
  1902. {
  1903. direction = -1;
  1904. }
  1905. double horizontal = PDFViewer.HorizontalOffset + PDFViewer.ViewportWidth / 2 * direction;
  1906. PDFViewer.SetHorizontalOffset(horizontal);
  1907. }
  1908. if (caretPoint.Y < 0 || caretPoint.Y > PDFViewer.ViewportHeight)
  1909. {
  1910. if (caretPoint.Y < 0)
  1911. {
  1912. direction = -1;
  1913. }
  1914. double vertical = PDFViewer.VerticalOffset + PDFViewer.ViewportHeight / 2 * direction;
  1915. PDFViewer.SetVerticalOffset(vertical);
  1916. }
  1917. }
  1918. public EditAreaObject CurrentEditAreaObject()
  1919. {
  1920. return currentEditAreaObject;
  1921. }
  1922. #region FrameSelect
  1923. int selectFrameSelectToolTag = -1;
  1924. private void InsertFrameSelectToolView()
  1925. {
  1926. FrameSelectTool frameSelectTool = new FrameSelectTool();
  1927. int annotViewindex = PDFViewer.GetMaxViewIndex();
  1928. PDFViewer.InsertView(annotViewindex, frameSelectTool);
  1929. selectFrameSelectToolTag = frameSelectTool.GetResTag();
  1930. }
  1931. public void DrawFrameSelect()
  1932. {
  1933. if (!isMultiSelected)
  1934. {
  1935. return;
  1936. }
  1937. if (PDFViewer.CurrentRenderFrame == null)
  1938. {
  1939. return;
  1940. }
  1941. BaseLayer baseLayer = PDFViewer.GetViewForTag(selectFrameSelectToolTag);
  1942. Point point = Mouse.GetPosition(this);
  1943. PDFViewer.GetPointPageInfo(point, out int index, out Rect paintRect, out Rect pageBound);
  1944. (baseLayer as FrameSelectTool).StartDraw(point, paintRect, pageBound, PDFViewer.CurrentRenderFrame.ZoomFactor, index);
  1945. }
  1946. public void DrawMoveFrameSelect()
  1947. {
  1948. if (!isMultiSelected)
  1949. {
  1950. return;
  1951. }
  1952. if (PDFViewer.CurrentRenderFrame == null)
  1953. {
  1954. return;
  1955. }
  1956. BaseLayer baseLayer = PDFViewer.GetViewForTag(selectFrameSelectToolTag);
  1957. Point point = Mouse.GetPosition(this);
  1958. (baseLayer as FrameSelectTool).MoveDraw(point, PDFViewer.CurrentRenderFrame.ZoomFactor);
  1959. }
  1960. int FrameSelectPageIndex = -1;
  1961. public Rect DrawEndFrameSelect()
  1962. {
  1963. if (PDFViewer.CurrentRenderFrame == null)
  1964. {
  1965. return new Rect();
  1966. }
  1967. BaseLayer baseLayer = PDFViewer.GetViewForTag(selectFrameSelectToolTag);
  1968. return (baseLayer as FrameSelectTool).EndDraw(ref FrameSelectPageIndex);
  1969. }
  1970. /// <summary>
  1971. /// Add multi Selected
  1972. /// </summary>
  1973. /// <param name="rectFrameSelect"></param>
  1974. public void FrameSelectAddRect(Rect rectFrameSelect)
  1975. {
  1976. if (rectFrameSelect.Width == 0 || rectFrameSelect.Height == 0)
  1977. {
  1978. return;
  1979. }
  1980. if (PDFViewer.CurrentRenderFrame == null)
  1981. {
  1982. return;
  1983. }
  1984. RenderFrame currentRenderFrame = PDFViewer.CurrentRenderFrame;
  1985. BaseLayer customizeLayer = PDFViewer.GetViewForTag(textEditTag);
  1986. customizeLayer.Children.Clear();
  1987. CaretVisual caretVisual = new CaretVisual(GetDefaultDrawParam());
  1988. customizeLayer.Children.Add(caretVisual);
  1989. currentZoom = currentRenderFrame.ZoomFactor;
  1990. MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(MultiSelectedRectViewTag));
  1991. foreach (RenderData item in currentRenderFrame.GetRenderDatas())
  1992. {
  1993. if (item.PageIndex == FrameSelectPageIndex)
  1994. {
  1995. if (item.CPDFEditPageObj == null)
  1996. {
  1997. continue;
  1998. }
  1999. foreach (CPDFEditArea editArea in item.CPDFEditPageObj.GetEditAreaList())
  2000. {
  2001. Rect TextBlock = DataConversionForWPF.CRectConversionForRect(editArea.GetFrame());
  2002. if (editArea.Type == CPDFEditType.EditImage)
  2003. {
  2004. if ((contentEditType & CPDFEditType.EditImage) != CPDFEditType.EditImage)
  2005. {
  2006. continue;
  2007. }
  2008. TextBlock = DataConversionForWPF.CRectConversionForRect((editArea as CPDFEditImageArea).GetClipRect());
  2009. }
  2010. else if (editArea.Type == CPDFEditType.EditText)
  2011. {
  2012. if ((contentEditType & CPDFEditType.EditText) != CPDFEditType.EditText)
  2013. {
  2014. continue;
  2015. }
  2016. }
  2017. Rect rect = TextBlock;
  2018. if (rectFrameSelect.IntersectsWith(rect))
  2019. {
  2020. SelectedRect selectedRects = GetSelectedRectForEditAreaObject(editArea);
  2021. SelectedRect selectedRect = new SelectedRect(GetDefaultDrawParam(), SelectedType.PDFEdit);
  2022. selectedRect.SetEditPen(editPen, editHoverPen);
  2023. multiSelectedRect.SetSelectedType(SelectedType.PDFEdit);
  2024. selectedRect.SetDrawMoveType(DrawMoveType.kReferenceLine);
  2025. selectedRect.SetRect(selectedRects.GetRect(), currentZoom);
  2026. selectedRect.SetMaxRect(selectedRects.GetMaxRect());
  2027. EditAreaObject editAreaObject = null;
  2028. foreach (var eitem in this.editArea)
  2029. {
  2030. if (eitem.Value.cPDFEditArea == editArea)
  2031. {
  2032. editAreaObject = eitem.Value;
  2033. break;
  2034. }
  2035. }
  2036. int pageIndex = editAreaObject.PageIndex;
  2037. if (multiPage != pageIndex && editAreaList.Count > 0)
  2038. {
  2039. foreach (int itemIndex in editAreaMultiIndex)
  2040. {
  2041. SelectedRect OldRect = GetEditAreaForIndex(multiPage, itemIndex);
  2042. if (OldRect != null)
  2043. {
  2044. OldRect.Draw();
  2045. }
  2046. }
  2047. editAreaMultiIndex.Clear();
  2048. multiSelectedRect.ClearDraw();
  2049. multiSelectedRect.CleanMulitSelectedRect();
  2050. multiPage = pageIndex;
  2051. }
  2052. multiPage = editAreaObject.PageIndex;
  2053. editAreaMultiIndex.Add(editAreaObject.EditAreaIndex);
  2054. editAreaList.Add(selectedRect, editAreaObject);
  2055. multiSelectedRect.Children.Add(selectedRect);
  2056. multiSelectedRect.SetMulitSelectedRect(selectedRect, editAreaObject.PageIndex, editAreaObject.EditAreaIndex);
  2057. multiSelectedRect.SetRect(selectedRects.GetRect());
  2058. multiSelectedRect.SetMaxRect(selectedRects.GetMaxRect());
  2059. multiSelectedRect.Draw();
  2060. }
  2061. }
  2062. }
  2063. }
  2064. PDFViewer.UpdateRenderFrame();
  2065. }
  2066. #endregion
  2067. #region Multiple selection alignment
  2068. public void SetPDFEditAlignment(AlignModes align)
  2069. {
  2070. List<CPDFEditArea> editAreaObjectlist = new List<CPDFEditArea>();
  2071. MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(MultiSelectedRectViewTag));
  2072. if (multiSelectedRect == null || multiSelectedRect.Children.Count <= 1 || align == AlignModes.AlignNone)
  2073. {
  2074. return;
  2075. }
  2076. Dictionary<AlignModes, Action> processAction = new Dictionary<AlignModes, Action>();
  2077. processAction[AlignModes.AlignLeft] = SetPDFEditAlignLeft;
  2078. processAction[AlignModes.AlignVerticalCenter] = SetPDFEditAlignVerticalCenter;
  2079. processAction[AlignModes.AlignRight] = SetPDFEditAlignRight;
  2080. processAction[AlignModes.AlignTop] = SetPDFEditAlignTop;
  2081. processAction[AlignModes.AlignHorizonCenter] = SetPDFEditAlignHorizonCenter;
  2082. processAction[AlignModes.AlignBottom] = SetPDFEditAlignBottom;
  2083. processAction[AlignModes.DistributeHorizontal] = SetPDFEditDistributeHorizontal;
  2084. processAction[AlignModes.DistributeVertical] = SetPDFEditDistributeVertical;
  2085. if (processAction.ContainsKey(align))
  2086. {
  2087. processAction[align].Invoke();
  2088. }
  2089. }
  2090. private Rect GetDrawAlignRect(Point RectMovePoint, Rect drawRect, Rect maxRect)
  2091. {
  2092. double TmpLeft, TmpRight, TmpUp, TmpDown;
  2093. Point OffsetPos = CalcMoveBound(drawRect, RectMovePoint, maxRect);
  2094. TmpLeft = drawRect.Left + OffsetPos.X;
  2095. TmpRight = drawRect.Right + OffsetPos.X;
  2096. TmpUp = drawRect.Top + OffsetPos.Y;
  2097. TmpDown = drawRect.Bottom + OffsetPos.Y;
  2098. return new Rect(TmpLeft, TmpUp, TmpRight - TmpLeft, TmpDown - TmpUp);
  2099. }
  2100. protected Point CalcMoveBound(Rect currentRect, Point offsetPoint, Rect maxRect)
  2101. {
  2102. double cLeft = currentRect.Left;
  2103. double cRight = currentRect.Right;
  2104. double cUp = currentRect.Top;
  2105. double cDown = currentRect.Bottom;
  2106. double TmpLeft = cLeft + offsetPoint.X;
  2107. double TmpRight = cRight + offsetPoint.X;
  2108. double TmpUp = cUp + offsetPoint.Y;
  2109. double TmpDown = cDown + offsetPoint.Y;
  2110. if (TmpLeft <= maxRect.Left)
  2111. {
  2112. TmpRight = (cRight - cLeft) + maxRect.Left;
  2113. TmpLeft = maxRect.Left;
  2114. }
  2115. if (TmpUp <= maxRect.Top)
  2116. {
  2117. TmpDown = (cDown - cUp) + maxRect.Top;
  2118. TmpUp = maxRect.Top;
  2119. }
  2120. if (TmpRight >= maxRect.Right)
  2121. {
  2122. TmpLeft = maxRect.Right - (cRight - cLeft);
  2123. TmpRight = maxRect.Right;
  2124. }
  2125. if (TmpDown >= maxRect.Bottom)
  2126. {
  2127. TmpUp = maxRect.Bottom - (cDown - cUp);
  2128. TmpDown = maxRect.Bottom;
  2129. }
  2130. offsetPoint = new Point(TmpLeft - cLeft, TmpUp - cUp);
  2131. return offsetPoint;
  2132. }
  2133. private void SetPDFEditAlignLeft()
  2134. {
  2135. List<CPDFEditArea> editAreaObjectlist = new List<CPDFEditArea>();
  2136. MultiSelectedRect MultiSelectEditList = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(MultiSelectedRectViewTag));
  2137. if (MultiSelectEditList == null || MultiSelectEditList.Children.Count <= 1)
  2138. {
  2139. return;
  2140. }
  2141. Rect maxRect = MultiSelectEditList.GetDrawRect();
  2142. if (maxRect == Rect.Empty || (maxRect.Width * maxRect.Height) == 0)
  2143. {
  2144. return;
  2145. }
  2146. Rect drawRect = MultiSelectEditList.GetDrawRect();
  2147. Rect MaxRect = MultiSelectEditList.GetMaxRect();
  2148. GroupHistory groupHistory = new GroupHistory();
  2149. CPDFDocument cPDFDocument = GetCPDFViewer().GetDocument();
  2150. CPDFPage cPDFPage = cPDFDocument.PageAtIndex(multiPage);
  2151. CPDFEditPage cPDFEditPage = cPDFPage.GetEditPage();
  2152. cPDFEditPage.BeginEdit(CPDFEditType.EditText | CPDFEditType.EditImage);
  2153. foreach (SelectedRect checkItem in MultiSelectEditList.GetMulitSelectList())
  2154. {
  2155. SelectedRect item = checkItem;
  2156. EditAreaObject editAreaObject = GetEditAreaObjectListForRect(item);
  2157. if (editAreaObject == null)
  2158. {
  2159. if (MultiSelectEditList.GetRelationKey(item, out int checkPage, out int checkEdit))
  2160. {
  2161. editAreaObject = GetEditAreaObjectListForIndex(checkPage, checkEdit);
  2162. }
  2163. }
  2164. if (item == null)
  2165. {
  2166. continue;
  2167. }
  2168. PDFEditHistory pDFEditHistory = new PDFEditHistory();
  2169. pDFEditHistory.PageIndex = multiPage;
  2170. pDFEditHistory.EditPage = cPDFEditPage;
  2171. if (editAreaObject == null)
  2172. {
  2173. continue;
  2174. }
  2175. EditAreaObject newEditAreaObject = GetSelectedForIndex(multiPage, editAreaObject.EditAreaIndex);
  2176. Rect rect = item.GetRect();
  2177. rect.X = rect.X + item.GetRectPadding();
  2178. item.SetRect(GetDrawAlignRect(AlignmentsHelp.SetAlignLeft(rect, drawRect), rect, drawRect), currentZoom);
  2179. Rect rect2 = item.GetRect();
  2180. rect2.X = rect2.X + item.GetRectPadding();
  2181. Rect pageBound = newEditAreaObject.PageBound;
  2182. Rect PDFRect = DpiHelper.StandardRectToPDFRect(new Rect((rect2.Left - pageBound.Left) / currentZoom, (rect2.Top - pageBound.Top) / currentZoom, rect2.Width / currentZoom, rect2.Height / currentZoom));
  2183. editAreaObject.cPDFEditArea.SetFrame(DataConversionForWPF.RectConversionForCRect(PDFRect));
  2184. groupHistory.Histories.Add(pDFEditHistory);
  2185. }
  2186. PDFViewer.UndoManager.AddHistory(groupHistory);
  2187. cPDFEditPage.EndEdit();
  2188. MultiSelectEditList.Draw();
  2189. PDFViewer.UpdateRenderFrame();
  2190. }
  2191. private void SetPDFEditAlignVerticalCenter()
  2192. {
  2193. List<CPDFEditArea> editAreaObjectlist = new List<CPDFEditArea>();
  2194. MultiSelectedRect MultiSelectEditList = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(MultiSelectedRectViewTag));
  2195. if (MultiSelectEditList == null || MultiSelectEditList.Children.Count <= 1)
  2196. {
  2197. return;
  2198. }
  2199. Rect maxRect = MultiSelectEditList.GetDrawRect();
  2200. if (maxRect == Rect.Empty || (maxRect.Width * maxRect.Height) == 0)
  2201. {
  2202. return;
  2203. }
  2204. Rect drawRect = MultiSelectEditList.GetDrawRect();
  2205. GroupHistory groupHistory = new GroupHistory();
  2206. CPDFDocument cPDFDocument = GetCPDFViewer().GetDocument();
  2207. CPDFPage cPDFPage = cPDFDocument.PageAtIndex(multiPage);
  2208. CPDFEditPage cPDFEditPage = cPDFPage.GetEditPage();
  2209. cPDFEditPage.BeginEdit(CPDFEditType.EditText | CPDFEditType.EditImage);
  2210. foreach (SelectedRect checkItem in MultiSelectEditList.GetMulitSelectList())
  2211. {
  2212. SelectedRect item = checkItem;
  2213. EditAreaObject editAreaObject = GetEditAreaObjectListForRect(item);
  2214. if (editAreaObject == null)
  2215. {
  2216. if (MultiSelectEditList.GetRelationKey(item, out int checkPage, out int checkEdit))
  2217. {
  2218. editAreaObject = GetEditAreaObjectListForIndex(checkPage, checkEdit);
  2219. }
  2220. }
  2221. if (item == null)
  2222. {
  2223. continue;
  2224. }
  2225. PDFEditHistory pDFEditHistory = new PDFEditHistory();
  2226. pDFEditHistory.PageIndex = multiPage;
  2227. pDFEditHistory.EditPage = cPDFEditPage;
  2228. if (editAreaObject == null)
  2229. {
  2230. continue;
  2231. }
  2232. EditAreaObject newEditAreaObject = GetSelectedForIndex(multiPage, editAreaObject.EditAreaIndex);
  2233. Rect rect = item.GetRect();
  2234. if (currentZoom < 1)
  2235. {
  2236. rect.Y = rect.Y + currentZoom;
  2237. }
  2238. else
  2239. {
  2240. rect.Y = rect.Y;
  2241. }
  2242. item.SetRect(GetDrawAlignRect(AlignmentsHelp.SetAlignVerticalCenter(rect, drawRect), rect, drawRect), currentZoom);
  2243. Rect rect2 = item.GetRect();
  2244. if (currentZoom < 1)
  2245. {
  2246. rect2.Y = rect2.Y + currentZoom;
  2247. }
  2248. else
  2249. {
  2250. rect2.Y = rect2.Y;
  2251. }
  2252. Rect pageBound = newEditAreaObject.PageBound;
  2253. Rect PDFRect = DpiHelper.StandardRectToPDFRect(new Rect((rect2.Left - pageBound.Left) / currentZoom, (rect2.Top - pageBound.Top) / currentZoom, rect2.Width / currentZoom, rect2.Height / currentZoom));
  2254. editAreaObject.cPDFEditArea.SetFrame(DataConversionForWPF.RectConversionForCRect(PDFRect));
  2255. groupHistory.Histories.Add(pDFEditHistory);
  2256. }
  2257. PDFViewer.UndoManager.AddHistory(groupHistory);
  2258. cPDFEditPage.EndEdit();
  2259. MultiSelectEditList.Draw();
  2260. PDFViewer.UpdateRenderFrame();
  2261. }
  2262. private void SetPDFEditAlignRight()
  2263. {
  2264. List<CPDFEditArea> editAreaObjectlist = new List<CPDFEditArea>();
  2265. MultiSelectedRect MultiSelectEditList = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(MultiSelectedRectViewTag));
  2266. if (MultiSelectEditList == null || MultiSelectEditList.Children.Count <= 1)
  2267. {
  2268. return;
  2269. }
  2270. Rect maxRect = MultiSelectEditList.GetDrawRect();
  2271. if (maxRect == Rect.Empty || (maxRect.Width * maxRect.Height) == 0)
  2272. {
  2273. return;
  2274. }
  2275. Rect drawRect = MultiSelectEditList.GetDrawRect();
  2276. GroupHistory groupHistory = new GroupHistory();
  2277. CPDFDocument cPDFDocument = GetCPDFViewer().GetDocument();
  2278. CPDFPage cPDFPage = cPDFDocument.PageAtIndex(multiPage);
  2279. CPDFEditPage cPDFEditPage = cPDFPage.GetEditPage();
  2280. cPDFEditPage.BeginEdit(CPDFEditType.EditText | CPDFEditType.EditImage);
  2281. foreach (SelectedRect checkItem in MultiSelectEditList.GetMulitSelectList())
  2282. {
  2283. SelectedRect item = checkItem;
  2284. EditAreaObject editAreaObject = GetEditAreaObjectListForRect(item);
  2285. if (editAreaObject == null)
  2286. {
  2287. if (MultiSelectEditList.GetRelationKey(item, out int checkPage, out int checkEdit))
  2288. {
  2289. editAreaObject = GetEditAreaObjectListForIndex(checkPage, checkEdit);
  2290. }
  2291. }
  2292. if (item == null)
  2293. {
  2294. continue;
  2295. }
  2296. PDFEditHistory pDFEditHistory = new PDFEditHistory();
  2297. pDFEditHistory.PageIndex = multiPage;
  2298. pDFEditHistory.EditPage = cPDFEditPage;
  2299. if (editAreaObject == null)
  2300. {
  2301. continue;
  2302. }
  2303. EditAreaObject newEditAreaObject = GetSelectedForIndex(multiPage, editAreaObject.EditAreaIndex);
  2304. Rect rect = item.GetRect();
  2305. if (currentZoom < 1)
  2306. {
  2307. rect.X = rect.X - editPadding;
  2308. }
  2309. else
  2310. {
  2311. rect.X = rect.X - editPadding;
  2312. }
  2313. item.SetRect(GetDrawAlignRect(AlignmentsHelp.SetAlignRight(rect, drawRect), rect, drawRect), currentZoom);
  2314. Rect rect2 = item.GetRect();
  2315. if (currentZoom < 1)
  2316. {
  2317. rect2.X = rect2.X - editPadding;
  2318. }
  2319. else
  2320. {
  2321. rect2.X = rect2.X - editPadding;
  2322. }
  2323. Rect pageBound = newEditAreaObject.PageBound;
  2324. Rect PDFRect = DpiHelper.StandardRectToPDFRect(new Rect((rect2.Left - pageBound.Left) / currentZoom, (rect2.Top - pageBound.Top) / currentZoom, rect2.Width / currentZoom, rect2.Height / currentZoom));
  2325. editAreaObject.cPDFEditArea.SetFrame(DataConversionForWPF.RectConversionForCRect(PDFRect));
  2326. groupHistory.Histories.Add(pDFEditHistory);
  2327. }
  2328. PDFViewer.UndoManager.AddHistory(groupHistory);
  2329. cPDFEditPage.EndEdit();
  2330. MultiSelectEditList.Draw();
  2331. PDFViewer.UpdateRenderFrame();
  2332. }
  2333. private void SetPDFEditAlignTop()
  2334. {
  2335. List<CPDFEditArea> editAreaObjectlist = new List<CPDFEditArea>();
  2336. MultiSelectedRect MultiSelectEditList = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(MultiSelectedRectViewTag));
  2337. if (MultiSelectEditList == null || MultiSelectEditList.Children.Count <= 1)
  2338. {
  2339. return;
  2340. }
  2341. Rect maxRect = MultiSelectEditList.GetDrawRect();
  2342. if (maxRect == Rect.Empty || (maxRect.Width * maxRect.Height) == 0)
  2343. {
  2344. return;
  2345. }
  2346. Rect drawRect = MultiSelectEditList.GetDrawRect();
  2347. GroupHistory groupHistory = new GroupHistory();
  2348. CPDFDocument cPDFDocument = GetCPDFViewer().GetDocument();
  2349. CPDFPage cPDFPage = cPDFDocument.PageAtIndex(multiPage);
  2350. CPDFEditPage cPDFEditPage = cPDFPage.GetEditPage();
  2351. cPDFEditPage.BeginEdit(CPDFEditType.EditText | CPDFEditType.EditImage);
  2352. foreach (SelectedRect checkItem in MultiSelectEditList.GetMulitSelectList())
  2353. {
  2354. SelectedRect item = checkItem;
  2355. EditAreaObject editAreaObject = GetEditAreaObjectListForRect(item);
  2356. if (editAreaObject == null)
  2357. {
  2358. if (MultiSelectEditList.GetRelationKey(item, out int checkPage, out int checkEdit))
  2359. {
  2360. editAreaObject = GetEditAreaObjectListForIndex(checkPage, checkEdit);
  2361. }
  2362. }
  2363. if (item == null)
  2364. {
  2365. continue;
  2366. }
  2367. if (editAreaObject == null)
  2368. {
  2369. continue;
  2370. }
  2371. PDFEditHistory pDFEditHistory = new PDFEditHistory();
  2372. pDFEditHistory.PageIndex = multiPage;
  2373. pDFEditHistory.EditPage = cPDFEditPage;
  2374. EditAreaObject newEditAreaObject = GetSelectedForIndex(multiPage, editAreaObject.EditAreaIndex);
  2375. Rect rect = item.GetRect();
  2376. rect.Y = rect.Y + editPadding;
  2377. item.SetRect(GetDrawAlignRect(AlignmentsHelp.SetAlignTop(rect, drawRect), rect, drawRect), currentZoom);
  2378. Rect rect2 = item.GetRect();
  2379. rect2.Y = rect2.Y + editPadding;
  2380. Rect pageBound = newEditAreaObject.PageBound;
  2381. Rect PDFRect = DpiHelper.StandardRectToPDFRect(new Rect((rect2.Left - pageBound.Left) / currentZoom, (rect2.Top - pageBound.Top) / currentZoom, rect2.Width / currentZoom, rect2.Height / currentZoom));
  2382. editAreaObject.cPDFEditArea.SetFrame(DataConversionForWPF.RectConversionForCRect(PDFRect));
  2383. groupHistory.Histories.Add(pDFEditHistory);
  2384. }
  2385. PDFViewer.UndoManager.AddHistory(groupHistory);
  2386. cPDFEditPage.EndEdit();
  2387. MultiSelectEditList.Draw();
  2388. PDFViewer.UpdateRenderFrame();
  2389. }
  2390. private void SetPDFEditAlignHorizonCenter()
  2391. {
  2392. List<CPDFEditArea> editAreaObjectlist = new List<CPDFEditArea>();
  2393. MultiSelectedRect MultiSelectEditList = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(MultiSelectedRectViewTag));
  2394. if (MultiSelectEditList == null || MultiSelectEditList.Children.Count <= 1)
  2395. {
  2396. return;
  2397. }
  2398. Rect maxRect = MultiSelectEditList.GetDrawRect();
  2399. if (maxRect == Rect.Empty || (maxRect.Width * maxRect.Height) == 0)
  2400. {
  2401. return;
  2402. }
  2403. Rect drawRect = MultiSelectEditList.GetDrawRect();
  2404. GroupHistory groupHistory = new GroupHistory();
  2405. CPDFDocument cPDFDocument = GetCPDFViewer().GetDocument();
  2406. CPDFPage cPDFPage = cPDFDocument.PageAtIndex(multiPage);
  2407. CPDFEditPage cPDFEditPage = cPDFPage.GetEditPage();
  2408. cPDFEditPage.BeginEdit(CPDFEditType.EditText | CPDFEditType.EditImage);
  2409. foreach (SelectedRect checkItem in MultiSelectEditList.GetMulitSelectList())
  2410. {
  2411. SelectedRect item = checkItem;
  2412. EditAreaObject editAreaObject = GetEditAreaObjectListForRect(item);
  2413. if (editAreaObject == null)
  2414. {
  2415. if (MultiSelectEditList.GetRelationKey(item, out int checkPage, out int checkEdit))
  2416. {
  2417. editAreaObject = GetEditAreaObjectListForIndex(checkPage, checkEdit);
  2418. }
  2419. }
  2420. if (item == null)
  2421. {
  2422. continue;
  2423. }
  2424. PDFEditHistory pDFEditHistory = new PDFEditHistory();
  2425. pDFEditHistory.PageIndex = multiPage;
  2426. pDFEditHistory.EditPage = cPDFEditPage;
  2427. if (editAreaObject == null)
  2428. {
  2429. continue;
  2430. }
  2431. EditAreaObject newEditAreaObject = GetSelectedForIndex(multiPage, editAreaObject.EditAreaIndex);
  2432. Rect rect = item.GetRect();
  2433. item.SetRect(GetDrawAlignRect(AlignmentsHelp.SetAlignHorizonCenter(rect, drawRect), rect, drawRect), currentZoom);
  2434. Rect rect2 = item.GetRect();
  2435. Rect pageBound = newEditAreaObject.PageBound;
  2436. Rect PDFRect = DpiHelper.StandardRectToPDFRect(new Rect((rect2.Left - pageBound.Left) / currentZoom, (rect2.Top - pageBound.Top) / currentZoom, rect2.Width / currentZoom, rect2.Height / currentZoom));
  2437. editAreaObject.cPDFEditArea.SetFrame(DataConversionForWPF.RectConversionForCRect(PDFRect));
  2438. groupHistory.Histories.Add(pDFEditHistory);
  2439. }
  2440. PDFViewer.UndoManager.AddHistory(groupHistory);
  2441. cPDFEditPage.EndEdit();
  2442. MultiSelectEditList.Draw();
  2443. PDFViewer.UpdateRenderFrame();
  2444. }
  2445. private void SetPDFEditAlignBottom()
  2446. {
  2447. List<CPDFEditArea> editAreaObjectlist = new List<CPDFEditArea>();
  2448. MultiSelectedRect MultiSelectEditList = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(MultiSelectedRectViewTag));
  2449. if (MultiSelectEditList == null || MultiSelectEditList.Children.Count <= 1)
  2450. {
  2451. return;
  2452. }
  2453. Rect maxRect = MultiSelectEditList.GetDrawRect();
  2454. if (maxRect == Rect.Empty || (maxRect.Width * maxRect.Height) == 0)
  2455. {
  2456. return;
  2457. }
  2458. Rect drawRect = MultiSelectEditList.GetDrawRect();
  2459. GroupHistory groupHistory = new GroupHistory();
  2460. CPDFDocument cPDFDocument = GetCPDFViewer().GetDocument();
  2461. CPDFPage cPDFPage = cPDFDocument.PageAtIndex(multiPage);
  2462. CPDFEditPage cPDFEditPage = cPDFPage.GetEditPage();
  2463. cPDFEditPage.BeginEdit(CPDFEditType.EditText | CPDFEditType.EditImage);
  2464. foreach (SelectedRect checkItem in MultiSelectEditList.GetMulitSelectList())
  2465. {
  2466. SelectedRect item = checkItem;
  2467. EditAreaObject editAreaObject = GetEditAreaObjectListForRect(item);
  2468. if (editAreaObject == null)
  2469. {
  2470. if (MultiSelectEditList.GetRelationKey(item, out int checkPage, out int checkEdit))
  2471. {
  2472. editAreaObject = GetEditAreaObjectListForIndex(checkPage, checkEdit);
  2473. }
  2474. }
  2475. if (item == null)
  2476. {
  2477. continue;
  2478. }
  2479. PDFEditHistory pDFEditHistory = new PDFEditHistory();
  2480. pDFEditHistory.PageIndex = multiPage;
  2481. pDFEditHistory.EditPage = cPDFEditPage;
  2482. if (editAreaObject == null)
  2483. {
  2484. continue;
  2485. }
  2486. EditAreaObject newEditAreaObject = GetSelectedForIndex(multiPage, editAreaObject.EditAreaIndex);
  2487. Rect rect = item.GetRect();
  2488. rect.Y = rect.Y - editPadding;
  2489. item.SetRect(GetDrawAlignRect(AlignmentsHelp.SetAlignBottom(rect, drawRect), rect, drawRect), currentZoom);
  2490. Rect rect2 = item.GetRect();
  2491. rect2.Y = rect2.Y - editPadding;
  2492. Rect pageBound = newEditAreaObject.PageBound;
  2493. Rect PDFRect = DpiHelper.StandardRectToPDFRect(new Rect((rect2.Left - pageBound.Left) / currentZoom, (rect2.Top - pageBound.Top) / currentZoom, rect2.Width / currentZoom, rect2.Height / currentZoom));
  2494. editAreaObject.cPDFEditArea.SetFrame(DataConversionForWPF.RectConversionForCRect(PDFRect));
  2495. groupHistory.Histories.Add(pDFEditHistory);
  2496. }
  2497. PDFViewer.UndoManager.AddHistory(groupHistory);
  2498. cPDFEditPage.EndEdit();
  2499. MultiSelectEditList.Draw();
  2500. PDFViewer.UpdateRenderFrame();
  2501. }
  2502. private void SetPDFEditDistributeHorizontal()
  2503. {
  2504. List<CPDFEditArea> editAreaObjectlist = new List<CPDFEditArea>();
  2505. MultiSelectedRect MultiSelectEditList = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(MultiSelectedRectViewTag));
  2506. if (MultiSelectEditList == null || MultiSelectEditList.Children.Count <= 1)
  2507. {
  2508. return;
  2509. }
  2510. Rect maxRect = MultiSelectEditList.GetDrawRect();
  2511. if (maxRect == Rect.Empty || (maxRect.Width * maxRect.Height) == 0)
  2512. {
  2513. return;
  2514. }
  2515. List<Rect> rects = new List<Rect>();
  2516. Rect drawRect = MultiSelectEditList.GetDrawRect();
  2517. GroupHistory groupHistory = new GroupHistory();
  2518. CPDFDocument cPDFDocument = GetCPDFViewer().GetDocument();
  2519. CPDFPage cPDFPage = cPDFDocument.PageAtIndex(multiPage);
  2520. CPDFEditPage cPDFEditPage = cPDFPage.GetEditPage();
  2521. cPDFEditPage.BeginEdit(CPDFEditType.EditText | CPDFEditType.EditImage);
  2522. foreach (SelectedRect item in MultiSelectEditList.GetMulitSelectList())
  2523. {
  2524. Rect rect = item.GetRect();
  2525. rects.Add(rect);
  2526. }
  2527. Dictionary<Rect, Point> rectandpoint = AlignmentsHelp.SetGapDistributeHorizontal(rects, drawRect);
  2528. foreach (SelectedRect checkItem in MultiSelectEditList.GetMulitSelectList())
  2529. {
  2530. SelectedRect item = checkItem;
  2531. EditAreaObject editAreaObject = GetEditAreaObjectListForRect(item);
  2532. if (editAreaObject == null)
  2533. {
  2534. if (MultiSelectEditList.GetRelationKey(item, out int checkPage, out int checkEdit))
  2535. {
  2536. editAreaObject = GetEditAreaObjectListForIndex(checkPage, checkEdit);
  2537. }
  2538. }
  2539. if (item == null)
  2540. {
  2541. continue;
  2542. }
  2543. PDFEditHistory pDFEditHistory = new PDFEditHistory();
  2544. pDFEditHistory.PageIndex = multiPage;
  2545. pDFEditHistory.EditPage = cPDFEditPage;
  2546. if (editAreaObject == null)
  2547. {
  2548. continue;
  2549. }
  2550. EditAreaObject newEditAreaObject = GetSelectedForIndex(multiPage, editAreaObject.EditAreaIndex);
  2551. Rect rect = item.GetRect();
  2552. item.SetRect(GetDrawAlignRect(rectandpoint[rect], rect, drawRect), currentZoom);
  2553. Rect rect2 = item.GetRect();
  2554. Rect pageBound = newEditAreaObject.PageBound;
  2555. Rect PDFRect = DpiHelper.StandardRectToPDFRect(new Rect((rect2.Left - pageBound.Left) / currentZoom, (rect2.Top - pageBound.Top) / currentZoom, rect2.Width / currentZoom, rect2.Height / currentZoom));
  2556. editAreaObject.cPDFEditArea.SetFrame(DataConversionForWPF.RectConversionForCRect(PDFRect));
  2557. groupHistory.Histories.Add(pDFEditHistory);
  2558. }
  2559. PDFViewer.UndoManager.AddHistory(groupHistory);
  2560. cPDFEditPage.EndEdit();
  2561. MultiSelectEditList.Draw();
  2562. PDFViewer.UpdateRenderFrame();
  2563. }
  2564. private void SetPDFEditDistributeVertical()
  2565. {
  2566. List<CPDFEditArea> editAreaObjectlist = new List<CPDFEditArea>();
  2567. MultiSelectedRect MultiSelectEditList = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(MultiSelectedRectViewTag));
  2568. if (MultiSelectEditList == null || MultiSelectEditList.Children.Count <= 1)
  2569. {
  2570. return;
  2571. }
  2572. Rect maxRect = MultiSelectEditList.GetDrawRect();
  2573. if (maxRect == Rect.Empty || (maxRect.Width * maxRect.Height) == 0)
  2574. {
  2575. return;
  2576. }
  2577. List<Rect> rects = new List<Rect>();
  2578. Rect drawRect = MultiSelectEditList.GetDrawRect();
  2579. GroupHistory groupHistory = new GroupHistory();
  2580. CPDFDocument cPDFDocument = GetCPDFViewer().GetDocument();
  2581. CPDFPage cPDFPage = cPDFDocument.PageAtIndex(multiPage);
  2582. CPDFEditPage cPDFEditPage = cPDFPage.GetEditPage();
  2583. cPDFEditPage.BeginEdit(CPDFEditType.EditText | CPDFEditType.EditImage);
  2584. foreach (SelectedRect item in MultiSelectEditList.GetMulitSelectList())
  2585. {
  2586. Rect rect = item.GetRect();
  2587. rects.Add(rect);
  2588. }
  2589. Dictionary<Rect, Point> rectandpoint = AlignmentsHelp.SetGapDistributeVertical(rects, drawRect);
  2590. foreach (SelectedRect checkItem in MultiSelectEditList.GetMulitSelectList())
  2591. {
  2592. SelectedRect item = checkItem;
  2593. EditAreaObject editAreaObject = GetEditAreaObjectListForRect(item);
  2594. if (editAreaObject == null)
  2595. {
  2596. if (MultiSelectEditList.GetRelationKey(item, out int checkPage, out int checkEdit))
  2597. {
  2598. editAreaObject = GetEditAreaObjectListForIndex(checkPage, checkEdit);
  2599. }
  2600. }
  2601. if (item == null)
  2602. {
  2603. continue;
  2604. }
  2605. PDFEditHistory pDFEditHistory = new PDFEditHistory();
  2606. pDFEditHistory.PageIndex = multiPage;
  2607. pDFEditHistory.EditPage = cPDFEditPage;
  2608. if (editAreaObject == null)
  2609. {
  2610. continue;
  2611. }
  2612. EditAreaObject newEditAreaObject = GetSelectedForIndex(multiPage, editAreaObject.EditAreaIndex);
  2613. Rect rect = item.GetRect();
  2614. item.SetRect(GetDrawAlignRect(rectandpoint[rect], rect, drawRect), currentZoom);
  2615. Rect rect2 = item.GetRect();
  2616. Rect pageBound = newEditAreaObject.PageBound;
  2617. Rect PDFRect = DpiHelper.StandardRectToPDFRect(new Rect((rect2.Left - pageBound.Left) / currentZoom, (rect2.Top - pageBound.Top) / currentZoom, rect2.Width / currentZoom, rect2.Height / currentZoom));
  2618. editAreaObject.cPDFEditArea.SetFrame(DataConversionForWPF.RectConversionForCRect(PDFRect));
  2619. groupHistory.Histories.Add(pDFEditHistory);
  2620. }
  2621. PDFViewer.UndoManager.AddHistory(groupHistory);
  2622. cPDFEditPage.EndEdit();
  2623. MultiSelectEditList.Draw();
  2624. PDFViewer.UpdateRenderFrame();
  2625. }
  2626. #endregion
  2627. }
  2628. }