Browse Source

Merge branch 'dev' of http://git.kdan.cc:8865/Windows/PDFOffice_Windows_exe into dev

ZhouJieSheng 1 năm trước cách đây
mục cha
commit
59e0f270b8

+ 28 - 15
PDF Office/DataConvert/StringToDateConvert.cs

@@ -66,26 +66,31 @@ namespace PDF_Master.DataConvert
             string tag = "";
             var last = (DateTime)value;
             var now = System.DateTime.Now;
-            TimeSpan ts = (now - last).Duration();
-
-            //同一周
-            bool isSameWeek = !(ts.TotalDays >= 7 || (DateTime.Compare(now, last) > 0 ? (now.DayOfWeek < last.DayOfWeek) : (now.DayOfWeek > last.DayOfWeek)));
+            //时间间隔
+            //TimeSpan ts = (now - last).Duration();
+            //7天之内
+            bool isSameWeek = false;
+            //bool isSameWeek = !(ts.TotalDays >= 7 || (DateTime.Compare(now, last) > 0 ? (now.DayOfWeek < last.DayOfWeek) : (now.DayOfWeek > last.DayOfWeek)));
+            isSameWeek = WeekSpan(now, last);
             //同年同月
             if (now.Year == last.Year)
-            {
-                //同日
-                if (now.Day == last.Day)
-                {
-                    tag = "Today";
-                }
-                {
-                    if (isSameWeek)
-                        tag = "week";
-                }
+            { //同日
+                if (now.Month == last.Month)
+                {
+                    if (now.Day == last.Day)
+                    {
+                        tag = "Today";
+                    }
+                    else if (isSameWeek)
+                    {
+                        tag = "week";
+                    }
+                }
+
             }
 
             string result = "";
-            switch(tag)
+            switch (tag)
             {
                 case "Today":
                     result = "Today, " + last.Hour + ":" + last.Minute;
@@ -109,6 +114,14 @@ namespace PDF_Master.DataConvert
         public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
         {
             throw new NotImplementedException();
+        }
+
+        public bool WeekSpan(DateTime now, DateTime last)
+        {
+            int ts = DateTime.Compare(now, last) > 0 ? (now.Day - last.Day) : (last.Day - now.Day);
+            int a = DateTime.Compare(now, last) > 0 ? (now.DayOfWeek - last.DayOfWeek) : (last.DayOfWeek - now.DayOfWeek);
+            if (ts == a) { return true; }
+            return false;
         }
     }
 }

+ 71 - 33
PDF Office/Model/AnnotPanel/FontBoard.cs

@@ -1,4 +1,5 @@
 using ComPDFKit.PDFAnnotation;
+using ComPDFKitViewer.AnnotEvent;
 using PDF_Master.CustomControl.CompositeControl;
 using PDF_Master.Model.PropertyPanel.AnnotPanel;
 using PDFSettings;
@@ -22,14 +23,15 @@ namespace PDF_Master.Model.AnnotPanel
         FontWeight_Style,
         FontColor,
         TextAlignment
-
     }
 
     //设置字体大小、字体内容排版、字体颜色、字体样式、字重
     public class FontBoard : BindableBase
     {
         #region 变量
+
         protected event EventHandler<FontSetModeType> ChangedValue;
+
         protected bool IsCanSave = false;
         public List<ComboDataItem> FontFamilyItems { get; protected set; }
         public List<ComboDataItem> FontStyleItems { get; protected set; }
@@ -37,9 +39,10 @@ namespace PDF_Master.Model.AnnotPanel
 
         public List<PresetFontItem> PresetFontList = new List<PresetFontItem>();
 
-        #endregion
+        #endregion 变量
 
         #region 初始化下拉框或列表默认的数据
+
         protected void InitBaseVariable()
         {
             InitBase_PresetFontStyles();
@@ -58,24 +61,26 @@ namespace PDF_Master.Model.AnnotPanel
                 ComboDataItem itemData = new ComboDataItem(item.mTag, item.mTagContent);
                 PresetFontItems.Add(itemData);
             }
-
         }
+
         //字体
         private void InitBase_FontFamilys()
         {
             FontFamilyItems = TextFont.GetFamily();
         }
+
         //字重
         private void InitBase_FontStyles()
         {
             FontStyleItems = TextFont.GetFontStyle();
         }
 
-        #endregion
+        #endregion 初始化下拉框或列表默认的数据
 
         #region 属性
 
         private ComboDataItem _currentPresetFont;
+
         public ComboDataItem CurrentPresetFont
         {
             get { return _currentPresetFont; }
@@ -94,6 +99,7 @@ namespace PDF_Master.Model.AnnotPanel
 
         //下拉框列表
         private ComboDataItem _currentFontFamily;
+
         public ComboDataItem CurrentFontFamily
         {
             get { return _currentFontFamily; }
@@ -103,16 +109,18 @@ namespace PDF_Master.Model.AnnotPanel
                 SetProperty(ref _currentFontFamily, value);
                 if (isChange)
                 {
-
                     ChangedValue?.Invoke(_currentFontFamily.ValueStr, FontSetModeType.FontFamilys);
                 }
             }
         }
-        #endregion
+
+        #endregion 字体样式
 
         #region 字体大小
+
         //下拉框列表:字体大小
         private ComboDataItem _currentFontSize = new ComboDataItem(6);
