using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
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
{
///
/// CPDFFontStyleUI.xaml 的交互逻辑
///
public partial class CPDFTextStyleUI : UserControl
{
public event EventHandler TextFontChanged;
public event EventHandler TextBoldChanged;
public event EventHandler TextItalicChanged;
public event EventHandler TextSizeChanged;
public CPDFTextStyleUI()
{
InitializeComponent();
}
public void SetFontNames(List fontNames)
{
FontNameComboBox.ItemsSource = null;
if (fontNames != null && fontNames.Count > 0)
{
List fontNameList = new List();
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 fontNameList = FontNameComboBox.ItemsSource as List;
if (fontNameList != null && fontNameList.Count>0)
{
int selectIndex = -1;
for(int i=0;i 0)
{
FontSizeTextBox.Text = (newFontSize).ToString("F2");
}
else
{
FontSizeTextBox.Text = ((int)(newFontSize)).ToString();
}
}
}
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 FontStyleBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
int selectIndex = Math.Max(0, FontStyleBox.SelectedIndex);
switch(selectIndex)
{
case 0:
TextBoldChanged?.Invoke(this,false);
TextItalicChanged?.Invoke(this, false);
break;
case 1:
TextBoldChanged?.Invoke(this, true);
TextItalicChanged?.Invoke(this, false);
break;
case 2:
TextBoldChanged?.Invoke(this, false);
TextItalicChanged?.Invoke(this, true);
break;
case 3:
TextBoldChanged?.Invoke(this, true);
TextItalicChanged?.Invoke(this, true);
break;
default:
break;
}
}
private void FontSizeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ComboBoxItem selectItem = FontSizeComboBox.SelectedItem as ComboBoxItem;
if (selectItem != null && selectItem.Content != null)
{
if (int.TryParse(selectItem.Content.ToString(), out int newFontSize))
{
FontSizeTextBox.Text = (newFontSize).ToString();
TextSizeChanged?.Invoke(this, newFontSize);
}
}
}
}
}