liyijie 2 éve
szülő
commit
966b36a611

+ 1 - 0
PDF Office/EventAggregators/EditToolsEvent.cs

@@ -62,6 +62,7 @@ namespace PDF_Office.EventAggregators
     public class SetBackgroundEvent : PubSubEvent<BackgroundInfo>
     {
     }
+
     public class SetWatermarkEvent : PubSubEvent<WatermarkInfo>
     {
     }

+ 0 - 32
PDF Office/Helper/EditToolsHelper.cs

@@ -86,38 +86,6 @@ namespace PDF_Office.Helper
             }
         }
 
-        public static void ChooseFile(string filePath, ref WatermarkInfo watermarkInfo, CPDFDocument document) {
-
-            GetBitmapFromDocment(filePath, document);
-            watermarkInfo.ImageArray = BitmapData;
-            watermarkInfo.ImageWidth = Width;
-            watermarkInfo.ImageHeight = Height;
-        }
-
-        public static void ChooseFile(string filePath, ref BackgroundInfo backgroundInfo, CPDFDocument document)
-        {
-
-            GetBitmapFromDocment(filePath, document);
-            backgroundInfo.ImageArray = BitmapData;
-            backgroundInfo.ImageWidth = Width;
-            backgroundInfo.ImageHeight = Height;
-        }
-
-        public static async void GetBitmapFromDocment(string filePath,CPDFDocument document)
-        {
-            CPDFPage page = document.PageAtIndex(0);
-            byte[] bmp_data = new byte[(int)page.PageSize.Width * (int)page.PageSize.Height * 4];
-            await Task.Run(delegate
-            {
-                page.RenderPageBitmap(0, 0, (int)page.PageSize.Width, (int)page.PageSize.Height, 0xffffffff, bmp_data, 1);
-            });
-            BitmapData = bmp_data;
-            Width = (int)page.PageSize.Width;
-            Height = (int)page.PageSize.Height;
-
-        }
-
-
 
         public static string ParseRange(string str)
         {

+ 3 - 3
PDF Office/ViewModels/EditTools/Background/BackgroundTemplateListBaseContentViewModel.cs

@@ -25,11 +25,11 @@ namespace PDF_Office.ViewModels.EditTools.Background
         public EnumColorOrFile CurrentCreateMod;
 
 
-        private string _currentTemplateListName;
+        private string _currentTemplateListModName;
         public string CurrentTemplateListModName
         {
-            get { return _currentTemplateListName; }
-            set { _currentTemplateListName = value; }
+            get { return _currentTemplateListModName; }
+            set { _currentTemplateListModName = value; }
         }
 
         private string backgroundTemplateListRegionName;

+ 31 - 0
PDF Office/ViewModels/EditTools/Watermark/WatermarkContentViewModel.cs

@@ -26,6 +26,9 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
         public string CreateModTextName = "WatermarkCreateTextContent";
         public string CreateModFileName = "WatermarkCreateFileContent";
 
+        public string TemplateListModTextName = "WatermarkTemplateListTextContent";
+        public string TemplateListModFileName = "WatermarkTemplateListFileContent";
+
         public string WatermarkDocumentName = "WatermarkDocumentContent";
 
         private string _watermarkSettingsRegionName;
@@ -69,6 +72,13 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
             set { _currentCreateMod = value; }
         }
 
+        private EnumTextOrFile _currentTemplateListMod;
+        public EnumTextOrFile CurrentTemplateListMod
+        {
+            get { return _currentTemplateListMod; }
+            set { _currentTemplateListMod = value; }
+        }
+
         public DelegateCommand CloseEditToolCommand { get; set; }
 
         public DelegateCommand ConfirmEditToolCommand { get; set; }
@@ -88,6 +98,7 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
 
             eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Subscribe(EnterTemplateListOrCreate);
             eventAggregator.GetEvent<SetCurrentCreateModEvent>().Subscribe(SetCurrentCreateMod);
