Przeglądaj źródła

编辑-字体库 排序 ;UX优化

OYXH\oyxh 1 rok temu
rodzic
commit
f8875b5cee

+ 49 - 10
PDF Office/Helper/EditHelper.cs

@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using System.Globalization;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -8,6 +9,27 @@ namespace PDF_Master.Helper
 {
     public static class EditHelper
     {
+        /// <summary>
+        /// 字体更改失效:
+        ///MT Extra
+        ///Symbol
+        ///HoloLens MDL2 Assets
+        ///Wingdings
+        ///Wingdings 2
+        ///Wingdings 3
+        ///Webdings
+        ///ZWAdobeF
+        ///Algerian
+        ///Bookshelf Symbol 7
+        ///Castellar
+        ///Marlett
+        ///MS Outlook(adobe、万兴没效果)
+        ///MS Reference Specialty
+        ///Segoe Fluent Icons(adobe、万兴没效果)
+        ///Segoe MDL2 Assets(adobe、万兴没效果)
+        ///Stencil
+        /// 未选择 文本时候,暂时注释SDK 目前没有效果的字体
+        /// </summary>
         public static List<string> FontFamily { get; set; } = new List<string>
 {
     "Adobe Devanagari",
@@ -42,7 +64,7 @@ namespace PDF_Master.Helper
     "Gabriola",
     "Gadugi",
     "Georgia",
-    "HoloLens MDL2 Assets",
+    //"HoloLens MDL2 Assets",
     "Impact",
     "Indie Flower",
     "Ink Free",
@@ -55,11 +77,11 @@ namespace PDF_Master.Helper
     "MS Gothic",
     "MS PGothic",
     "MS UI Gothic",
-    "MT Extra",
+    //"MT Extra",
     "MV Boli",
     "Malgun Gothic",
     "Malgun Gothic Semilight",
-    "Marlett",
+    //"Marlett",
     "Microsoft Himalaya",
     "Microsoft JhengHei",
     "Microsoft JhengHei UI",
@@ -84,8 +106,8 @@ namespace PDF_Master.Helper
     "Roboto Condensed",
     "Roboto Slab",
     "Sans Serif Collection",
-    "Segoe Fluent Icons",
-    "Segoe MDL2 Assets",
+    //"Segoe Fluent Icons",
+    //"Segoe MDL2 Assets",
     "Segoe Print",
     "Segoe Script",
     "Segoe UI",
@@ -105,17 +127,17 @@ namespace PDF_Master.Helper
     "Sitka Subheading",
     "Sitka Text",
     "Sylfaen",
-    "Symbol",
+    //"Symbol",
     "Tahoma",
     "Times New",
     "Trebuchet MS",
     "Verdana",
-    "Webdings",
-    "Wingdings",
+    //"Webdings",
+    //"Wingdings",
     "Yu Gothic",
     "Yu Gothic UI",
     "Yu Gothic UI Semilight",
-    "ZWAdobeF",
+    //"ZWAdobeF",
     "等线",
     "仿宋",
     "黑体",
@@ -123,5 +145,22 @@ namespace PDF_Master.Helper
     "宋体",
     "微软雅黑"
 };
+
+        public static List<string> GetFontFamily()
+        {
+            var sortedStrings = FontFamily.OrderBy(item => IsChinese(item)).ThenBy(item => item).ToList();
+
+            return sortedStrings.ToList();
+        }
+
+        private static bool IsChinese(string str)
+        {
+            foreach (char c in str)
+            {
+                if (c >= 0x4E00 && c <= 0x9FFF)
+                    return true;
+            }
+            return false;
+        }
     }
-}
+}

+ 20 - 24
PDF Office/Model/AnnotPanel/FontBoard.cs

@@ -7,6 +7,7 @@ using Prism.Mvvm;
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
+using System.Diagnostics;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -45,13 +46,13 @@ namespace PDF_Master.Model.AnnotPanel
                 SetProperty(ref _fontFamilyItems, value);
             }
         }
+
         public List<ComboDataItem> FontStyleItems { get; protected set; }
         public List<ComboDataItem> FontSizeItems { get; protected set; }
         public List<ComboDataItem> PresetFontItems { get; protected set; }
 
         public List<PresetFontItem> PresetFontList = new List<PresetFontItem>();
 
-
         #endregion 变量
 
         #region 初始化下拉框或列表默认的数据
@@ -63,6 +64,7 @@ namespace PDF_Master.Model.AnnotPanel
             InitBase_FontStyles();
             InitBase_FontSize();
         }
