123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace compdfkit_tools.Edit
- {
- /// <summary>
- /// CPDFFontStyleUI.xaml 的交互逻辑
- /// </summary>
- public partial class CPDFTextStyleUI : UserControl
- {
- public event EventHandler<string> TextFontChanged;
- public event EventHandler<bool> TextBoldChanged;
- public event EventHandler<bool> TextItalicChanged;
- public CPDFTextStyleUI()
- {
- InitializeComponent();
- }
- public Orientation Orientation
- {
- get
- {
- return TextStyleUI.Orientation;
- }
- set
- {
- TextStyleUI.Orientation = value;
- }
- }
- public void SetFontNames(List<string> fontNames)
- {
- FontNameComboBox.Items?.Clear();
- if (fontNames != null && fontNames.Count > 0)
- {
- List<ComboBoxItem> fontNameList = new List<ComboBoxItem>();
- foreach (string fontName in fontNames)
- {
- fontNameList.Add(new ComboBoxItem()
- {
- Content = fontName
- });
- }
- FontNameComboBox.ItemsSource = fontNameList;
- }
- }
- public void SelectFontName(string fontName)
- {
- if(string.IsNullOrEmpty(fontName))
- {
- return;
- }
- List<ComboBoxItem> fontNameList = FontNameComboBox.ItemsSource as List<ComboBoxItem>;
- if (fontNameList != null && fontNameList.Count>0)
- {
- int selectIndex = -1;
- for(int i=0;i<fontNameList.Count; i++)
- {
- ComboBoxItem checkItem= fontNameList[i];
- if(checkItem.Content!=null && checkItem.Content.ToString().ToLower()==fontName.ToLower() )
- {
- selectIndex=i;
- break;
- }
- }
- FontNameComboBox.SelectedIndex = selectIndex;
- }
- }
- public void SetFontBold(bool isBold)
- {
- FontBoldBtn.IsChecked = isBold;
- }
- public void SetFontItalic(bool isItalic)
- {
- FontItalicBtn.IsChecked= isItalic;
- }
- private void FontNameComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if(FontNameComboBox.SelectedIndex==-1)
- {
- TextFontChanged?.Invoke(this,string.Empty);
- return;
- }
- ComboBoxItem selectItem= FontNameComboBox.SelectedItem as ComboBoxItem;
- if(selectItem != null && selectItem.Content != null)
- {
- TextFontChanged?.Invoke(this, selectItem.Content.ToString());
- }
- }
- private void FontBoldBtn_CheckChanged(object sender, RoutedEventArgs e)
- {
- TextBoldChanged?.Invoke(this, FontBoldBtn.IsChecked==true);
- }
- private void FontItalicBtn_CheckChanged(object sender, RoutedEventArgs e)
- {
- TextItalicChanged?.Invoke(this, FontItalicBtn.IsChecked == true);
- }
- }
- }
|