CPDFViewerTool.TextEdit.cs 127 KB

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