+
         //预设字体大小
         private void InitBase_FontSize()
         {
@@ -84,7 +86,7 @@ namespace PDF_Master.Model.AnnotPanel
 
         //字体
         public void InitBase_FontFamilys()
-        { 
+        {
             FontFamilyItems = TextFont.GetFamilyEdit();
         }
 
@@ -111,7 +113,6 @@ namespace PDF_Master.Model.AnnotPanel
         /// 预设样式
         /// </summary>
 
-
         private int presetFontSelectedIndex;
 
         public int PresetFontSelectedIndex
@@ -122,7 +123,8 @@ namespace PDF_Master.Model.AnnotPanel
                 SetProperty(ref presetFontSelectedIndex, value);
             }
         }
-        private ComboDataItem _currentPresetFont=new ComboDataItem("Custom", "Custom");
+
+        private ComboDataItem _currentPresetFont = new ComboDataItem("Custom", "Custom");
 
         public ComboDataItem CurrentPresetFont
         {
@@ -187,28 +189,27 @@ namespace PDF_Master.Model.AnnotPanel
                 SetProperty(ref _currentFontFamily, value);
                 if (isChange)
                 {
-                    string str= _currentFontFamily.Content;
-                    if (_currentFontFamily.Content== "Times New Roman")
+                    string str = _currentFontFamily.Content;
+                    if (_currentFontFamily.Content == "Times New Roman")
                     {
                         str = "Times-Roman";
                     }
                     ChangedValue?.Invoke(str, FontSetModeType.FontFamilys);
-
                 }
                 SetProperty(ref _currentFontFamily, value);
                 if (value.Content != null)
                 {
-                    FontFamilySelectedIndex=FontFamilyItems.IndexOf(value);
+                    int index = FontFamilyItems.FindIndex(item => item.Content == value.Content);
+                    FontFamilySelectedIndex = index;
+                    Trace.WriteLine(index);
                 }
                 else
                 {
                     FontFamilySelectedIndex = 0;
                 }
-                
             }
         }
 
-
         private int fontFamilySelectedIndex = -1;
 
         public int FontFamilySelectedIndex
@@ -217,9 +218,9 @@ namespace PDF_Master.Model.AnnotPanel
             set
             {
                 SetProperty(ref fontFamilySelectedIndex, value);
-
             }
         }
+
         #endregion 字体样式
 
         #region 字体大小
@@ -234,6 +235,7 @@ namespace PDF_Master.Model.AnnotPanel
                 SetProperty(ref fontSizeSelectedIndex, value);
             }
         }
+
         //下拉框列表:字体大小
         private ComboDataItem _currentFontSize = new ComboDataItem(6);
 
@@ -319,11 +321,8 @@ namespace PDF_Master.Model.AnnotPanel
                         //FontSizeSelectedIndex = 0;
                         //FontSizeSelectedIndex = -1;
                         break;
-
                 }
-               
             }
-
         }
 
         #endregion 字体大小
@@ -356,12 +355,13 @@ namespace PDF_Master.Model.AnnotPanel
                 SetProperty(ref fontStyleSelectedIndex, value);
             }
         }
+
         private ComboDataItem _currrentFontWeightStyle = new ComboDataItem("Regular", "Regular");
+
         public ComboDataItem CurrrentFontWeightStyle
         {
             get { return _currrentFontWeightStyle; }
 
-
             set
             {
                 bool isChange = IsEqualStrComboData(_currrentFontWeightStyle, value);
@@ -389,11 +389,7 @@ namespace PDF_Master.Model.AnnotPanel
                         FontStyleSelectedIndex = 3;
                         break;
                 }
-
-
             }
-
-
         }
 
         protected void UpdateFontWeight_Style()
@@ -539,6 +535,7 @@ namespace PDF_Master.Model.AnnotPanel
                 uiStr = "Times New Roman";
             }
             //WPF的UI字体不包含Helvetica
+
             if (fontFamily == "Helvetica")
             {
                 fontFamily = "Arial";
@@ -550,8 +547,6 @@ namespace PDF_Master.Model.AnnotPanel
         #endregion 列表选中赋值
     }
 
