Browse Source

页面编辑-修复页面编辑部分bug

ZhouJieSheng 1 year ago
parent
commit
fecaa39e1b

+ 33 - 15
PDF Office/ViewModels/PageEdit/PageEditContentViewModel.cs

@@ -950,6 +950,7 @@ namespace PDF_Office.ViewModels.PageEdit
                     string pageparm = CommonHelper.GetPageParmFromList(selectedPageList);
                     TbPageRange = pageparm;
                 }
+                
             }
 
             //Ctrl+A时让所有item选中
@@ -1876,10 +1877,7 @@ namespace PDF_Office.ViewModels.PageEdit
                     return false;
                 }
                 PageEditItem item = new PageEditItem();
-                if (width > height)
-                {
-                    item.isVertical = false;
-                }
+                item.Size = PDFViewer.Document.GetPageSize(insertIndex);
                 PageEditItems.Insert(insertIndex, item);
                 ReloadAfterOption(true, true, Tuple.Create(insertIndex - 1, insertIndex + 1));
                 return true;
@@ -1904,9 +1902,9 @@ namespace PDF_Office.ViewModels.PageEdit
             item.PageNumber = index + 1;
             var pagesize = PDFViewer.Document.GetPageSize(index);
             item.Size = pagesize;
-            double width =  CommonHelper.GetUnitsFromPageSize(pagesize.Width);
-            double height = CommonHelper.GetUnitsFromPageSize(pagesize.Height);
-            item.PageSize = $"{width.ToString("F0")}mm*{height.ToString("F0")} mm";
+            //double width =  CommonHelper.GetUnitsFromPageSize(pagesize.Width);
+            //double height = CommonHelper.GetUnitsFromPageSize(pagesize.Height);
+            //item.PageSize = $"{width.ToString("F0")}mm*{height.ToString("F0")} mm";
             return item;
         }
 
@@ -1973,8 +1971,8 @@ namespace PDF_Office.ViewModels.PageEdit
                         PDFViewer.Document.ReleasePages(i);
                         items.Add(i, i);
 
+                        PageEditItems[i].Size = PDFViewer.Document.GetPageSize(i);
                         //重新拿图
-                        PageEditItems[i].isVertical = !PageEditItems[i].isVertical;
                         PageEditItems[i].IsGetImage = false;
                     }
                 }
@@ -1989,8 +1987,8 @@ namespace PDF_Office.ViewModels.PageEdit
                     items.Add(pageitems[i], pageitems[i]);
 
                     //重新拿图
-                    PageEditItems[pageitems[i]].isVertical = !PageEditItems[pageitems[i]].isVertical;
                     PageEditItems[pageitems[i]].IsGetImage = false;
+                    PageEditItems[i].Size = PDFViewer.Document.GetPageSize(i);
                 }
             }
 
@@ -2076,9 +2074,10 @@ namespace PDF_Office.ViewModels.PageEdit
                     }
                     break;
                 case 3://横向页面
+                    ListSelectedIndex = -1;
                     for (int i = 0; i < PageEditItems.Count; i++)
                     {
-                        if (PDFViewer.Document.PageAtIndex(i).Rotation % 2 != 0)
+                        if (!PageEditItems[i].isVertical)
                         {
                             pageRange.Add(i + 1);
                         }
@@ -2087,7 +2086,7 @@ namespace PDF_Office.ViewModels.PageEdit
                 case 4://纵向页面
                     for (int i = 0; i < PageEditItems.Count; i++)
                     {
-                        if (PDFViewer.Document.PageAtIndex(i).Rotation % 2 == 0)
+                        if (PageEditItems[i].isVertical)
                         {
                             pageRange.Add(i + 1);
                         }
@@ -2208,12 +2207,27 @@ namespace PDF_Office.ViewModels.PageEdit
                     //宽高为样式中图片控件宽高
                     if (PageEditItems[i].isVertical)
                     {
-                        await PDFViewer.GetThumbnail(i, 208, 294);
+                        //等比例缩放
+                        if (PageEditItems[i].Size.Height > 300)
+                        {
+                            await PDFViewer.GetThumbnail(i, (int)(PageEditItems[i].Size.Width / (PageEditItems[i].Size.Height / 300)), 300);
+                        }
+                        else
+                        {
+                            await PDFViewer.GetThumbnail(i, (int)PageEditItems[i].Size.Width, (int)PageEditItems[i].Size.Height);
+                        }
                     }
                     else
                     {
-                        //获取横图
-                        await PDFViewer.GetThumbnail(i, 294, 208);
+                        if (PageEditItems[i].Size.Width > 300)
+                        {
+                            await PDFViewer.GetThumbnail(i, 300, (int)(PageEditItems[i].Size.Height / (PageEditItems[i].Size.Width / 300)));
+                        }
+                        else
+                        {
+                            //获取横图
+                            await PDFViewer.GetThumbnail(i, (int)PageEditItems[i].Size.Width, (int)PageEditItems[i].Size.Height);
+                        }
                     }
                 }
             }