+
         public ComboDataItem CurrentFontSize
         {
             get { return _currentFontSize; }
@@ -130,12 +138,12 @@ namespace PDF_Master.Model.AnnotPanel
             }
         }
 
-        #endregion
-
+        #endregion 字体大小
 
         //FontStyle & FontWeight
 
         private FontStyle _fontStyle;
+
         public FontStyle FontStyleItem
         {
             get { return _fontStyle; }
@@ -143,6 +151,7 @@ namespace PDF_Master.Model.AnnotPanel
         }
 
         private FontWeight _fontWeight;
+
         public FontWeight FontWeightItem
         {
             get { return _fontWeight; }
@@ -150,6 +159,7 @@ namespace PDF_Master.Model.AnnotPanel
         }
 
         private ComboDataItem _currrentFontWeightStyle;
+
         public ComboDataItem CurrrentFontWeightStyle
         {
             get { return _currrentFontWeightStyle; }
@@ -191,6 +201,7 @@ namespace PDF_Master.Model.AnnotPanel
         }
 
         private C_TEXT_ALIGNMENT _textAlignment;
+
         public C_TEXT_ALIGNMENT TextAlignmentItem
         {
             get { return _textAlignment; }
@@ -199,6 +210,7 @@ namespace PDF_Master.Model.AnnotPanel
 
         //颜色
         private Brush selectColor = new SolidColorBrush(Colors.Black);
+
         public Brush SelectColor
         {
             get { return selectColor; }
@@ -213,11 +225,11 @@ namespace PDF_Master.Model.AnnotPanel
                 {
                     CurrentFontColor = selectColor;
                 }
-
             }
         }
 
         private Brush _currentFontColor = new SolidColorBrush(Colors.Transparent);
+
         public Brush CurrentFontColor
         {
             get { return _currentFontColor; }
@@ -239,6 +251,7 @@ namespace PDF_Master.Model.AnnotPanel
             }
             return false;
         }
+
         private bool IsEqualStrComboData(ComboDataItem oldValue, ComboDataItem newValue)
         {
             if (newValue == null || string.IsNullOrEmpty(newValue.ValueStr) == true || IsCanSave == false)
@@ -251,8 +264,8 @@ namespace PDF_Master.Model.AnnotPanel
             }
             return false;
         }
-        #endregion
 
+        #endregion 属性
 
         #region 列表选中赋值
 
@@ -267,13 +280,11 @@ namespace PDF_Master.Model.AnnotPanel
                     strValue = "Regular";
                     strContent = "常规";
                 }
-
                 else
                 {
                     strValue = "Bold";
                     strContent = "粗体";
                 }
-
             }
             else
             {
@@ -287,13 +298,11 @@ namespace PDF_Master.Model.AnnotPanel
                     strValue = "Bold Italic";
                     strContent = "粗斜体";
                 }
-
             }
 
             CurrrentFontWeightStyle = new ComboDataItem(strValue, strContent);
         }
 
-
         protected void GetCurrentFontSize(int size)
         {
             CurrentFontSize = new ComboDataItem(size);
@@ -304,15 +313,14 @@ namespace PDF_Master.Model.AnnotPanel
             CurrentFontFamily = new ComboDataItem(fontFamily, uiStr);
         }
 
-        #endregion
+        #endregion 列表选中赋值
     }
 
-
-
     //设置字体大小、字体内容排版、字体颜色、字体样式、字重
     public class FontBoardVm : BindableBase
     {
         #region 变量
+
         public List<ComboDataItem> FontFamilyItems { get; protected set; }
         public List<ComboDataItem> FontStyleItems { get; protected set; }
         public List<ComboDataItem> PresetFontItems { get; protected set; }
@@ -324,9 +332,11 @@ namespace PDF_Master.Model.AnnotPanel
             if (isInitdata)
                 InitBaseVariable();
         }
-        #endregion
+
+        #endregion 变量
 
         #region 初始化下拉框或列表默认的数据
+
         protected void InitBaseVariable()
         {
             InitBase_PresetFontStyles();
@@ -345,24 +355,26 @@ namespace PDF_Master.Model.AnnotPanel
                 ComboDataItem itemData = new ComboDataItem(item.mTag, item.mTagContent);
                 PresetFontItems.Add(itemData);
             }
-
         }
+
         //字体
         private void InitBase_FontFamilys()
         {
             FontFamilyItems = TextFont.GetFamily();
         }
+
         //字重
         private void InitBase_FontStyles()
         {
             FontStyleItems = TextFont.GetFontStyle();
         }
 
-        #endregion
+        #endregion 初始化下拉框或列表默认的数据
 
         #region 属性
 
