瀏覽代碼

图章-动态图章

zhuyi 2 年之前
父節點
當前提交
e3423770d8

+ 33 - 0
PDF Office/Model/AnnotPanel/Stamp.cs

@@ -5,6 +5,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using System.Windows.Media.Imaging;
 
 namespace PDF_Office.Model.AnnotPanel
 {
@@ -86,6 +87,38 @@ namespace PDF_Office.Model.AnnotPanel
             }
         }
 
+        private BitmapSource imageSource;
+
+        public BitmapSource ImageSource
+        {
+            get { return imageSource; }
+            set
+            {
+                SetProperty(ref imageSource, value);
+            }
+        }
+
+        private TextStampColor textColor;
+
+        public TextStampColor TextColor
+        {
+            get { return textColor; }
+            set
+            {
+                SetProperty(ref textColor, value);
+            }
+        }
+
+        private string stampTextDate;
+
+        public string StampTextDate
+        {
+            get { return stampTextDate; }
+            set
+            {
+                SetProperty(ref stampTextDate, value);
+            }
+        }
 
     }
 }

+ 133 - 7
PDF Office/ViewModels/PropertyPanel/AnnotPanel/StampAnnotPropertyViewModel.cs

@@ -1,4 +1,5 @@
-using ComPDFKitViewer.AnnotEvent;
+using ComPDFKit.PDFAnnotation;
+using ComPDFKitViewer.AnnotEvent;
 using ComPDFKitViewer.PdfViewer;
 using PDF_Office.Model;
 using PDF_Office.Model.AnnotPanel;
