|
@@ -20,11 +20,15 @@ using ComPDFKit.Tool.UndoManger;
|
|
|
using ComPDFKitViewer.Helper;
|
|
|
using static ComPDFKit.PDFAnnotation.CTextAttribute.CFontNameHelper;
|
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Button;
|
|
|
+using System.Linq;
|
|
|
|
|
|
namespace Compdfkit_Tools.PDFControl
|
|
|
{
|
|
|
public partial class PushButtonProperty : UserControl,INotifyPropertyChanged
|
|
|
{
|
|
|
+ public bool isFontStyleCmbClicked;
|
|
|
+ public bool isFontCmbClicked;
|
|
|
+
|
|
|
private PushButtonParam widgetParam = null;
|
|
|
private CPDFPushButtonWidget cPDFAnnotation = null;
|
|
|
private PDFViewControl pdfViewerControl = null;
|
|
@@ -48,8 +52,8 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
DataContext = this;
|
|
|
}
|
|
|
|
|
|
- #region Loaded
|
|
|
|
|
|
+ #region Loaded
|
|
|
public void SetProperty(AnnotParam annotParam, CPDFAnnotation annotation, CPDFDocument doc, PDFViewControl cPDFViewer)
|
|
|
{
|
|
|
widgetParam = (PushButtonParam)annotParam;
|
|
@@ -65,18 +69,28 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
SizeListbinding.Path = new System.Windows.PropertyPath("SizeList");
|
|
|
FontSizeCmb.SetBinding(ComboBox.ItemsSourceProperty, SizeListbinding);
|
|
|
|
|
|
- TopTabControl.SelectedIndex = 2;
|
|
|
- FieldNameText.Text = widgetParam.FieldName;
|
|
|
+ TopTabControl.SelectedIndex = 2;
|
|
|
+
|
|
|
FormFieldCmb.SelectedIndex = (int)ParamConverter.ConverterWidgetFormFlags(widgetParam.Flags, widgetParam.IsHidden);
|
|
|
BorderColorPickerControl.SetCheckedForColor(ParamConverter.ConverterByteForColor(widgetParam.LineColor));
|
|
|
BackgroundColorPickerControl.SetCheckedForColor(ParamConverter.ConverterByteForColor(widgetParam.BgColor));
|
|
|
TextColorPickerControl.SetCheckedForColor(ParamConverter.ConverterByteForColor(widgetParam.FontColor));
|
|
|
- SetFontName(widgetParam.FontName);
|
|
|
- SetFontStyle(widgetParam.IsItalic, widgetParam.IsBold);
|
|
|
+
|
|
|
+ string familyName = string.Empty;
|
|
|
+ string styleName = string.Empty;
|
|
|
+
|
|
|
+ CPDFFont.GetFamlyStyleName(widgetParam.FontName,ref familyName,ref styleName);
|
|
|
+
|
|
|
+ FontCmb.ItemsSource = CPDFFont.GetFontNameDictionary().Keys.ToList();
|
|
|
+
|
|
|
+ SetFontName(familyName);
|
|
|
+ SetFontStyle(styleName);
|
|
|
SetFontSize(widgetParam.FontSize);
|
|
|
+
|
|
|
ItemText.Text = widgetParam.Text;
|
|
|
SetActionContext();
|
|
|
IsLoadedData = true;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private void UserControl_Unloaded(object sender, RoutedEventArgs e)
|
|
@@ -130,19 +144,17 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
|
|
|
private void SetFontName(string fontName)
|
|
|
{
|
|
|
- int index = -1;
|
|
|
- List<string> fontFamilyList = new List<string>() { "Helvetica", "Courier", "Times" };
|
|
|
- for (int i = 0; i < fontFamilyList.Count; i++)
|
|
|
+ FontCmb.SelectedValue = fontName;
|
|
|
+ if (FontCmb.SelectedValue != null)
|
|
|
{
|
|
|
- if (fontFamilyList[i].ToLower().Contains(fontName.ToLower())
|
|
|
- || fontName.ToLower().Contains(fontFamilyList[i].ToLower()))
|
|
|
- {
|
|
|
- index = i;
|
|
|
- }
|
|
|
+ FontStyleCmb.ItemsSource = CPDFFont.GetFontNameDictionary()[FontCmb.SelectedValue.ToString()];
|
|
|
}
|
|
|
- FontCmb.SelectedIndex = index;
|
|
|
}
|
|
|
|
|
|
+ private void SetFontStyle(string fontStyle)
|
|
|
+ {
|
|
|
+ FontStyleCmb.SelectedValue = fontStyle;
|
|
|
+ }
|
|
|
#endregion
|
|
|
|
|
|
#region Updata
|
|
@@ -254,22 +266,32 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
{
|
|
|
if (IsLoadedData)
|
|
|
{
|
|
|
- PushButtonHistory history = new PushButtonHistory();
|
|
|
- history.Action = HistoryAction.Update;
|
|
|
- history.PDFDoc = pdfViewerControl.GetCPDFViewer().GetDocument();
|
|
|
- history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
|
|
|
-
|
|
|
- CTextAttribute cTextAttribute = cPDFAnnotation.GetTextAttribute();
|
|
|
- bool isBold = IsBold(cTextAttribute.FontName);
|
|
|
- bool isItalic = IsItalic(cTextAttribute.FontName);
|
|
|
- FontType fontType = GetFontType((sender as ComboBox).SelectedItem?.ToString());
|
|
|
- cTextAttribute.FontName = ObtainFontName(fontType, isBold, isItalic);
|
|
|
- cPDFAnnotation.SetTextAttribute(cTextAttribute);
|
|
|
- cPDFAnnotation.UpdateFormAp();
|
|
|
- pdfViewerControl.UpdateAnnotFrame();
|
|
|
-
|
|
|
- history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
|
|
|
- pdfViewerControl.GetCPDFViewer().UndoManager.AddHistory(history);
|
|
|
+ if (isFontCmbClicked)
|
|
|
+ {
|
|
|
+ FontStyleCmb.ItemsSource = CPDFFont.GetFontNameDictionary()[FontCmb.SelectedValue.ToString()];
|
|
|
+ FontStyleCmb.SelectedIndex = 0;
|
|
|
+
|
|
|
+ PushButtonHistory history = new PushButtonHistory();
|
|
|
+ history.Action = HistoryAction.Update;
|
|
|
+ history.PDFDoc = pdfViewerControl.GetCPDFViewer().GetDocument();
|
|
|
+ history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
|
|
|
+
|
|
|
+ CTextAttribute cTextAttribute = cPDFAnnotation.GetTextAttribute();
|
|
|
+ string psFontName = string.Empty;
|
|
|
+ CPDFFont.GetPostScriptName(FontCmb.SelectedValue.ToString(), FontStyleCmb.SelectedValue.ToString(), ref psFontName);
|
|
|
+ cTextAttribute.FontName = psFontName;
|
|
|
+ cPDFAnnotation.SetTextAttribute(cTextAttribute);
|
|
|
+ cPDFAnnotation.UpdateFormAp();
|
|
|
+ pdfViewerControl.UpdateAnnotFrame();
|
|
|
+
|
|
|
+ history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
|
|
|
+ pdfViewerControl.GetCPDFViewer().UndoManager.AddHistory(history);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ FontStyleCmb.ItemsSource = CPDFFont.GetFontNameDictionary()[FontCmb.SelectedValue.ToString()];
|
|
|
+ }
|
|
|
+ isFontCmbClicked = false;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -277,42 +299,25 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
{
|
|
|
if (IsLoadedData)
|
|
|
{
|
|
|
- PushButtonHistory history = new PushButtonHistory();
|
|
|
- history.Action = HistoryAction.Update;
|
|
|
- history.PDFDoc = pdfViewerControl.GetCPDFViewer().GetDocument();
|
|
|
- history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
|
|
|
-
|
|
|
- CTextAttribute cTextAttribute = cPDFAnnotation.GetTextAttribute();
|
|
|
- bool isItalic = false;
|
|
|
- bool isBold = false;
|
|
|
- switch ((sender as ComboBox).SelectedIndex)
|
|
|
+ if (isFontStyleCmbClicked)
|
|
|
{
|
|
|
- case 0:
|
|
|
- break;
|
|
|
- case 1:
|
|
|
- isItalic = IsItalic(cTextAttribute.FontName);
|
|
|
- isBold = true;
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- isItalic = true;
|
|
|
- isBold = IsBold(cTextAttribute.FontName);
|
|
|
- break;
|
|
|
- case 3:
|
|
|
- isItalic = true;
|
|
|
- isBold = true;
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
+ PushButtonHistory history = new PushButtonHistory();
|
|
|
+ history.Action = HistoryAction.Update;
|
|
|
+ history.PDFDoc = pdfViewerControl.GetCPDFViewer().GetDocument();
|
|
|
+ history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
|
|
|
+
|
|
|
+ CTextAttribute cTextAttribute = cPDFAnnotation.GetTextAttribute();
|
|
|
+ string psFontName = string.Empty;
|
|
|
+ CPDFFont.GetPostScriptName(FontCmb.SelectedValue.ToString(), FontStyleCmb.SelectedValue.ToString(), ref psFontName);
|
|
|
+ cTextAttribute.FontName = psFontName;
|
|
|
+ cPDFAnnotation.SetTextAttribute(cTextAttribute);
|
|
|
+ cPDFAnnotation.UpdateFormAp();
|
|
|
+ pdfViewerControl.UpdateAnnotFrame();
|
|
|
+
|
|
|
+ history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
|
|
|
+ pdfViewerControl.GetCPDFViewer().UndoManager.AddHistory(history);
|
|
|
}
|
|
|
-
|
|
|
- FontType fontType = GetFontType(cTextAttribute.FontName);
|
|
|
- cTextAttribute.FontName = ObtainFontName(fontType, isBold, isItalic);
|
|
|
- cPDFAnnotation.SetTextAttribute(cTextAttribute);
|
|
|
- cPDFAnnotation.UpdateFormAp();
|
|
|
- pdfViewerControl.UpdateAnnotFrame();
|
|
|
-
|
|
|
- history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
|
|
|
- pdfViewerControl.GetCPDFViewer().UndoManager.AddHistory(history);
|
|
|
+ isFontStyleCmbClicked = false;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -467,5 +472,21 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
OnPropertyChanged(propertyName);
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ private void FontCmb_PreviewMouseDown(object sender, MouseButtonEventArgs e)
|
|
|
+ {
|
|
|
+ if (e.LeftButton == MouseButtonState.Pressed && sender is ComboBox)
|
|
|
+ {
|
|
|
+ isFontCmbClicked = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void FontStyleCmb_PreviewMouseDown(object sender, MouseButtonEventArgs e)
|
|
|
+ {
|
|
|
+ if (e.LeftButton == MouseButtonState.Pressed && sender is ComboBox)
|
|
|
+ {
|
|
|
+ isFontStyleCmbClicked = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|