-
-
     //设置字体大小、字体内容排版、字体颜色、字体样式、字重
     public class FontBoardVm : BindableBase
     {
@@ -699,6 +694,7 @@ namespace PDF_Master.Model.AnnotPanel
                     case "Times New Roman":
                         FontFamilySelectedIndex = 2;
                         break;
+
                     case "Adobe Devanagari":
                         FontFamilySelectedIndex = 3;
                         break;
@@ -1013,9 +1009,9 @@ namespace PDF_Master.Model.AnnotPanel
             //List<PresetFontItem> presetFontItems = TextFont.GetCachePresetFontList();
             foreach (var item in PresetFontList)
             {
-                if (annot.FontSize == item.mFontSize && annot.IsBold == (item.mFontWeight==FontWeights.Bold) && annot.IsItalic == (item.mFontStyle==FontStyles.Italic)
-                    && (annot.FontName == item.mFontFamily.Source || annot.FontName == "Arial" && item.mFontFamily.Source == "Arial")
-                    )
+                if (annot.FontSize == item.mFontSize && annot.IsBold == (item.mFontWeight == FontWeights.Bold) && annot.IsItalic == (item.mFontStyle == FontStyles.Italic)
+                && (annot.FontName == item.mFontFamily.Source || annot.FontName == "Arial" && item.mFontFamily.Source == "Helvetica")
+                )
                 {
                     if (item.mTag != "Custom")
                     {

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

@@ -5,6 +5,7 @@ using PDF_Master.Properties;
 using PDFSettings;
 using System;
 using System.Collections.Generic;
+using System.Globalization;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -335,7 +336,6 @@ namespace PDF_Master.Model.PropertyPanel.AnnotPanel
             return FontSizeItems;
         }
 
-
         public static List<ComboDataItem> GetFamily()
         {
             var FontFamilyItems = new List<ComboDataItem>();
@@ -345,8 +345,7 @@ namespace PDF_Master.Model.PropertyPanel.AnnotPanel
             FontFamilyItems.Add(item);
             item = new ComboDataItem(/*"Times-Roman"*/"Times", "Times New Roman");
             FontFamilyItems.Add(item);
-            return FontFamilyItems;
-
+            return FontFamilyItems;
         }
 
         public static List<ComboDataItem> GetFamilyEdit()
@@ -354,19 +353,23 @@ namespace PDF_Master.Model.PropertyPanel.AnnotPanel
             System.Drawing.Text.InstalledFontCollection objFont = new System.Drawing.Text.InstalledFontCollection();
             var FontFamilyItems = new List<ComboDataItem>();
             ComboDataItem item;
-            foreach (var itemFam in EditHelper.FontFamily)
-            {
-                item = new ComboDataItem(DeleteCharacters(itemFam),itemFam);
-                FontFamilyItems.Add(item);
 
+            foreach (var itemFam in EditHelper.GetFontFamily())
+            {
+                string content = itemFam;
+                if (itemFam.Equals("Informal"))
+                {
+                    content = "Informal Roman";
+                }
+                item = new ComboDataItem(DeleteCharacters(itemFam), content);
+                FontFamilyItems.Add(item);
             }
-            return FontFamilyItems;
-
-        }
-
+            return FontFamilyItems;
+        }
+
         public static string DeleteCharacters(string str)
         {
-            str=str.Replace(" ", string.Empty);
+            str = str.Replace(" ", string.Empty);
             str = str.Replace("-", string.Empty);
             str = str.Replace("_", string.Empty);
             return str;

+ 53 - 45
PDF Office/ViewModels/PropertyPanel/PDFEdit/TextEditPropertyViewModel.cs

@@ -14,6 +14,7 @@ using Prism.Mvvm;
 using Prism.Regions;
 using System;
 using System.Collections.Generic;
+using System.Diagnostics;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -21,6 +22,7 @@ using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Input;
 using System.Windows.Media;
+using static Dropbox.Api.Files.WriteMode;
 
 namespace PDF_Master.ViewModels.PropertyPanel.PDFEdit
 {
@@ -237,26 +239,16 @@ namespace PDF_Master.ViewModels.PropertyPanel.PDFEdit
                         {
                             if (CurrentFontFamily.ValueStr != item.mFontFamily.Source)
                             {
-                                string txt = string.Format($" * {currentItem.mTagContent}");
-
-                                if (Title == txt)
+                                if (noAddAnAsterisk(currentItem, item) == false)
                                 {
-                                    Title = "";
+                                    break;
                                 }
-                                Title = txt;
-                                break;
                             }
                             else
                             {
-                                if (FontWeightItem == item.mFontWeight && FontStyleItem == item.mFontStyle && CurrentFontSize.Value == item.mFontSize && CurrentFontFamily.ValueStr == item.mFontFamily.Source)
+                                if (noAddAnAsterisk(currentItem, item) == false)
                                 {
-                                    string txt = currentItem.mTagContent;
-
-                                    if (Title == txt)
-                                    {
-                                        Title = "";
-                                    }
-                                    Title = txt;
+                                    break;
                                 }
                             }
                         }
@@ -265,6 +257,37 @@ namespace PDF_Master.ViewModels.PropertyPanel.PDFEdit
             }
         }
 
+        private bool noAddAnAsterisk(PresetFontItem currentItem, PresetFontItem item)
+        {
+            if (FontWeightItem == item.mFontWeight && FontStyleItem == item.mFontStyle && CurrentFontSize.Value == item.mFontSize && (CurrentFontFamily.ValueStr == item.mFontFamily.Source || (CurrentFontFamily.ValueStr == "Arial" && item.mFontFamily.Source == "Helvetica")))
+            {
+                string txt = currentItem.mTagContent;
+
+                if (Title == txt)
+                {
+                    Title = "";
+                }
+                Title = txt;
+                return true;
+            }
+            else
+            {
+                addAnAsterisk(currentItem);
+                return false;
+            }
+        }
+
+        private void addAnAsterisk(PresetFontItem currentItem)
+        {
+            string txt = string.Format($" * {currentItem.mTagContent}");
+
+            if (Title == txt)
+            {
+                Title = "";
+            }
+            Title = txt;
+        }
+
         /// <summary>
         /// 设置文本字重、样式
         /// </summary>
@@ -658,15 +681,15 @@ namespace PDF_Master.ViewModels.PropertyPanel.PDFEdit
             navigationContext.Parameters.TryGetValue<List<PDFEditEvent>>(ParameterNames.AnnotEvent, out TextEditEventList);
             if (PDFViewer != null)
             {
-               
+
                 if (TextEditEventList != null && TextEditEventList.Count > 0)
                 {
                     TextEditEvent = TextEditEventList[0];
-                    if(TextEditEvent.FontName!=""&& TextEditEvent.FontName !=null)
+                    if (TextEditEvent.FontName != "" && TextEditEvent.FontName != null)
                     {
                         GetPDFEdit();
                     }
-                    
+
                     if (TextEditEventList.Count > 1)
                         IsSelectedEmpty = true;
                     else
@@ -688,39 +711,24 @@ namespace PDF_Master.ViewModels.PropertyPanel.PDFEdit
                         IsLayoutAvgAlign = false;
                     }
                 }
-                else if(TextEditEventList==null|| TextEditEvent.FontName == null|| TextEditEvent.FontName == "")
+                else if (TextEditEventList == null || TextEditEvent.FontName == null || TextEditEvent.FontName == "")
                 {
                     var defaultlists = TextFont.GetPresetFontStyle();
-
-                        //var defaulItem = defaultlists.FirstOrDefault(temp => temp.mTag == CurrentPresetFont.ValueStr);
-                        //if (defaulItem != null)
-                        //{
-                            var currentItem = PresetFontList.FirstOrDefault(temp => temp.mTag == "Custom");
-                            if (currentItem != null)
-                            {
-                           
-
-                                //currentItem.mTagContent = defaulItem.mTagContent;
-                                //currentItem.mFontStyle = defaulItem.mFontStyle;
-                                //currentItem.mFontWeight = defaulItem.mFontWeight;
-                                //currentItem.mFontFamily = defaulItem.mFontFamily;
-                                //currentItem.mFontSize = defaulItem.mFontSize;
-                                GetCurrentFontFamily(currentItem.mFontFamily.ToString(), currentItem.mFontFamily.ToString());
-                                GetCurrentFontSize(currentItem.mFontSize);
-                                GetFontWeights_Style(currentItem.mFontStyle, currentItem.mFontWeight);                           
-                                SelectedPresetFont();
-
-                            SelectColor = new SolidColorBrush(Colors.Black);
-                            CurrentFontSize = new ComboDataItem(currentItem.mFontSize);
+                    var currentItem = PresetFontList.FirstOrDefault(temp => temp.mTag == "Custom");
+                    if (currentItem != null)
+                    {
+                        SelectColor = new SolidColorBrush(Colors.Black);
+                        CurrentFontSize = new ComboDataItem(currentItem.mFontSize);
                         CurrentPresetFont = new ComboDataItem(currentItem.mTag, currentItem.mTagContent);
                         CurrentFontFamily = new ComboDataItem(currentItem.mFontFamily.ToString(), currentItem.mFontFamily.ToString());
-                            FontStyleItem = FontStyles.Normal;
-                            FontWeightItem = FontWeights.Normal;
-                            
-                        //}
-                        
-                    }
+                        FontStyleItem = FontStyles.Normal;
+                        FontWeightItem = FontWeights.Normal;
 
+                        GetCurrentFontFamily(currentItem.mFontFamily.ToString(), currentItem.mFontFamily.ToString());
+                        GetCurrentFontSize(currentItem.mFontSize);
+                        GetFontWeights_Style(currentItem.mFontStyle, currentItem.mFontWeight);
+                        SelectedPresetFont();
+                    }
                 }
 
                 PDFViewer.PDFEditCommandHandler -= PDFViewer_PDFEditCommandHandler;