+            eventAggregator.GetEvent<SetCurrentTemplateListModEvent>().Subscribe(SetCurrentTemplateListMod);
 
         }
         public void CloseEditTool()
@@ -125,10 +136,30 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
             }
         }
 
+        public void SetCurrentTemplateListMod(string currentTemplateListModName)
+        {
+            if (currentTemplateListModName == TemplateListModTextName)
+            {
+                CurrentTemplateListMod = EnumTextOrFile.StatusText;
+            }
+            else if (currentTemplateListModName == TemplateListModFileName)
+            {
+                CurrentTemplateListMod = EnumTextOrFile.StatusFile;
+            }
+        }
+
         public void EnterSelectedContent(string SelectedContentName)
         {
             NavigationParameters param = new NavigationParameters();
             param.Add(ParameterNames.PDFViewer, PDFViewer);
+            if (SelectedContentName == TemplateListName)
+            {
+                param.Add("CurrentCreateModName", CurrentCreateMod);
+            }
+            else if (SelectedContentName == CreateName)
+            {
+                param.Add("CurrentTemplateListModName", CurrentTemplateListMod);
+            }
             watermarkRegion.RequestNavigate(WatermarkSettingsRegionName, SelectedContentName, param);
             WatermarkSettingsVisible = Visibility.Visible;
         }

+ 13 - 0
PDF Office/ViewModels/EditTools/Watermark/WatermarkCreateBaseContentViewModel.cs

@@ -19,6 +19,8 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
 
         private CPDFViewer PDFViewer;
 
+        public EnumTextOrFile CurrentTemplateListMod;
+
         private string watermarkCreateRegionName;
 
         public string WatermarkCreateRegionName
@@ -98,6 +100,17 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
         public void OnNavigatedTo(NavigationContext navigationContext)
         {
             navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
+            navigationContext.Parameters.TryGetValue<EnumTextOrFile>("CurrentTemplateListModName", out CurrentTemplateListMod);
+            if (CurrentTemplateListMod == EnumTextOrFile.StatusText)
+            {
+                CurrentCreateModName = "WatermarkCreateTextContent";
+            }
+            else
+            {
+                CurrentCreateModName = "WatermarkCreateFileContent";
+            }
+            EnterSelectedCreateMod(CurrentCreateModName);
+            eventAggregator.GetEvent<SetCurrentCreateModEvent>().Publish(CurrentCreateModName);
         }
     }
 }

+ 21 - 3
PDF Office/ViewModels/EditTools/Watermark/WatermarkCreateFileContentViewModel.cs

@@ -1,4 +1,6 @@
-using ComPDFKit.PDFWatermark;
+using ComPDFKit.PDFDocument;
+using ComPDFKit.PDFPage;
+using ComPDFKit.PDFWatermark;
 using ComPDFKitViewer.PdfViewer;
 using PDF_Office.CustomControl;
 using PDF_Office.EventAggregators;
@@ -13,8 +15,10 @@ using Prism.Regions;
 using System;
 using System.Collections.Generic;
 using System.Diagnostics;
+using System.Drawing.Imaging;
 using System.IO;
 using System.Linq;
+using System.Threading.Tasks;
 using System.Windows;
 
 namespace PDF_Office.ViewModels.EditTools.Watermark
@@ -119,7 +123,7 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
             set
             {
                 SetProperty(ref _opacityValue, value);
-                WatermarkInfo.Opacity = (byte)((float)(OpacityValue / 100) * 225);
+                WatermarkInfo.Opacity = (byte)(((float)OpacityValue / 100) * 225);
             }
         }
 
@@ -309,7 +313,7 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
                 FileInfo file = new FileInfo(dlg.FileName);
                 if (file.Extension == ".pdf")
                 {
-                    EditToolsHelper.ChooseFile(dlg.FileName, ref WatermarkInfo, PDFViewer.Document);
+                    GetBitmapFromDocment(dlg.FileName, PDFViewer.Document);
                 }
                 else
                 {
@@ -319,6 +323,20 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
             }
         }
 