-        private ComboDataItem _currentPresetFont = new ComboDataItem("custom", "Custom");
+        private ComboDataItem _currentPresetFont = new ComboDataItem("Custom", "Custom");
+
         public ComboDataItem CurrentPresetFont
         {
             get { return _currentPresetFont; }
@@ -372,29 +384,33 @@ namespace PDF_Master.Model.AnnotPanel
         #region 字体样式
 
         //下拉框列表
-        private ComboDataItem _currentFontFamily = new ComboDataItem("Arial", "Helvetica");
+        private ComboDataItem _currentFontFamily = new ComboDataItem("Helvatica", "Helvetica");
+
         public ComboDataItem CurrentFontFamily
         {
             get { return _currentFontFamily; }
             set => SetProperty(ref _currentFontFamily, value);
         }
-        #endregion
+
+        #endregion 字体样式
 
         #region 字体大小
+
         //下拉框列表:字体大小
         private ComboDataItem _currentFontSize = new ComboDataItem(6);
+
         public ComboDataItem CurrentFontSize
         {
             get { return _currentFontSize; }
             set => SetProperty(ref _currentFontSize, value);
         }
 
-        #endregion
-
+        #endregion 字体大小
 
         //FontStyle & FontWeight
 
         private FontStyle _fontStyleItem;
+
         public FontStyle FontStyleItem
         {
             get { return _fontStyleItem; }
@@ -402,6 +418,7 @@ namespace PDF_Master.Model.AnnotPanel
         }
 
         private FontWeight _fontWeight;
+
         public FontWeight FontWeightItem
         {
             get { return _fontWeight; }
@@ -409,6 +426,7 @@ namespace PDF_Master.Model.AnnotPanel
         }
 
         private ComboDataItem _currrentFontWeightStyle = new ComboDataItem("Regular", "Regular");
+
         public ComboDataItem CurrrentFontWeightStyle
         {
             get { return _currrentFontWeightStyle; }
@@ -443,14 +461,16 @@ namespace PDF_Master.Model.AnnotPanel
 
         //文字内容对齐
         private string _strtextAlign;
+
         public string StrTextAlign
         {
             get { return _strtextAlign; }
             set { SetProperty(ref _strtextAlign, value); }
         }
-        
+
         //颜色
         private Brush _fontColor = new SolidColorBrush(Colors.Black);
+
         public Brush FontColor
         {
             get { return _fontColor; }
@@ -458,6 +478,7 @@ namespace PDF_Master.Model.AnnotPanel
         }
 
         private Brush _currentFontColor = new SolidColorBrush(Colors.Transparent);
+
         public Brush CurrentFontColor
         {
             get { return _currentFontColor; }
@@ -466,13 +487,14 @@ namespace PDF_Master.Model.AnnotPanel
 
         //外部UI引用,判断是否选中左对齐、居中对齐、右对齐,或都不选中
         public string strAglinState { get; private set; }
+
         //VM赋值
         public void SetStrAglinState(string str)
         {
             strAglinState = str;
         }
-        #endregion
 
+        #endregion 属性
 
         #region 列表选中赋值
 
@@ -487,13 +509,11 @@ namespace PDF_Master.Model.AnnotPanel
                     strValue = "Regular";
                     strContent = "常规";
                 }
-
                 else
                 {
                     strValue = "Bold";
                     strContent = "粗体";
                 }
-
             }
             else
             {
@@ -507,13 +527,11 @@ namespace PDF_Master.Model.AnnotPanel
                     strValue = "Bold Italic";
                     strContent = "粗斜体";
                 }
-
             }
 
             CurrrentFontWeightStyle = new ComboDataItem(strValue, strContent);
         }
 
-
         public void GetCurrentFontSize(int size)
         {
             CurrentFontSize = new ComboDataItem(size);
@@ -524,6 +542,26 @@ namespace PDF_Master.Model.AnnotPanel
             CurrentFontFamily = new ComboDataItem(fontFamily, uiStr);
         }
 
-        #endregion
+        public void GetCurrentPresetFont(string presetFont, string uiStr)
+        {
+            CurrentPresetFont = new ComboDataItem(presetFont, uiStr);
+        }
+
+        internal void GetCurrentPresetFont(FreeTextAnnotArgs annot)
+        {
+            //List<PresetFontItem> presetFontItems = TextFont.GetCachePresetFontList();
+            foreach (var item in PresetFontList)
+            {
+                if (annot.FontSize == item.mFontSize && annot.FontWeight == item.mFontWeight
+                    && (annot.FontFamily.Source == item.mFontFamily.Source || annot.FontFamily.Source == "Arial" && item.mFontFamily.Source == "Helvatica")
+                    )
+                {
+                    CurrentPresetFont = new ComboDataItem(item.mTag, item.mTagContent);
+                }
+            }
+           
+        }
+
+        #endregion 列表选中赋值
     }
-}
+}

+ 15 - 28
PDF Office/Model/PropertyPanel/AnnotPanel/FontStyleItem.cs

