Преглед изворни кода

背景-去除背景,相对页面尺寸

liuaoran пре 2 година
родитељ
комит
3df05dcd5a

+ 6 - 10
PDF Office/Model/EditTools/Background/BackgroundCreateModel.cs

@@ -44,15 +44,6 @@ namespace PDF_Office.Model.EditTools.Background
         /// </summary>
         public byte Opacity;
         
-        /// <summary>
-        /// 是否相对比例
-        /// </summary>
-        public bool IsRelativeRatio;
-        
-        /// <summary>
-        ///相对比例大小 
-        /// </summary>
-        public int RelativeRatio;
 
         /// <summary>
         /// 
@@ -103,5 +94,10 @@ namespace PDF_Office.Model.EditTools.Background
         /// 3:自定义页
         /// </summary>
         public int PageRangeIndex = 0;
-    }
+
+        /// <summary>
+        /// -
+        /// </summary>
+        public bool IsRelativeScale = true;
+     }
 }

+ 64 - 11
PDF Office/ViewModels/EditTools/Background/BackgroundCreateColorContentViewModel.cs

@@ -108,7 +108,7 @@ namespace PDF_Office.ViewModels.EditTools.Background
             set
             {
                 SetProperty(ref _opacityValue, value);
-                BackgroundInfo.Opacity = (byte)(((float)value / 100) * 255);
+                BackgroundInfo.Opacity = (byte)value;
                 eventAggregator.GetEvent<SetBackgroundEvent>().Publish(new BackgroundInfoUnicode
                 {
                     Unicode = Unicode,
@@ -117,14 +117,19 @@ namespace PDF_Office.ViewModels.EditTools.Background
             }
         }
 
-        private int _relativeRatioValue = 0;
+        private int _relativeRatioValue = 50;
         public int RelativeRatioValue
         {
             get { return _relativeRatioValue; }
             set
             {
                 SetProperty(ref _rotationValue, value);
-                BackgroundInfo.RelativeRatio = value;
+                BackgroundInfo.Scale = value;
+                eventAggregator.GetEvent<SetBackgroundEvent>().Publish(new BackgroundInfoUnicode
+                {
+                    Unicode = Unicode,
+                    Status = BackgroundInfo
+                });
             }
         }
 
@@ -223,6 +228,37 @@ namespace PDF_Office.ViewModels.EditTools.Background
             }
         }
 
+        private bool _isRelativeScaleValue = false;
+        public bool IsRelativeScaleValue
+        {
+            get { return _isRelativeScaleValue; }
+            set
+            {
+                SetProperty(ref _isRelativeScaleValue, value);
+                BackgroundInfo.IsRelativeScale = IsRelativeScaleValue;
+                eventAggregator.GetEvent<SetBackgroundEvent>().Publish(new BackgroundInfoUnicode
+                {
+                    Unicode = Unicode,
+                    Status = BackgroundInfo
+                });
+            }
+        }
+
+        private string _relativeScaleText = "50 %";
+        public string RelativeScaleText
+        {
+            get { return _relativeScaleText; }
+            set
+            {
+                SetProperty(ref _relativeScaleText, value);
+                eventAggregator.GetEvent<SetBackgroundEvent>().Publish(new BackgroundInfoUnicode
+                {
+                    Unicode = Unicode,
+                    Status = BackgroundInfo
+                });
+            }
+        }
+
 
 
         public DelegateCommand<object> ChangeLocationCommand { get; set; }
@@ -336,9 +372,9 @@ namespace PDF_Office.ViewModels.EditTools.Background
                 backgroundItem.horizalign = backgroundInfo.Horizalign;
                 backgroundItem.opacity = backgroundInfo.Opacity;
                 backgroundItem.rotation = backgroundInfo.Rotation;
-                backgroundItem.scale = backgroundInfo.Scale;
                 backgroundItem.PageRangeIndex = backgroundInfo.PageRangeIndex;
                 backgroundItem.pageRange = backgroundInfo.PageRange;
+                backgroundItem.isRelativeScale = backgroundInfo.IsRelativeScale;
                 backgroundItem.scale = backgroundInfo.Scale;
             }
 
@@ -377,14 +413,21 @@ namespace PDF_Office.ViewModels.EditTools.Background
                     var tempBackground = tempDocument.GetBackground();
                     tempBackground.SetBackgroundType(BackgroundInfo.BackgroundType);
                     tempBackground.SetColor(BackgroundInfo.Color);
-                    tempBackground.SetScale(1);
+                    if (!BackgroundInfo.IsRelativeScale)
+                    {
+                        tempBackground.SetScale(1);
+                    }
+                    else
+                    {
+                        tempBackground.SetScale(BackgroundInfo.Scale/100);
+                    }
                     tempBackground.SetRotation((float)((BackgroundInfo.Rotation / 180) * Math.PI));
