CPDFViewerTool.TextEdit.cs 127 KB

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