@@ -11,7 +11,6 @@ using System.Windows.Media;
 
 namespace PDF_Master.Model.PropertyPanel.AnnotPanel
 {
-
     public class TextFont
     {
         //获取本地缓存数据
@@ -25,7 +24,7 @@ namespace PDF_Master.Model.PropertyPanel.AnnotPanel
             if (Settings.Default.PresetFontList.Count == 0)
             {
                 cacheTempList = GetPresetFontStyle();
-                foreach(var cacheItem in cacheTempList)
+                foreach (var cacheItem in cacheTempList)
                 {
                     var newItem = new PresetFontItem();
                     newItem.mTag = cacheItem.mTag;
@@ -62,25 +61,24 @@ namespace PDF_Master.Model.PropertyPanel.AnnotPanel
         {
             if (list == null) return;
 
-           if(Settings.Default.PresetFontList == null)
+            if (Settings.Default.PresetFontList == null)
                 Settings.Default.PresetFontList = new PresetFontList();
 
             bool isCanSave = false;
             List<PresetFontItem> TempLists = new List<PresetFontItem>();
 
-           foreach (var item in list)
+            foreach (var item in list)
             {
                 var cacheItem = Settings.Default.PresetFontList.FirstOrDefault(temp => temp.mTag == item.mTag);
                 if (cacheItem != null)
                 {
-                    if(cacheItem.mFontFamily != item.mFontFamily ||
+                    if (cacheItem.mFontFamily != item.mFontFamily ||
                        cacheItem.mFontSize != item.mFontSize ||
                        cacheItem.mFontStyle != item.mFontStyle ||
                        cacheItem.mFontWeight != item.mFontWeight
                         )
                     {
                         isCanSave = true;
-                        
                     }
                     break;
                 }
@@ -90,7 +88,7 @@ namespace PDF_Master.Model.PropertyPanel.AnnotPanel
                 }
             }
 
-            foreach(var itemTemp in TempLists)
+            foreach (var itemTemp in TempLists)
             {
                 Settings.Default.PresetFontList.Add(itemTemp);
             }
@@ -102,11 +100,11 @@ namespace PDF_Master.Model.PropertyPanel.AnnotPanel
         public static void BackDefaultPresetFontStyle(string tag)
         {
             bool isCanSave = false;
-           var list = GetPresetFontStyle();
+            var list = GetPresetFontStyle();
             var itemDefault = list.FirstOrDefault(temp => temp.mTag == tag);
             if (Settings.Default.PresetFontList == null)
                 Settings.Default.PresetFontList = new PresetFontList();
-            if(Settings.Default.PresetFontList.Count == 0)
+            if (Settings.Default.PresetFontList.Count == 0)
             {
                 Settings.Default.PresetFontList.Add(itemDefault);
                 isCanSave = true;
@@ -130,7 +128,6 @@ namespace PDF_Master.Model.PropertyPanel.AnnotPanel
 
             if (isCanSave == true)
                 Settings.Default.Save();
-
         }
 
         //获取拟定的预设样式
@@ -153,18 +150,17 @@ namespace PDF_Master.Model.PropertyPanel.AnnotPanel
             h1.mFontSize = 36;
             h1.mFontFamily = new FontFamily("Helvatica");
             h1.mFontStyle = FontStyles.Normal;
-            h1.mFontWeight = FontWeights.Normal;
+            h1.mFontWeight = FontWeights.Bold;
 
             PresetFontItem h2 = new PresetFontItem();
             h2.mTag = "H2";
-            h2.mTagContent = "h2(标准)";
+            h2.mTagContent = "H2(标准)";
 
             h2.mFontSize = 24;
             h2.mFontFamily = new FontFamily("Helvatica");
             h2.mFontStyle = FontStyles.Normal;
             h2.mFontWeight = FontWeights.Bold;
 
-
             PresetFontItem h3 = new PresetFontItem();
             h3.mTag = "H3";
             h3.mTagContent = "H3小标题";
@@ -181,8 +177,7 @@ namespace PDF_Master.Model.PropertyPanel.AnnotPanel
             b1.mFontSize = 14;
             b1.mFontFamily = new FontFamily("Helvatica");
             b1.mFontStyle = FontStyles.Normal;
-            b1.mFontWeight = FontWeights.Normal;
-
+            b1.mFontWeight = FontWeights.Regular;
 
             PresetFontItem b2 = new PresetFontItem();
             b2.mTag = "B2";
@@ -191,7 +186,7 @@ namespace PDF_Master.Model.PropertyPanel.AnnotPanel
             b2.mFontSize = 12;
             b2.mFontFamily = new FontFamily("Helvatica");
             b2.mFontStyle = FontStyles.Normal;
-            b2.mFontWeight = FontWeights.Normal;
+            b2.mFontWeight = FontWeights.Regular;
 
             PresetFontItem b3 = new PresetFontItem();
             b3.mTag = "B3";
@@ -200,7 +195,7 @@ namespace PDF_Master.Model.PropertyPanel.AnnotPanel
             b3.mFontSize = 11;
             b3.mFontFamily = new FontFamily("Helvatica");
             b3.mFontStyle = FontStyles.Normal;
-            b3.mFontWeight = FontWeights.Normal;
+            b3.mFontWeight = FontWeights.Regular;
 
             fontStyleList.Add(custom);
             fontStyleList.Add(h1);
@@ -233,7 +228,7 @@ namespace PDF_Master.Model.PropertyPanel.AnnotPanel
             var FontFamilyItems = new List<ComboDataItem>();
             ComboDataItem item = new ComboDataItem("Courier", "Courier New");
             FontFamilyItems.Add(item);
-            item = new ComboDataItem("Arial", "Helvetica");
+            item = new ComboDataItem("Helvetica", "Helvetica");
             FontFamilyItems.Add(item);
             item = new ComboDataItem(/*"Times-Roman"*/"Times", "Times New Roman");
             FontFamilyItems.Add(item);
@@ -244,7 +239,7 @@ namespace PDF_Master.Model.PropertyPanel.AnnotPanel
         public static List<ComboDataItem> GetDateFormats()
         {
             var dateFormatItems = new List<ComboDataItem>();
-            foreach(var itemFormat in GetTimesFormats())
+            foreach (var itemFormat in GetTimesFormats())
             {
                 ComboDataItem item = new ComboDataItem(itemFormat, "format");
                 dateFormatItems.Add(item);
@@ -284,14 +279,6 @@ namespace PDF_Master.Model.PropertyPanel.AnnotPanel
             TimesItems.Add("yy-MM-dd");
             TimesItems.Add("yyyy-MM-dd");
             return TimesItems;
-
-
-
-
-
-
-
         }
     }
-   
-}
+}

+ 30 - 43
PDF Office/ViewModels/PropertyPanel/AnnotPanel/FreetextAnnotPropertyViewModel.cs

@@ -46,7 +46,7 @@ namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
                 SetProperty(ref T_font, value);
             }
         }
-        
+
         private string T_fill;
 
         public string T_Fill
@@ -58,7 +58,6 @@ namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
             }
         }
 