-                    tempBackground.SetOpacity((byte)((BackgroundInfo.Opacity / 100) * 255));
+                    tempBackground.SetOpacity((byte)((float)(BackgroundInfo.Opacity / 100) * 255));
                     tempBackground.SetVertalign(BackgroundInfo.Vertalign);
                     tempBackground.SetHorizalign(BackgroundInfo.Horizalign);
                     tempBackground.SetXOffset(BackgroundInfo.HorizOffset);
                     tempBackground.SetYOffset(BackgroundInfo.VertOffset);
-                    tempBackground.SetPages(BackgroundInfo.PageRange);
+                    tempBackground.SetPages("0");
                     tempBackground.SetAllowsPrint(true);
                     tempBackground.SetAllowsView(true);
                     tempBackground.Update();
@@ -427,6 +470,7 @@ namespace PDF_Office.ViewModels.EditTools.Background
                 backgroundInfo.Horizalign = backgroundItem.horizalign;
                 backgroundInfo.Opacity = backgroundItem.opacity;
                 backgroundInfo.Rotation = backgroundItem.rotation;
+                backgroundInfo.IsRelativeScale = backgroundItem.isRelativeScale;
                 backgroundInfo.Scale = backgroundItem.scale;
                 backgroundInfo.PageRangeIndex = backgroundItem.PageRangeIndex;
                 backgroundInfo.PageRange = backgroundItem.pageRange;
@@ -441,11 +485,12 @@ namespace PDF_Office.ViewModels.EditTools.Background
             ConvertItemToInfo(TemplateBackgroundItem, ref BackgroundInfo);
             Color = EditToolsHelper.ConvertColor(BackgroundInfo.Color);
             RotationText = BackgroundInfo.Rotation.ToString();
-            OpacityText = BackgroundInfo.Opacity.ToString();
+            OpacityText = BackgroundInfo.Opacity.ToString() + "%";
             InitLocationButtonMatrix();
             HorizontalOffsetValue = (BackgroundInfo.HorizOffset).ToString();
             VerticalOffsetValue = (BackgroundInfo.VertOffset).ToString();
             PageRangeSelectIndex = BackgroundInfo.PageRangeIndex;
+            IsRelativeScaleValue = BackgroundInfo.IsRelativeScale;
         }
 
         public void ConfirmEditBackgroundTemplateItem(EnumColorOrFileUnicode enumColorOrFileunicode)
@@ -483,14 +528,22 @@ namespace PDF_Office.ViewModels.EditTools.Background
                         var tempBackground = tempDocument.GetBackground();
                         tempBackground.SetBackgroundType(BackgroundInfo.BackgroundType);
                         tempBackground.SetColor(BackgroundInfo.Color);
-                        tempBackground.SetScale(1);
+                        if (!BackgroundInfo.IsRelativeScale)
+                        {
+                            tempBackground.SetScale(1);
+                        }
+                        else
+                        {
+                            tempBackground.SetScale(BackgroundInfo.Scale/100);
+
+                        }
                         tempBackground.SetRotation((float)((BackgroundInfo.Rotation / 180) * Math.PI));
-                        tempBackground.SetOpacity((byte)((BackgroundInfo.Opacity / 100) * 255));
+                        tempBackground.SetOpacity((byte)((float)(BackgroundInfo.Opacity / 100) * 255));
                         tempBackground.SetVertalign(BackgroundInfo.Vertalign);
                         tempBackground.SetHorizalign(BackgroundInfo.Horizalign);
                         tempBackground.SetXOffset(BackgroundInfo.HorizOffset);
                         tempBackground.SetYOffset(BackgroundInfo.VertOffset);
-                        tempBackground.SetPages(BackgroundInfo.PageRange);
+                        tempBackground.SetPages("0");
                         tempBackground.SetAllowsPrint(true);
                         tempBackground.SetAllowsView(true);
                         tempBackground.Update();

+ 75 - 12
PDF Office/ViewModels/EditTools/Background/BackgroundCreateFileContentViewModel.cs