+        public  async void GetBitmapFromDocment(string filePath, CPDFDocument document)
+        {
+            CPDFPage page = document.PageAtIndex(0);
+            byte[] bmp_data = new byte[(int)page.PageSize.Width * (int)page.PageSize.Height * 4];
+            await Task.Run(delegate
+            {
+                page.RenderPageBitmap(0, 0, (int)page.PageSize.Width, (int)page.PageSize.Height, 0xffffffff, bmp_data, 1);
+            });
+            WatermarkInfo.ImageArray= bmp_data;
+            WatermarkInfo.ImageWidth = (int)page.PageSize.Width;
+            WatermarkInfo.ImageHeight = (int)page.PageSize.Height;
+
+        }
+
         public bool IsNavigationTarget(NavigationContext navigationContext)
         {
             return true;

+ 19 - 1
PDF Office/ViewModels/EditTools/Watermark/WatermarkCreateTextContentViewModel.cs

@@ -1,5 +1,6 @@
 using ComPDFKit.PDFDocument;
 using ComPDFKit.PDFWatermark;
+using ComPDFKitViewer.AnnotEvent;
 using ComPDFKitViewer.PdfViewer;
 using PDF_Office.EventAggregators;
 using PDF_Office.Helper;
@@ -13,6 +14,7 @@ using Prism.Regions;
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Windows.Media;
 
 namespace PDF_Office.ViewModels.EditTools.Watermark
 {
@@ -274,7 +276,7 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
             }
             set
             {
-                SetProperty(ref _stringColor, value);
+                 _stringColor= value;
                 WatermarkInfo.TextColor = EditToolsHelper.ConvertColor(value); 
             }
         }
@@ -301,12 +303,15 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
 
         public DelegateCommand<object> ChangeLocationCommand { get; set; }
 
+        public DelegateCommand<object> SelectedColorChangedCommand { get; set; }
+
         public WatermarkCreateTextContentViewModel(IEventAggregator eventAggregator)
         {
             this.eventAggregator=eventAggregator;
             WatermarkInfo.WatermarkType = C_Watermark_Type.WATERMARK_TYPE_TEXT;
             StringColor = "#FFFF00";
             ChangeLocationCommand = new DelegateCommand<object>(ChangeLocation);
+            SelectedColorChangedCommand = new DelegateCommand<object>(SelectedColorChanged_Click);
             InitList();
             WatermarkInfo.WatermarkHorizalign = C_Watermark_Horizalign.WATERMARK_HORIZALIGN_CENTER;
             WatermarkInfo.WatermarkVertalign = C_Watermark_Vertalign.WATERMARK_VERTALIGN_CENTER;
@@ -341,6 +346,19 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
             }
         }
 
+        private void SelectedColorChanged_Click(object obj)
+        {
+            if (obj != null)
+            {
+                var colorValue = (Color)obj;
+                if (colorValue != null)
+                {
+
+                    StringColor = colorValue.ToString();
+                }
+            }
+        }
+
         private void SetFontName(int Index)
         {
             WatermarkInfo.FontName = FontNameList[Index];

+ 7 - 11
PDF Office/ViewModels/EditTools/Watermark/WatermarkDocumentContentViewModel.cs

@@ -50,7 +50,7 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
         public void SetWatermark(WatermarkInfo watermarkInfo)
         {
             CreateWatermark(watermarkInfo);
-            document.PdfToImage("0-1", "C:\\Users\\kdanmobile\\Desktop");
+            document.PdfToImage("1", "C:\\Users\\kdanmobile\\Desktop");
             document.WriteToFilePath("C:\\Users\\kdanmobile\\Desktop\\sb22222.pdf");
             AwaitRenderBitmap(document);
         }
@@ -65,6 +65,7 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
                 {
                     watermarkInfo.TextSize = "6";
                 }
+                watermark.SetFontName(watermarkInfo.FontName);
                 watermark.SetScale(float.Parse(watermarkInfo.TextSize));
                 watermark.SetTextRGBColor(watermarkInfo.TextColor);
             }
