12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541 |
- using System.Windows;
- using ComPDFKit.Compare;
- using ComPDFKit.PDFDocument;
- using ComPDFKit.PDFPage;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.Linq;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- using System.Windows.Controls;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.IO;
- using System.Windows.Forms;
- using System.Windows.Interop;
- using System.Runtime.InteropServices;
- using ComPDFKit.Controls.Common;
- using ComPDFKit.Controls.Helper;
- using ComPDFKit.Controls.PDFControl;
- using ComPDFKit.Controls.Properties;
- using Color = System.Windows.Media.Color;
- using ColorConverter = System.Windows.Media.ColorConverter;
- using ComboBox = System.Windows.Forms.ComboBox;
- using Image = System.Windows.Controls.Image;
- namespace ComPDFKit.Controls.Comparison
- {
- /// <summary>
- /// ConvertPage.xaml 的交互逻辑
- /// </summary>
- ///
- public enum CompareType
- {
- ContentCompare = 1,
- OverwriteCompare = 2
- }
- public partial class ComparisonSettingDialog : Window
- {
- [DllImport("gdi32.dll")]
- public static extern bool DeleteObject(IntPtr hObject);
- /// <summary>
- /// 0 Unknow 1 Content Compare 2 Overwrite Compare
- /// </summary>
- private CompareType CompareType { get; set; } = CompareType.ContentCompare;
- public CPDFDocument OldDocument { get; private set; }
- public CPDFDocument NewDocument { get; private set; }
- private List<string> NewFilePathList { get; set; } = new List<string>();
- private List<string> OldFilePathList { get; set; } = new List<string>();
- public Dictionary<string, string> FileAndPassword = new Dictionary<string, string>();
- //private List<int> OldRange { get; set; } = new List<int>();
- //private List<int> NewRange { get; set; } = new List<int>();
- private CPDFCompareType ObjectCompareType { get; set; } = CPDFCompareType.CPDFCompareTypeAll;
- private Color ReplaceColor { get; set; } = Color.FromRgb(255, 214, 102);
- private Color InsertColor { get; set; } = Color.FromRgb(51, 135, 255);
- private Color DeleteColor { get; set; } = Color.FromRgb(255, 51, 51);
- private double OldOpacity { get; set; } = 1;
- private double NewOpacity { get; set; } = 1;
- private Color OldMarkColor { get; set; } = Color.FromRgb(255, 51, 51);
- private Color NewMarkColor { get; set; } = Color.FromRgb(51, 135, 255);
- private CPDFBlendMode MixMode { get; set; } = CPDFBlendMode.CPDFBlendModeDarken;
- private PDFViewControl viewCtrl = null;
- private List<CPDFBlendMode> MixModeList { get; set; } = new List<CPDFBlendMode>()
- {
- CPDFBlendMode.CPDFBlendModeNormal,
- CPDFBlendMode.CPDFBlendModeMultiply,
- CPDFBlendMode.CPDFBlendModeScreen,
- CPDFBlendMode.CPDFBlendModeOverlay,
- CPDFBlendMode.CPDFBlendModeDarken,
- CPDFBlendMode.CPDFBlendModeLighten,
- CPDFBlendMode.CPDFBlendModeColorDodge,
- CPDFBlendMode.CPDFBlendModeColorBurn,
- CPDFBlendMode.CPDFBlendModeHardLight,
- CPDFBlendMode.CPDFBlendModeSoftLight,
- CPDFBlendMode.CPDFBlendModeDifference,
- CPDFBlendMode.CPDFBlendModeExclusion,
- CPDFBlendMode.CPDFBlendModeHue,
- CPDFBlendMode.CPDFBlendModeSaturation,
- CPDFBlendMode.CPDFBlendModeColor,
- CPDFBlendMode.CPDFBlendModeLuminosity
- };
- private bool IsFillWhite { get; set; } = false;
- public event EventHandler<UIElement> OnCompareStatusChanged;
- public ComparisonSettingDialog(PDFViewControl viewCtrl)
- {
- InitializeComponent();
- this.viewCtrl = viewCtrl;
- SwapeImage.IsEnabled = false;
- }
-
- public string ConvertBrushToHex(Color color)
- {
- return $"#{color.A:X2}{color.R:X2}{color.G:X2}{color.B:X2}";
- }
- public static Color ConvertHexToColor(string hex)
- {
- return (Color)ColorConverter.ConvertFromString(hex);
- }
- private int AddNewFileList(string filename, string filepath)
- {
- if (!NewFilePathList.Contains(filepath))
- {
- NewFileComboBox.Items.Insert(0, filename);
- NewFilePathList.Insert(0, filepath);
- NewFileComboBox.IsEnabled = true;
- if (NewFilePathList.Count > 5 && NewFileComboBox.Items.Count > 5)
- {
- NewFilePathList.RemoveAt(NewFilePathList.Count - 1);
- NewFileComboBox.Items.RemoveAt(NewFileComboBox.Items.Count - 1);
- }
- return 0;
- }
- else
- {
- return NewFilePathList.IndexOf(filepath);
- }
- }
- private int AddOldFileList(string filename, string filepath)
- {
- if (!OldFilePathList.Contains(filepath))
- {
- OldFileComboBox.Items.Insert(0, filename);
- OldFilePathList.Insert(0, filepath);
- if (OldFilePathList.Count > 5 && OldFileComboBox.Items.Count > 5)
- {
- OldFilePathList.RemoveAt(OldFilePathList.Count - 1);
- OldFileComboBox.Items.RemoveAt(OldFileComboBox.Items.Count - 1);
- }
- return 0;
- }
- else
- {
- return OldFilePathList.IndexOf(filepath);
- }
- }
- private void CompareType_MouseLeftDown(object sender, MouseButtonEventArgs e)
- {
- }
- public void SetCompareType(CompareType compareType)
- {
- if (compareType == CompareType.ContentCompare)
- {
- CompareTypeTab.SelectedIndex = 0;
- }
- else
- {
- CompareTypeTab.SelectedIndex = 1;
- }
- }
- private void CompareTypeTab_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (CompareTypeTab != null)
- {
- if (CompareTypeTab.SelectedIndex == 0)
- {
- CompareType = CompareType.ContentCompare;
- ContentSettingBox.Visibility = Visibility.Visible;
- OverlaySettingBox.Visibility = Visibility.Collapsed;
- }
- if (CompareTypeTab.SelectedIndex == 1)
- {
- CompareType = CompareType.OverwriteCompare;
- ContentSettingBox.Visibility = Visibility.Collapsed;
- OverlaySettingBox.Visibility = Visibility.Visible;
- }
- }
- }
- private void Close_MouseLeftDown(object sender, MouseButtonEventArgs e)
- {
- //MainWindow parentWnd = Window.GetWindow(this) as MainWindow;
- //if (parentWnd == null)
- //{
- // return;
- //}
- //parentWnd.ContentGrid.Children.Clear();
- //if (parentWnd.PrevElement != null)
- //{
- // parentWnd.ContentGrid.Children.Add(parentWnd.PrevElement);
- //}
- }
- public void UpdateDocCover(bool isOld)
- {
- if (isOld)
- {
- InitOldDocument();
- int select = AddOldFileList(OldDocument.FileName, OldDocument.FilePath);
- OldFileComboBox.SelectedIndex = select;
- }
- else
- {
- InitNewDocument();
- int select = AddNewFileList(NewDocument.FileName, NewDocument.FilePath);
- NewFileComboBox.SelectedIndex = select;
- }
- }
- public void SetDocument(CPDFDocument doc, bool isOld)
- {
- if (isOld)
- {
- OldDocument = doc;
- if (OldRange != null && OldRange.Count > 0)
- {
- List<int> rangeList = new List<int>();
- for (int i = OldRange.Min(); i <= OldRange.Max(); i++)
- {
- if (i >= doc.PageCount)
- {
- break;
- }
- rangeList.Add(i);
- }
- OldRange = rangeList;
- }
- }
- else
- {
- NewDocument = doc;
- if (NewRange != null && NewRange.Count > 0)
- {
- List<int> rangeList = new List<int>();
- for (int i = NewRange.Min(); i <= NewRange.Max(); i++)
- {
- if (i >= doc.PageCount)
- {
- break;
- }
- rangeList.Add(i);
- }
- NewRange = rangeList;
- }
- }
- }
- private void UpdateCover(CPDFDocument doc, Image imageControl, int pageIndex)
- {
- imageControl.Source = null;
- if (doc != null && doc.PageCount > 0 && doc.PageCount > pageIndex)
- {
- CPDFPage pdfPage = doc.PageAtIndex(pageIndex, true);
- int width = (int)pdfPage.PageSize.width;
- int height = (int)pdfPage.PageSize.height;
- Bitmap bitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
- BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, bitmap.PixelFormat);
- pdfPage.RenderPageBitmap(0, 0, width, height, uint.MaxValue, bitmapData.Scan0, 1 , true);
- bitmap.UnlockBits(bitmapData);
- IntPtr bitmapHandle = bitmap.GetHbitmap();
- BitmapSource bitmapSource = Imaging.CreateBitmapSourceFromHBitmap(bitmapHandle, IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
- imageControl.Source = bitmapSource;
- DeleteObject(bitmapHandle);
- }
- }
- private string GetChoosePdf()
- {
- Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog();
- openFileDialog.Filter = "PDF Files(*.pdf;)|*.pdf;";
- if (openFileDialog.ShowDialog() == true)
- {
- return openFileDialog.FileName;
- }
- return string.Empty;
- }
- private void CheckDocPassword(CPDFDocument checkDoc)
- {
- if (checkDoc == null)
- {
- return;
- }
- if (checkDoc.IsLocked)
- {
- checkDoc.UnlockWithPassword(FileAndPassword[checkDoc.FilePath]);
- if (checkDoc.IsLocked)
- {
- PasswordDialog dialog = new PasswordDialog();
- dialog.Confirmed += (sender, s) =>
- {
- if (checkDoc.UnlockWithPassword(s))
- {
- FileAndPassword.Add(checkDoc.FilePath, s);
- }
- };
- }
- }
- }
- private void InitOldDocument()
- {
- TxtOldPage.Text = "1";
- CurrentOldPageIndex = 0;
- TxtOldPageCount.Text = "/" + OldDocument.PageCount;
- OldRange.Clear();
- for (int i = 0; i < OldDocument.PageCount; i++)
- {
- if (i < OldDocument.PageCount)
- {
- OldRange.Add(i);
- }
- }
- CmbOldPageRange.SelectedIndex = "0";
- if (OldFileComboBox.SelectedIndex != OldFilePathList.IndexOf(OldDocument.FilePath))
- {
- OldFileComboBox.SelectedIndex = OldFilePathList.IndexOf(OldDocument.FilePath);
- }
- UpdateCover(OldDocument, OldImageControl, CurrentOldPageIndex);
- CheckOldPageBtnState();
- UpdateOldPageIndex();
- }
- private void InitNewDocument()
- {
- TxtNewPage.Text = "1";
- CurrentNewPageIndex = 0;
- TxtNewPageCount.Text = "/" + NewDocument.PageCount;
- NewRange.Clear();
- for (int i = 0; i < NewDocument.PageCount; i++)
- {
- if (i < NewDocument.PageCount)
- {
- NewRange.Add(i);
- }
- }
- CmbNewPageRange.SelectedIndex = "0";
- if (NewFileComboBox.SelectedIndex != NewFilePathList.IndexOf(NewDocument.FilePath))
- {
- NewFileComboBox.SelectedIndex = NewFilePathList.IndexOf(NewDocument.FilePath);
- }
- UpdateCover(NewDocument, NewImageControl, CurrentNewPageIndex);
- CheckNewPageBtnState();
- UpdateNewPageIndex();
- }
- private void OldFileComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (OldFilePathList != null && OldFilePathList.Count > OldFileComboBox.SelectedIndex && OldFileComboBox.SelectedIndex > -1)
- {
- string pdfFile = OldFilePathList[OldFileComboBox.SelectedIndex];
- if (File.Exists(pdfFile))
- {
- if (NewFilePathList != null && NewFileComboBox.SelectedIndex > -1 && !swapeImage)
- {
- if (pdfFile == NewFilePathList[NewFileComboBox.SelectedIndex])
- {
- OldFileComboBox.SelectedIndex = 0;
- // // MessageBoxEx.Show(App.MainPageLoader.GetString("FileCompare_DifferentFiles"));
- return;
- }
- }
- if (OldDocument != null)
- {
- if (OldDocument.FilePath != pdfFile)
- {
- CPDFDocument oldDocument = CPDFDocument.InitWithFilePath(pdfFile);
- CheckDocPassword(oldDocument);
- if (oldDocument.IsLocked == false)
- {
- OldDocument = oldDocument;
- }
- }
- }
- else
- {
- CPDFDocument oldDocument = CPDFDocument.InitWithFilePath(pdfFile);
- CheckDocPassword(oldDocument);
- if (oldDocument.IsLocked == false)
- {
- NewDocument = oldDocument;
- }
- }
- if (OldDocument != null && OldDocument.IsLocked == false)
- {
- if (OldFilePathList.IndexOf(OldDocument.FilePath) != 0)
- {
- OldFileComboBox.Items.RemoveAt(OldFilePathList.IndexOf(OldDocument.FilePath));
- OldFileComboBox.Items.Insert(0, OldDocument.FileName);
- OldFilePathList.Remove(OldDocument.FilePath);
- OldFilePathList.Insert(0, OldDocument.FilePath);
- OldFileComboBox.SelectedIndex = 0;
- }
- InitOldDocument();
- }
- else
- {
- NewFileComboBox.SelectedIndex = -1;
- }
- }
- else
- {
- OldFilePathList.RemoveAt(OldFileComboBox.SelectedIndex);
- NewFileComboBox.Items.RemoveAt(OldFileComboBox.SelectedIndex);
- if (OldFileComboBox.Items.Count > 0)
- {
- OldFileComboBox.SelectedIndex = 0;
- }
- else
- {
- OldFileComboBox.SelectedIndex = -1;
- }
- // // MessageBoxEx.Show(App.MainPageLoader.GetString("FileCompare_FileRemoved"));
- return;
- }
- }
- }
- private void NewFileComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (NewFilePathList != null && NewFilePathList.Count > NewFileComboBox.SelectedIndex && NewFileComboBox.SelectedIndex > -1)
- {
- string pdfFile = NewFilePathList[NewFileComboBox.SelectedIndex];
- if (File.Exists(pdfFile))
- {
- if (OldFilePathList != null && OldFileComboBox.SelectedIndex > -1 && !swapeImage)
- {
- if (pdfFile == OldFilePathList[OldFileComboBox.SelectedIndex])
- {
- if (ADDFileBorder.Visibility != Visibility.Visible)
- {
- NewFileComboBox.SelectedIndex = 0;
- }
- else
- {
- NewFileComboBox.SelectedIndex = -1;
- }
- // // MessageBoxEx.Show(App.MainPageLoader.GetString("FileCompare_DifferentFiles"));
- return;
- }
- }
- if (NewDocument != null)
- {
- if (NewDocument.FilePath != pdfFile)
- {
- CPDFDocument newDocument = CPDFDocument.InitWithFilePath(pdfFile);
- CheckDocPassword(newDocument);
- if (newDocument.IsLocked == false)
- {
- NewDocument = newDocument;
- }
- }
- }
- else
- {
- CPDFDocument newDocument = CPDFDocument.InitWithFilePath(pdfFile);
- CheckDocPassword(newDocument);
- if (newDocument.IsLocked == false)
- {
- NewDocument = newDocument;
- }
- }
- if (NewDocument != null && NewDocument.IsLocked == false)
- {
- if (ADDFileBorder.Visibility == Visibility.Visible)
- {
- ADDFileBorder.Visibility = Visibility.Collapsed;
- }
- if (NewFilePathList.IndexOf(NewDocument.FilePath) != 0)
- {
- NewFileComboBox.Items.RemoveAt(NewFilePathList.IndexOf(NewDocument.FilePath));
- NewFileComboBox.Items.Insert(0, NewDocument.FileName);
- NewFilePathList.Remove(NewDocument.FilePath);
- NewFilePathList.Insert(0, NewDocument.FilePath);
- NewFileComboBox.SelectedIndex = 0;
- }
- SwapeImage.IsEnabled = true;
- InitNewDocument();
- }
- else
- {
- NewFileComboBox.SelectedIndex = -1;
- }
- }
- else
- {
- NewFilePathList.RemoveAt(NewFileComboBox.SelectedIndex);
- NewFileComboBox.Items.RemoveAt(NewFileComboBox.SelectedIndex);
- if (NewFileComboBox.Items.Count > 0)
- {
- NewFileComboBox.SelectedIndex = 0;
- }
- else
- {
- NewFileComboBox.SelectedIndex = -1;
- }
- // MessageBoxEx.Show(App.MainPageLoader.GetString("FileCompare_FileRemoved"));
- return;
- }
- }
- }
- private void BrowseOldBtn_Click(object sender, RoutedEventArgs e)
- {
- string pdfFile = GetChoosePdf();
- if (File.Exists(pdfFile))
- {
- if (NewFilePathList != null && NewFileComboBox.SelectedIndex > -1)
- {
- if (pdfFile == NewFilePathList[NewFileComboBox.SelectedIndex])
- {
- // MessageBoxEx.Show(App.MainPageLoader.GetString("FileCompare_DifferentFiles"));
- return;
- }
- }
- OldDocument = CPDFDocument.InitWithFilePath(pdfFile);
- CheckDocPassword(OldDocument);
- if (OldDocument != null && OldDocument.IsLocked == false)
- {
- int select = AddOldFileList(OldDocument.FileName, pdfFile);
- OldFileComboBox.SelectedIndex = select;
- InitOldDocument();
- }
- }
- }
- private void BrowseNewBtn_Click(object sender, RoutedEventArgs e)
- {
- string pdfFile = GetChoosePdf();
- if (File.Exists(pdfFile))
- {
- if (OldFilePathList != null && OldFileComboBox.SelectedIndex > -1)
- {
- if (pdfFile == OldFilePathList[OldFileComboBox.SelectedIndex])
- {
- // MessageBoxEx.Show(App.MainPageLoader.GetString("FileCompare_DifferentFiles"));
- return;
- }
- }
- NewDocument = CPDFDocument.InitWithFilePath(pdfFile);
- CheckDocPassword(NewDocument);
- if (NewDocument != null && NewDocument.IsLocked == false)
- {
- int select = AddNewFileList(NewDocument.FileName, pdfFile);
- NewFileComboBox.SelectedIndex = select;
- InitNewDocument();
- }
- }
- }
- public bool swapeImage = false;
- private void SwapeImage_MouseLeftDown(object sender, RoutedEventArgs e)
- {
- try
- {
- if (NewDocument != null && OldDocument != null)
- {
- swapeImage = true;
- UpdateCover(NewDocument, OldImageControl, CurrentOldPageIndex);
- UpdateCover(OldDocument, NewImageControl, CurrentNewPageIndex);
- CPDFDocument tempDoc = NewDocument;
- NewDocument = OldDocument;
- OldDocument = tempDoc;
- int oldselect = AddOldFileList(OldDocument.FileName, OldDocument.FilePath);
- OldFileComboBox.SelectedIndex = oldselect;
- int newselect = AddNewFileList(NewDocument.FileName, NewDocument.FilePath);
- NewFileComboBox.SelectedIndex = newselect;
- InitOldDocument();
- InitNewDocument();
- swapeImage = false;
- }
- else
- {
- swapeImage = false;
- // MessageBoxEx.Show(App.MainPageLoader.GetString("Main_NoSelectedFilesWarning"));
- }
- }
- catch
- {
- swapeImage = false;
- }
- }
- private void SavePageRanges(System.Windows.Controls.TextBox textBox, CPDFDocument doc, List<int> rangeList)
- {
- rangeList.Clear();
- if (textBox.Text != string.Empty && doc != null)
- {
- string[] checkTextArray = textBox.Text.Split(',');
- foreach (string checkText in checkTextArray)
- {
- if (Regex.IsMatch(checkText, "[0-9]+") && Regex.IsMatch(checkText, "[^0-9]") == false)
- {
- int range = int.Parse(checkText) - 1;
- if (range < 0)
- {
- continue;
- }
- if (rangeList.Contains(range) == false)
- {
- rangeList.Add(range);
- }
- continue;
- }
- if (Regex.IsMatch(checkText, "[1-9]+[0-9]*(-)[0-9]+") && Regex.IsMatch(checkText, "[^0-9\\-]") == false)
- {
- if (Regex.Matches(checkText, "[-]+").Count == 1)
- {
- string[] pagesArray = checkText.Split('-');
- int rangeLeft = int.Parse(pagesArray[0]);
- int rangeRight = int.Parse(pagesArray[1]);
- for (int i = Math.Min(rangeLeft, rangeRight) - 1; i < Math.Max(rangeLeft, rangeRight); i++)
- {
- if (i >= doc.PageCount)
- {
- break;
- }
- if (rangeList.Contains(i) == false)
- {
- rangeList.Add(i);
- }
- }
- }
- }
- }
- }
- }
- private void SetCoverGrid()
- {
- ReplaceColorRect.Fill = new SolidColorBrush(ReplaceColor);
- InsertColorRect.Fill = new SolidColorBrush(InsertColor);
- DeleteColorRect.Fill = new SolidColorBrush(DeleteColor);
- }
- private void ShowSelectFileBorder(bool isShow)
- {
- SelectFileBorder.Visibility = isShow ? Visibility.Visible : Visibility.Collapsed;
- }
-
- private void SaveCoverGrid()
- {
- if (ReplaceColorRect.Fill != null && ((SolidColorBrush)ReplaceColorRect.Fill).Color != ReplaceColor)
- {
- ReplaceColor = ((SolidColorBrush)ReplaceColorRect.Fill).Color;
- }
- if (InsertColorRect.Fill != null && ((SolidColorBrush)InsertColorRect.Fill).Color != InsertColor)
- {
- InsertColor = ((SolidColorBrush)InsertColorRect.Fill).Color;
- }
- if (DeleteColorRect.Fill != null && ((SolidColorBrush)DeleteColorRect.Fill).Color != DeleteColor)
- {
- DeleteColor = ((SolidColorBrush)DeleteColorRect.Fill).Color;
- }
- }
-
- private void CompareDocBtn_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- if(OldFileComboBox.Text == "" || NewFileComboBox.Text == "")
- {
- ShowSelectFileBorder(true);
- return;
- }
- if (NewDocument != null && OldDocument != null && NewDocument.IsLocked == false && OldDocument.IsLocked == false && viewCtrl != null)
- {
- if (Math.Min(OldRange.Count, NewRange.Count) == 0 || (CmbOldPageRange.SelectedIndex == "3" && CmbOldPageRange.Text == "") || (CmbNewPageRange.SelectedIndex == "3" && CmbNewPageRange.Text == ""))
- {
- PageRangeBorder.Visibility = Visibility.Visible;
- return;
- }
- this.Close();
- if (CompareType == CompareType.ContentCompare)
- {
- ObjectCompareType = CPDFCompareType.CPDFCompareTypeAll;
- if (TextCheckBox.IsChecked == true && ImageCheckBox.IsChecked == true)
- {
- ObjectCompareType = CPDFCompareType.CPDFCompareTypeAll;
- }
- else
- {
- if (TextCheckBox.IsChecked == true)
- {
- ObjectCompareType = CPDFCompareType.CPDFCompareTypeText;
- }
- if (ImageCheckBox.IsChecked == true)
- {
- ObjectCompareType = CPDFCompareType.CPDFCompareTypeImage;
- }
- }
- Task.Factory.StartNew(() =>
- {
- CPDFCompareContent CPdfContent = new CPDFCompareContent(OldDocument, NewDocument);
- CPdfContent.SetInsertColor(new byte[] { InsertColor.R, InsertColor.G, InsertColor.B });
- CPdfContent.SetReplaceColor(new byte[] { ReplaceColor.R, ReplaceColor.G, ReplaceColor.B });
- CPdfContent.SetDeleteColor(new byte[] { DeleteColor.R, DeleteColor.G, DeleteColor.B });
- CPdfContent.SetReplaceTransparency(ReplaceColor.A);
- CPdfContent.SetDeleteTransparency(DeleteColor.A);
- CPdfContent.SetInsertTransparency(InsertColor.A);
- List<CPDFCompareResults> resultList = new List<CPDFCompareResults>();
- int minLength = Math.Min(OldRange.Count, NewRange.Count);
- List<int> oldTemp = new List<int>(OldRange);
- List<int> newTemp = new List<int>(NewRange);
- if (minLength == 0)
- {
- int maxCount = Math.Max(OldDocument.PageCount, NewDocument.PageCount);
- for (int i = 0; i < maxCount; i++)
- {
- if (i < OldDocument.PageCount)
- {
- oldTemp.Add(i);
- }
- if (i >= OldDocument.PageCount)
- {
- oldTemp.Add(OldDocument.PageCount);
- }
- if (i < NewDocument.PageCount)
- {
- newTemp.Add(i);
- }
- if (i >= NewDocument.PageCount)
- {
- newTemp.Add(OldDocument.PageCount);
- }
- }
- minLength = oldTemp.Count;
- }
- else
- {
- if (oldTemp.Count != newTemp.Count)
- {
- if (oldTemp.Count < newTemp.Count)
- {
- for (int i = oldTemp.Count; i < newTemp.Count; i++)
- {
- oldTemp.Add(OldDocument.PageCount);
- }
- }
- if (oldTemp.Count > newTemp.Count)
- {
- for (int i = newTemp.Count; i < oldTemp.Count; i++)
- {
- newTemp.Add(NewDocument.PageCount);
- }
- }
- minLength = oldTemp.Count;
- }
- }
- for (int i = 0; i < minLength; i++)
- {
- CPDFCompareResults result = CPdfContent.Compare(oldTemp[i], newTemp[i], ObjectCompareType, true);
- if (result != null && (result.TextResults.Count > 0 || result.ImageResults.Count > 0))
- {
- // if (viewCtrl.ParentPage.loadingConceal.Visibility == Visibility.Collapsed)
- // {
- // return;
- // }
- resultList.Add(result);
- // Dispatcher.Invoke(() =>
- // {
- // if (minLength != 0)
- // {
- // viewCtrl.ParentPage.loadingConcealBar.Value = (0.3 + ((double)i / (double)minLength) / (double)2);
- // }
- // });
- }
- }
- string tempPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), Guid.NewGuid().ToString() + ".pdf");
- CPdfContent.SaveAsComparisonDocument(tempPath);
- CPDFDocument combineDoc = CPDFDocument.InitWithFilePath(tempPath);
- Dispatcher.Invoke(() =>
- {
- if (viewCtrl != null)
- {
- FileCompareGrid.Visibility = Visibility.Collapsed;
- CompareContentResultControl resultPage = new CompareContentResultControl();
- resultPage.SetCompareColor(new SolidColorBrush(DeleteColor), new SolidColorBrush(ReplaceColor), new SolidColorBrush(InsertColor));
- resultPage.SetCompareName(OldDocument.FileName, NewDocument.FileName);
- resultPage.pdfViewerCtrl = viewCtrl;
- resultPage.LoadComparePdf(combineDoc, OldDocument, NewDocument);
- resultPage.SetCompareResult(resultList);
- resultPage.ExitCompareEvent += (s, r) =>
- {
- OnCompareStatusChanged?.Invoke(this, null);
- };
- OnCompareStatusChanged?.Invoke(this, resultPage);
- }
- });
- });
- }
- if (CompareType == CompareType.OverwriteCompare)
- {
- List<int> oldTemp = new List<int>(OldRange);
- List<int> newTemp = new List<int>(NewRange);
- string oldRnage = "";
- string newRnage = "";
- foreach (var odlrange in oldTemp)
- {
- if (oldRnage != "")
- {
- oldRnage += ",";
- }
- oldRnage += (odlrange + 1);
- }
- foreach (var newrange in newTemp)
- {
- if (newRnage != "")
- {
- newRnage += ",";
- }
- newRnage += (newrange + 1);
- }
- Task.Factory.StartNew(() =>
- {
- CPDFCompareOverlay CPdfOverlay = null;
- if (string.IsNullOrEmpty(oldRnage) || string.IsNullOrEmpty(newRnage))
- {
- CPdfOverlay = new CPDFCompareOverlay(OldDocument, NewDocument);
- }
- else
- {
- CPdfOverlay = new CPDFCompareOverlay(OldDocument, oldRnage, NewDocument, newRnage);
- }
- CPdfOverlay?.SetBlendMode(MixMode);
- CPdfOverlay?.SetNoFill(IsFillWhite);
- CPdfOverlay?.SetNewDocumentStrokeAlpha((float)NewOpacity);
- CPdfOverlay?.SetOldDocumentStrokeAlpha((float)OldOpacity);
- CPdfOverlay?.SetNewDocumentFillAlpha((float)NewOpacity);
- CPdfOverlay?.SetOldDocumentFillAlpha((float)OldOpacity);
- CPdfOverlay?.SetNewDocumentStrokeColor(new byte[] { NewMarkColor.R, NewMarkColor.G, NewMarkColor.B });
- CPdfOverlay?.SetOldDocumentStrokeColor(new byte[] { OldMarkColor.R, OldMarkColor.G, OldMarkColor.B });
- CPdfOverlay?.Compare();
- CPDFDocument resultDoc = CPdfOverlay?.ComparisonDocument();
- Dispatcher.Invoke(() =>
- {
- if (viewCtrl != null)
- {
- // if (viewCtrl.ParentPage.loadingConceal.Visibility == Visibility.Collapsed)
- // {
- // return;
- // }
- // viewCtrl.ParentPage.loadingConcealBar.Value = 0.6;
- FileCompareGrid.Visibility = Visibility.Collapsed;
- CompareOverwriteResultControl resultPage = new CompareOverwriteResultControl();
- resultPage.SetCompareColor(new SolidColorBrush(NewMarkColor), new SolidColorBrush(OldMarkColor));
- resultPage.pdfViewerCtrl = viewCtrl;
- // resultPage.pdfViewerCtrl.ParentPage.SetCompareModel(false);
- // viewCtrl.ParentPage.loadingConcealClose.Visibility = Visibility.Visible;
- // viewCtrl.ParentPage.loadingConceal.Visibility = Visibility.Collapsed;
- resultPage.LoadComparePdf(resultDoc);
- resultPage.LeftDoc = OldDocument;
- resultPage.RightDoc = NewDocument;
- resultPage.ExitCompareEvent += (s, r) =>
- {
- OnCompareStatusChanged?.Invoke(this, null);
- };
- OnCompareStatusChanged?.Invoke(this, resultPage);
- }
- });
- });
- }
- }
- else
- {
- // MessageBoxEx.Show(App.MainPageLoader.GetString("FileCompare_PleaseSelect"));
- }
- }
- catch
- {
- return;
- }
- }
- private void TextBox_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
- {
- List<Key> allowKeyStroke = new List<Key>()
- {
- Key.D0, Key.D1, Key.D2, Key.D3, Key.D4, Key.D5,
- Key.D6,Key.D7,Key.D8,Key.D9,Key.NumPad0,Key.NumPad1,
- Key.NumPad2,Key.NumPad3,Key.NumPad4,Key.NumPad5,
- Key.NumPad6,Key.NumPad7,Key.NumPad8,Key.NumPad9,
- Key.Delete,Key.Back
- };
- if (allowKeyStroke.Contains(e.Key) == false)
- {
- e.Handled = true;
- }
- }
- private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
- {
- e.CanExecute = false;
- e.Handled = true;
- }
- private void PageRangeCheck_LostFocus(object sender, RoutedEventArgs e)
- {
- System.Windows.Controls.TextBox textBox = sender as System.Windows.Controls.TextBox;
- if (textBox != null && string.IsNullOrEmpty(textBox.Text) == false)
- {
- bool isMatch = true;
- string[] checkTextArray = textBox.Text.Split(',');
- foreach (string checkText in checkTextArray)
- {
- if (Regex.IsMatch(checkText, "[0-9]+") && Regex.IsMatch(checkText, "[^0-9]") == false)
- {
- continue;
- }
- if (Regex.IsMatch(checkText, "[1-9]+[0-9]*(-)[0-9]+") && Regex.IsMatch(checkText, "[^0-9\\-]") == false)
- {
- if (Regex.Matches(checkText, "[-]+").Count == 1)
- {
- continue;
- }
- }
- isMatch = false;
- }
- if (isMatch == false)
- {
- textBox.Text = string.Empty;
- }
- }
- }
- int CurrentOldPageIndex = 0;
- private List<int> OldRange = new List<int>();
- private void UpdateOldPageIndex()
- {
- TxtOldPage.Text = (CurrentOldPageIndex + 1).ToString();
- TxtOldPageCount.Text = "/" + OldRange.Count;
- }
- private void CheckOldPageBtnState()
- {
- if (CurrentOldPageIndex + 1 >= OldRange.Count)
- {
- BtnOldNext.IsEnabled = false;
- }
- else
- {
- BtnOldNext.IsEnabled = true;
- }
- if (CurrentOldPageIndex + 1 <= 1)
- {
- BtnOldPre.IsEnabled = false;
- }
- else
- {
- BtnOldPre.IsEnabled = true;
- }
- }
- private void btnOldPre_Click(object sender, RoutedEventArgs e)
- {
- if (OldDocument == null)
- {
- return;
- }
- CurrentOldPageIndex--;
- if (CurrentOldPageIndex < 0 || CurrentOldPageIndex >= OldRange.Count)
- {
- CheckOldPageBtnState();
- TxtOldPage.Focus();
- return;
- }
- UpdateCover(OldDocument, OldImageControl, OldRange[CurrentOldPageIndex]);
- //RefreshPicture(pageOldIndexLists[CurrentPageIndex]);
- CheckOldPageBtnState();
- UpdateOldPageIndex();
- }
- private void txtOldPage_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
- {
- if (OldDocument == null)
- {
- return;
- }
- if (e == null)
- {
- return;
- }
- //限制文本框输入内容
- List<Key> NumberKeys = new List<Key>() { Key.D0, Key.D1, Key.D2, Key.D3, Key.D4, Key.D5, Key.D6, Key.D7, Key.D8, Key.D9, Key.NumPad0, Key.NumPad1, Key.NumPad2, Key.NumPad3, Key.NumPad4, Key.NumPad5, Key.NumPad6, Key.NumPad7, Key.NumPad8, Key.NumPad9, Key.Delete, Key.Back, Key.Enter, Key.Right, Key.Left };
- if (!NumberKeys.Contains(e.Key))
- {
- e.Handled = true;
- }
- if (e.Key == Key.Enter)
- {
- int value = 0;
- bool result = int.TryParse(TxtOldPage.Text, out value);
- if (!result || value <= 0 || value > OldRange.Count)
- {
- TxtOldPage.Text = "1";
- CurrentOldPageIndex = 0;
- }
- else
- {
- CurrentOldPageIndex = value - 1;
- UpdateCover(OldDocument, OldImageControl, OldRange[CurrentOldPageIndex]);
- }
- CheckOldPageBtnState();
- }
- }
- private void txtOldPage_LostFocus(object sender, RoutedEventArgs e)
- {
- if (OldDocument == null)
- {
- return;
- }
- int value = 0;
- bool result = int.TryParse(TxtOldPage.Text, out value);
- if (!result || value < 0 || value > OldRange.Count)
- {
- TxtOldPage.Text = "1";
- CurrentOldPageIndex = 0;
- }
- else
- {
- CurrentOldPageIndex = value - 1;
- if(CurrentOldPageIndex < 0 || CurrentOldPageIndex >= OldRange.Count)
- {
- CurrentOldPageIndex = 0;
- }
- UpdateCover(OldDocument, OldImageControl, OldRange[CurrentOldPageIndex]);
- }
- CheckOldPageBtnState();
- }
- private void btnOldNext_Click(object sender, RoutedEventArgs e)
- {
- if (OldDocument == null)
- {
- return;
- }
- CurrentOldPageIndex++;
- if (CurrentOldPageIndex < 0 || CurrentOldPageIndex >= OldRange.Count)
- {
- CheckOldPageBtnState();
- TxtOldPage.Focus();
- return;
- }
- UpdateCover(OldDocument, OldImageControl, OldRange[CurrentOldPageIndex]);
- CheckOldPageBtnState();
- UpdateOldPageIndex();
- }
- int CurrentNewPageIndex = 0;
- private List<int> NewRange = new List<int>();
- private void UpdateNewPageIndex()
- {
- TxtNewPage.Text = (CurrentNewPageIndex + 1).ToString();
- TxtNewPageCount.Text = "/" + NewRange.Count;
- }
- private void CheckNewPageBtnState()
- {
- if (CurrentNewPageIndex + 1 >= NewRange.Count)
- {
- BtnNewNext.IsEnabled = false;
- }
- else
- {
- BtnNewNext.IsEnabled = true;
- }
- if (CurrentNewPageIndex + 1 <= 1)
- {
- BtnNewPre.IsEnabled = false;
- }
- else
- {
- BtnNewPre.IsEnabled = true;
- }
- }
- private void btnNewPre_Click(object sender, RoutedEventArgs e)
- {
- if (NewDocument == null)
- {
- return;
- }
- CurrentNewPageIndex--;
- if (CurrentNewPageIndex < 0 || CurrentNewPageIndex >= NewRange.Count)
- {
- CheckNewPageBtnState();
- TxtNewPage.Focus();
- return;
- }
- UpdateCover(NewDocument, NewImageControl, NewRange[CurrentNewPageIndex]);
- CheckNewPageBtnState();
- UpdateNewPageIndex();
- }
- private void txtNewPage_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
- {
- if (NewDocument == null)
- {
- return;
- }
- if (e == null)
- {
- return;
- }
- //限制文本框输入内容
- List<Key> NumberKeys = new List<Key>() { Key.D0, Key.D1, Key.D2, Key.D3, Key.D4, Key.D5, Key.D6, Key.D7, Key.D8, Key.D9, Key.NumPad0, Key.NumPad1, Key.NumPad2, Key.NumPad3, Key.NumPad4, Key.NumPad5, Key.NumPad6, Key.NumPad7, Key.NumPad8, Key.NumPad9, Key.Delete, Key.Back, Key.Enter, Key.Right, Key.Left };
- if (!NumberKeys.Contains(e.Key))
- {
- e.Handled = true;
- }
- if (e.Key == Key.Enter)
- {
- int value = 0;
- bool result = int.TryParse(TxtNewPage.Text, out value);
- if (!result || value <= 0 || value > NewRange.Count)
- {
- TxtNewPage.Text = "1";
- CurrentNewPageIndex = 0;
- }
- else
- {
- CurrentNewPageIndex = value - 1;
- UpdateCover(NewDocument, NewImageControl, NewRange[CurrentNewPageIndex]);
- }
- CheckNewPageBtnState();
- }
- }
- private void txtNewPage_LostFocus(object sender, RoutedEventArgs e)
- {
- if (NewDocument == null)
- {
- return;
- }
- int value = 0;
- bool result = int.TryParse(TxtNewPage.Text, out value);
- if (!result || value < 0 || value > NewRange.Count)
- {
- TxtNewPage.Text = "1";
- CurrentNewPageIndex = 0;
- }
- else
- {
- CurrentNewPageIndex = value - 1;
- UpdateCover(NewDocument, NewImageControl, NewRange[CurrentNewPageIndex]);
- }
- CheckNewPageBtnState();
- }
- private void btnNewNext_Click(object sender, RoutedEventArgs e)
- {
- if (NewDocument == null)
- {
- return;
- }
- CurrentNewPageIndex++;
- if (CurrentNewPageIndex < 0 || CurrentNewPageIndex >= NewRange.Count)
- {
- CheckNewPageBtnState();
- TxtNewPage.Focus();
- return;
- }
- UpdateCover(NewDocument, NewImageControl, NewRange[CurrentNewPageIndex]);
- CheckNewPageBtnState();
- UpdateNewPageIndex();
- }
- private void CmbOldPageRange_SelectionChanged(object sender, RoutedEventArgs e)
- {
- if (OldDocument != null)
- {
- switch (int.Parse(CmbOldPageRange.SelectedIndex))
- {
- case 0:
- OldRange.Clear();
- for (int i = 0; i < OldDocument.PageCount; i++)
- {
- if (i < OldDocument.PageCount)
- {
- OldRange.Add(i);
- }
- }
- break;
- case 1:
- var numType1 = int.Parse(CmbOldPageRange.SelectedIndex) == 1 ? 1 : 0;
- int[] page1 = new int[(OldDocument.PageCount + numType1) / 2];
- for (int i = 0; i < page1.Length; i++)
- {
- page1[i] = i * 2 + 1 - numType1;
- }
- OldRange = page1.ToList();
- break;
- case 2:
- var numType2 = int.Parse(CmbOldPageRange.SelectedIndex) == 1 ? 1 : 0;
- int[] page2 = new int[(OldDocument.PageCount + numType2) / 2];
- for (int i = 0; i < page2.Length; i++)
- {
- page2[i] = i * 2 + 1 - numType2;
- }
- OldRange = page2.ToList();
- break;
- case 3:
- CmbOldPageRange.MaxPageRange = OldRange.Count;
- if (CmbOldPageRange.PageIndexList != null && CmbOldPageRange.PageIndexList.Count > 0)
- {
- OldRange = CmbOldPageRange.PageIndexList;
- }
- break;
- }
- if (CurrentOldPageIndex > OldRange.Count)
- {
- CurrentOldPageIndex = OldRange.Count - 1;
- }
- if (OldRange.Count != 0)
- {
- UpdateCover(OldDocument, OldImageControl, OldRange[CurrentOldPageIndex]);
- CheckOldPageBtnState();
- UpdateOldPageIndex();
- }
- else
- {
- CmbOldPageRange.SelectedIndex = "0";
- }
- }
- }
- private void CmbOldPageRange_TextChanged(object sender, RoutedEventArgs e)
- {
- if (OldDocument != null)
- {
- List<int> TargetPages = new List<int>();
- if (CommonHelper.GetPagesInRange(ref TargetPages, CmbOldPageRange.Text, OldDocument.PageCount, new char[] { ',' }, new char[] { '-' }))
- {
- OldRange = TargetPages;
- if (CurrentOldPageIndex > OldRange.Count)
- {
- CurrentOldPageIndex = OldRange.Count - 1;
- }
- UpdateCover(OldDocument, OldImageControl, OldRange[CurrentOldPageIndex]);
- CheckOldPageBtnState();
- UpdateOldPageIndex();
- }
- }
- }
- private void CmbNewPageRange_SelectionChanged(object sender, RoutedEventArgs e)
- {
- if (NewDocument != null)
- {
- switch (int.Parse(CmbNewPageRange.SelectedIndex))
- {
- case 0:
- NewRange.Clear();
- for (int i = 0; i < NewDocument.PageCount; i++)
- {
- if (i < NewDocument.PageCount)
- {
- NewRange.Add(i);
- }
- }
- break;
- case 1:
- var numType1 = int.Parse(CmbNewPageRange.SelectedIndex) == 1 ? 1 : 0;
- int[] page1 = new int[(NewDocument.PageCount + numType1) / 2];
- for (int i = 0; i < page1.Length; i++)
- {
- page1[i] = i * 2 + 1 - numType1;
- }
- NewRange = page1.ToList();
- break;
- case 2:
- var numType2 = int.Parse(CmbNewPageRange.SelectedIndex) == 1 ? 1 : 0;
- int[] page2 = new int[(NewDocument.PageCount + numType2) / 2];
- for (int i = 0; i < page2.Length; i++)
- {
- page2[i] = i * 2 + 1 - numType2;
- }
- NewRange = page2.ToList();
- break;
- case 3:
- CmbNewPageRange.MaxPageRange = NewRange.Count;
- if (CmbNewPageRange.PageIndexList != null && CmbNewPageRange.PageIndexList.Count > 0)
- {
- NewRange = CmbNewPageRange.PageIndexList;
- }
- break;
- }
- if (CurrentNewPageIndex > NewRange.Count)
- {
- CurrentNewPageIndex = NewRange.Count - 1;
- }
- if (NewRange.Count != 0)
- {
- UpdateCover(NewDocument, NewImageControl, NewRange[CurrentNewPageIndex]);
- CheckNewPageBtnState();
- UpdateNewPageIndex();
- }
- else
- {
- CmbNewPageRange.SelectedIndex = "0";
- }
- }
- }
- private void CmbNewPageRange_TextChanged(object sender, RoutedEventArgs e)
- {
- if (NewDocument != null)
- {
- List<int> TargetPages = new List<int>();
- if (CommonHelper.GetPagesInRange(ref TargetPages, CmbNewPageRange.Text, NewDocument.PageCount, new char[] { ',' }, new char[] { '-' }))
- {
- NewRange = TargetPages;
- if (CurrentNewPageIndex > NewRange.Count)
- {
- CurrentNewPageIndex = NewRange.Count - 1;
- }
- UpdateCover(NewDocument, NewImageControl, NewRange[CurrentNewPageIndex]);
- CheckNewPageBtnState();
- UpdateNewPageIndex();
- }
- }
- }
- public System.Drawing.Color mediaColorToDrawing(System.Windows.Media.Color mediaColor)
- {
- return System.Drawing.Color.FromArgb(mediaColor.A, mediaColor.R, mediaColor.G, mediaColor.B);
- }
- public System.Windows.Media.Color drawingColorToMedia(System.Drawing.Color drawColor)
- {
- return System.Windows.Media.Color.FromArgb(drawColor.A, drawColor.R, drawColor.G, drawColor.B);
- }
- private void ReplaceColorRect_Click(object sender, MouseButtonEventArgs e)
- {
- ColorDialog colorDialog = new ColorDialog();
- colorDialog.AllowFullOpen = true;
- colorDialog.FullOpen = true;
- if (colorDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- ReplaceColor = drawingColorToMedia(colorDialog.Color);
- ReplaceColorRect.Fill = new SolidColorBrush(ReplaceColor);
- }
- }
- private void InsertColorRect_Click(object sender, MouseButtonEventArgs e)
- {
- ColorDialog colorDialog = new ColorDialog();
- colorDialog.AllowFullOpen = true;
- colorDialog.FullOpen = true;
- if (colorDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- InsertColor = drawingColorToMedia(colorDialog.Color);
- InsertColorRect.Fill = new SolidColorBrush(InsertColor);
- }
- }
- private void DeleteColorRect_Click(object sender, MouseButtonEventArgs e)
- {
- ColorDialog colorDialog = new ColorDialog();
- colorDialog.AllowFullOpen = true;
- colorDialog.FullOpen = true;
- if (colorDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- DeleteColor = drawingColorToMedia(colorDialog.Color);
- DeleteColorRect.Fill = new SolidColorBrush(DeleteColor);
- }
- }
- private void OldMarkColorRect_Click(object sender, MouseButtonEventArgs e)
- {
- ColorDialog colorDialog = new ColorDialog();
- colorDialog.AllowFullOpen = true;
- colorDialog.FullOpen = true;
- if (colorDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- OldMarkColor = drawingColorToMedia(colorDialog.Color);
- OldColorRect.Fill = new SolidColorBrush(OldMarkColor);
- }
- }
- private void NewMarkColorRect_Click(object sender, MouseButtonEventArgs e)
- {
- ColorDialog colorDialog = new ColorDialog();
- colorDialog.AllowFullOpen = true;
- colorDialog.FullOpen = true;
- if (colorDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- NewMarkColor = drawingColorToMedia(colorDialog.Color);
- NewColorRect.Fill = new SolidColorBrush(NewMarkColor);
- }
- }
- private void CancleBtn_Click(object sender, RoutedEventArgs e)
- {
- this.Close();
- }
- private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- string pdfFile = GetChoosePdf();
- if (File.Exists(pdfFile))
- {
- if (OldFilePathList != null && OldFileComboBox.SelectedIndex > -1)
- {
- if (pdfFile == OldFilePathList[OldFileComboBox.SelectedIndex])
- {
- // MessageBoxEx.Show(App.MainPageLoader.GetString("FileCompare_DifferentFiles"));
- return;
- }
- }
- NewDocument = CPDFDocument.InitWithFilePath(pdfFile);
- CheckDocPassword(NewDocument);
- if (NewDocument != null && NewDocument.IsLocked == false)
- {
- int select = AddNewFileList(NewDocument.FileName, pdfFile);
- NewFileComboBox.SelectedIndex = select;
- InitNewDocument();
- }
- }
- }
- private void ADDFileBorder_DragOver(object sender, System.Windows.DragEventArgs e)
- {
- e.Effects = e.Data.GetDataPresent(System.Windows.DataFormats.FileDrop) ? System.Windows.DragDropEffects.Copy : System.Windows.DragDropEffects.None;
- e.Handled = true;
- }
- private void ADDFileBorder_Drop(object sender, System.Windows.DragEventArgs e)
- {
- // 检查拖拽的文件类型
- if (e.Data.GetDataPresent(System.Windows.DataFormats.FileDrop))
- {
- var files = (string[])e.Data.GetData(System.Windows.DataFormats.FileDrop);
- var pdfFiles = files.Where(f => f.EndsWith(".pdf", StringComparison.OrdinalIgnoreCase)).ToArray();
- if (pdfFiles.Length > 0)
- {
- if (File.Exists(pdfFiles[0]))
- {
- if (OldFilePathList != null && OldFileComboBox.SelectedIndex > -1)
- {
- if (pdfFiles[0] == OldFilePathList[OldFileComboBox.SelectedIndex])
- {
- // MessageBoxEx.Show(App.MainPageLoader.GetString("FileCompare_DifferentFiles"));
- return;
- }
- }
- NewDocument = CPDFDocument.InitWithFilePath(pdfFiles[0]);
- CheckDocPassword(NewDocument);
- if (NewDocument != null && NewDocument.IsLocked == false)
- {
- int select = AddNewFileList(NewDocument.FileName, pdfFiles[0]);
- NewFileComboBox.SelectedIndex = select;
- InitNewDocument();
- }
- }
- }
- else
- {
- }
- }
- }
- private void SelectFileCancel_OnClick(object sender, RoutedEventArgs e)
- {
- ShowSelectFileBorder(false);
- }
- private void PageRangeCancel_OnClick(object sender, RoutedEventArgs e)
- {
- PageRangeBorder.Visibility = Visibility.Collapsed;
- }
- private void Selector_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (sender is ComboBox cmb)
- {
- if(cmb.SelectedIndex < 0 || cmb.SelectedIndex > 16)
- {
- return;
- }
- MixMode = (CPDFBlendMode)cmb.SelectedIndex;
- }
- }
- private void OldOpacityControl_OnTextInput(object sender, string e)
- {
- if (float.TryParse(e, out float oldOpacity))
- {
- OldOpacity = oldOpacity / 100.0;
- }
- }
- private void NewOpacityControl_OnTextInput(object sender, string e)
- {
- if (float.TryParse(e, out float newOpacity))
- {
- NewOpacity = newOpacity / 100.0;
- }
- }
- }
- }
|