123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- using System.Collections.Generic;
- using System.IO;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Controls.Primitives;
- using System.Windows.Ink;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- namespace Compdfkit_Tools.PDFControl
- {
- /// <summary>
- /// CPDFSignControl.xaml 的交互逻辑
- /// </summary>
- public partial class FillDigitalSignatureControl : UserControl
- {
- private Dictionary<string,Border> TabDict { get; set; }
- public FillDigitalSignatureControl()
- {
- InitializeComponent();
- TabDict=new Dictionary<string,Border>();
- TabDict["Keyboard"] = KeyboardBorder;
- TabDict["Trackpad"] = TrackpadBorder;
- TabDict["Image"] = ImageBorder;
- TabDict["None"] = NoneBorder;
- SetCheckedTab("Keyboard");
- }
- private void TextAlignBtn_Click(object sender, RoutedEventArgs e)
- {
- ToggleButton checkBtn=sender as ToggleButton;
- if(checkBtn == null)
- {
- return;
- }
- checkBtn.IsChecked = true;
- if(checkBtn!= TextAlignLeftBtn)
- {
- TextAlignLeftBtn.IsChecked= false;
- }
- if (checkBtn != TextAlignRightBtn)
- {
- TextAlignRightBtn.IsChecked = false;
- }
- }
- private void Border_MouseDown(object sender, MouseButtonEventArgs e)
- {
- Border clickBorder = sender as Border;
- if(clickBorder == null || clickBorder.Tag==null)
- {
- return;
- }
- SetCheckedTab(clickBorder.Tag.ToString());
- ImagePickPanel.Visibility = Visibility.Hidden;
- if (clickBorder== TrackpadBorder)
- {
- CanvaDrawPopup.Visibility = Visibility.Visible;
- }
- if(clickBorder== ImageBorder)
- {
- ImagePickPanel.Visibility = Visibility.Visible;
- }
- }
- private void SetCheckedTab(string tab)
- {
- if (TabDict != null && TabDict.ContainsKey(tab))
- {
- foreach (string key in TabDict.Keys)
- {
- Border checkBorder = TabDict[key];
- if(checkBorder == null)
- {
- continue;
- }
- checkBorder.BorderThickness = new Thickness(0);
- if(key==tab)
- {
- checkBorder.BorderThickness = new Thickness(0, 0, 0, 2);
- }
- }
- }
- }
- private void CanvasPopupClose_Click(object sender, RoutedEventArgs e)
- {
- CanvaDrawPopup.Visibility = Visibility.Collapsed;
- }
- private void CanvasClearBtn_Click(object sender, RoutedEventArgs e)
- {
- DrawInkCanvas.Strokes.Clear();
- }
- public void GetDrawInk()
- {
- if (DrawInkCanvas != null && DrawInkCanvas.Strokes != null && DrawInkCanvas.Strokes.Count > 0)
- {
- Rect bound= DrawInkCanvas.Strokes.GetBounds();
- DrawingVisual drawVisual = new DrawingVisual();
- DrawingContext drawContext= drawVisual.RenderOpen();
- foreach (Stroke drawStroke in DrawInkCanvas.Strokes)
- {
- Pen drawPen = new Pen(new SolidColorBrush(drawStroke.DrawingAttributes.Color), drawStroke.DrawingAttributes.Width);
- PathGeometry drawPath = new PathGeometry();
- PathFigureCollection Figures = new PathFigureCollection();
- PathFigure AddFigure = new PathFigure();
- Figures.Add(AddFigure);
- drawPath.Figures = Figures;
- if(drawStroke.StylusPoints.Count>1)
- {
- StylusPoint startPoint= drawStroke.StylusPoints[0];
- AddFigure.StartPoint= new Point(startPoint.X - bound.X, startPoint.Y - bound.Y);
- for (int i = 1;i< drawStroke.StylusPoints.Count;i++)
- {
- StylusPoint drawPoint = drawStroke.StylusPoints[i];
- Point offsetPoint = new Point(drawPoint.X - bound.X, drawPoint.Y - bound.Y);
- LineSegment drawSegment = new LineSegment();
- drawSegment.Point = offsetPoint;
- AddFigure.Segments.Add(drawSegment);
- }
- }
- if(AddFigure.Segments.Count > 0)
- {
- drawContext.DrawGeometry(null, drawPen, drawPath);
- }
- }
- drawContext.Close();
- RenderTargetBitmap renderBitmap=new RenderTargetBitmap((int)bound.Width,(int)bound.Height,96,96,PixelFormats.Pbgra32);
- renderBitmap.Render(drawVisual);
- }
- }
- private void ReasonCheckBox_Click(object sender, RoutedEventArgs e)
- {
- CheckBox checkItem = sender as CheckBox;
- if (checkItem == null)
- {
- return;
- }
- ReasonPanel.Visibility=checkItem.IsChecked==true? Visibility.Visible: Visibility.Collapsed;
- }
- }
- }
|