TextEditPropertyViewModel.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  1. using ComPDFKitViewer;
  2. using ComPDFKitViewer.PdfViewer;
  3. using Microsoft.Win32;
  4. using PDF_Office.Model;
  5. using PDF_Office.Model.PropertyPanel.AnnotPanel;
  6. using Prism.Commands;
  7. using Prism.Mvvm;
  8. using Prism.Regions;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Windows;
  15. using System.Windows.Controls;
  16. using System.Windows.Input;
  17. using System.Windows.Media;
  18. namespace PDF_Office.ViewModels.PropertyPanel.PDFEdit
  19. {
  20. public class TextEditPropertyViewModel : PDFEditVM, INavigationAware
  21. {
  22. #region 属性
  23. #region 文本属性
  24. private double _angle;
  25. public double Angle{ get { return _angle; }set{ SetProperty(ref _angle, value);}}
  26. private Brush selectColor = new SolidColorBrush(Colors.Black);
  27. public Brush SelectColor {
  28. get { return selectColor; }
  29. set{
  30. SetProperty(ref selectColor, value);
  31. if (TextEditEvent != null)
  32. {
  33. bool isok = TextEditEvent.FontColor.A != (SelectColor as SolidColorBrush).Color.A ||TextEditEvent.FontColor.B != (SelectColor as SolidColorBrush).Color.B ||
  34. TextEditEvent.FontColor.G != (SelectColor as SolidColorBrush).Color.G ||TextEditEvent.FontColor.R != (SelectColor as SolidColorBrush).Color.R;
  35. if (isok)
  36. {
  37. TextEditEvent.FontColor = (SelectColor as SolidColorBrush).Color;
  38. TextEditEvent.UpdatePDFEditByEventArgs();
  39. }
  40. }
  41. }
  42. }
  43. private FontFamily fontFamily = new FontFamily("Courier");
  44. public FontFamily TextFontFamily
  45. {
  46. get { return fontFamily; }
  47. set
  48. {
  49. SetProperty(ref fontFamily, value);
  50. if (TextEditEvent != null)
  51. {
  52. TextEditEvent.FontFamily = fontFamily;
  53. TextEditEvent.UpdatePDFEditByEventArgs();
  54. }
  55. }
  56. }
  57. private FontWeight fontWeights = FontWeights.Normal;
  58. public FontWeight TextFontWeights
  59. {
  60. get { return fontWeights; }
  61. set
  62. {
  63. SetProperty(ref fontWeights, value);
  64. if (TextEditEvent != null)
  65. {
  66. TextEditEvent.FontWeight = fontWeights;
  67. TextEditEvent.UpdatePDFEditByEventArgs();
  68. }
  69. }
  70. }
  71. private FontStyle fontStyle = FontStyles.Normal;
  72. public FontStyle TextFontStyle
  73. {
  74. get { return fontStyle; }
  75. set
  76. {
  77. SetProperty(ref fontStyle, value);
  78. if (TextEditEvent != null)
  79. {
  80. TextEditEvent.FontStyle = fontStyle;
  81. TextEditEvent.UpdatePDFEditByEventArgs();
  82. }
  83. }
  84. }
  85. private int fontSize = 24;
  86. public int TextFontSize
  87. {
  88. get { return fontSize; }
  89. set
  90. {
  91. SetProperty(ref fontSize, value);
  92. if (TextEditEvent != null)
  93. {
  94. TextEditEvent.FontSize = fontSize;
  95. TextEditEvent.UpdatePDFEditByEventArgs();
  96. }
  97. }
  98. }
  99. private List<FontStyleItem> fontStyleList = new List<FontStyleItem>();
  100. public List<FontStyleItem> FontStyleList
  101. {
  102. get { return fontStyleList; }
  103. set
  104. {
  105. SetProperty(ref fontStyleList, value);
  106. }
  107. }
  108. #endregion
  109. #region 图像属性
  110. private bool _isCrop = false;
  111. public bool IsCrop
  112. {
  113. get { return _isCrop; }
  114. set
  115. {
  116. SetProperty(ref _isCrop, value);
  117. }
  118. }
  119. //选中的图像
  120. private System.Windows.Media.Imaging.BitmapSource _currentImg;
  121. public System.Windows.Media.Imaging.BitmapSource CurrentImg
  122. {
  123. get { return _currentImg; }
  124. set
  125. {
  126. SetProperty(ref _currentImg, value);
  127. }
  128. }
  129. #endregion
  130. #endregion
  131. #region Command
  132. #region 文本Command
  133. public DelegateCommand AddTextCommand { get; set; }
  134. public DelegateCommand AddImgCommand { get; set; }
  135. public DelegateCommand<object> SelectedColorCommand { get; set; }
  136. public DelegateCommand<object> SelectedFontStyleCommand { get; set; }
  137. public DelegateCommand<object> FontFamilyChangedCommand { get; set; }
  138. public DelegateCommand<object> FontStyleChangedCommand { get; set; }
  139. public DelegateCommand<object> FontSizeChangedCommand { get; set; }
  140. public DelegateCommand<object> TextAlignCheckedCommand { get; set; }
  141. public DelegateCommand EditTextModeCommand { get; set; }
  142. #endregion
  143. #region 图像Command
  144. public DelegateCommand ReplaceImgCommand { get; set; }
  145. public DelegateCommand ExportImgCommand { get; set; }
  146. public DelegateCommand CropImgCommand { get; set; }
  147. public DelegateCommand<object> ImgAlignCheckedCommand { get; set; }
  148. /// <summary>
  149. /// 逆时针旋转
  150. /// </summary>
  151. public DelegateCommand AntiClockwiseCommand { get; set; }
  152. /// <summary>
  153. /// 顺时针旋转
  154. /// </summary>
  155. public DelegateCommand ClockwiseCommand { get; set; }
  156. public DelegateCommand CropModeCommand { get; set; }
  157. public DelegateCommand CancelCropCommand { get; set; }
  158. #endregion
  159. #endregion
  160. #region 初始化
  161. public TextEditPropertyViewModel()
  162. {
  163. InitVariable();
  164. InitCommand();
  165. }
  166. private void InitVariable()
  167. {
  168. InitFontStyles();
  169. }
  170. private void InitFontStyles()
  171. {
  172. FontStyleList = LoadFontStyle.Load();
  173. }
  174. private void InitCommand()
  175. {
  176. AddTextCommand = new DelegateCommand(AddText);
  177. AddImgCommand = new DelegateCommand(AddImg);
  178. ReplaceImgCommand = new DelegateCommand(ReplaceImg);
  179. ExportImgCommand = new DelegateCommand(ExportImg);
  180. CropImgCommand = new DelegateCommand(CropImg);
  181. ImgAlignCheckedCommand = new DelegateCommand<object>(ImgAlignChecked);
  182. SelectedColorCommand = new DelegateCommand<object>(SelectedColor);
  183. SelectedFontStyleCommand = new DelegateCommand<object>(SelectedFontStyle);
  184. FontFamilyChangedCommand = new DelegateCommand<object>(FontFamilyChanged);
  185. FontStyleChangedCommand = new DelegateCommand<object>(FontStyleChanged);
  186. FontSizeChangedCommand = new DelegateCommand<object>(FontSizeChanged);
  187. TextAlignCheckedCommand = new DelegateCommand<object>(TextAlignChecked);
  188. EditTextModeCommand = new DelegateCommand(EditTextMode);
  189. AntiClockwiseCommand = new DelegateCommand(AntiClockwise);
  190. ClockwiseCommand = new DelegateCommand(Clockwise);
  191. CropModeCommand = new DelegateCommand(CropMode);
  192. CancelCropCommand = new DelegateCommand(CancelCropImg);
  193. }
  194. #endregion
  195. #region 文本处理
  196. private void AddText()
  197. {
  198. PDFViewer.SetPDFEditCreateType(ComPDFKit.PDFPage.CPDFEditType.EditText);
  199. }
  200. private void EditTextMode()
  201. {
  202. }
  203. private void TextAlignChecked(object obj)
  204. {
  205. if ((string)obj != null && TextEditEvent != null)
  206. {
  207. switch ((string)obj)
  208. {
  209. case "AlignLeft":
  210. TextEditEvent.TextAlign = ComPDFKit.PDFPage.Edit.TextAlignType.AlignLeft;
  211. break;
  212. case "AlignCenter":
  213. TextEditEvent.TextAlign = ComPDFKit.PDFPage.Edit.TextAlignType.AlignMiddle;
  214. break;
  215. case "AlignRight":
  216. TextEditEvent.TextAlign = ComPDFKit.PDFPage.Edit.TextAlignType.AlignRight;
  217. break;
  218. case "Align":
  219. TextEditEvent.TextAlign = ComPDFKit.PDFPage.Edit.TextAlignType.AlignNone;
  220. break;
  221. }
  222. TextEditEvent.UpdatePDFEditByEventArgs();
  223. }
  224. }
  225. private void Clockwise()
  226. {
  227. Angle = TextEditEvent.Rotate = TextEditEvent.Rotate + 90;
  228. TextEditEvent.UpdatePDFEditByEventArgs();
  229. }
  230. private void AntiClockwise()
  231. {
  232. Angle = TextEditEvent.Rotate = TextEditEvent.Rotate - 90;
  233. TextEditEvent.UpdatePDFEditByEventArgs();
  234. }
  235. private void SelectedColor(object obj)
  236. {
  237. if (obj != null)
  238. {
  239. var colorValue = (Color)obj;
  240. if (colorValue != null)
  241. {
  242. SelectColor = new SolidColorBrush(colorValue);
  243. }
  244. }
  245. }
  246. private void SelectedFontStyle(object obj)
  247. {
  248. if (obj != null && (FontStyleItem)obj != null)
  249. {
  250. var item = (FontStyleItem)obj;
  251. }
  252. }
  253. private void FontFamilyChanged(object obj)
  254. {
  255. if (obj != null && (int)obj > -1)
  256. {
  257. switch ((int)obj)
  258. {
  259. case 0: TextFontFamily = new FontFamily("Courier"); break;
  260. case 1: TextFontFamily = new FontFamily("Helvetica"); break;
  261. case 2: TextFontFamily = new FontFamily("Times"); break;
  262. }
  263. }
  264. }
  265. private void FontStyleChanged(object obj)
  266. {
  267. if (obj != null && (ComboBoxItem)obj != null)
  268. {
  269. var item = (ComboBoxItem)obj;
  270. var content = (string)item.Content;
  271. if (content != null)
  272. {
  273. switch (content)
  274. {
  275. case "Regular":
  276. TextFontWeights = FontWeights.Normal;
  277. TextFontStyle = FontStyles.Normal;
  278. break;
  279. case "Bold":
  280. TextFontWeights = FontWeights.Bold;
  281. TextFontStyle = FontStyles.Normal;
  282. break;
  283. case "Italic":
  284. TextFontWeights = FontWeights.Normal;
  285. TextFontStyle = FontStyles.Italic;
  286. break;
  287. case "Bold Italic":
  288. TextFontWeights = FontWeights.Bold;
  289. TextFontStyle = FontStyles.Italic;
  290. break;
  291. }
  292. }
  293. }
  294. }
  295. private void FontSizeChanged(object obj)
  296. {
  297. if (obj != null)
  298. {
  299. var item = (ComboBoxItem)obj;
  300. var content = (string)item.Content;
  301. if (content != null)
  302. {
  303. var intData = int.Parse(content);
  304. TextFontSize = intData;
  305. }
  306. }
  307. }
  308. #endregion
  309. #region 图像处理
  310. private void CancelCropImg()
  311. {
  312. if (TextEditEvent != null)
  313. {
  314. TextEditEvent.ClipImage = false;
  315. TextEditEvent.CancelClip();
  316. TextEditEvent.UpdatePDFEditByEventArgs();
  317. IsCrop = false;
  318. }
  319. }
  320. private void CropImg()
  321. {
  322. if (TextEditEvent != null)
  323. {
  324. TextEditEvent.SaveClip();
  325. TextEditEvent.ClipImage = false;
  326. TextEditEvent.UpdatePDFEditByEventArgs();
  327. IsCrop = false;
  328. }
  329. }
  330. private void ExportImg()
  331. {
  332. if (PDFViewer == null || TextEditEvent == null || TextEditEvent.EditType != ComPDFKit.PDFPage.CPDFEditType.EditImage) return;
  333. System.Windows.Forms.FolderBrowserDialog folder = new System.Windows.Forms.FolderBrowserDialog();
  334. folder.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
  335. if (folder.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  336. {
  337. if (string.IsNullOrEmpty(folder.SelectedPath))
  338. return;
  339. var keyValueList = PDFViewer.GetSelectedImages();
  340. int i = 0;
  341. foreach (var bitmap in keyValueList)
  342. {
  343. foreach (var bitmapItem in bitmap.Value)
  344. {
  345. bitmapItem.Save(folder.SelectedPath + "\\" + i + ".png", System.Drawing.Imaging.ImageFormat.Png);
  346. i++;
  347. }
  348. }
  349. }
  350. }
  351. private void AddImg()
  352. {
  353. OpenFileDialog openFileDialog = new OpenFileDialog();
  354. openFileDialog.Filter = "png|*.png;|Image|*.gif;*.jpg;*.jpeg;*.bmp;*.jfif;*.png;";
  355. openFileDialog.Multiselect = true;
  356. if ((bool)openFileDialog.ShowDialog())
  357. {
  358. if (string.IsNullOrEmpty(openFileDialog.FileName) == false)
  359. {
  360. PDFViewer.SetPDFEditCreateType(ComPDFKit.PDFPage.CPDFEditType.EditImage);
  361. PDFViewer.AddPDFEditImage(openFileDialog.FileName);
  362. }
  363. }
  364. }
  365. private void ReplaceImg()
  366. {
  367. OpenFileDialog openFileDialog = new OpenFileDialog();
  368. openFileDialog.Filter = "png|*.png;|Image|*.gif;*.jpg;*.jpeg;*.bmp;*.jfif;*.png;";
  369. openFileDialog.Multiselect = true;
  370. if ((bool)openFileDialog.ShowDialog())
  371. {
  372. if (string.IsNullOrEmpty(openFileDialog.FileName) == false)
  373. {
  374. PDFViewer.SetPDFEditCreateType(ComPDFKit.PDFPage.CPDFEditType.EditImage);
  375. TextEditEvent.ReplaceImagePath = openFileDialog.FileName;
  376. TextEditEvent.UpdatePDFEditByEventArgs();
  377. }
  378. }
  379. }
  380. private void CropMode()
  381. {
  382. IsCrop = true;
  383. if (TextEditEvent != null)
  384. {
  385. TextEditEvent.ClipImage = true;
  386. TextEditEvent.UpdatePDFEditByEventArgs();
  387. }
  388. }
  389. #endregion
  390. #region 布局处理
  391. private void ImgAlignChecked(object obj)
  392. {
  393. if (obj != null)
  394. {
  395. switch ((string)obj)
  396. {
  397. case "AlignLeft":
  398. PDFViewer.SetPDFEditAligment(AlignModes.AlignLeft);
  399. break;
  400. case "AlignHorizonCenter":
  401. PDFViewer.SetPDFEditAligment(AlignModes.AlignHorizonCenter);
  402. break;
  403. case "AlignRight":
  404. PDFViewer.SetPDFEditAligment(AlignModes.AlignRight);
  405. break;
  406. case "DistributeHorizontal":
  407. PDFViewer.SetPDFEditAligment(AlignModes.DistributeHorizontal);
  408. break;
  409. case "AlignTop":
  410. PDFViewer.SetPDFEditAligment(AlignModes.AlignTop);
  411. break;
  412. case "AlignVerticalCenter":
  413. PDFViewer.SetPDFEditAligment(AlignModes.AlignVerticalCenter);
  414. break;
  415. case "AlignBottom":
  416. PDFViewer.SetPDFEditAligment(AlignModes.AlignBottom);
  417. break;
  418. case "DistributeVertical":
  419. PDFViewer.SetPDFEditAligment(AlignModes.DistributeVertical);
  420. break;
  421. }
  422. }
  423. }
  424. private void ReLoadLayoutAlign(int count)
  425. {
  426. if (count >= 2)
  427. IsLayoutAlign = true;
  428. else
  429. IsLayoutAlign = false;
  430. if (count >= 3)
  431. IsLayoutAvgAlign = true;
  432. else
  433. IsLayoutAvgAlign = false;
  434. }
  435. #endregion
  436. #region 右键菜单
  437. //点击空白处时
  438. private ContextMenu EmptyStateMenu(object sender)
  439. {
  440. var popMenu = App.Current.FindResource("NoneMenu") as ContextMenu;
  441. if (popMenu != null && popMenu.Items.Count == 3)
  442. {
  443. //粘贴
  444. SetPopMenuItem(popMenu.Items[0] as MenuItem, sender, ApplicationCommands.Paste);
  445. //添加文本
  446. SetPopMenuItem(popMenu.Items[1] as MenuItem, sender, AddTextCommand);
  447. //添加图像
  448. SetPopMenuItem(popMenu.Items[2] as MenuItem, sender, AddImgCommand);
  449. }
  450. return popMenu;
  451. }
  452. //选中图像时
  453. private ContextMenu SelectImgPDFEdit(object sender)
  454. {
  455. var popMenu = App.Current.FindResource("SelectImgMenu") as ContextMenu;
  456. if (popMenu != null && popMenu.Items.Count == 7)
  457. {
  458. //复制
  459. SetPopMenuItem(popMenu.Items[0] as MenuItem, sender, ApplicationCommands.Copy);
  460. //剪切
  461. SetPopMenuItem(popMenu.Items[1] as MenuItem, sender, ApplicationCommands.Cut);
  462. //粘贴
  463. SetPopMenuItem(popMenu.Items[2] as MenuItem, sender, ApplicationCommands.Paste);
  464. //删除
  465. SetPopMenuItem(popMenu.Items[3] as MenuItem, sender, ApplicationCommands.Delete);
  466. //裁剪
  467. SetPopMenuItem(popMenu.Items[4] as MenuItem, sender, CropModeCommand);
  468. //替换
  469. SetPopMenuItem(popMenu.Items[5] as MenuItem, sender, ReplaceImgCommand);
  470. //导出
  471. SetPopMenuItem(popMenu.Items[6] as MenuItem, sender, ExportImgCommand);
  472. }
  473. return popMenu;
  474. }
  475. //选中文字的框
  476. private ContextMenu SelectTextBorder(object sender)
  477. {
  478. var popMenu = App.Current.FindResource("SelectTextMenu") as ContextMenu;
  479. if (popMenu != null && popMenu.Items.Count == 5)
  480. {
  481. //编辑
  482. SetPopMenuItem(popMenu.Items[0] as MenuItem, sender, EditTextModeCommand);
  483. //复制
  484. SetPopMenuItem(popMenu.Items[1] as MenuItem, sender, ApplicationCommands.Copy);
  485. //剪切
  486. SetPopMenuItem(popMenu.Items[2] as MenuItem, sender, ApplicationCommands.Cut);
  487. //粘贴
  488. SetPopMenuItem(popMenu.Items[3] as MenuItem, sender, ApplicationCommands.Paste);
  489. //删除
  490. SetPopMenuItem(popMenu.Items[4] as MenuItem, sender, ApplicationCommands.Delete);
  491. }
  492. return popMenu;
  493. }
  494. //选中文字内容
  495. private ContextMenu SelectTextContent(object sender)
  496. {
  497. var popMenu = App.Current.FindResource("SelectContentMenu") as ContextMenu;
  498. if (popMenu != null && popMenu.Items.Count == 6)
  499. {
  500. //复制
  501. SetPopMenuItem(popMenu.Items[0] as MenuItem, sender, ApplicationCommands.Copy);
  502. //剪切
  503. SetPopMenuItem(popMenu.Items[1] as MenuItem, sender, ApplicationCommands.Cut);
  504. //粘贴
  505. SetPopMenuItem(popMenu.Items[2] as MenuItem, sender, ApplicationCommands.Paste);
  506. //粘贴并匹配样式
  507. SetPopMenuItem(popMenu.Items[3] as MenuItem, sender, ApplicationCommands.Paste);
  508. //删除
  509. SetPopMenuItem(popMenu.Items[4] as MenuItem, sender, ApplicationCommands.Delete);
  510. ////全部选定
  511. SetPopMenuItem(popMenu.Items[5] as MenuItem, sender, ApplicationCommands.SelectAll);
  512. }
  513. return popMenu;
  514. }
  515. #endregion
  516. #region 编辑PDF内容触发的事件
  517. /// <summary>
  518. /// 右键菜单的事件
  519. /// </summary>
  520. private void PDFViewer_PDFEditCommandHandler(object sender, PDFEditCommand e)
  521. {
  522. if (e == null)
  523. return;
  524. switch (e.CommandType)
  525. {
  526. case CommandType.Context:
  527. if (e.EditType == ComPDFKit.PDFPage.CPDFEditType.None)
  528. {
  529. e.PopupMenu = EmptyStateMenu(sender);
  530. }
  531. else if (e.EditType == ComPDFKit.PDFPage.CPDFEditType.EditImage)
  532. {
  533. e.PopupMenu = SelectImgPDFEdit(sender);
  534. }
  535. else if (e.EditType == ComPDFKit.PDFPage.CPDFEditType.EditText)
  536. {
  537. //文字编辑
  538. if (e.PressOnBorder == true)
  539. {
  540. e.PopupMenu = SelectTextBorder(sender);
  541. }
  542. if (e.PressOnSelectedText == true)
  543. {
  544. e.PopupMenu = SelectTextContent(sender);
  545. }
  546. }
  547. break;
  548. default:
  549. e.DoCommand();
  550. break;
  551. }
  552. if (e.PopupMenu != null)
  553. {
  554. e.Handle = true;
  555. }
  556. }
  557. ///// <summary>
  558. ///// 选中编辑PDF内容的事件
  559. ///// </summary>
  560. //private void PDFViewer_PDFEditActiveHandler(object sender, List<PDFEditEvent> e)
  561. //{
  562. // if (e != null && e.Count > 0)
  563. // {
  564. // ReLoadLayoutAlign(e.Count);
  565. // IsTextEdit = (e[0].EditType == ComPDFKit.PDFPage.CPDFEditType.EditText);
  566. // TextEditEvent = e[0];
  567. // if (IsTextEdit == false)
  568. // {
  569. // var list = PDFViewer.GetSelectedImages();
  570. // if (list != null && list.Count > 0)
  571. // {
  572. // System.Drawing.Bitmap bitmap = null;
  573. // foreach (var item in list)
  574. // {
  575. // if (item.Value.Count > 0)
  576. // {
  577. // bitmap = item.Value[0];
  578. // break;
  579. // }
  580. // }
  581. // if (bitmap != null)
  582. // {
  583. // IntPtr ip = bitmap.GetHbitmap();
  584. // System.Windows.Media.Imaging.BitmapSource bitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(ip, IntPtr.Zero, Int32Rect.Empty,
  585. // System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
  586. // CurrentImg = bitmapSource;
  587. // }
  588. // }
  589. // }
  590. // bool isText = false;
  591. // bool isImg = false;
  592. // foreach (var item in e)
  593. // {
  594. // if (item.EditType == ComPDFKit.PDFPage.CPDFEditType.EditText)
  595. // {
  596. // isText = true;
  597. // }
  598. // if (item.EditType == ComPDFKit.PDFPage.CPDFEditType.EditImage)
  599. // {
  600. // isImg = true;
  601. // }
  602. // }
  603. // if (isImg == true && isText == true)
  604. // IsSelectTextAndImg = true;
  605. // else
  606. // IsSelectTextAndImg = false;
  607. // }
  608. // else
  609. // {
  610. // IsLayoutAlign = false;
  611. // IsLayoutAvgAlign = false;
  612. // IsSelectTextAndImg = false;
  613. // IsTextEdit = true;
  614. // ClearCheckedAglin?.Invoke(null, null);
  615. // }
  616. //}
  617. #region 全局
  618. public event EventHandler ClearCheckedAglin;
  619. #endregion
  620. #endregion
  621. protected List<PDFEditEvent> TextEditEventList;
  622. public void OnNavigatedTo(NavigationContext navigationContext)
  623. {
  624. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  625. navigationContext.Parameters.TryGetValue<List<PDFEditEvent>>(ParameterNames.AnnotEvent, out TextEditEventList);
  626. if (PDFViewer != null)
  627. {
  628. if (TextEditEventList != null && TextEditEventList.Count > 0)
  629. {
  630. TextEditEvent = TextEditEventList[0];
  631. GetPDFEdit();
  632. }
  633. //PDFViewer.PDFEditActiveHandler -= PDFViewer_PDFEditActiveHandler;
  634. //PDFViewer.PDFEditActiveHandler += PDFViewer_PDFEditActiveHandler;
  635. PDFViewer.PDFEditCommandHandler -= PDFViewer_PDFEditCommandHandler;
  636. PDFViewer.PDFEditCommandHandler += PDFViewer_PDFEditCommandHandler;
  637. }
  638. }
  639. private void GetPDFEdit()
  640. {
  641. if(TextEditEvent != null)
  642. {
  643. TextFontFamily = TextEditEvent.FontFamily;
  644. TextFontSize = (int)TextEditEvent.FontSize;
  645. TextFontStyle = TextEditEvent.FontStyle;
  646. TextFontWeights = TextEditEvent.FontWeight;
  647. SelectColor = new SolidColorBrush(TextEditEvent.FontColor);
  648. }
  649. }
  650. public bool IsNavigationTarget(NavigationContext navigationContext){ return true; }
  651. public void OnNavigatedFrom(NavigationContext navigationContext)
  652. {
  653. TextEditEvent = null;
  654. ClearCheckedAglin?.Invoke(null, null);
  655. PDFViewer.PDFEditCommandHandler -= PDFViewer_PDFEditCommandHandler;
  656. }
  657. }
  658. }