@@ -11,13 +12,14 @@ using System.Collections.ObjectModel;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using System.Windows.Media;
 using System.Windows.Media.Imaging;
 
 namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
 {
     internal class StampAnnotPropertyViewModel : BindableBase, INavigationAware
     {
-        #region 标准图章相关默认配置(如果需要修改,要留意按顺序一一对应的)
+        #region 标准图章相关默认配置(如果需要修改,要留意按顺序一一对应的,如果要支持多语,Path则需要替换成SDK获取图片的方法,并修改对应参数与实现代码)
 
         List<string> Path = new List<string>
         {
@@ -60,6 +62,49 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
 
         #endregion
 
+        #region 动态图章相关配置(需要支持多语则修改DynamicStampText的内容)
+
+        List<string> DynamicStampText = new List<string>
+        {
+            "REVISED","REVIEWED","Completed","RECEIVED","APPROVED","CONFIDENTIAL"
+        };
+        List<C_TEXTSTAMP_COLOR> DynamicColor = new List<C_TEXTSTAMP_COLOR>
+        {
+          C_TEXTSTAMP_COLOR.TEXTSTAMP_RED,  C_TEXTSTAMP_COLOR.TEXTSTAMP_GREEN,
+          C_TEXTSTAMP_COLOR.TEXTSTAMP_GREEN,C_TEXTSTAMP_COLOR.TEXTSTAMP_GREEN,
+          C_TEXTSTAMP_COLOR.TEXTSTAMP_GREEN,C_TEXTSTAMP_COLOR.TEXTSTAMP_RED,
+        };
+
+        #endregion
+
+        private string author = "12312";
+
+        public string Author
+        {
+            get { return author; }
+            set
+            {
+                SetProperty(ref author, value);
+            }
+        }
+
+        private bool isSetAuthor = false;
+
+        public bool IsSetAuthor
+        {
+            get { return isSetAuthor; }
+            set
+            {
+                SetProperty(ref isSetAuthor, value);
+                if (PDFViewer!=null)
+                {
+                    UpDataDynamicStampList();
+                }
+            }
+        }
+
+
+
         private CPDFViewer PDFViewer;
         public ObservableCollection<Stamp> StandardStampList { get; set; }
         public ObservableCollection<Stamp> DynamicStampList { get; set; }
@@ -71,6 +116,7 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             DynamicStampList = new ObservableCollection<Stamp>();
             CustomStampList = new ObservableCollection<Stamp>();
             InitStandardStamp();
+            UpDataDynamicStampList();
         }
 
         /// <summary>
@@ -117,14 +163,94 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             Args.Opacity = stamp.Opacity;
             Args.MaxWidth = stamp.MaxWidth;
             Args.MaxHeight = stamp.MaxHeight;
-            BitmapImage image = new BitmapImage(new Uri(stamp.SourcePath));
-            Args.ImageArray = new byte[image.PixelWidth * image.PixelHeight * 4];
-            image.CopyPixels(Args.ImageArray, image.PixelWidth * 4, 0);
-            Args.ImageHeight = image.PixelHeight;
-            Args.ImageWidth = image.PixelWidth;
+            Args.StampTextDate = stamp.StampTextDate;
+            Args.TextColor = stamp.TextColor;
+            if (!string.IsNullOrEmpty(stamp.SourcePath))
+            {
+                BitmapImage image = new BitmapImage(new Uri(stamp.SourcePath));
+                Args.ImageArray = new byte[image.PixelWidth * image.PixelHeight * 4];
+                image.CopyPixels(Args.ImageArray, image.PixelWidth * 4, 0);
+                Args.ImageHeight = image.PixelHeight;
+                Args.ImageWidth = image.PixelWidth;
+            }
+            else
+            {
+                Args.ImageArray = new byte[stamp.ImageSource.PixelWidth * stamp.ImageSource.PixelHeight * 4];
+                stamp.ImageSource.CopyPixels(Args.ImageArray, stamp.ImageSource.PixelWidth * 4, 0);
+                Args.ImageHeight = stamp.ImageSource.PixelHeight;
+                Args.ImageWidth = stamp.ImageSource.PixelWidth;
+            }
             Args.Type = stamp.Type;
             PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
             PDFViewer.SetToolParam(Args);
         }
+
+        /// <summary>
+        /// 更新动态图章对象相关属性
+        /// </summary>
+        public void UpDataDynamicStampList()
+        {
+            DynamicStampList.Clear();
+            for (int i = 0; i < DynamicStampText.Count; i++)
+            {
+                string date = "";
+                //区分机密(CONFIDENTIAL)和其他动态图章的区别
+                if (i < DynamicStampText.Count - 1)
+                {
+                    date = System.DateTime.Now.ToString("F");
+                }
+
+                Stamp standardStamp = new Stamp();
+                if (IsSetAuthor && !string.IsNullOrEmpty(Author))
+                {
+                    standardStamp.Author = Author;
+                    if (i < DynamicStampText.Count - 1)
+                    {
+                        standardStamp.StampTextDate = "By " + Author + " at " + date;
+                    }
+                    else
+                    {
+                        standardStamp.StampTextDate = Author;
+                    }
+
+                }
+                else
+                {
+                    standardStamp.StampTextDate = date;
+                    standardStamp.Author = "";
+                }
+
+                var bytes = CPDFStampAnnotation.GetTempTextStampImage(DynamicStampText[i], standardStamp.StampTextDate,
+                C_TEXTSTAMP_SHAPE.TEXTSTAMP_RECT, DynamicColor[i], out int stampWidth, out int stampHeight, out int width, out int height);
+                PixelFormat fmt = PixelFormats.Bgra32;
+                BitmapSource bps = BitmapSource.Create(width, height, 96, 96, fmt, null, bytes, (width * fmt.BitsPerPixel + 7) / 8);
+
+
+
+                standardStamp.Opacity = 1;
+                standardStamp.SourcePath = "";
+                standardStamp.StampText = DynamicStampText[i];
+                standardStamp.MaxWidth = stampWidth;
+                standardStamp.MaxHeight = stampHeight;
+                standardStamp.Type = StampType.TEXT_STAMP;
+                standardStamp.ImageSource = bps;
+                switch (DynamicColor[i])
+                {
+                    case C_TEXTSTAMP_COLOR.TEXTSTAMP_WHITE:
+                        break;
+                    case C_TEXTSTAMP_COLOR.TEXTSTAMP_RED:
+                        standardStamp.TextColor = TextStampColor.TEXTSTAMP_RED;
+                        break;
+                    case C_TEXTSTAMP_COLOR.TEXTSTAMP_GREEN:
+                        standardStamp.TextColor = TextStampColor.TEXTSTAMP_GREEN;
+                        break;
+                    case C_TEXTSTAMP_COLOR.TEXTSTAMP_BLUE:
+                        break;
+                    default:
+                        break;
+                }
+                DynamicStampList.Add(standardStamp);
+            }
+        }
     }
 }

