|
@@ -6,6 +6,7 @@ using ComPDFKitViewer.PdfViewer;
|
|
|
using PDF_Office.EventAggregators;
|
|
|
using PDF_Office.Helper;
|
|
|
using PDF_Office.Model;
|
|
|
+using Prism.Commands;
|
|
|
using Prism.Events;
|
|
|
using Prism.Mvvm;
|
|
|
using Prism.Regions;
|
|
@@ -47,8 +48,11 @@ namespace PDF_Office.ViewModels.Scan
|
|
|
SetProperty(ref textRectList, value);
|
|
|
}
|
|
|
}
|
|
|
- private bool isEnhanced;
|
|
|
|
|
|
+ private bool isEnhanced;
|
|
|
+ /// <summary>
|
|
|
+ /// 当前是否为增强扫描状态
|
|
|
+ /// </summary>
|
|
|
public bool IsEnhanced
|
|
|
{
|
|
|
get { return isEnhanced; }
|
|
@@ -63,11 +67,25 @@ namespace PDF_Office.ViewModels.Scan
|
|
|
/// 增强扫描结果路径
|
|
|
/// </summary>
|
|
|
public List<string> EnhancedFilePathList;
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// OCR结果路径
|
|
|
/// </summary>
|
|
|
private Dictionary<int, List<KeyValuePair<Rect, string>>> cacahe;
|
|
|
|
|
|
+ private Visibility showTooltip = Visibility.Collapsed;
|
|
|
+
|
|
|
+ public Visibility ShowTooltip
|
|
|
+ {
|
|
|
+ get { return showTooltip; }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ SetProperty(ref showTooltip, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public DelegateCommand CloseTooltipCommand { get; set; }
|
|
|
+ public DelegateCommand CancelEnhancedCommand { get; set; }
|
|
|
|
|
|
public bool IsNavigationTarget(NavigationContext navigationContext)
|
|
|
{
|
|
@@ -143,10 +161,43 @@ namespace PDF_Office.ViewModels.Scan
|
|
|
|
|
|
public ScanViwerViewModel(IEventAggregator eventAggregator)
|
|
|
{
|
|
|
+ CloseTooltipCommand = new DelegateCommand(CloseTooltip);
|
|
|
+ CancelEnhancedCommand = new DelegateCommand(CancelEnhanced);
|
|
|
EnhancedFilePathList = new List<string>();
|
|
|
eventAggregator.GetEvent<ScanEvent>().Subscribe(ChangeScanMode, e => e.Unicode == App.mainWindowViewModel.SelectedItem.Unicode);
|
|
|
cacahe = new Dictionary<int, List<KeyValuePair<Rect, string>>>();
|
|
|
}
|
|
|
+
|
|
|
+ private void CancelEnhanced()
|
|
|
+ {
|
|
|
+ ShowTooltip = Visibility.Collapsed;
|
|
|
+ IsEnhanced = false;
|
|
|
+ CPDFPage pdfPage = PDFViewer.Document.PageAtIndex(PDFViewer.CurrentIndex);
|
|
|
+ float zoom = (float)(DpiHelpers.Dpi / 72D);
|
|
|
+ int renderWidth = (int)(pdfPage.PageSize.Width * zoom);
|
|
|
+ int renderHeight = (int)(pdfPage.PageSize.Height * zoom);
|
|
|
+ byte[] Data = new byte[renderWidth * renderHeight * 4];
|
|
|
+ pdfPage.RenderPageBitmapWithMatrix(zoom, new Rect(0, 0, renderWidth, renderHeight), 0xFFFFFFFF, Data, 0);
|
|
|
+ BgImage = new WriteableBitmap(renderWidth, renderHeight, DpiHelpers.Dpi, DpiHelpers.Dpi, PixelFormats.Bgra32, null);
|
|
|
+ BgImage.WritePixels(new Int32Rect(0, 0, renderWidth, renderHeight), Data, BgImage.BackBufferStride, 0);
|
|
|
+
|
|
|
+ if (cacahe.Count > 0)
|
|
|
+ {
|
|
|
+ if (cacahe.ContainsKey(PDFViewer.CurrentIndex))
|
|
|
+ {
|
|
|
+ TextRectList = cacahe[PDFViewer.CurrentIndex];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ TextRectList = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private void CloseTooltip()
|
|
|
+ {
|
|
|
+ ShowTooltip = Visibility.Collapsed;
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 根据Vm事件通知处理OCR与区域识别或者增强扫描事件
|
|
|
/// </summary>
|
|
@@ -178,6 +229,9 @@ namespace PDF_Office.ViewModels.Scan
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 增强扫描
|
|
|
+ /// </summary>
|
|
|
private void EnhancedProcess(ScanEventArgs args)
|
|
|
{
|
|
|
CPDFDocument CurrentDoc = PDFViewer.Document;
|
|
@@ -232,6 +286,7 @@ namespace PDF_Office.ViewModels.Scan
|
|
|
BgImage = new WriteableBitmap(image);
|
|
|
});
|
|
|
imEngine.Release();
|
|
|
+ ShowTooltip = Visibility.Visible;
|
|
|
});
|
|
|
}
|
|
|
|
|
@@ -244,7 +299,6 @@ namespace PDF_Office.ViewModels.Scan
|
|
|
Task.Run(() =>
|
|
|
{
|
|
|
COCREngine imEngine = new COCREngine(App.modelFolderPath);
|
|
|
- //CIMEngine imEngine = new CIMEngine(App.modelFolderPath);
|
|
|
|
|
|
string path = App.CachePath.MergeFilePath;
|
|
|
string name = Guid.NewGuid().ToString();
|