@@ -72,7 +73,7 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
             {
                 watermark = document.InitWatermark(C_Watermark_Type.WATERMARK_TYPE_IMG);
                 watermark.SetImage(watermarkInfo.ImageArray, watermarkInfo.ImageWidth, watermarkInfo.ImageHeight);
-                watermark.SetScale(watermarkInfo.ImageSize % 100);
+                watermark.SetScale(0.1f);
             }
             watermark.SetRotation(watermarkInfo.Rotation);
             watermark.SetOpacity(watermarkInfo.Opacity);
@@ -89,7 +90,7 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
             watermark.UpdateWatermark();
             
         }
-        public static BitmapSource ToBitmapSource(System.Drawing.Bitmap image)
+        public BitmapSource ToBitmapSource(System.Drawing.Bitmap image)
         {
             IntPtr ptr = image.GetHbitmap();//obtain the Hbitmap
             BitmapSource bs = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap
@@ -106,17 +107,12 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
         {
             
             CPDFPage page = doc.PageAtIndex(0,true);
-            
             byte[] bmp_data = new byte[(int)page.PageSize.Width * (int)page.PageSize.Height * 4];
             Bitmap bitmap = await ToolMethod.RenderPageBitmap(document, (int)(page.PageSize.Width * 1 * 1.4), (int)(page.PageSize.Height * 1 * 1.4), 0, true, true);
-            //await Task.Run(delegate
-            //{
-
-            //    page.RenderPageBitmap(0, 0, (int)page.PageSize.Width, (int)page.PageSize.Height, 0xffffffff, bmp_data, 1);
-            //});
-            //PixelFormat fmt = PixelFormats.Bgra32;
-            //BitmapSource bps = BitmapSource.Create((int)page.PageSize.Width, (int)page.PageSize.Height, 96.0, 96.0, fmt, null, bmp_data, ((int)page.PageSize.Width * fmt.BitsPerPixel + 7) / 8);
             ImageSource = ToBitmapSource(bitmap);
+            doc.ReleasePages();
+
+
         }
         public async void AwaitRenderBitmap(CPDFDocument doc)
         {

+ 36 - 6
PDF Office/ViewModels/EditTools/Watermark/WatermarkTemplateListBaseContentViewModel.cs

@@ -15,11 +15,18 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
         public IRegionManager watermarkTemplateListRegion;
         private readonly IEventAggregator eventAggregator;
 
-        private string _currentTemplateListName;
-        public string CurrentTemplateListName
+        private string WatermarkTemplateListTextContentName = "WatermarkTemplateListTextContent";
+        private string WatermarkTemplateListFileContentName = "WatermarkTemplateListFileContent";
+
+        public bool IsFirstEnter=true;
+
+        public EnumTextOrFile CurrentCreateMod;
+
+        private string _currentTemplateListModName;
+        public string CurrentTemplateListModName
         {
-            get { return _currentTemplateListName; }
-            set { _currentTemplateListName = value; }
+            get { return _currentTemplateListModName; }
+            set { _currentTemplateListModName = value; }
         }
 
         private string watermarkTemplateListRegionName;
@@ -67,8 +74,9 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
             var args = e as Button;
             if (args != null)
             {
-                CurrentTemplateListName = args.Name;
-                EnterSelectedTemplateListMod(CurrentTemplateListName);
+                CurrentTemplateListModName = args.Name;
+                EnterSelectedTemplateListMod(CurrentTemplateListModName);
+                eventAggregator.GetEvent<SetCurrentTemplateListModEvent>().Publish(CurrentTemplateListModName);
             }
         }
 
@@ -83,6 +91,28 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
 
         public void OnNavigatedTo(NavigationContext navigationContext)
         {
+
+            if (IsFirstEnter)
+            {
+                CurrentTemplateListModName = WatermarkTemplateListTextContentName;
+                EnterSelectedTemplateListMod(CurrentTemplateListModName);
+                IsFirstEnter = false;
+            }
+            else
+            {
+                navigationContext.Parameters.TryGetValue<EnumTextOrFile>("CurrentCreateModName", out CurrentCreateMod);
+                if (CurrentCreateMod == EnumTextOrFile.StatusText)
+                {
+                    CurrentTemplateListModName = WatermarkTemplateListTextContentName;
+                }
+                else
+                {
+                    CurrentTemplateListModName = WatermarkTemplateListFileContentName;
+                }
+                EnterSelectedTemplateListMod(CurrentTemplateListModName);
+                eventAggregator.GetEvent<SetCurrentTemplateListModEvent>().Publish(CurrentTemplateListModName);
+
+            }
         }
     }
 }