-
         private void InitString()
         {
             T_Title = App.MainPageLoader.GetString("FreeText_Title");
@@ -66,9 +65,10 @@ namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
             T_Fill = App.MainPageLoader.GetString("FreeText_Fill");
         }
 
-        #endregion
+        #endregion 文案
 
         private FontBoardVm _fontVm = new FontBoardVm(true);
+
         public FontBoardVm FontVm
         {
             get { return _fontVm; }
@@ -76,6 +76,7 @@ namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
         }
 
         private AnnotCommon _basicVm = new AnnotCommon();
+
         public AnnotCommon BasicVm
         {
             get { return _basicVm; }
@@ -83,6 +84,7 @@ namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
         }
 
         private bool _isFillFreeText = false;
+
         public bool IsFillFreeTextAnnot
         {
             get { return _isFillFreeText; }
@@ -90,6 +92,7 @@ namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
         }
 
         private bool _isCheckedTime = false;
+
         public bool IsCheckedTime
         {
             get { return _isCheckedTime; }
@@ -97,13 +100,13 @@ namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
         }
 
         private ComboDataItem _currrentDateFormat = new ComboDataItem("M/d", "format");
+
         public ComboDataItem CurrrentDateFormat
         {
             get { return _currrentDateFormat; }
             set => SetProperty(ref _currrentDateFormat, value);
         }
 
-
         public List<ComboDataItem> DateFormatItems { get; private set; }
 
         public AnnotAttribEvent AnnotEvent { get; set; }
@@ -115,10 +118,9 @@ namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
         public DelegateCommand FontStyleWeightChangedCommand { get; set; }
 
         public DelegateCommand<object> SelectedFillOpacityCommand { get; set; }
-        
+
         public DelegateCommand<object> SelectedColorCommand { get; set; }
         public DelegateCommand<object> SelectedFillColorCommand { get; set; }
-        
 
         public DelegateCommand FontSizeChangedCommand { get; set; }
         public DelegateCommand<object> TextAlignCheckedCommand { get; set; }
@@ -171,14 +173,12 @@ namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
             InitVariable();
         }
 
-      
         private void InitVariable()
         {
             DateFormatItems = new List<ComboDataItem>();
             DateFormatItems = TextFont.GetDateFormats();
             UpdateDateFormatLists();
             InitFillColorItems();
-
         }
 
         private void InitFillColorItems()
@@ -206,8 +206,6 @@ namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
             CurrrentDateFormat = new ComboDataItem(CurrrentDateFormat.ValueStr, CurrrentDateFormat.Content);
         }
 
-     
-
         private void TextAlignChecked(object obj)
         {
             if ((string)obj != null)
@@ -234,13 +232,12 @@ namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
                         PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.TextAlign, TextAlignment.Justify);
                         break;
                 }
-                
             }
         }
 
         private void LineMode_Checked(object obj)
         {
-            if(obj != null)
+            if (obj != null)
             {
                 var tag = ((string)obj);
                 switch (tag)
@@ -252,12 +249,11 @@ namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
                     case "Solid":
                         AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, DashStyles.Solid);
                         break;
-
                 }
                 AnnotEvent?.UpdateAnnot();
             }
         }
-        
+
         //从预设样式设置文本
         private void SelectedPresetFont()
         {
@@ -271,7 +267,9 @@ namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
                     FontVm.GetCurrentFontSize(item.mFontSize);
 
                     if (item.mFontFamily != null)
+                    {
                         FontVm.GetCurrentFontFamily(item.mFontFamily.ToString(), item.mFontFamily.ToString());
+                    }
 
                     FontVm.GetFontWeights_Style(item.mFontStyle, item.mFontWeight);
 
@@ -288,7 +286,7 @@ namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
         //设置文本字重、样式
         private void FontStyleWeightChanged()
         {
-            if(FontVm.CurrrentFontWeightStyle != null)
+            if (FontVm.CurrrentFontWeightStyle != null)
             {
                 FontVm.UpdateFontWeight_Style();
 
@@ -298,7 +296,6 @@ namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
                 PropertyPanel.UpdateAnnotAllAttribs(AnnotAttribDir);
             }
         }
-        
 
         private void SelectedFillOpacity(object obj)
         {
@@ -319,7 +316,7 @@ namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
                 PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Transparency, BasicVm.FillOpacity);
             }
         }
-        
+
         //设置字体大小
         private void FontSizeChanged()
         {
@@ -386,7 +383,6 @@ namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
                     menu.IsOpen = true;
                 }
             }
-
         }
 
         private ContextMenu SelectAnnotContextMenu(bool isEnable)
@@ -407,9 +403,9 @@ namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
         }
 
         public List<PresetFontItem> FontStyleList = new List<PresetFontItem>();