@@ -67,7 +67,7 @@ namespace PDF_Office.ViewModels.EditTools.Background
             set
             {
                 SetProperty(ref _rotationValue, value);
-                BackgroundInfo.Rotation = ((float)RotationValue / 180) * 3.1415926f;
+                BackgroundInfo.Rotation = value;
                 eventAggregator.GetEvent<SetBackgroundEvent>().Publish(new BackgroundInfoUnicode
                 {
                     Unicode = Unicode,
@@ -84,7 +84,7 @@ namespace PDF_Office.ViewModels.EditTools.Background
             set
             {
                 SetProperty(ref _opacityValue, value);
-                BackgroundInfo.Opacity = (byte)(((float)OpacityValue / 100) * 225);
+                BackgroundInfo.Opacity = (byte)(value);
                 eventAggregator.GetEvent<SetBackgroundEvent>().Publish(new BackgroundInfoUnicode
                 {
                     Unicode = Unicode,
@@ -93,11 +93,20 @@ namespace PDF_Office.ViewModels.EditTools.Background
             }
         }
 
-        private int _relativeRatioValue = 0;
+        private int _relativeRatioValue = 50;
         public int RelativeRatioValue
         {
             get { return _relativeRatioValue; }
-            set { SetProperty(ref _relativeRatioValue, value); }
+            set
+            {
+                SetProperty(ref _rotationValue, value);
+                BackgroundInfo.Scale = value;
+                eventAggregator.GetEvent<SetBackgroundEvent>().Publish(new BackgroundInfoUnicode
+                {
+                    Unicode = Unicode,
+                    Status = BackgroundInfo
+                });
+            }
         }
 
         private string _verticalOffsetValue = "0";
@@ -116,6 +125,22 @@ namespace PDF_Office.ViewModels.EditTools.Background
             }
         }
 
+        private string _relativeScaleText = "50 %";
+        public string RelativeScaleText
+        {
+            get { return _relativeScaleText; }
+            set
+            {
+                SetProperty(ref _relativeScaleText, value);
+                eventAggregator.GetEvent<SetBackgroundEvent>().Publish(new BackgroundInfoUnicode
+                {
+                    Unicode = Unicode,
+                    Status = BackgroundInfo
+                });
+            }
+        }
+
+
         private string _horizOffsetValue = "0";
         public string HorizontalOffsetValue
         {
@@ -183,6 +208,23 @@ namespace PDF_Office.ViewModels.EditTools.Background
             set => SetProperty(ref _createModFileVisible, value);
         }
 
+        private bool _isRelativeScaleValue = false;
+        public bool IsRelativeScaleValue
+        {
+            get { return _isRelativeScaleValue; }
+            set
+            {
+                SetProperty(ref _isRelativeScaleValue, value);
+                BackgroundInfo.IsRelativeScale = IsRelativeScaleValue;
+                eventAggregator.GetEvent<SetBackgroundEvent>().Publish(new BackgroundInfoUnicode
+                {
+                    Unicode = Unicode,
+                    Status = BackgroundInfo
+                });
+            }
+        }
+
+
 
         public DelegateCommand OpenFileCommand { get; set; }
         public DelegateCommand<object> ChangeLocationCommand { get; set; }
@@ -287,6 +329,8 @@ namespace PDF_Office.ViewModels.EditTools.Background
             RotationText = BackgroundInfo.Rotation.ToString();
             OpacityText = BackgroundInfo.Opacity.ToString();
             InitLocationButtonMatrix();
+            IsRelativeScaleValue = BackgroundInfo.IsRelativeScale;
+            RelativeScaleText = BackgroundInfo.Scale.ToString();
             HorizontalOffsetValue = (BackgroundInfo.HorizOffset).ToString();
             VerticalOffsetValue = (BackgroundInfo.VertOffset).ToString();
             PageRangeSelectIndex = BackgroundInfo.PageRangeIndex;
@@ -362,6 +406,8 @@ namespace PDF_Office.ViewModels.EditTools.Background
                 backgroundInfo.Horizalign = backgroundItem.horizalign;
                 backgroundInfo.Opacity = backgroundItem.opacity;
                 backgroundInfo.Rotation = backgroundItem.rotation;
+                backgroundInfo.IsRelativeScale = backgroundItem.isRelativeScale;
+
                 backgroundInfo.Scale = backgroundItem.scale;
                 backgroundInfo.PageRangeIndex = backgroundItem.PageRangeIndex;
                 backgroundInfo.PageRange = backgroundItem.pageRange;
@@ -379,6 +425,7 @@ namespace PDF_Office.ViewModels.EditTools.Background
             backgroundItem.horizalign = backgroundInfo.Horizalign;
             backgroundItem.opacity = backgroundInfo.Opacity;
             backgroundItem.rotation = backgroundInfo.Rotation;
+            backgroundItem.isRelativeScale = backgroundInfo.IsRelativeScale;
             backgroundItem.scale = backgroundInfo.Scale;
             //backgroundItem.pagRangeMode = backgroundInfo.PageRange;
         }
@@ -416,14 +463,22 @@ namespace PDF_Office.ViewModels.EditTools.Background
                     var tempBackground = tempDocument.GetBackground();
                     tempBackground.SetBackgroundType(BackgroundInfo.BackgroundType);
                     tempBackground.SetImage(BackgroundInfo.ImageArray, BackgroundInfo.ImageWidth, BackgroundInfo.ImageHeight, ComPDFKit.Import.C_Scale_Type.fitCenter);
-                    tempBackground.SetScale(1);
-                    tempBackground.SetRotation(BackgroundInfo.Rotation);
-                    tempBackground.SetOpacity(BackgroundInfo.Opacity);
+                    if (!BackgroundInfo.IsRelativeScale)
+                    {
+                        tempBackground.SetScale(1);
+                    }
+                    else
+                    {
+                        tempBackground.SetScale(BackgroundInfo.Scale/100);
+
+                    }
+                    tempBackground.SetRotation((float)((BackgroundInfo.Rotation / 180) * Math.PI));
+                    tempBackground.SetOpacity((byte)((float)(BackgroundInfo.Opacity / 100) * 255));
                     tempBackground.SetVertalign(BackgroundInfo.Vertalign);
                     tempBackground.SetHorizalign(BackgroundInfo.Horizalign);
                     tempBackground.SetXOffset(BackgroundInfo.HorizOffset);
                     tempBackground.SetYOffset(BackgroundInfo.VertOffset);
-                    tempBackground.SetPages(BackgroundInfo.PageRange);
+                    tempBackground.SetPages("0");
                     tempBackground.SetAllowsPrint(true);
                     tempBackground.SetAllowsView(true);
                     tempBackground.Update();
@@ -491,14 +546,22 @@ namespace PDF_Office.ViewModels.EditTools.Background
                         var tempBackground = tempDocument.GetBackground();
                         tempBackground.SetBackgroundType(BackgroundInfo.BackgroundType);
                         tempBackground.SetImage(BackgroundInfo.ImageArray, BackgroundInfo.ImageWidth, BackgroundInfo.ImageHeight, ComPDFKit.Import.C_Scale_Type.fitCenter);
-                        tempBackground.SetScale(1);
-                        tempBackground.SetRotation(BackgroundInfo.Rotation);
-                        tempBackground.SetOpacity(BackgroundInfo.Opacity);
+                        if (!BackgroundInfo.IsRelativeScale)
+                        {
+                            tempBackground.SetScale(1);
+                        }
+                        else
+                        {
+                            tempBackground.SetScale(BackgroundInfo.Scale/100);
+
+                        }
+                        tempBackground.SetRotation((float)((BackgroundInfo.Rotation / 180) * Math.PI));
+                        tempBackground.SetOpacity((byte)((float)(BackgroundInfo.Opacity / 100) * 255));
                         tempBackground.SetVertalign(BackgroundInfo.Vertalign);
                         tempBackground.SetHorizalign(BackgroundInfo.Horizalign);
                         tempBackground.SetXOffset(BackgroundInfo.HorizOffset);
                         tempBackground.SetYOffset(BackgroundInfo.VertOffset);
-                        tempBackground.SetPages(BackgroundInfo.PageRange);
+                        tempBackground.SetPages("0");
                         tempBackground.SetAllowsPrint(true);
                         tempBackground.SetAllowsView(true);
                         tempBackground.Update();

+ 9 - 3
PDF Office/ViewModels/EditTools/Background/BackgroundDocumentContentViewModel.cs

@@ -173,10 +173,16 @@ namespace PDF_Office.ViewModels.EditTools.Background
                     background.SetBackgroundType(C_Background_Type.BG_TYPE_IMAGE);
                     background.SetImage(backgroundInfo.ImageArray, backgroundInfo.ImageWidth, backgroundInfo.ImageHeight, ComPDFKit.Import.C_Scale_Type.fitCenter);
                 }
