CPDFViewerTool.TextEdit.cs 127 KB

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