+ 4 - 11
PDF Office/Views/EditTools/Watermark/WatermarkCreateTextContent.xaml

@@ -5,6 +5,7 @@
              prism:ViewModelLocator.AutoWireViewModel="True"
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
              xmlns:cus="clr-namespace:PDF_Office.CustomControl"
+             xmlns:CompositeControl="clr-namespace:PDF_Office.CustomControl.CompositeControl"
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
              mc:Ignorable="d"
              d:DesignHeight="632"
@@ -29,17 +30,9 @@
                         <Button Width="34.67" Height="32"></Button>
                         <Button Width="34.67" Height="32"></Button>
                     </StackPanel>
-                    <Button Height="32" Width="66"  Margin="8,0,0,0">
-                        <Grid Height="32" Width="66" HorizontalAlignment="Center" VerticalAlignment="Center">
-                            <Grid.ColumnDefinitions>
-                                <ColumnDefinition></ColumnDefinition>
-                                <ColumnDefinition></ColumnDefinition>
-                            </Grid.ColumnDefinitions>
-                            <Grid Grid.Column="0" Height="22" Width="22">
-                                <Rectangle Fill="{Binding StringColor, Mode=TwoWay}" RadiusX="20" RadiusY="20"></Rectangle>
-                            </Grid>
-                        </Grid>
-                    </Button>
+                    <CompositeControl:ColorContent x:Name="cusColor" Height="32" Width="66"  Margin="8,0,0,0" >
+                        
+                    </CompositeControl:ColorContent>
                 </StackPanel>
             </StackPanel>
         </Grid>

+ 14 - 1
PDF Office/Views/EditTools/Watermark/WatermarkCreateTextContent.xaml.cs

@@ -1,4 +1,7 @@
-using System.Windows.Controls;
+using PDF_Office.ViewModels.EditTools.Watermark;
+using PDF_Office.ViewModels.PropertyPanel.AnnotPanel;
+using System.Windows.Controls;
+using System.Windows.Media;
 
 namespace PDF_Office.Views.EditTools.Watermark
 {
@@ -10,6 +13,16 @@ namespace PDF_Office.Views.EditTools.Watermark
         public WatermarkCreateTextContent()
         {
             InitializeComponent();
+            cusColor.SelectedColorHandler += cusColor_SelectedColor;
+        }
+
+        private void cusColor_SelectedColor(object sender, Color e)
+        {
+            var data = this.DataContext as WatermarkCreateTextContentViewModel;
+            if (data != null)
+            {
+                data.SelectedColorChangedCommand?.Execute(e);
+            }
         }
     }
 }

+ 1 - 1
PDF Office/Views/EditTools/Watermark/WatermarkDocumentContent.xaml

@@ -11,7 +11,7 @@
     <Grid Height="720" Width="1020" Background="SkyBlue">
         <Border  Margin="0,16,0,0" HorizontalAlignment="Center" VerticalAlignment="Top" Background="#FFFFFF"  Height="679" Width="514">
             <Viewbox>
-                <Image Name="Image"  Source="{Binding ImageSource,Mode=TwoWay}"></Image>
+                <Image Name="Image"  Source="{Binding ImageSource}"></Image>
             </Viewbox>
         </Border>
         <Border  Height="64" Width="293" HorizontalAlignment="Center"  VerticalAlignment="Bottom"  Panel.ZIndex="1" Margin="9" Background="#323232" CornerRadius="4">