+ 38 - 0
PDF Office/Views/PropertyPanel/AnnotPanel/StampAnnotProperty.xaml

@@ -49,6 +49,44 @@
                         HorizontalContentAlignment="Center"
                         FontSize="16"
                         Width="86">
+                <Grid>
+                    <Grid.RowDefinitions>
+                        <RowDefinition Height="*"/>
+                        <RowDefinition Height="96"/>
+                    </Grid.RowDefinitions>
+                <ListBox ItemsSource="{Binding DynamicStampList}" Loaded="DydamicListBox_Loaded" SelectionMode="Single" Width="256" Height="auto" VerticalAlignment="Top"  BorderThickness="0" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
+                    <ListBox.ItemTemplate>
+                        <DataTemplate >
+                            <ListBoxItem>
+                                <Image Source="{Binding ImageSource}" Stretch="Uniform" Height="48"/>
+                            </ListBoxItem>
+                        </DataTemplate>
+                    </ListBox.ItemTemplate>
+                    <ListBox.ItemContainerStyle>
+                        <Style TargetType="ListBoxItem">
+                            <Setter Property="Height" Value="64"/>
+                            <Setter Property="Padding" Value="12 8 12 8"/>
+                            <Setter Property="HorizontalContentAlignment" Value="Center"/>
+                            <EventSetter Event="PreviewMouseLeftButtonDown" Handler="ListBoxItem_PreviewMouseLeftButtonDown"/>
+                        </Style>
+                    </ListBox.ItemContainerStyle>
+                </ListBox>
+                    <Grid VerticalAlignment="Bottom" Margin="12,0,11.6,20.2" Grid.Row="1">
+                        <Grid.RowDefinitions>
+                            <RowDefinition/>
+                            <RowDefinition/>
+                        </Grid.RowDefinitions>
+                        <CheckBox Name="chkAuthor" VerticalAlignment="Center" FontFamily="Seoge UI" FontSize="14" Margin="0 0 0 8" Content="Author" Padding="7 0 0 0" IsChecked="{Binding IsSetAuthor}" />
+                        <TextBox x:Name="txtAuthor"  VerticalContentAlignment="Center" IsEnabled="{Binding ElementName=chkAuthor, Path=IsChecked}" Text="{Binding Author}" Width="152" Height="32" HorizontalAlignment="Right" Margin="0 0 0 8"/>
+                        <TextBlock x:Name="lbCreateDate" Grid.Row="1" FontFamily="Seoge UI" FontSize="14" Foreground="Black" VerticalAlignment="Center" Margin="27 0 0 0" Text="Date"/>
+                        <ComboBox Name="txtCreateDate" Grid.Row="1" Background ="Transparent"  Width="152" BorderThickness="1" BorderBrush="#FFE2E3E6" HorizontalAlignment="Right" >
+                            <ComboBoxItem x:Name="DefualtItem" Content="Defualt" Width="152" />
+                            <ComboBoxItem Content="m/d" Width="152" />
+                            <ComboBoxItem Content="m/d/yy" Width="152" />
+                            <ComboBoxItem Content="m/d/yyyy" Width="152" />
+                        </ComboBox>
+                    </Grid>
+                </Grid>
             </TabItem>
             <TabItem  x:Name="TabCustom"
                         Header="Custom"

+ 5 - 0
PDF Office/Views/PropertyPanel/AnnotPanel/StampAnnotProperty.xaml.cs

@@ -31,5 +31,10 @@ namespace PDF_Office.Views.PropertyPanel.AnnotPanel
         {
             (DataContext as StampAnnotPropertyViewModel).SetStandardStamp((sender as ListBoxItem).DataContext as Stamp);
         }
+
+        private void DydamicListBox_Loaded(object sender, RoutedEventArgs e)
+        {
+            (DataContext as StampAnnotPropertyViewModel).UpDataDynamicStampList();
+        }
     }
 }