|
@@ -4,6 +4,7 @@ using ComPDFKit.PDFPage;
|
|
|
using ComPDFKitViewer.PdfViewer;
|
|
|
using PDF_Office.Model;
|
|
|
using PDF_Office.Model.BOTA;
|
|
|
+using Prism.Commands;
|
|
|
using Prism.Mvvm;
|
|
|
using Prism.Regions;
|
|
|
using System;
|
|
@@ -13,6 +14,7 @@ using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Windows;
|
|
|
+using System.Windows.Controls;
|
|
|
using System.Windows.Media;
|
|
|
using System.Windows.Media.Imaging;
|
|
|
|
|
@@ -20,6 +22,10 @@ namespace PDF_Office.ViewModels.BOTA
|
|
|
{
|
|
|
class OutLineControlViewModel : BindableBase, INavigationAware
|
|
|
{
|
|
|
+ //缩略图相关全局变量,减少内存申请次数
|
|
|
+ private WriteableBitmap WirteBitmap;
|
|
|
+ private byte[] bmpData;
|
|
|
+
|
|
|
private CPDFViewer PDFViewer;
|
|
|
|
|
|
public ObservableCollection<OutlineNode> Outlinelist { get; set; }
|
|
@@ -35,9 +41,25 @@ namespace PDF_Office.ViewModels.BOTA
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private bool isOnDrop = false;
|
|
|
+
|
|
|
+ public bool IsOnDrop
|
|
|
+ {
|
|
|
+ get { return isOnDrop; }
|
|
|
+ set { isOnDrop = value; }
|
|
|
+ }
|
|
|
+
|
|
|
+ public DelegateCommand<ObservableCollection<OutlineNode>> CollapseAllCommand { get; set; }
|
|
|
+ public DelegateCommand<ObservableCollection<OutlineNode>> ExpandAllCommand { get; set; }
|
|
|
+ public DelegateCommand DeleteAllCommand { get; set; }
|
|
|
+ public DelegateCommand<OutlineNode> DowngradeCommand { get; set; }
|
|
|
+
|
|
|
public OutLineControlViewModel()
|
|
|
{
|
|
|
Outlinelist = new ObservableCollection<OutlineNode>();
|
|
|
+ DeleteAllCommand = new DelegateCommand(DeleteAll);
|
|
|
+ CollapseAllCommand = new DelegateCommand<ObservableCollection<OutlineNode>>(CollapseAll);
|
|
|
+ ExpandAllCommand = new DelegateCommand<ObservableCollection<OutlineNode>>(ExpandAll);
|
|
|
}
|
|
|
|
|
|
public bool IsNavigationTarget(NavigationContext navigationContext)
|
|
@@ -61,7 +83,7 @@ namespace PDF_Office.ViewModels.BOTA
|
|
|
Outlinelist.Clear();
|
|
|
foreach (CPDFOutline item in datasource)
|
|
|
{
|
|
|
- OutlineNode dto = ConvertCPDFToOutlineNode(item, null,false);
|
|
|
+ OutlineNode dto = ConvertCPDFToOutlineNode(item, null, false);
|
|
|
if (dto != null)
|
|
|
{
|
|
|
Outlinelist.Add(dto);
|
|
@@ -94,6 +116,7 @@ namespace PDF_Office.ViewModels.BOTA
|
|
|
|
|
|
PDFViewer.UndoManager.CanSave = true;
|
|
|
}
|
|
|
+
|
|
|
public bool SetTitle(CPDFOutline cPDFOutline, string Title)
|
|
|
{
|
|
|
if (cPDFOutline == null)
|
|
@@ -103,6 +126,87 @@ namespace PDF_Office.ViewModels.BOTA
|
|
|
return cPDFOutline.SetTitle(Title);
|
|
|
}
|
|
|
|
|
|
+ public void GoToPage(TreeViewItem treeViewItem)
|
|
|
+ {
|
|
|
+ OutlineNode outline = treeViewItem.DataContext as OutlineNode;
|
|
|
+ if (outline == null)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ CPDFAction action = outline.Outline.GetAction();
|
|
|
+ if (action != null && action.ActionType != C_ACTION_TYPE.ACTION_TYPE_UNKNOWN)
|
|
|
+ PDFViewer.ProcessAction(action);
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Size size = PDFViewer.Document.GetPageSize(Convert.ToInt32(outline.PageIndex) - 1);
|
|
|
+ PDFViewer.GoToPage(Convert.ToInt32(outline.PageIndex) - 1, new Point(size.Width - outline.PositionX, size.Height - outline.PositionY));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void CollapseAll(ObservableCollection<OutlineNode> outlineNodes)
|
|
|
+ {
|
|
|
+ foreach (var item in outlineNodes)
|
|
|
+ {
|
|
|
+ item.IsExpanded = false;
|
|
|
+ if (item.Chlidlist.Count > 0)
|
|
|
+ {
|
|
|
+ CollapseAll(item.Chlidlist);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void ExpandAll(ObservableCollection<OutlineNode> outlineNodes)
|
|
|
+ {
|
|
|
+ foreach (var item in outlineNodes)
|
|
|
+ {
|
|
|
+ item.IsExpanded = true;
|
|
|
+ if (item.Chlidlist.Count > 0)
|
|
|
+ {
|
|
|
+ ExpandAll(item.Chlidlist);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void DeleteAll()
|
|
|
+ {
|
|
|
+ foreach (var item in Outlinelist)
|
|
|
+ {
|
|
|
+ item.Outline.RemoveFromParent(this.PDFViewer.Document);
|
|
|
+ }
|
|
|
+ Updata(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void Downgrade(OutlineNode outline)
|
|
|
+ {
|
|
|
+ if (outline != null)
|
|
|
+ {
|
|
|
+ CPDFOutline parent = outline.Outline.GetParent();
|
|
|
+ int index = GetOutlinesIndexFormParent(parent, outline.Outline);
|
|
|
+ CPDFOutline newparent = parent.ChildList[index - 2];
|
|
|
+ int insertindex = newparent.ChildList.Count;
|
|
|
+ newparent.MoveChildAtIndex(PDFViewer.Document, outline.Outline, insertindex);
|
|
|
+ Updata(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void Upgrade(OutlineNode outline)
|
|
|
+ {
|
|
|
+ if (outline != null)
|
|
|
+ {
|
|
|
+ CPDFOutline parent = outline.Outline.GetParent();
|
|
|
+ CPDFOutline newparent = parent.GetParent();
|
|
|
+ int index = GetOutlinesIndexFormParent(parent.GetParent(), parent);
|
|
|
+ newparent.MoveChildAtIndex(PDFViewer.Document, outline.Outline, index);
|
|
|
+ Updata(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void RemoveOutline(OutlineNode outline)
|
|
|
+ {
|
|
|
+ outline.Outline.RemoveFromParent(PDFViewer.Document);
|
|
|
+ Updata(false);
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 插入大纲到目标节点
|
|
|
/// </summary>
|
|
@@ -153,27 +257,42 @@ namespace PDF_Office.ViewModels.BOTA
|
|
|
}
|
|
|
return Tag;
|
|
|
}
|
|
|
- public WriteableBitmap WirteBitmap;
|
|
|
- byte[] bmpData;
|
|
|
- public WriteableBitmap LoadPreview()
|
|
|
- {
|
|
|
- CPDFPage page = PDFViewer.Document.PageAtIndex(1);
|
|
|
- Size size = PDFViewer.Document.GetPageSize(1);
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 获取对应大纲所需的缩略图数据
|
|
|
+ /// </summary>
|
|
|
+ public WriteableBitmap LoadPreview(OutlineNode outlineNode)
|
|
|
+ {
|
|
|
+ CPDFPage page = PDFViewer.Document.PageAtIndex(Convert.ToInt32(outlineNode.PageIndex) - 1);
|
|
|
+ Size size = PDFViewer.Document.GetPageSize(Convert.ToInt32(outlineNode.PageIndex) - 1);
|
|
|
+ Point zoomXY = new Point(outlineNode.PositionX * outlineNode.Zoom, outlineNode.PositionY * outlineNode.Zoom);
|
|
|
+ //数据校验,暂不确定SDK会不会给垃圾值。说是从底层返回的。
|
|
|
+ if (zoomXY.X > size.Width || zoomXY.X < 0)
|
|
|
+ {
|
|
|
+ zoomXY.X = 0;
|
|
|
+ }
|
|
|
+ if (zoomXY.Y > size.Height || zoomXY.Y < 0)
|
|
|
+ {
|
|
|
+ zoomXY.Y = 0;
|
|
|
+ }
|
|
|
+ Size zoomSize = new Size((int)(size.Width * outlineNode.Zoom), (int)(size.Height * outlineNode.Zoom));
|
|
|
+ bmpData = new byte[(int)(zoomSize.Width * zoomSize.Height * 4)];
|
|
|
+ WirteBitmap = new WriteableBitmap((int)zoomSize.Width, (int)zoomSize.Height, 96, 96, PixelFormats.Bgra32, null);
|
|
|
|
|
|
- bmpData = new byte[(int)(size.Width * size.Height * 4)];
|
|
|
- WirteBitmap = new WriteableBitmap((int)size.Width, (int)size.Height, 96, 96, PixelFormats.Bgra32, null);
|
|
|
-
|
|
|
- if (page.IsValid())
|
|
|
+ if (!page.IsValid())
|
|
|
{
|
|
|
- page.RenderPageBitmapWithMatrix((float)0.5, new Rect(0, 0, (int)size.Width, (int)size.Height), 0xFFFFFFFF, bmpData, 1, true);
|
|
|
+ return null;
|
|
|
}
|
|
|
- WirteBitmap.WritePixels(new Int32Rect(0, 0, (int)size.Width, (int)size.Height), bmpData, WirteBitmap.BackBufferStride, 0);
|
|
|
+ page.RenderPageBitmapWithMatrix((float)outlineNode.Zoom, new Rect(zoomXY.X, zoomXY.Y, zoomSize.Width, zoomSize.Height), 0xFFFFFFFF, bmpData, 1, true);
|
|
|
+ WirteBitmap.WritePixels(new Int32Rect(0, 0, (int)zoomSize.Width, (int)zoomSize.Height), bmpData, WirteBitmap.BackBufferStride, 0);
|
|
|
WirteBitmap.Freeze();
|
|
|
return WirteBitmap;
|
|
|
}
|
|
|
|
|
|
- private OutlineNode ConvertCPDFToOutlineNode(CPDFOutline outline, OutlineNode parent,bool IsMoveData)
|
|
|
+ /// <summary>
|
|
|
+ /// 将PDF对象转换为自定义数据类型,并存储
|
|
|
+ /// </summary>
|
|
|
+ private OutlineNode ConvertCPDFToOutlineNode(CPDFOutline outline, OutlineNode parent, bool IsMoveData)
|
|
|
{
|
|
|
OutlineNode node = new OutlineNode();
|
|
|
if (outline != null)
|
|
@@ -181,7 +300,10 @@ namespace PDF_Office.ViewModels.BOTA
|
|
|
node.IsInsertNextLayer = false;
|
|
|
node.IsInsertCurrentLayer = false;
|
|
|
node.IsExpanded = false;
|
|
|
+ node.IsSelected = false;
|
|
|
node.Outline = outline;
|
|
|
+ node.CanUp = outline.Level == 0 ? false : true;
|
|
|
+ node.CanAddParent = outline.Level == 0 ? false : true;
|
|
|
CPDFAction action = outline.GetAction();
|
|
|
if (action != null)
|
|
|
{
|
|
@@ -190,24 +312,44 @@ namespace PDF_Office.ViewModels.BOTA
|
|
|
CPDFDestination cPDFDestination = outline.GetDestination(PDFViewer.Document);
|
|
|
if (cPDFDestination != null)
|
|
|
{
|
|
|
+ //存储大纲相关属性
|
|
|
node.PageIndex = (cPDFDestination.PageIndex + 1).ToString();
|
|
|
+ node.PositionX = cPDFDestination.Position_X;
|
|
|
+ node.PositionY = cPDFDestination.Position_Y;
|
|
|
+ if (cPDFDestination.Zoom <= 0)
|
|
|
+ {
|
|
|
+ node.Zoom = 1;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ node.Zoom = cPDFDestination.Zoom;
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
node.PageIndex = "";
|
|
|
+ node.PositionX = 0;
|
|
|
+ node.PositionY = 0;
|
|
|
+ node.Zoom = 1;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
node.PageIndex = "";
|
|
|
+ node.PositionX = 0;
|
|
|
+ node.PositionY = 0;
|
|
|
+ node.Zoom = 1;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
node.PageIndex = "";
|
|
|
+ node.PositionX = 0;
|
|
|
+ node.PositionY = 0;
|
|
|
+ node.Zoom = 1;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (parent != null)
|
|
|
{
|
|
|
node.Parent = parent;
|
|
@@ -218,6 +360,7 @@ namespace PDF_Office.ViewModels.BOTA
|
|
|
if (oldnode != null)
|
|
|
{
|
|
|
node.IsExpanded = oldnode.IsExpanded;
|
|
|
+ node.IsSelected = oldnode.IsSelected;
|
|
|
}
|
|
|
}
|
|
|
node.Chlidlist = new ObservableCollection<OutlineNode>();
|
|
@@ -228,11 +371,15 @@ namespace PDF_Office.ViewModels.BOTA
|
|
|
node.Chlidlist.Add(ConvertCPDFToOutlineNode(item, node, IsMoveData));
|
|
|
}
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ node.CanDown = false;
|
|
|
+ }
|
|
|
}
|
|
|
return node;
|
|
|
}
|
|
|
|
|
|
- public OutlineNode FindOutlineFromDto(ObservableCollection<OutlineNode> list, CPDFOutline outline,bool IsMoveData)
|
|
|
+ public OutlineNode FindOutlineFromDto(ObservableCollection<OutlineNode> list, CPDFOutline outline, bool IsMoveData)
|
|
|
{
|
|
|
foreach (OutlineNode item in list)
|
|
|
{
|
|
@@ -286,5 +433,23 @@ namespace PDF_Office.ViewModels.BOTA
|
|
|
}
|
|
|
return -1;
|
|
|
}
|
|
|
+ private int GetOutlinesIndexFormParent(CPDFOutline parentoutline, CPDFOutline outline)
|
|
|
+ {
|
|
|
+ if (parentoutline != null)
|
|
|
+ {
|
|
|
+ if (parentoutline.ChildList.Count > 0)
|
|
|
+ {
|
|
|
+ for (int i = 0; i < parentoutline.ChildList.Count; i++)
|
|
|
+ {
|
|
|
+ if (parentoutline.ChildList[i] == outline)
|
|
|
+ {
|
|
|
+ return i + 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return parentoutline.ChildList.Count;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
}
|
|
|
}
|