-
-                background.SetScale((float)(backgroundInfo.Scale/100));
+                if (!backgroundInfo.IsRelativeScale)
+                {
+                    background.SetScale(1);
+                }
+                else
+                {
+                    background.SetScale((float)(backgroundInfo.Scale / 100));
+                }
                 background.SetRotation((float)((backgroundInfo.Rotation / 180) * Math.PI ));
-                background.SetOpacity((byte)((backgroundInfo.Opacity / 100) * 255));
+                background.SetOpacity((byte)(((float)backgroundInfo.Opacity / 100) * 255));
                 background.SetVertalign(backgroundInfo.Vertalign);
                 background.SetHorizalign(backgroundInfo.Horizalign);
                 background.SetXOffset(backgroundInfo.HorizOffset);

+ 2 - 2
PDF Office/Views/EditTools/Background/BackgroundCreateColorContent.xaml

@@ -64,9 +64,9 @@
                 <StackPanel Orientation="Horizontal"></StackPanel>
                 <Grid Margin="0,19,0,0">
 
-                    <CheckBox Grid.Column="0" Style="{StaticResource EditToolsCheckBoxStyle}" Content="相对目标页面的比例" Margin="0,0,0,0" Height="22" ></CheckBox>
+                    <CheckBox Name="RelativeScaleCheckBox"  Grid.Column="0" Style="{StaticResource EditToolsCheckBoxStyle}" Content="相对目标页面的比例" Margin="0,0,0,0" Height="22"  IsChecked="{Binding IsRelativeScaleValue}"></CheckBox>
                 </Grid>