+
         private void ReDefineFontStyle()
         {
-            
             var item = FontVm.PresetFontList.FirstOrDefault(temp => temp.mTag == FontVm.CurrentPresetFont.ValueStr);
             if (item == null) return;
 
@@ -437,7 +433,7 @@ namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
         private void RestoreDefaultStyle()
         {
             var defaultlists = TextFont.GetPresetFontStyle();
-            if(FontVm.CurrentPresetFont.ValueStr != "custom")
+            if (FontVm.CurrentPresetFont.ValueStr != "custom")
             {
                 var defaulItem = defaultlists.FirstOrDefault(temp => temp.mTag == FontVm.CurrentPresetFont.ValueStr);
                 if (defaulItem != null)
@@ -456,19 +452,17 @@ namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
                     }
                 }
             }
-           
         }
 
         private void DateFormatChanged()
         {
-            if(CurrrentDateFormat != null)
+            if (CurrrentDateFormat != null)
             {
                 if (IsCheckedTime)
                     UpdateDateFormatLists();
 
                 PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.NoteText, CurrrentDateFormat.Content);
             }
-
         }
 
         private void ShowTimeCheckedChnaged()
@@ -480,7 +474,6 @@ namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
             }
         }
 
-
         public bool IsNavigationTarget(NavigationContext navigationContext)
         {
             return true;
@@ -489,7 +482,7 @@ namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
         public void OnNavigatedFrom(NavigationContext navigationContext)
         {
             BasicVm.IsMultiSelected = false;
-          //  IsCheckedTime = false;
+            //  IsCheckedTime = false;
         }
 
         public void OnNavigatedTo(NavigationContext navigationContext)
@@ -497,7 +490,6 @@ namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
             navigationContext.Parameters.TryGetValue<AnnotTransfer>(ParameterNames.PropertyPanelContentViewModel, out PropertyPanel);
             if (PropertyPanel != null)
             {
-               
                 AnnotEvent = PropertyPanel.AnnotEvent;
                 Annot = PropertyPanel.annot as FreeTextAnnotArgs;
                 LoadPropertyHandler?.Invoke(this, Annot);
@@ -518,9 +510,9 @@ namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
             }
         }
 
-       /// <summary>
-       /// 多选的注释
-       /// </summary>
+        /// <summary>
+        /// 多选的注释
+        /// </summary>
         private List<FreeTextAnnotArgs> ConvertLists()
         {
             List<FreeTextAnnotArgs> FreeTextLists = new List<FreeTextAnnotArgs>();
@@ -538,6 +530,7 @@ namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
             else
                 return FreeTextLists;
         }
+
         private void IsAttributeEquals()
         {
             var list = ConvertLists();
@@ -563,7 +556,6 @@ namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
                         FontVm.StrTextAlign = "None";
                     }
 
-
                     if (temp.FontFamily != item.FontFamily)
                     {
                         isNoEqualsDir["FontFamily"] = true;
@@ -604,8 +596,6 @@ namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
                             isNoEqualsDir["FillColor"] = true;
                         }
                     }
-
-
                 }
 
                 ////以下是多选注释的属性相等时
@@ -617,7 +607,6 @@ namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
                 if (isNoEqualsDir["FontFamily"] == false)
                 {
                     FontVm.GetCurrentFontFamily(temp.FontFamily.ToString(), temp.FontFamily.ToString());
-
                 }
 
                 if (isNoEqualsDir["FontSize"] == false)
@@ -629,19 +618,16 @@ namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
                 {
                     FontVm.GetFontWeights_Style(temp.FontStyle, temp.FontWeight);
                 }
-               
+
                 if (isNoEqualsDir["FontColor"] == false)
                 {
                     FontVm.FontColor = new SolidColorBrush(temp.FontColor);
-
                 }
 
                 if (isNoEqualsDir["FillColor"] == false)
                 {
                     FontVm.FontColor = new SolidColorBrush(temp.BgColor);
-
                 }
-
             }
         }
 
@@ -652,6 +638,7 @@ namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
 
             FontVm.FontColor = new SolidColorBrush(Annot.FontColor);
             FontVm.GetCurrentFontSize((int)Annot.FontSize);
+            FontVm.GetCurrentPresetFont(Annot);
             FontVm.GetCurrentFontFamily(Annot.FontFamily.ToString(), Annot.FontFamily.ToString());
             FontVm.GetFontWeights_Style(Annot.FontStyle, Annot.FontWeight);
 
@@ -665,7 +652,7 @@ namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
             if (IsFillFreeTextAnnot == false)
                 return;
 
-            if(string.IsNullOrEmpty(Annot.TextContent))
+            if (string.IsNullOrEmpty(Annot.TextContent))
             {
                 if (CurrrentDateFormat != null)
                 {
@@ -675,7 +662,6 @@ namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
                     PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.NoteText, CurrrentDateFormat.Content);
                 }
                 return;
-
             }
             DateTime dtDate;
             bool isTime = false;
@@ -703,17 +689,14 @@ namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
                     {
                         string stadate = System.DateTime.Now.ToString(strFormat);
                         item.SetContent(stadate);
-
                     }
 
                     CurrrentDateFormat = new ComboDataItem(item.ValueStr, item.Content);
 
                     break;
-
                 }
             }
 
-
             IsCheckedTime = isTime;
         }
 
@@ -725,19 +708,23 @@ namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
                 case TextAlignment.Left:
                     FontVm.StrTextAlign = "Left";
                     break;
+
                 case TextAlignment.Center:
                     FontVm.StrTextAlign = "Center";
                     break;
+
                 case TextAlignment.Right:
                     FontVm.StrTextAlign = "Right";
                     break;
