CPDFViewerTool.TextEdit.cs 127 KB

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