-                <cus:CommonWritableComboBox HorizontalAlignment="Left" Width="66" Height="32" Margin="0,11,0,0" TypeSouce="{Binding RelativeRatioList,Mode=TwoWay}" Value="{Binding RelativeRatioValue,Mode=TwoWay}" Text="50 %"></cus:CommonWritableComboBox>
+                <cus:CommonWritableComboBox HorizontalAlignment="Left" Width="66" Height="32" Margin="0,11,0,0" TypeSouce="{Binding RelativeRatioList,Mode=TwoWay}" Value="{Binding RelativeRatioValue,Mode=TwoWay}" Text="{Binding RelativeScaleText,Mode=TwoWay}"  IsEnabled="{Binding ElementName=RelativeScaleCheckBox,Path=IsChecked}" ></cus:CommonWritableComboBox>
 
 
             </StackPanel>

+ 2 - 2
PDF Office/Views/EditTools/Background/BackgroundCreateFileContent.xaml

@@ -49,9 +49,9 @@
                     </StackPanel>
                     <StackPanel Orientation="Horizontal"></StackPanel>
                     <Grid Margin="0,19,0,0">
-                        <CheckBox Grid.Column="0" Style="{StaticResource EditToolsCheckBoxStyle}" Content="相对目标页面的比例" Margin="0,0,0,0" Height="22"></CheckBox>
+                        <CheckBox Name="RelativeScaleCheckBox"  Grid.Column="0" Style="{StaticResource EditToolsCheckBoxStyle}" Content="相对目标页面的比例" Margin="0,0,0,0" Height="22"  IsChecked="{Binding IsRelativeScaleValue}"></CheckBox>
                     </Grid>
-                    <cus:CommonWritableComboBox HorizontalAlignment="Left" Width="66" Height="32" Margin="0,11,28,0" TypeSouce="{Binding RelativeRatioList, Mode=TwoWay}"  Text="100 %"></cus:CommonWritableComboBox>
+                    <cus:CommonWritableComboBox HorizontalAlignment="Left" Width="66" Height="32" Margin="0,11,28,0" TypeSouce="{Binding RelativeRatioList, Mode=TwoWay}" Value="{Binding RelativeRatioValue,Mode=TwoWay}"   Text="{Binding RelativeScaleText,Mode=TwoWay}"  IsEnabled="{Binding ElementName=RelativeScaleCheckBox,Path=IsChecked}"></cus:CommonWritableComboBox>
                 </StackPanel>
             </Grid>
             <Grid  Grid.Row="1" Margin="0,16,0,0" VerticalAlignment="Bottom">

+ 6 - 6
PDF Office/Views/EditTools/Watermark/WatermarkCreateFileContent.xaml

@@ -9,12 +9,12 @@
              mc:Ignorable="d"
              d:DesignHeight="632"
              d:DesignWidth="260" >
-    <UserControl.Resources>
-        <ResourceDictionary>
-            <ResourceDictionary.MergedDictionaries>
-                <ResourceDictionary Source="../../../Styles/CheckBoxStyle.xaml"/>
-            </ResourceDictionary.MergedDictionaries>
-        </ResourceDictionary>
+    <UserControl.Resources>
+        <ResourceDictionary>
+            <ResourceDictionary.MergedDictionaries>
+                <ResourceDictionary Source="../../../Styles/CheckBoxStyle.xaml"/>
+            </ResourceDictionary.MergedDictionaries>
+        </ResourceDictionary>
     </UserControl.Resources>
     <Grid>
         <Grid.RowDefinitions>

+ 2 - 0
PDFSettings/BackgroundTemplateList.cs

@@ -122,5 +122,7 @@ namespace PDFSettings
         /// 3:自定义页
         /// </summary>
         public int PageRangeIndex = 0;
+
+        public bool isRelativeScale = true;
     }
 }