+
                 case TextAlignment.Justify:
                     FontVm.StrTextAlign = "Justify";
                     break;
+
                 default:
                     FontVm.StrTextAlign = "None";
                     break;
             }
         }
     }
-}
+}

+ 1 - 1
PDF Office/ViewModels/Tools/AnnotManager/AnnotTransfer.cs

@@ -214,7 +214,7 @@ namespace PDF_Master.ViewModels.Tools.AnnotManager
                 }
 
                 AnnotEvent?.UpdateAnnot();
-                this.annot = AnnotEvent.AnnotItemsList[0];
+                //this.annot = AnnotEvent.AnnotItemsList[0];
             }
         }
 

+ 40 - 36
PDF Office/ViewModels/Tools/AnnotToolContentViewModel.Command.cs

@@ -126,6 +126,7 @@ namespace PDF_Master.ViewModels.Tools
             }
             if (e.ClickCount == 2)
             {
+
                 if (CurrentSelectedAnnot != null)
                 {
                     var type = CurrentSelectedAnnot.EventType;
@@ -134,28 +135,23 @@ namespace PDF_Master.ViewModels.Tools
                     {
                         int dpi = DpiHelpers.Dpi;
                         var rect = CurrentSelectedAnnot.ClientRect;
-                        //rect = new Rect(
-                        //    rect.Left / 72D * dpi,
-                        //    rect.Top / 72D * dpi,
-                        //    rect.Width / 72D * dpi,
-                        //    rect.Height / 72D * dpi);
+                        rect = new Rect(
+                            rect.Left * PDFViewer.ZoomFactor,
+                            rect.Top * PDFViewer.ZoomFactor,
+                            rect.Width * PDFViewer.ZoomFactor,
+                            rect.Height * PDFViewer.ZoomFactor);
                         var ui = PDFViewer.Parent as ContentControl;
                         if (ui != null)
                         {
                             var point = e.GetPosition(ui);
+                            int pageIndex = 0;
+                            Point pagePoint = new Point(0, 0);
+                            //Todo:等黎总需要更新ComPDFKit.dll
+                            //PDFViewer.ConvertViewPointToPage(point, out pageIndex, out pagePoint);
+                            if (pagePoint.X >= rect.Left  && pagePoint.X <= rect.Right  && pagePoint.Y >= rect.Top  && pagePoint.Y <= rect.Bottom)
+                                PopAnnotNoteText(CurrentSelectedAnnot);
+
 
-                            double x = point.X / 72D * dpi;
-                            double y = point.Y / 72D * dpi;
-                            point = new Point(x, y);
-                            //if (rect.Contains(point))
-                            //{
-                            PopAnnotNoteText(CurrentSelectedAnnot);
-                            //}
-                            //if (rect.Left <= x && rect.Right >= x && rect.Top <= y && rect.Bottom >= y)
-                            ////if (rect.Left < x && rect.Top > y && (rect.Width + rect.X) >= x && (rect.Height + rect.Y) >= y)
-                            //{
-                            //    PopAnnotNoteText(CurrentSelectedAnnot);
-                            //}
                         }
                     }
 
@@ -164,6 +160,7 @@ namespace PDF_Master.ViewModels.Tools
                         (CurrentSelectedAnnot as StickyAnnotArgs).PopupEditWnd();
                     }
                 }
+
             }
         }
 
@@ -351,6 +348,7 @@ namespace PDF_Master.ViewModels.Tools
         {
             if (e != null)
             {
+               
                 CurrentSelectedAnnot = null;
                 var annot = e.AnnotItemsList[0];
                 if (annot != null)
@@ -1218,25 +1216,7 @@ namespace PDF_Master.ViewModels.Tools
                                         BtnMyTools_Click(btn);
                                         break;
                                     }
-                                    EraseArgs eraseArgs = new EraseArgs();
-                                    eraseArgs.UIBorderColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
-                                    eraseArgs.UIFillColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
-                                    eraseArgs.Thickness = 10;
-                                    DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotErase);
-                                    if (annotProperty != null)
-                                    {
-                                        eraseArgs.Thickness = annotProperty.Thickness;
-                                    }
-
-                                    PDFViewer.ClearSelectAnnots(false);
-                                    PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
-                                    PDFViewer.SetToolParam(eraseArgs);
-
-                                    List<AnnotHandlerEventArgs> eraseArgsList = new List<AnnotHandlerEventArgs>();
-                                    if (eraseArgs != null)
-                                        eraseArgsList.Add(eraseArgs);
-
-                                    AddToPropertyPanel("FreehandAnnotProperty", "Freehand", eraseArgsList);
+                                    CreateEraseArgs();
                                 }
                             }
                             break;
@@ -1257,6 +1237,30 @@ namespace PDF_Master.ViewModels.Tools
             }
         }
 
+
+        private void CreateEraseArgs()
+        {
+            EraseArgs eraseArgs = new EraseArgs();
+            eraseArgs.UIBorderColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
+            eraseArgs.UIFillColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
+            eraseArgs.Thickness = 10;
+            DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotErase);
+            if (annotProperty != null)
+            {
+                eraseArgs.Thickness = annotProperty.Thickness;
+            }
+
+            PDFViewer.ClearSelectAnnots(false);
+            PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
+            PDFViewer.SetToolParam(eraseArgs);
+
+            List<AnnotHandlerEventArgs> eraseArgsList = new List<AnnotHandlerEventArgs>();
+            if (eraseArgs != null)
+                eraseArgsList.Add(eraseArgs);
+
+            AddToPropertyPanel("FreehandAnnotProperty", "Freehand", eraseArgsList);
+        }
+
         #endregion BindingEvent事件
     }
 }