@@ -2306,7 +2320,7 @@ namespace PDF_Office.ViewModels.PageEdit
                 }
             }
             //通知UI选中Items
-            NotifyUIToRefresh(selectedPages);
+            //NotifyUIToRefresh(selectedPages);
             //刷新页码和图片
             ReloadAfterOption(true,true,new Tuple<int, int>(0,PDFViewer.Document.PageCount));
 
@@ -2417,6 +2431,10 @@ namespace PDF_Office.ViewModels.PageEdit
                 {
                     IsBOTAThumb = Visibility.Visible;
                 }
+                else
+                {
+                    IsBOTAThumb = Visibility.Collapsed;
+                }
 
                 GetSourceItems(isFirstLoad);
 

+ 12 - 5
PDF Office/Views/PageEdit/PageEditContent.xaml

@@ -8,6 +8,7 @@
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
     xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
     xmlns:local="clr-namespace:PDF_Office.Views.PageEdit"
+    xmlns:mainpage="clr-namespace:PDF_Office.Strings.MainPage"
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     xmlns:model="clr-namespace:PDF_Office.Model"
     xmlns:pageedit="clr-namespace:PDF_Office.Model.PageEdit"
@@ -23,7 +24,6 @@
     FocusVisualStyle="{x:Null}"
     IsVisibleChanged="PageEdit_IsVisibleChanged"
     SizeChanged="PageEdit_SizeChanged"
-    xmlns:mainpage="clr-namespace:PDF_Office.Strings.MainPage"
     mc:Ignorable="d">
     <UserControl.Resources>
         <ResourceDictionary>
@@ -42,7 +42,7 @@
                             Width="{Binding ItemSize.Width}"
                             Height="{Binding ItemSize.Height}"
                             Margin="1"
-                            Background="Gray">
+                            Background="Transparent">
                             <Image Source="{Binding Image}" Stretch="Uniform" />
                             <Border
                                 Width="10"
@@ -114,9 +114,11 @@
                 <MenuItem Command="{Binding DeleteCommand}" Header="{x:Static mainpage:MainPage.PageEdit_MenuDelete}" />
                 <MenuItem Command="{Binding RightRotateCommand}" Header="{x:Static mainpage:MainPage.PageEdit_MenuRotateClockwise}" />
                 <MenuItem Command="{Binding LeftRotateCommand}" Header="{x:Static mainpage:MainPage.PageEdit_MenuRotateCounterclockwise}" />
+                <Separator Style="{StaticResource HorizontalSeparatorStyle}" />
                 <MenuItem Command="{Binding CopyCommand}" Header="{x:Static mainpage:MainPage.PageEdit_MenuCopy}" />
                 <MenuItem Command="{Binding CutCommand}" Header="{x:Static mainpage:MainPage.PageEdit_MenuCut}" />
                 <MenuItem Command="{Binding PasteCommand}" Header="{x:Static mainpage:MainPage.PageEdit_MenuPaste}" />
+                <Separator Style="{StaticResource HorizontalSeparatorStyle}" />
                 <MenuItem
                     Command="{Binding ShowPageSizeCommand}"
                     Header="{x:Static mainpage:MainPage.PageEdit_MenuShowPageSize}"
@@ -126,6 +128,7 @@
                     Command="{Binding ShowPageSizeCommand}"
                     Header="隐藏页面大小"
                     Visibility="{Binding HasShowPageSize}" />
+                <Separator Style="{StaticResource HorizontalSeparatorStyle}" />
                 <MenuItem Command="{Binding PrintCommand}" Header="{x:Static mainpage:MainPage.PageEdit_MenuPrint}" />
             </ContextMenu>
 
@@ -146,7 +149,7 @@
         <KeyBinding Command="{Binding RightRotateCommand}" Gesture="Ctrl+R" />
         <KeyBinding Command="{Binding LeftRotateCommand}" Gesture="Ctrl+L" />
         <KeyBinding Command="{Binding DeleteCommand}" Gesture="Delete" />
-        <KeyBinding Command="{Binding ClearSelectedCommand}" Key="Esc"/>
+        <KeyBinding Key="Esc" Command="{Binding ClearSelectedCommand}" />
         <KeyBinding
             Key="Add"
             Command="{Binding ZoomInCommand}"
@@ -155,10 +158,14 @@
             Key="Subtract"
             Command="{Binding ZoomOutCommand}"
             Modifiers="Ctrl" />
-        
+
     </UserControl.InputBindings>
 
-    <Border AllowDrop="True" BorderBrush="#F2F2F2" BorderThickness="0,1,0,0" Drop="Border_Drop">
+    <Border
+        AllowDrop="True"
+        BorderBrush="#F2F2F2"
+        BorderThickness="0,1,0,0"
+        Drop="Border_Drop">
         <Grid
             DragLeave="Grid_DragLeave"
             DragOver="Grid_DragOver"