CompareContentResultControl.xaml.cs 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.ComponentModel;
  5. using System.Diagnostics;
  6. using System.Globalization;
  7. using System.Linq;
  8. using System.Runtime.CompilerServices;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Controls;
  12. using System.Windows.Data;
  13. using System.Windows.Documents;
  14. using System.Windows.Input;
  15. using System.Windows.Media;
  16. using System.Windows.Media.Imaging;
  17. using System.Windows.Shapes;
  18. using System.Windows.Threading;
  19. using ComPDFKit.Compare;
  20. using ComPDFKit.Controls.Common;
  21. using ComPDFKit.Controls.Helper;
  22. using ComPDFKit.Controls.PDFControl;
  23. using ComPDFKit.Controls.Properties;
  24. using ComPDFKit.Import;
  25. using ComPDFKit.PDFDocument;
  26. using ComPDFKit.PDFPage;
  27. using ComPDFKitViewer;
  28. using Microsoft.WindowsAPICodePack.Dialogs;
  29. namespace ComPDFKit.Controls.Comparison
  30. {
  31. public class RichTextBoxHelper : DependencyObject
  32. {
  33. public static FlowDocument GetDocumentBind(DependencyObject obj)
  34. {
  35. return (FlowDocument)obj.GetValue(DocumentBindProperty);
  36. }
  37. public static void SetDocumentBind(DependencyObject obj, FlowDocument value)
  38. {
  39. obj.SetValue(DocumentBindProperty, value);
  40. }
  41. public static readonly DependencyProperty DocumentBindProperty =
  42. DependencyProperty.RegisterAttached("DocumentBind",
  43. typeof(TextBindProperty),
  44. typeof(RichTextBoxHelper),
  45. new FrameworkPropertyMetadata
  46. {
  47. BindsTwoWayByDefault = true,
  48. PropertyChangedCallback = (obj, e) =>
  49. {
  50. RichTextBox richTextBox = obj as RichTextBox;
  51. TextBindProperty bindItem = e.NewValue as TextBindProperty;
  52. if (richTextBox != null && bindItem != null)
  53. {
  54. richTextBox.Document = GetFlowDocument(bindItem);
  55. }
  56. }
  57. });
  58. public static FlowDocument GetFlowDocument(TextBindProperty bindItem)
  59. {
  60. FlowDocument Document = new FlowDocument();
  61. Paragraph textPara = new Paragraph();
  62. TextBlock addBlock = new TextBlock();
  63. textPara.Inlines.Add(addBlock);
  64. Document.Blocks.Add(textPara);
  65. if (bindItem.ResultType == 2)
  66. {
  67. if (bindItem.ObjType == 1)
  68. {
  69. Run textRun = new Run(LanguageHelper.CompareManager.GetString("Content_Insert"));
  70. if (bindItem.OldPageIndex == -1 || bindItem.NewPageIndex == -1)
  71. {
  72. textRun = new Run(LanguageHelper.CompareManager.GetString("Title_Insert"));
  73. }
  74. textRun.Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#42464D"));
  75. addBlock.Inlines.Add(textRun);
  76. }
  77. if (bindItem.ObjType == 2)
  78. {
  79. Run textRun = new Run(LanguageHelper.CompareManager.GetString("Insert_Image"));
  80. if (bindItem.OldPageIndex == -1 || bindItem.NewPageIndex == -1)
  81. {
  82. textRun = new Run(LanguageHelper.CompareManager.GetString("Title_Insert"));
  83. }
  84. textRun.Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#42464D"));
  85. addBlock.Inlines.Add(textRun);
  86. }
  87. }
  88. if (bindItem.ResultType == 1)
  89. {
  90. if (bindItem.ObjType == 1)
  91. {
  92. Run textRun = new Run(LanguageHelper.CompareManager.GetString("Content_Deleted"));
  93. if (bindItem.OldPageIndex == -1 || bindItem.NewPageIndex == -1)
  94. {
  95. textRun = new Run(LanguageHelper.CompareManager.GetString("Title_Delete"));
  96. }
  97. textRun.Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#42464D"));
  98. addBlock.Inlines.Add(textRun);
  99. }
  100. if (bindItem.ObjType == 2)
  101. {
  102. Run textRun = new Run("FileCompare_DeleteImage");
  103. if (bindItem.OldPageIndex == -1 || bindItem.NewPageIndex == -1)
  104. {
  105. textRun = new Run(LanguageHelper.CompareManager.GetString("Title_Delete"));
  106. }
  107. textRun.Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#42464D"));
  108. addBlock.Inlines.Add(textRun);
  109. }
  110. }
  111. if (bindItem.ResultType == 3)
  112. {
  113. if (bindItem.ObjType == 1)
  114. {
  115. Run textRun = new Run(LanguageHelper.CompareManager.GetString("Content_Replaced"));
  116. textRun.Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#42464D"));
  117. addBlock.Inlines.Add(textRun);
  118. }
  119. if (bindItem.ObjType == 2)
  120. {
  121. Run textRun = new Run("FileCompare_ReplaceImage");
  122. textRun.Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#42464D"));
  123. addBlock.Inlines.Add(textRun);
  124. }
  125. }
  126. if (bindItem.ResultType == 4)
  127. {
  128. if (bindItem.ObjType == 1)
  129. {
  130. //插入的文本
  131. Run textRun = new Run("FileCompare_ModifyText");
  132. textRun.Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#42464D"));
  133. addBlock.Inlines.Add(textRun);
  134. }
  135. if (bindItem.ObjType == 2)
  136. {
  137. //插入的文本
  138. Run textRun = new Run("FileCompare_ModifyImage");
  139. textRun.Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#42464D"));
  140. addBlock.Inlines.Add(textRun);
  141. }
  142. }
  143. return Document;
  144. }
  145. }
  146. public class BoolToVisibleConvert : IValueConverter
  147. {
  148. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  149. {
  150. if (value == null)
  151. {
  152. return Visibility.Visible;
  153. }
  154. else
  155. {
  156. if ((bool)value)
  157. {
  158. return Visibility.Visible;
  159. }
  160. else
  161. {
  162. return Visibility.Collapsed;
  163. }
  164. }
  165. }
  166. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  167. {
  168. return null;
  169. }
  170. }
  171. public class GroupHeaderConverter : IValueConverter
  172. {
  173. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  174. {
  175. try
  176. {
  177. if (value != null && value is string name)
  178. {
  179. return name;
  180. }
  181. return null;
  182. }
  183. catch
  184. {
  185. return null;
  186. }
  187. }
  188. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  189. {
  190. return null;
  191. }
  192. }
  193. public class TextBindProperty
  194. {
  195. /// <summary>
  196. /// 1 text 2 image
  197. /// </summary>
  198. public int ObjType { get; set; }
  199. /// <summary>
  200. /// 0 NULL 1 Delete 2 Insert 3 Replace 4 Change
  201. /// </summary>
  202. public int ResultType { get; set; }
  203. public CPDFCompareResult RawResult { get; set; }
  204. public int OldPageIndex { get; set; }
  205. public int NewPageIndex { get; set; }
  206. }
  207. public class CompareBindItem : INotifyPropertyChanged
  208. {
  209. public string ShowPageIndex { get; set; }
  210. public TextBindProperty BindProperty { get; set; }
  211. public Brush BindColorProperty { get; set; }
  212. public int BindIndexProperty { get; set; }
  213. public CompareBindItem()
  214. {
  215. BindProperty = new TextBindProperty();
  216. }
  217. public event PropertyChangedEventHandler PropertyChanged;
  218. protected void OnPropertyChanged([CallerMemberName] string name = null)
  219. {
  220. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
  221. }
  222. }
  223. public partial class CompareContentResultControl : UserControl
  224. {
  225. public List<CPDFCompareResults> CompareResultList { get; private set; } = new List<CPDFCompareResults>();
  226. private double[] zoomLevel = { 1.00f, 8f, 12f, 25, 33f, 50, 66f, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
  227. private ObservableCollection<CompareBindItem> BindList = new ObservableCollection<CompareBindItem>();
  228. private string filePath { get; set; } = string.Empty;
  229. private bool IsOldSave { get; set; } = true;
  230. private string OldFileName { get; set; } = string.Empty;
  231. private bool IsNewSave { get; set; } = false;
  232. private string NewFileName { get; set; } = string.Empty;
  233. private bool IsCombineSave { get; set; } = false;
  234. private string CombineFileName { get; set; } = string.Empty;
  235. private string oldName = "";
  236. private string newName = "";
  237. private bool IsCanScrollChanged = true;
  238. private CPDFDocument CombineDoc { get; set; }
  239. private CPDFDocument OldDoc { get; set; }
  240. private CPDFDocument NewDoc { get; set; }
  241. private ObservableCollection<ListBoxItem> bindNewPageList = new ObservableCollection<ListBoxItem>();
  242. private ObservableCollection<ListBoxItem> bindOldPageList = new ObservableCollection<ListBoxItem>();
  243. private List<int> visibleOldPageIndexes = new List<int>();
  244. private List<int> visibleNewPageIndexes = new List<int>();
  245. private DispatcherTimer oldTimer = new DispatcherTimer();
  246. private DispatcherTimer newTimer = new DispatcherTimer();
  247. public PDFViewControl pdfViewerCtrl { get; set; }
  248. private delegate void OnThumbnailGeneratedEventHandler(int pageIndex, byte[] thumb, int w, int h);
  249. private OnThumbnailGeneratedEventHandler OnLeftThumbnailGenerated;
  250. private OnThumbnailGeneratedEventHandler OnRightThumbnailGenerated;
  251. public event EventHandler ExitCompareEvent;
  252. public CompareContentResultControl()
  253. {
  254. InitializeComponent();
  255. ICollectionView groupView = CollectionViewSource.GetDefaultView(BindList);
  256. groupView.GroupDescriptions.Add(new PropertyGroupDescription(nameof(CompareBindItem.ShowPageIndex)));
  257. }
  258. private void Timer_Tick(object sender, EventArgs e)
  259. {
  260. if (LeftViewer == null || LeftViewer.GetCPDFViewer().GetDocument() == null)
  261. return;
  262. ItemsInViewHitTest(LeftViewer, PageOldEditListBox, bindOldPageList, visibleOldPageIndexes);
  263. oldTimer.Stop();
  264. }
  265. private void NewTimer_Tick(object sender, EventArgs e)
  266. {
  267. if (RightViewer == null || RightViewer.GetCPDFViewer().GetDocument() == null)
  268. return;
  269. ItemsInViewHitTest(RightViewer, PageNewEditListBox, bindNewPageList, visibleNewPageIndexes);
  270. newTimer.Stop();
  271. }
  272. public void LoadComparePdf(CPDFDocument combineDoc, CPDFDocument oldDoc, CPDFDocument newDoc)
  273. {
  274. CombineDoc = combineDoc;
  275. OldDoc = oldDoc;
  276. NewDoc = newDoc;
  277. OldFileTxb.Text = oldDoc.FileName + ".pdf";
  278. NewFileTxb.Text = newDoc.FileName + ".pdf";
  279. LeftViewer.InitDocument(oldDoc);
  280. LeftViewer.SetToolType(ComPDFKit.Tool.ToolType.Viewer);
  281. CPDFSaclingControl.InitWithPDFViewer(LeftViewer);
  282. RightViewer.InitDocument(newDoc);
  283. RightViewer.SetToolType(ComPDFKit.Tool.ToolType.Viewer);
  284. CPDFSaclingControl1.InitWithPDFViewer(RightViewer);
  285. OnLeftThumbnailGenerated -= _leftviewer_OnThumbnailGenerated;
  286. OnLeftThumbnailGenerated += _leftviewer_OnThumbnailGenerated;
  287. OnRightThumbnailGenerated -= _rightviewer_OnThumbnailGenerated;
  288. OnRightThumbnailGenerated += _rightviewer_OnThumbnailGenerated;
  289. LeftViewer.PDFViewTool.ScrollChangedHandler -= LeftViewerTool_ScrollChangedHandler;
  290. LeftViewer.PDFViewTool.ScrollChangedHandler += LeftViewerTool_ScrollChangedHandler;
  291. RightViewer.PDFViewTool.ScrollChangedHandler -= RightViewerTool_ScrollChangedHandler;
  292. RightViewer.PDFViewTool.ScrollChangedHandler += RightViewerTool_ScrollChangedHandler;
  293. PopulateOldThumbnailList();
  294. PopulateNewThumbnailList();
  295. oldTimer.Interval = TimeSpan.FromSeconds(0.3);
  296. oldTimer.Tick += Timer_Tick;
  297. newTimer.Interval = TimeSpan.FromSeconds(0.3);
  298. newTimer.Tick += NewTimer_Tick;
  299. oldTimer.Start();
  300. newTimer.Start();
  301. }
  302. public bool synchronizedScrolling = true;
  303. private void LeftViewerTool_ScrollChangedHandler(object sender, ScrollChangedEventArgs e)
  304. {
  305. if (SynchronizedScrollingCKBox != null && SynchronizedScrollingCKBox.IsChecked.Value&& synchronizedScrolling)
  306. {
  307. if (RightViewer != null)
  308. {
  309. RightViewer.ScrollToVerticalOffset(LeftViewer.GetVerticalOffset());
  310. }
  311. }
  312. synchronizedScrolling = true;
  313. }
  314. private void RightViewerTool_ScrollChangedHandler(object sender, ScrollChangedEventArgs e)
  315. {
  316. if (SynchronizedScrollingCKBox != null && SynchronizedScrollingCKBox.IsChecked.Value&& synchronizedScrolling)
  317. {
  318. if (LeftViewer != null)
  319. {
  320. LeftViewer.ScrollToVerticalOffset(RightViewer.GetVerticalOffset());
  321. }
  322. }
  323. }
  324. private void _rightviewer_OnThumbnailGenerated(int pageIndex, byte[] thumb, int w, int h)
  325. {
  326. try
  327. {
  328. if (PageNewEditListBox.Items.IsEmpty)
  329. {
  330. return;
  331. }
  332. ScrollViewer sv = GetScrollHost(PageNewEditListBox);
  333. //ListBoxItem item = PageEditListBox.Items[pageIndex] as ListBoxItem;
  334. ListBoxItem listboxitem = PageNewEditListBox.ItemContainerGenerator.ContainerFromIndex(pageIndex) as ListBoxItem;
  335. if (CommonHelper.ViewportHelper.IsInViewport(sv, listboxitem))
  336. {
  337. Debug.WriteLine("Got thumbnail for page {0}. It is visible, so adding thumb", pageIndex);
  338. PixelFormat fmt = PixelFormats.Bgra32;
  339. BitmapSource bps = BitmapSource.Create(w, h, 96.0, 96.0, fmt, null, thumb, (w * fmt.BitsPerPixel + 7) / 8);
  340. Image image = GetImageElement(PageNewEditListBox.Items[pageIndex] as ListBoxItem);
  341. image.Source = bps;
  342. }
  343. else
  344. {
  345. Debug.WriteLine("Got thumbnail for page {0}. It is NOT visible, so ignoring thumb", pageIndex);
  346. }
  347. }
  348. catch (Exception ex)
  349. {
  350. Debug.WriteLine(ex.ToString());
  351. }
  352. }
  353. private void _leftviewer_OnThumbnailGenerated(int pageIndex, byte[] thumb, int w, int h)
  354. {
  355. try
  356. {
  357. if (PageOldEditListBox.Items.IsEmpty)
  358. {
  359. return;
  360. }
  361. ScrollViewer sv = GetScrollHost(PageOldEditListBox);
  362. //ListBoxItem item = PageEditListBox.Items[pageIndex] as ListBoxItem;
  363. ListBoxItem listboxitem = PageOldEditListBox.ItemContainerGenerator.ContainerFromIndex(pageIndex) as ListBoxItem;
  364. if (CommonHelper.ViewportHelper.IsInViewport(sv, listboxitem))
  365. {
  366. Debug.WriteLine("Got thumbnail for page {0}. It is visible, so adding thumb", pageIndex);
  367. PixelFormat fmt = PixelFormats.Bgra32;
  368. BitmapSource bps = BitmapSource.Create(w, h, 96.0, 96.0, fmt, null, thumb, (w * fmt.BitsPerPixel + 7) / 8);
  369. Image image = GetImageElement(PageOldEditListBox.Items[pageIndex] as ListBoxItem);
  370. image.Source = bps;
  371. }
  372. else
  373. {
  374. Debug.WriteLine("Got thumbnail for page {0}. It is NOT visible, so ignoring thumb", pageIndex);
  375. }
  376. }
  377. catch (Exception ex)
  378. {
  379. Debug.WriteLine(ex.ToString());
  380. }
  381. }
  382. private async void ItemsInViewHitTest(PDFViewControl pdfViewer, ListBox PageEditListBox, ObservableCollection<ListBoxItem> bindPageList, List<int> visiblePageIndexes)
  383. {
  384. if (pdfViewer == null || pdfViewer.GetCPDFViewer().GetDocument() == null)
  385. return;
  386. try
  387. {
  388. ScrollViewer sv = GetScrollHost(PageEditListBox);
  389. if (sv == null) return;
  390. if (VisualTreeHelper.GetParent(this) == null)
  391. return;
  392. //List<int> pagesOnScreen = new List<int>();
  393. //pageThumbnailsToRequest.Clear();
  394. var range = GetRoughViewportRange(pdfViewer.GetCPDFViewer().GetDocument(), PageEditListBox, (PageEditListBox.Items[0] as ListBoxItem).DesiredSize, new Thickness(6, 10, 6, 10));
  395. for (int i = 0; i < PageEditListBox.Items.Count; ++i)
  396. {
  397. //if (i>=pdfViewer.Document.PageCount)
  398. //{
  399. // break;
  400. //}
  401. ListBoxItem item = PageEditListBox.Items[i] as ListBoxItem;
  402. // ListBoxItem listboxitem = PageEditListBox.ItemContainerGenerator.ContainerFromIndex(i) as ListBoxItem;
  403. Image img = GetImageElement(item);
  404. if (i >= (range.Item1 - 1) && i <= range.Item2 || CommonHelper.ViewportHelper.IsInViewport(sv, item))//更改判断方式 因为BOTA缩略图不准确
  405. {
  406. if (img.Source == null && !visiblePageIndexes.Contains(i))
  407. {
  408. visiblePageIndexes.Add(i);
  409. await Task.Delay(1);//有刷不出图的情况 增减页面时
  410. await GetThumbnail(pdfViewer, i, (int)img.Width, (int)img.Height);
  411. Debug.WriteLine("Page {0} is visible, asking for thumb", (i + 1));
  412. }
  413. else if (img.Source == null)
  414. {
  415. // await pdfViewer.GetThumbnail(i, (int)img.Width, (int)img.Height);
  416. Debug.WriteLine("Page {0} is visible, asking for thumb", (i + 1));
  417. }
  418. }
  419. else
  420. {
  421. if (visiblePageIndexes.Contains(i))
  422. {
  423. Image image = GetImageElement(PageEditListBox.Items[i] as ListBoxItem);
  424. if (image.Source != null)
  425. {
  426. image.Source = null;
  427. //(image.Parent as Border).BorderBrush = Brushes.Transparent;
  428. Debug.WriteLine("Page {0} is out of range, removed thumb", (i + 1));
  429. }
  430. else
  431. {
  432. Debug.WriteLine("Page {0} is out of range, but had no thumb", (i + 1));
  433. }
  434. visiblePageIndexes.Remove(i);
  435. }
  436. }
  437. }
  438. }
  439. catch (Exception ex)
  440. {
  441. Debug.WriteLine(ex.ToString());
  442. }
  443. }
  444. public async Task GetThumbnail(PDFViewControl pdfViewer,int pageIndex, int imageWidth, int imageHeight)
  445. {
  446. if (imageWidth <= 0 || imageHeight <= 0)
  447. {
  448. return;
  449. }
  450. CPDFDocument pdfdoc = pdfViewer?.GetCPDFViewer()?.GetDocument();
  451. if (pdfdoc == null)
  452. {
  453. return;
  454. }
  455. CPDFPage page = pdfdoc.PageAtIndex(pageIndex);
  456. byte[] bmpData = new byte[imageWidth * imageHeight * 4];
  457. await Task.Run(() => page.RenderPageBitmap(0, 0, imageWidth, imageHeight, 0xFFFFFFFF, bmpData, 1, true));
  458. if (pdfViewer == LeftViewer && OnLeftThumbnailGenerated != null)
  459. {
  460. OnLeftThumbnailGenerated(pageIndex, bmpData, imageWidth, imageHeight);
  461. }
  462. else if (pdfViewer == RightViewer && OnRightThumbnailGenerated != null)
  463. {
  464. OnRightThumbnailGenerated(pageIndex, bmpData, imageWidth, imageHeight);
  465. }
  466. }
  467. public void SetCompareResult(List<CPDFCompareResults> resultList)
  468. {
  469. CompareResultList = resultList;
  470. BindList.Clear();
  471. int ResultIndex = 0;
  472. int ResultPage = 1;
  473. foreach (CPDFCompareResults result in CompareResultList)
  474. {
  475. if (result.TextResults != null && result.TextResults.Count > 0)
  476. {
  477. for (int i = result.TextResults.Count - 1; i >= 0; i--)
  478. {
  479. CPDFCompareResult item = result.TextResults[i];
  480. if ((item.OldRect.width() > 0 && item.OldRect.height() > 0) || (item.NewRect.width() > 0 && item.NewRect.height() > 0))
  481. {
  482. CompareBindItem bindItem = new CompareBindItem();
  483. string page = LanguageHelper.CompareManager.GetString("Text_Page");
  484. if (item.OldPageIndex == -1)
  485. {
  486. bindItem.ShowPageIndex = "-" + " VS " + page + " " + (item.NewPageIndex + 1);
  487. }
  488. if (item.NewPageIndex == -1)
  489. {
  490. bindItem.ShowPageIndex = page + " " + (item.OldPageIndex + 1) + " VS " + "-";
  491. }
  492. if (item.NewPageIndex != -1 && item.OldPageIndex != -1)
  493. {
  494. bindItem.ShowPageIndex = page + " " + (item.OldPageIndex + 1) + " VS " + page + " " + (item.NewPageIndex + 1);
  495. }
  496. bindItem.BindProperty.ResultType = (int)item.Type;
  497. bindItem.BindProperty.ObjType = 1;
  498. bindItem.BindProperty.RawResult = item;
  499. bindItem.BindProperty.OldPageIndex = item.OldPageIndex;
  500. bindItem.BindProperty.NewPageIndex = item.NewPageIndex;
  501. bindItem.BindColorProperty = GetBrushFlowDocument(item);
  502. BindList.Add(bindItem);
  503. }
  504. }
  505. }
  506. if (result.ImageResults != null && result.ImageResults.Count > 0)
  507. {
  508. for (int i = 0; i < result.ImageResults.Count; i++)
  509. {
  510. CPDFCompareResult item = result.ImageResults[i];
  511. if ((item.OldRect.width() > 0 && item.OldRect.height() > 0) || (item.NewRect.width() > 0 && item.NewRect.height() > 0))
  512. {
  513. CompareBindItem bindItem = new CompareBindItem();
  514. string page = LanguageHelper.CompareManager.GetString("Text_Page");
  515. if (item.OldPageIndex == -1)
  516. {
  517. bindItem.ShowPageIndex = "-" + " VS " + page + " " + (item.NewPageIndex + 1);
  518. }
  519. if (item.NewPageIndex == -1)
  520. {
  521. bindItem.ShowPageIndex = page + " " + (item.OldPageIndex + 1) + " VS " + "-";
  522. }
  523. if (item.NewPageIndex != -1 && item.OldPageIndex != -1)
  524. {
  525. bindItem.ShowPageIndex = page + " " + (item.OldPageIndex + 1) + " VS " + page + " " + (item.NewPageIndex + 1);
  526. }
  527. bindItem.BindProperty.ResultType = (int)item.Type;
  528. bindItem.BindProperty.ObjType = 2;
  529. bindItem.BindProperty.RawResult = item;
  530. bindItem.BindProperty.OldPageIndex = item.OldPageIndex;
  531. bindItem.BindProperty.NewPageIndex = item.NewPageIndex;
  532. bindItem.BindColorProperty = GetBrushFlowDocument(item);
  533. BindList.Add(bindItem);
  534. }
  535. }
  536. }
  537. }
  538. if (BindList.Count > 0)
  539. {
  540. List<string> pageList=BindList.AsEnumerable().Select(x=>x.ShowPageIndex).Distinct().ToList();
  541. if(pageList!=null && pageList.Count > 0)
  542. {
  543. foreach (string page in pageList)
  544. {
  545. int orderIndex = 1;
  546. List<CompareBindItem> orderList= BindList.AsEnumerable().Where(x => x.ShowPageIndex == page).ToList();
  547. foreach (CompareBindItem order in orderList)
  548. {
  549. order.BindIndexProperty=orderIndex++;
  550. }
  551. }
  552. }
  553. ResultList.ItemsSource = BindList;
  554. TotalResultText.Text = string.Format("{0}", BindList.Count);
  555. }
  556. else
  557. {
  558. NoCompareGrid.Visibility = Visibility.Visible;
  559. }
  560. }
  561. public Brush GetBrushFlowDocument(CPDFCompareResult bindItem)
  562. {
  563. if ((int)bindItem.Type == 2)
  564. {
  565. return InsertColorRect.Fill;
  566. }
  567. if ((int)bindItem.Type == 1)
  568. {
  569. return DeleteColorRect.Fill;
  570. }
  571. if ((int)bindItem.Type == 3)
  572. {
  573. return ReplaceColorRect.Fill;
  574. }
  575. if ((int)bindItem.Type == 4)
  576. {
  577. return ReplaceColorRect.Fill;
  578. }
  579. return new SolidColorBrush(Colors.Red);
  580. }
  581. private double CheckZoomLevel(double zoom, bool IsGrowth)
  582. {
  583. double standardZoom = 100;
  584. if (zoom <= 0.01)
  585. {
  586. return 0.01;
  587. }
  588. if (zoom >= 10)
  589. {
  590. return 10;
  591. }
  592. zoom *= 100;
  593. for (int i = 0; i < zoomLevel.Length - 1; i++)
  594. {
  595. if (zoom > zoomLevel[i] && zoom <= zoomLevel[i + 1] && IsGrowth)
  596. {
  597. standardZoom = zoomLevel[i + 1];
  598. break;
  599. }
  600. if (zoom >= zoomLevel[i] && zoom < zoomLevel[i + 1] && !IsGrowth)
  601. {
  602. standardZoom = zoomLevel[i];
  603. break;
  604. }
  605. }
  606. return standardZoom / 100;
  607. }
  608. private void SearchResultList_SelectionChanged(object sender, SelectionChangedEventArgs e)
  609. {
  610. synchronizedScrolling = false;
  611. if (ResultList.SelectedIndex == -1)
  612. {
  613. //synchronizedScrolling = true;
  614. return;
  615. }
  616. CompareBindItem bindItem = ResultList.SelectedItem as CompareBindItem;
  617. if (bindItem != null && LeftViewer != null && RightViewer != null)
  618. {
  619. CPDFCompareResult rawResult = bindItem.BindProperty.RawResult;
  620. int boundOffset = 3;
  621. SolidColorBrush fillBrush = Brushes.Transparent;
  622. switch (rawResult.Type)
  623. {
  624. case CPDFCompareResultType.CPDFCompareResultTypeDelete:
  625. fillBrush = Brushes.Red;
  626. break;
  627. case CPDFCompareResultType.CPDFCompareResultTypeInsert:
  628. fillBrush = Brushes.Blue;
  629. break;
  630. case CPDFCompareResultType.CPDFCompareResultTypeReplace:
  631. fillBrush = new SolidColorBrush(Color.FromRgb(0xF3, 0x90, 0x24));
  632. break;
  633. case CPDFCompareResultType.CPDFCompareResultTypeChange:
  634. fillBrush = new SolidColorBrush(Color.FromRgb(0xF3, 0x90, 0x24));
  635. break;
  636. default:
  637. break;
  638. }
  639. if (rawResult.OldPageIndex >= 0)
  640. {
  641. CPDFViewer pdfViewer = LeftViewer.GetCPDFViewer();
  642. if (pdfViewer != null)
  643. {
  644. pdfViewer.GoToPage(rawResult.OldPageIndex, new Point(rawResult.OldRect.left, rawResult.OldRect.top));
  645. }
  646. if (rawResult.Type != CPDFCompareResultType.CPDFCompareResultTypeInsert)
  647. {
  648. LeftViewer.PDFViewTool.SetPDFCompareView(null, new Pen(Brushes.Red, 2), rawResult.OldPageIndex, new List<Rect>()
  649. {
  650. new Rect(rawResult.OldRect.left-boundOffset,
  651. rawResult.OldRect.top-boundOffset,
  652. rawResult.OldRect.width()+boundOffset*2,
  653. rawResult.OldRect.height()+boundOffset*2)
  654. });
  655. }
  656. else
  657. {
  658. LeftViewer.PDFViewTool.ClearPDFCompareView();
  659. }
  660. }
  661. if (rawResult.NewPageIndex >= 0)
  662. {
  663. CPDFViewer pdfViewer = RightViewer.GetCPDFViewer();
  664. if (pdfViewer != null)
  665. {
  666. pdfViewer.GoToPage(rawResult.NewPageIndex, new Point(rawResult.NewRect.left, rawResult.NewRect.top));
  667. }
  668. if (rawResult.Type != CPDFCompareResultType.CPDFCompareResultTypeDelete)
  669. {
  670. RightViewer.PDFViewTool.SetPDFCompareView(null, new Pen(Brushes.Red, 2), rawResult.NewPageIndex, new List<Rect>()
  671. {
  672. new Rect(rawResult.NewRect.left-boundOffset,
  673. rawResult.NewRect.top-boundOffset,
  674. rawResult.NewRect.width()+boundOffset*2,
  675. rawResult.NewRect.height()+boundOffset*2)
  676. });
  677. }
  678. else
  679. {
  680. RightViewer.PDFViewTool.ClearPDFCompareView();
  681. }
  682. }
  683. }
  684. //synchronizedScrolling = true;
  685. }
  686. private void SaveBtn_Click(object sender, RoutedEventArgs e)
  687. {
  688. SavePopGrid.Visibility = Visibility.Visible;
  689. }
  690. private void ConfirmSaveBtn_Click(object sender, RoutedEventArgs e)
  691. {
  692. string oldSaveName = string.Empty;
  693. string newSaveName = string.Empty;
  694. string combineSaveName = string.Empty;
  695. filePath = CmbFilePath.Text;
  696. IsOldSave = OldCheckBox.IsChecked == true;
  697. OldFileName = filePath + "\\old.pdf";
  698. IsNewSave = NewCheckBox.IsChecked == true;
  699. NewFileName = filePath + "\\new.pdf";
  700. IsCombineSave = CombineCheckBox.IsChecked == true;
  701. CombineFileName = filePath + "\\combine.pdf";
  702. if (IsOldSave)
  703. {
  704. oldSaveName = CommonHelper.GetFileNameAddSuffix(filePath, oldName + "_compare", ".pdf");
  705. }
  706. if (IsNewSave)
  707. {
  708. newSaveName = oldSaveName = CommonHelper.GetFileNameAddSuffix(filePath, newName + "_compare", ".pdf");
  709. }
  710. if (IsCombineSave)
  711. {
  712. combineSaveName = CommonHelper.GetFileNameAddSuffix(filePath, "MergedCompareFile", ".pdf");
  713. }
  714. if (oldSaveName != string.Empty || newSaveName != string.Empty || combineSaveName != string.Empty)
  715. {
  716. if (oldSaveName != string.Empty && OldDoc != null && IsOldSave)
  717. {
  718. OldDoc.WriteToFilePath(oldSaveName);
  719. Process.Start(@"explorer.exe", "/select,\"" + oldSaveName + "\"");
  720. }
  721. if (newSaveName != string.Empty && NewDoc != null && IsNewSave)
  722. {
  723. NewDoc.WriteToFilePath(newSaveName);
  724. Process.Start(@"explorer.exe", "/select,\"" + newSaveName + "\"");
  725. }
  726. if (combineSaveName != string.Empty && CombineDoc != null && IsCombineSave)
  727. {
  728. CombineDoc.WriteToFilePath(combineSaveName);
  729. Process.Start(@"explorer.exe", "/select,\"" + combineSaveName + "\"");
  730. }
  731. //CloseLeave();
  732. }
  733. }
  734. private void CloseBtn_Click(object sender, RoutedEventArgs e)
  735. {
  736. CloseConfirmGrid.Visibility = Visibility.Visible;
  737. }
  738. private void CloseLeave()
  739. {
  740. ExitCompareEvent?.Invoke(null,null);
  741. }
  742. private void CompareBtn_Click(object sender, RoutedEventArgs e)
  743. {
  744. ThumbnailBtn.IsChecked = false;
  745. CompareBtn.IsChecked = true;
  746. ThumbnailBtnPath.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#000000"));
  747. CompareBtnPath.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFFFFF"));
  748. }
  749. private void ThumbnailBtn_Click(object sender, RoutedEventArgs e)
  750. {
  751. ThumbnailBtn.IsChecked = true;
  752. CompareBtn.IsChecked = false;
  753. ThumbnailBtnPath.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFFFFF"));
  754. CompareBtnPath.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#000000"));
  755. }
  756. private void ListBoxItem_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
  757. {
  758. }
  759. private void ListBoxItem_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  760. {
  761. }
  762. private void PageEditListBox_SizeChanged(object sender, SizeChangedEventArgs e)
  763. {
  764. PageOldEditListBox.ScrollIntoView(PageOldEditListBox.SelectedItem);
  765. PageNewEditListBox.ScrollIntoView(PageNewEditListBox.SelectedItem);
  766. }
  767. private void PageEditListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  768. {
  769. var list = sender as ListBox;
  770. if (list != null)
  771. {
  772. if (SynchronizedScrollingCKBox.IsChecked.Value)
  773. {
  774. if (list.Name == "PageOldEditListBox")
  775. {
  776. PageNewEditListBox.SelectedIndex = PageOldEditListBox.SelectedIndex;
  777. e.Handled = false;
  778. }
  779. if (list.Name == "PageNewEditListBox")
  780. {
  781. PageOldEditListBox.SelectedIndex = PageNewEditListBox.SelectedIndex;
  782. e.Handled = false;
  783. }
  784. if (PageNewEditListBox.SelectedIndex < LeftViewer.GetCPDFViewer().GetDocument().PageCount)
  785. {
  786. LeftViewer.GetCPDFViewer().GoToPage(PageNewEditListBox.SelectedIndex);
  787. }
  788. else
  789. {
  790. LeftViewer.GetCPDFViewer().GoToPage(LeftViewer.GetCPDFViewer().GetDocument().PageCount - 1);
  791. }
  792. if (PageOldEditListBox.SelectedIndex < RightViewer.GetCPDFViewer().GetDocument().PageCount)
  793. {
  794. RightViewer.GetCPDFViewer().GoToPage(PageNewEditListBox.SelectedIndex);
  795. }
  796. else
  797. {
  798. RightViewer.GetCPDFViewer().GoToPage(RightViewer.GetCPDFViewer().GetDocument().PageCount - 1);
  799. }
  800. }
  801. else
  802. {
  803. if (list.Name == "PageNewEditListBox")
  804. {
  805. if (PageNewEditListBox.SelectedIndex < RightViewer.GetCPDFViewer().GetDocument().PageCount)
  806. {
  807. if (PageNewEditListBox.SelectedIndex != -1)
  808. {
  809. RightViewer.GetCPDFViewer().GoToPage(PageNewEditListBox.SelectedIndex);
  810. PageOldEditListBox.SelectedIndex = -1;
  811. }
  812. }
  813. else
  814. {
  815. PageNewEditListBox.SelectedIndex = -1;
  816. LeftViewer.GetCPDFViewer().GoToPage(LeftViewer.GetCPDFViewer().GetDocument().PageCount - 1);
  817. }
  818. }
  819. if (list.Name == "PageOldEditListBox")
  820. {
  821. if (PageOldEditListBox.SelectedIndex < LeftViewer.GetCPDFViewer().GetDocument().PageCount)
  822. {
  823. if (PageOldEditListBox.SelectedIndex != -1)
  824. {
  825. LeftViewer.GetCPDFViewer().GoToPage(PageOldEditListBox.SelectedIndex);
  826. PageNewEditListBox.SelectedIndex = -1;
  827. }
  828. }
  829. else
  830. {
  831. PageOldEditListBox.SelectedIndex = -1;
  832. RightViewer.GetCPDFViewer().GoToPage(RightViewer.GetCPDFViewer().GetDocument().PageCount - 1);
  833. }
  834. }
  835. }
  836. }
  837. }
  838. private void PageEditListBox_ScrollChanged(object sender, ScrollChangedEventArgs e)
  839. {
  840. ItemsInViewHitTest(LeftViewer, PageOldEditListBox, bindOldPageList, visibleOldPageIndexes);
  841. ItemsInViewHitTest(RightViewer, PageNewEditListBox, bindNewPageList, visibleNewPageIndexes);
  842. }
  843. private ScrollViewer GetScrollHost(ListBox listBox)
  844. {
  845. if (VisualTreeHelper.GetChildrenCount(listBox) > 0)
  846. {
  847. int s = VisualTreeHelper.GetChildrenCount(listBox);
  848. Border border = VisualTreeHelper.GetChild(listBox, 0) as Border;
  849. if (border != null)
  850. {
  851. return VisualTreeHelper.GetChild(border, 0) as ScrollViewer;
  852. }
  853. }
  854. return null;
  855. }
  856. // return the range of items in the current view
  857. private Tuple<int, int, int> GetRoughViewportRange(CPDFDocument doc, ListBox view, Size itemSize, Thickness itemMargin)
  858. {
  859. var scrollViewer = GetScrollHost(view);
  860. if (doc == null || scrollViewer == null || scrollViewer.ActualHeight == 0 || scrollViewer.ActualWidth == 0)//视图展开
  861. return new Tuple<int, int, int>(0, 0, 0);
  862. try
  863. {
  864. var currentHeight = scrollViewer.ActualHeight - view.Padding.Top;
  865. var currentWidth = scrollViewer.ActualWidth;
  866. //计算当前窗口大小能显示的行数和列数
  867. var columnCount = (int)(currentWidth / (itemSize.Width + itemMargin.Left));
  868. var rowCount = (int)Math.Ceiling(currentHeight / (itemSize.Height + itemMargin.Bottom));
  869. var preItemCount = (int)((scrollViewer.VerticalOffset / scrollViewer.ExtentHeight) * ((doc.PageCount + columnCount - 1) / columnCount));//滑动百分比*行数 = 大概的垂直位置
  870. preItemCount = preItemCount * columnCount;
  871. var preEnd = (int)(((scrollViewer.VerticalOffset + scrollViewer.ActualHeight) / scrollViewer.ExtentHeight) * ((doc.PageCount + columnCount - 1) / columnCount));
  872. preEnd = preEnd * columnCount + columnCount - 1;
  873. var middle = (int)Math.Ceiling(preItemCount + preEnd / 2d);
  874. return new Tuple<int, int, int>(
  875. Math.Max(preItemCount, 0),
  876. Math.Min(view.Items.Count, preEnd),
  877. middle);
  878. }
  879. catch (Exception ex)
  880. {
  881. }
  882. return new Tuple<int, int, int>(0, 0, 0);
  883. }
  884. private Image GetImageElement(ListBoxItem item)
  885. {
  886. Viewbox viewBox = (item.Content as StackPanel).Children[0] as Viewbox;
  887. Image img = ((viewBox.Child as Border).Child as Grid).Children[0] as Image;
  888. return img;
  889. }
  890. private int[] thumbnailSize = { 100, 150, 200, 300, 500 };
  891. public void PopulateOldThumbnailList()
  892. {
  893. visibleOldPageIndexes.Clear();
  894. bindOldPageList.Clear();
  895. // GC.Collect();
  896. int thumbnailWidth = thumbnailSize[0];
  897. bool pageRatio = OldDoc.PageCount >= NewDoc.PageCount;
  898. int pageCount = pageRatio ? OldDoc.PageCount : NewDoc.PageCount;
  899. Brush borderBrush = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#A0A2AE"));
  900. Brush fillBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFBB00"));
  901. Brush fontBrush = Brushes.Black;
  902. Brush transparentBrush = new SolidColorBrush(Colors.Transparent);
  903. for (int i = 0; i < pageCount; i++)
  904. {
  905. CSize pageSize = new CSize();
  906. if (i < OldDoc.PageCount)
  907. {
  908. pageSize = OldDoc.GetPageSize(i);
  909. }
  910. else
  911. {
  912. borderBrush = transparentBrush;
  913. fillBrush = transparentBrush;
  914. fontBrush = transparentBrush;
  915. pageSize = NewDoc.GetPageSize(i);
  916. }
  917. if (pageSize.height == 0 || pageSize.width == 0)
  918. continue;
  919. int imageWidth = pageSize.width > pageSize.height ? thumbnailWidth * 2 : (int)(pageSize.width / pageSize.height * thumbnailWidth * 2);
  920. int imageHeight = pageSize.height > pageSize.width ? thumbnailWidth * 2 : (int)(pageSize.height / pageSize.width * thumbnailWidth * 2);
  921. Image img = new Image()
  922. {
  923. //Margin = new Thickness(0, 0, 5, 0),
  924. Width = imageWidth,
  925. Height = imageHeight,
  926. Stretch = Stretch.Uniform,
  927. };
  928. Grid grid = new Grid();
  929. grid.Children.Add(img);
  930. List<Point> points = new List<Point>()
  931. {
  932. new Point(16.75,1.25),
  933. new Point(3.25,1.25 ),
  934. new Point(3.25,19.4013878),
  935. new Point(10,14.902),
  936. new Point(16.75,19.4013878),
  937. };
  938. Polygon bookmark = new Polygon()
  939. {
  940. Points = new PointCollection(points),
  941. Fill = fillBrush,
  942. Margin = new Thickness(0, 16, 16, 0),
  943. VerticalAlignment = VerticalAlignment.Top,
  944. HorizontalAlignment = HorizontalAlignment.Right,
  945. Visibility = Visibility.Collapsed,
  946. };
  947. grid.Children.Add(bookmark);
  948. Border border = new Border()
  949. {
  950. BorderThickness = new Thickness(2),
  951. BorderBrush = borderBrush,
  952. Child = grid,
  953. };
  954. Viewbox viewBox = new Viewbox()
  955. {
  956. Margin = new Thickness(0, 8, 0, 0),
  957. Stretch = System.Windows.Media.Stretch.Uniform,
  958. Width = thumbnailWidth,
  959. Height = thumbnailWidth,
  960. Child = border,
  961. };
  962. TextBlock text = new TextBlock()
  963. {
  964. HorizontalAlignment = System.Windows.HorizontalAlignment.Center,
  965. Text = (i + 1).ToString(),
  966. Foreground = fontBrush,
  967. Margin = new Thickness(0, 8, 0, 8),
  968. };
  969. StackPanel panel = new StackPanel();
  970. panel.Children.Add(viewBox);
  971. panel.Children.Add(text);
  972. ListBoxItem item = new ListBoxItem();
  973. item.Content = panel;
  974. item.Tag = i;
  975. item.Margin = new Thickness(6, 10, 6, 10);
  976. bindOldPageList.Add(item);
  977. }
  978. PageOldEditListBox.ItemsSource = bindOldPageList;
  979. }
  980. public void PopulateNewThumbnailList()
  981. {
  982. visibleNewPageIndexes.Clear();
  983. bindNewPageList.Clear();
  984. // GC.Collect();
  985. bool pageRatio = NewDoc.PageCount >= OldDoc.PageCount;
  986. int pageCount = pageRatio ? NewDoc.PageCount : OldDoc.PageCount;
  987. int thumbnailWidth = thumbnailSize[0];
  988. Brush borderBrush = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#A0A2AE"));
  989. Brush fillBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFBB00"));
  990. Brush fontBrush = Brushes.Black;
  991. Brush transparentBrush = new SolidColorBrush(Colors.Transparent);
  992. for (int i = 0; i < pageCount; i++)
  993. {
  994. CSize pageSize = new CSize();
  995. if (i < NewDoc.PageCount)
  996. {
  997. pageSize = NewDoc.GetPageSize(i);
  998. }
  999. else
  1000. {
  1001. borderBrush = transparentBrush;
  1002. fillBrush = transparentBrush;
  1003. fontBrush = transparentBrush;
  1004. pageSize = OldDoc.GetPageSize(i);
  1005. }
  1006. if (pageSize.height == 0 || pageSize.width == 0)
  1007. continue;
  1008. int imageWidth = pageSize.width > pageSize.height ? thumbnailWidth * 2 : (int)(pageSize.width / pageSize.height * thumbnailWidth * 2);
  1009. int imageHeight = pageSize.height > pageSize.width ? thumbnailWidth * 2 : (int)(pageSize.height / pageSize.width * thumbnailWidth * 2);
  1010. Image img = new Image()
  1011. {
  1012. //Margin = new Thickness(0, 0, 5, 0),
  1013. Width = imageWidth,
  1014. Height = imageHeight,
  1015. Stretch = Stretch.Uniform,
  1016. };
  1017. Grid grid = new Grid();
  1018. grid.Children.Add(img);
  1019. List<Point> points = new List<Point>()
  1020. {
  1021. new Point(16.75,1.25),
  1022. new Point(3.25,1.25 ),
  1023. new Point(3.25,19.4013878),
  1024. new Point(10,14.902),
  1025. new Point(16.75,19.4013878),
  1026. };
  1027. Polygon bookmark = new Polygon()
  1028. {
  1029. Points = new PointCollection(points),
  1030. Fill = fillBrush,
  1031. Margin = new Thickness(0, 16, 16, 0),
  1032. VerticalAlignment = VerticalAlignment.Top,
  1033. HorizontalAlignment = HorizontalAlignment.Right,
  1034. Visibility = Visibility.Collapsed,
  1035. };
  1036. grid.Children.Add(bookmark);
  1037. Border border = new Border()
  1038. {
  1039. BorderThickness = new Thickness(2),
  1040. BorderBrush = borderBrush,
  1041. Child = grid,
  1042. };
  1043. Viewbox viewBox = new Viewbox()
  1044. {
  1045. Margin = new Thickness(0, 8, 0, 0),
  1046. Stretch = System.Windows.Media.Stretch.Uniform,
  1047. Width = thumbnailWidth,
  1048. Height = thumbnailWidth,
  1049. Child = border,
  1050. };
  1051. TextBlock text = new TextBlock()
  1052. {
  1053. HorizontalAlignment = System.Windows.HorizontalAlignment.Center,
  1054. Text = (i + 1).ToString(),
  1055. Foreground = fontBrush,
  1056. Margin = new Thickness(0, 8, 0, 8),
  1057. };
  1058. StackPanel panel = new StackPanel();
  1059. panel.Children.Add(viewBox);
  1060. panel.Children.Add(text);
  1061. ListBoxItem item = new ListBoxItem();
  1062. item.Content = panel;
  1063. item.Tag = i;
  1064. item.Margin = new Thickness(6, 10, 6, 10);
  1065. bindNewPageList.Add(item);
  1066. }
  1067. PageNewEditListBox.ItemsSource = bindNewPageList;
  1068. }
  1069. public void SetCompareColor(Brush dbrush, Brush rbrush, Brush Ibrush)
  1070. {
  1071. DeleteColorRect.Fill = dbrush;
  1072. ReplaceColorRect.Fill = rbrush;
  1073. InsertColorRect.Fill = Ibrush;
  1074. }
  1075. public void SetCompareName(string oldname, string newname)
  1076. {
  1077. oldName = oldname;
  1078. newName = newname;
  1079. }
  1080. private void ScrollViewer_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
  1081. {
  1082. double currentOffset = EditListBoxSV.VerticalOffset;
  1083. // Manually handle scrolling
  1084. // Scroll up
  1085. if (e.Delta > 0)
  1086. {
  1087. EditListBoxSV.ScrollToVerticalOffset(currentOffset - 20);
  1088. }
  1089. // Scroll down
  1090. else if (e.Delta < 0)
  1091. {
  1092. EditListBoxSV.ScrollToVerticalOffset(currentOffset + 20);
  1093. }
  1094. // Mark the event as handled, to prevent it from bubbling
  1095. e.Handled = true;
  1096. }
  1097. private void LeftToolPanelButton_Click(object sender, RoutedEventArgs e)
  1098. {
  1099. }
  1100. private void CancelBtn_Click(object sender, RoutedEventArgs e)
  1101. {
  1102. SavePopGrid.Visibility = Visibility.Collapsed;
  1103. }
  1104. private void ConfirmExitBtn_Click(object sender, RoutedEventArgs e)
  1105. {
  1106. CloseConfirmGrid.Visibility = Visibility.Collapsed;
  1107. CloseLeave();
  1108. }
  1109. private void BrowseFilePathButton_Click(object sender, RoutedEventArgs e)
  1110. {
  1111. CommonOpenFileDialog commonFileDialog = new CommonOpenFileDialog(LanguageHelper.CompressManager.GetString("Main_OpenFolderNoteWarning"));
  1112. commonFileDialog.IsFolderPicker = true;
  1113. if (commonFileDialog.ShowDialog() == CommonFileDialogResult.Ok)
  1114. {
  1115. CmbFilePath.Text = commonFileDialog.FileName;
  1116. }
  1117. }
  1118. private void CancelCloseBtn_Click(object sender, RoutedEventArgs e)
  1119. {
  1120. CloseConfirmGrid.Visibility = Visibility.Collapsed;
  1121. }
  1122. }
  1123. }