+ 56 - 0
PDF Office/ViewModels/Tools/AnnotToolContentViewModel.Function.cs

@@ -347,6 +347,7 @@ namespace PDF_Master.ViewModels.Tools
                 {
                     selectedArgs = new List<AnnotHandlerEventArgs>();
                     selectedArgs.Add(linkArgs);
+                    CreateAnnotFromSelectPageText(linkArgs);
                 }
             }
             AddToPropertyPanel("LinkAnnotProperty", "Link", selectedArgs, annotAttribEvent);
@@ -693,6 +694,60 @@ namespace PDF_Master.ViewModels.Tools
             }
         }
 
+        //获取选中文字内容的区域大小,以及内容内容所在的页码
+        private Tuple<int, Rect> DrawRectCreateAnnot()
+        {
+            List<TextSelectNode> selectList = PDFViewer.GetSelectTextInfo();
+            Rect clientRect = Rect.Empty;
+            int pageIndex = -1;
+            if (selectList != null && selectList.Count > 0)
+            {
+                pageIndex = selectList[0].PageIndex;
+            }
+
+
+            if (selectList != null && selectList.Count > 0)
+            {
+                foreach (TextSelectNode selectNode in selectList)
+                {
+
+                    foreach (Rect rawRect in selectNode.RawRect)
+                    {
+                        clientRect.Union(rawRect);
+                    }
+                    int dpi = DpiHelpers.Dpi;
+                    if (clientRect.IsEmpty == false)
+                    {
+                        clientRect = new Rect(
+                            clientRect.Left / 72D * dpi,
+                            clientRect.Top / 72D * dpi,
+                            clientRect.Width / 72D * dpi,
+                            clientRect.Height / 72D * dpi);
+                    }
+
+                    break;
+                }
+            }
+
+            if (clientRect != Rect.Empty && pageIndex > -1)
+            {
+                return new Tuple<int, Rect>(pageIndex, clientRect);
+            }
+            return null;
+        }
+
+        //根据选中的文本内容,来创建指定大小的注释。
+        private void CreateAnnotFromSelectPageText(AnnotHandlerEventArgs annotArgs)
+        {
+            //点击注释工具,在阅读页根据选中的文本内容,创建注释矩形大小
+            var drawRectTuple = DrawRectCreateAnnot();
+            if (drawRectTuple != null)
+            {
+                annotArgs.ClientRect = drawRectTuple.Item2;
+                PDFViewer.CreatePageAnnot(drawRectTuple.Item1, annotArgs);
+            }
+        }
+
         //Event导航到填写与签名的属性面板
         private bool NavigatedToFillAndSignVM(List<AnnotHandlerEventArgs> annots, string tag)
         {
@@ -851,6 +906,7 @@ namespace PDF_Master.ViewModels.Tools
                 {
                     selectedArgs = new List<AnnotHandlerEventArgs>();
                     selectedArgs.Add(squareArgs);
+                    CreateAnnotFromSelectPageText(squareArgs);
                 }
             }
             else

+ 23 - 1
PDF Office/ViewModels/Tools/AnnotToolContentViewModel.cs

@@ -59,6 +59,16 @@ namespace PDF_Master.ViewModels.Tools
             InitToolTipDict();
             InitPopMenu();
             SubscribeEvent();
+            AnnotContainerBorderColor();
+        }
+
+        //注释容器选中边框的颜色
+
+        private void AnnotContainerBorderColor()
+        {
+            var pen = new Pen(new SolidColorBrush(Color.FromArgb(0xFF, 0x17, 0x70, 0xF4)), 1);
+            CommonDrawData.ActiveBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0x17, 0x70, 0xF4));
+            CommonDrawData.ActivePen = pen;
         }
 
         //事件聚合器
@@ -1547,6 +1557,13 @@ namespace PDF_Master.ViewModels.Tools
                 if (tuple.Item1 == Key.L)
                     BtnLinkIsChecked = false;
 
+                if(tuple.Item2 == "Eraser")
+                {
+                    CreateEraseArgs();
+                    StrAnnotToolChecked = "Freehand";
+                    return;
+                }
+
                 AnnotHandlerEventArgs annotArgs = null;
                 StrAnnotToolChecked = tuple.Item2;
                 FindAnnotTypeKey(tuple.Item2, ref annotArgs);
@@ -1622,6 +1639,8 @@ namespace PDF_Master.ViewModels.Tools
                     tag = "Arrow";
                 else if (AnnotToolDir[Key.L])
                     tag = "Line";
+                else if(AnnotToolDir[Key.E])
+                    tag = "Eraser";
             }
 
             if (tag == "")
@@ -1658,7 +1677,10 @@ namespace PDF_Master.ViewModels.Tools
             BindingPDFViewerHandler();
             BindingEvent();
             LoaedStickyNotePopup();
-            BtnHandIsChecked = (PDFViewer.MouseMode == MouseModes.Scroll ? true : false);
+            //获取当前是否为滚动状态
+            // BtnHandIsChecked = (PDFViewer.MouseMode == MouseModes.Scroll ? true : false);
+            BtnHandIsChecked = false;
+            HandToolIsCheckedEvent(false);
         }
 
         #endregion Navigation