123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554 |
- using ComPDFKit.PDFAnnotation;
- using ComPDFKit.Tool;
- using Compdfkit_Tools.Common;
- using Compdfkit_Tools.Data;
- using Compdfkit_Tools.PDFControl;
- using ComPDFKitViewer;
- using ComPDFKitViewer.Annot;
- using System;
- using System.Collections.Generic;
- using System.IO.Ports;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media;
- namespace Compdfkit_Tools.PDFControlUI
- {
- public partial class CPDFShapeUI : UserControl
- {
- private CPDFAnnotationType currentAnnotationType;
- private AnnotParam annotParam;
- private CPDFAnnotation annotCore;
- private PDFViewControl viewControl;
- public event EventHandler<CPDFAnnotationData> PropertyChanged;
- public CPDFShapeUI()
- {
- InitializeComponent();
- BorderColorPickerControl.ColorChanged += BorderColorPickerControl_ColorChanged;
- CPDFOpacityControl.OpacityChanged += CPDFOpacityControl_OpacityChanged;
- CPDFThicknessControl.ThicknessChanged += CPDFThicknessControl_ThicknessChanged;
- CPDFLineStyleControl.LineStyleChanged += CPDFLineStyleControl_LineStyleChanged;
- CPDFAnnotationPreviewerControl.DrawShapePreview(GetShapeData());
- }
- private void BorderColorPickerControl_ColorChanged(object sender, EventArgs e)
- {
- if (annotParam == null)
- {
- PropertyChanged?.Invoke(this, GetShapeData());
- }
- else
- {
- SolidColorBrush borderBrush=BorderColorPickerControl.Brush as SolidColorBrush;
- if(annotCore!=null && annotCore.IsValid() && borderBrush!=null)
- {
- if(annotCore.Type==C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE)
- {
- CPDFSquareAnnotation squareAnnot = annotCore as CPDFSquareAnnotation;
- squareAnnot?.SetLineColor(new byte[3]
- {
- borderBrush.Color.R,
- borderBrush.Color.G,
- borderBrush.Color.B
- });
- }
-
- if(annotCore.Type==C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE)
- {
- CPDFCircleAnnotation circleAnnot= annotCore as CPDFCircleAnnotation;
- circleAnnot?.SetLineColor(new byte[3]
- {
- borderBrush.Color.R,
- borderBrush.Color.G,
- borderBrush.Color.B
- });
- }
- if(annotCore.Type==C_ANNOTATION_TYPE.C_ANNOTATION_LINE)
- {
- CPDFLineAnnotation lineAnnot = annotCore as CPDFLineAnnotation;
- lineAnnot?.SetLineColor(new byte[3]
- {
- borderBrush.Color.R,
- borderBrush.Color.G,
- borderBrush.Color.B
- });
- }
- if (viewControl != null && viewControl.PDFViewTool != null)
- {
- CPDFViewer pdfViewer = viewControl.PDFViewTool.GetCPDFViewer();
- pdfViewer?.UpDataAnnotFrame();
- }
- }
- }
- CPDFAnnotationPreviewerControl.DrawShapePreview(GetShapeData());
- }
- private void FillColorPickerControl_ColorChanged(object sender, EventArgs e)
- {
- if (annotParam == null)
- {
- PropertyChanged?.Invoke(this, GetShapeData());
- }
- else
- {
- SolidColorBrush fillBrush = FillColorPickerControl.Brush as SolidColorBrush;
- if (annotCore != null && annotCore.IsValid() && fillBrush != null)
- {
- if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE)
- {
- CPDFSquareAnnotation squareAnnot = annotCore as CPDFSquareAnnotation;
- squareAnnot?.SetBgColor(new byte[3]
- {
- fillBrush.Color.R,
- fillBrush.Color.G,
- fillBrush.Color.B
- });
- }
- if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE)
- {
- CPDFCircleAnnotation circleAnnot = annotCore as CPDFCircleAnnotation;
- circleAnnot?.SetBgColor(new byte[3]
- {
- fillBrush.Color.R,
- fillBrush.Color.G,
- fillBrush.Color.B
- });
- }
- if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_LINE)
- {
- CPDFLineAnnotation lineAnnot = annotCore as CPDFLineAnnotation;
- lineAnnot?.SetBgColor(new byte[3]
- {
- fillBrush.Color.R,
- fillBrush.Color.G,
- fillBrush.Color.B
- });
- }
- if (viewControl != null && viewControl.PDFViewTool != null)
- {
- CPDFViewer pdfViewer = viewControl.PDFViewTool.GetCPDFViewer();
- pdfViewer?.UpDataAnnotFrame();
- }
- }
- }
- CPDFAnnotationPreviewerControl.DrawShapePreview(GetShapeData());
- }
- private void CPDFThicknessControl_ThicknessChanged(object sender, EventArgs e)
- {
- if (annotParam == null)
- {
- PropertyChanged?.Invoke(this, GetShapeData());
- }
- else
- {
-
- if (annotCore != null && annotCore.IsValid())
- {
- if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE)
- {
- CPDFSquareAnnotation squareAnnot = annotCore as CPDFSquareAnnotation;
- squareAnnot?.SetBorderWidth(CPDFThicknessControl.Thickness);
- }
- if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE)
- {
- CPDFCircleAnnotation circleAnnot = annotCore as CPDFCircleAnnotation;
- circleAnnot?.SetBorderWidth(CPDFThicknessControl.Thickness);
- }
- if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_LINE)
- {
- CPDFLineAnnotation lineAnnot = annotCore as CPDFLineAnnotation;
- lineAnnot?.SetBorderWidth(CPDFThicknessControl.Thickness);
- }
- if (viewControl != null && viewControl.PDFViewTool != null)
- {
- CPDFViewer pdfViewer = viewControl.PDFViewTool.GetCPDFViewer();
- pdfViewer?.UpDataAnnotFrame();
- }
- }
- }
- CPDFAnnotationPreviewerControl.DrawShapePreview(GetShapeData());
- }
- private void CPDFOpacityControl_OpacityChanged(object sender, EventArgs e)
- {
- if (annotParam == null)
- {
- PropertyChanged?.Invoke(this, GetShapeData());
- }
- else
- {
- double opacity = CPDFOpacityControl.OpacityValue / 100.0;
- if (opacity > 0 && opacity <= 1)
- {
- opacity = opacity * 255;
- }
- if (annotCore != null && annotCore.IsValid())
- {
- if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE)
- {
- CPDFSquareAnnotation squareAnnot = annotCore as CPDFSquareAnnotation;
- squareAnnot?.SetTransparency((byte)opacity);
- }
- if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE)
- {
- CPDFCircleAnnotation circleAnnot = annotCore as CPDFCircleAnnotation;
- circleAnnot?.SetTransparency((byte)opacity);
- }
- if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_LINE)
- {
- CPDFLineAnnotation lineAnnot = annotCore as CPDFLineAnnotation;
- lineAnnot?.SetTransparency((byte)opacity);
- }
- if (viewControl != null && viewControl.PDFViewTool != null)
- {
- CPDFViewer pdfViewer = viewControl.PDFViewTool.GetCPDFViewer();
- pdfViewer?.UpDataAnnotFrame();
- }
- }
- }
- CPDFAnnotationPreviewerControl.DrawShapePreview(GetShapeData());
- }
- private void CPDFLineStyleControl_LineStyleChanged(object sender, EventArgs e)
- {
- if (annotParam == null)
- {
- PropertyChanged?.Invoke(this, GetShapeData());
- }
- else
- {
- if (annotCore != null && annotCore.IsValid())
- {
- float[] dashArray = null;
- C_BORDER_STYLE borderStyle;
- if (CPDFLineStyleControl.DashStyle == DashStyles.Solid || CPDFLineStyleControl.DashStyle == null)
- {
- dashArray = new float[0];
- borderStyle = C_BORDER_STYLE.BS_SOLID;
- }
- else
- {
- List<float> floatArray = new List<float>();
- foreach (double num in CPDFLineStyleControl.DashStyle.Dashes)
- {
- floatArray.Add((float)num);
- }
- dashArray = floatArray.ToArray();
- borderStyle = C_BORDER_STYLE.BS_DASHDED;
- }
- if (dashArray != null)
- {
- if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE)
- {
- CPDFSquareAnnotation squareAnnot = annotCore as CPDFSquareAnnotation;
- squareAnnot?.SetBorderStyle(borderStyle, dashArray);
- }
- if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE)
- {
- CPDFCircleAnnotation circleAnnot = annotCore as CPDFCircleAnnotation;
- circleAnnot?.SetBorderStyle(borderStyle, dashArray);
- }
- if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_LINE)
- {
- CPDFLineAnnotation lineAnnot = annotCore as CPDFLineAnnotation;
- lineAnnot?.SetBorderStyle(borderStyle, dashArray);
- }
- if (viewControl != null && viewControl.PDFViewTool != null)
- {
- CPDFViewer pdfViewer = viewControl.PDFViewTool.GetCPDFViewer();
- pdfViewer?.UpDataAnnotFrame();
- }
- }
- }
- }
- CPDFAnnotationPreviewerControl.DrawShapePreview(GetShapeData());
- }
- private void CPDFArrowControl_ArrowChanged(object sender, EventArgs e)
- {
- if (annotParam == null)
- {
- PropertyChanged?.Invoke(PropertyChanged, GetShapeData());
- }
- else
- {
- if (annotCore != null && annotCore.IsValid())
- {
- if(annotCore.Type==C_ANNOTATION_TYPE.C_ANNOTATION_LINE)
- {
- CPDFLineAnnotation lineAnnot= annotCore as CPDFLineAnnotation;
- if(lineAnnot!=null)
- {
- lineAnnot.SetLineType(CPDFArrowControl.LineType.HeadLineType, CPDFArrowControl.LineType.TailLineType);
- if (viewControl != null && viewControl.PDFViewTool != null)
- {
- CPDFViewer pdfViewer = viewControl.PDFViewTool.GetCPDFViewer();
- pdfViewer?.UpDataAnnotFrame();
- }
- }
- }
- }
- }
- CPDFAnnotationPreviewerControl.DrawShapePreview(GetShapeData());
- }
- private void NoteTextBox_TextChanged(object sender, TextChangedEventArgs e)
- {
- if (annotParam == null)
- {
- PropertyChanged?.Invoke(this, GetShapeData());
- }
- else
- {
- if (annotCore != null && annotCore.IsValid())
- {
- annotCore.SetContent(NoteTextBox.Text);
- if (viewControl != null && viewControl.PDFViewTool != null)
- {
- CPDFViewer pdfViewer = viewControl.PDFViewTool.GetCPDFViewer();
- pdfViewer?.UpDataAnnotFrame();
- }
- }
- }
- }
- public CPDFAnnotationData GetShapeData()
- {
- if (currentAnnotationType == CPDFAnnotationType.Circle || currentAnnotationType == CPDFAnnotationType.Square)
- {
- CPDFShapeData pdfShapeData = new CPDFShapeData();
- pdfShapeData.AnnotationType = currentAnnotationType;
- pdfShapeData.BorderColor = ((SolidColorBrush)BorderColorPickerControl.Brush).Color;
- pdfShapeData.FillColor = ((SolidColorBrush)FillColorPickerControl.Brush).Color;
- pdfShapeData.Opacity = CPDFOpacityControl.OpacityValue / 100.0;
- pdfShapeData.Thickness = CPDFThicknessControl.Thickness;
- pdfShapeData.DashStyle = CPDFLineStyleControl.DashStyle;
- pdfShapeData.Note = NoteTextBox.Text;
- return pdfShapeData;
- }
- else
- {
- CPDFLineShapeData pdfLineShapeData = new CPDFLineShapeData();
- pdfLineShapeData.AnnotationType = currentAnnotationType;
- pdfLineShapeData.BorderColor = ((SolidColorBrush)BorderColorPickerControl.Brush).Color;
- pdfLineShapeData.Opacity = CPDFOpacityControl.OpacityValue / 100.0;
- pdfLineShapeData.LineType = CPDFArrowControl.LineType;
- pdfLineShapeData.Thickness = CPDFThicknessControl.Thickness;
- pdfLineShapeData.DashStyle = CPDFLineStyleControl.DashStyle;
- pdfLineShapeData.LineType = CPDFArrowControl.LineType;
- pdfLineShapeData.Note = NoteTextBox.Text;
- return pdfLineShapeData;
- }
- }
- public void SetPresentAnnotAttrib(AnnotParam param,CPDFAnnotation annot,PDFViewControl view)
- {
- this.annotParam = null;
- this.annotCore = null;
- this.viewControl = null;
- if(param != null)
- {
- if(param is SquareParam)
- {
- SquareParam squareParam= (SquareParam)param;
- CPDFThicknessControl.Thickness = (int)squareParam.LineWidth;
- if (squareParam.LineColor != null)
- {
- BorderColorPickerControl.Brush = new SolidColorBrush(Color.FromRgb(
- squareParam.LineColor[0],
- squareParam.LineColor[1],
- squareParam.LineColor[2]));
- BorderColorPickerControl.SetCheckedForColor(Color.FromRgb(
- squareParam.LineColor[0],
- squareParam.LineColor[1],
- squareParam.LineColor[2]));
- }
- if (squareParam.BgColor!=null)
- {
- FillColorPickerControl.SetCheckedForColor(Color.FromRgb(
- squareParam.BgColor[0],
- squareParam.BgColor[1],
- squareParam.BgColor[2]));
- }
- if (squareParam.BorderStyle == C_BORDER_STYLE.BS_SOLID)
- {
- CPDFLineStyleControl.DashStyle = DashStyles.Solid;
- }
- else
- {
- CPDFLineStyleControl.DashStyle = DashStyles.Dash;
- }
- }
- if(param is CircleParam)
- {
- CircleParam circleParam= (CircleParam)param;
- CPDFThicknessControl.Thickness = (int)circleParam.LineWidth;
- if (circleParam.LineColor != null)
- {
- BorderColorPickerControl.Brush = new SolidColorBrush(Color.FromRgb(
- circleParam.LineColor[0],
- circleParam.LineColor[1],
- circleParam.LineColor[2]));
- BorderColorPickerControl.SetCheckedForColor(Color.FromRgb(
- circleParam.LineColor[0],
- circleParam.LineColor[1],
- circleParam.LineColor[2]));
- }
- if (circleParam.BgColor!=null)
- {
- FillColorPickerControl.SetCheckedForColor(Color.FromRgb(
- circleParam.BgColor[0],
- circleParam.BgColor[1],
- circleParam.BgColor[2]));
- }
- if (circleParam.BorderStyle == C_BORDER_STYLE.BS_SOLID)
- {
- CPDFLineStyleControl.DashStyle = DashStyles.Solid;
- }
- else
- {
- CPDFLineStyleControl.DashStyle = DashStyles.Dash;
- }
- }
- if(param is LineParam)
- {
- LineParam lineParam= (LineParam)param;
- CPDFThicknessControl.Thickness = (int)lineParam.LineWidth;
- if (lineParam.LineColor != null)
- {
- BorderColorPickerControl.Brush = new SolidColorBrush(Color.FromRgb(
- lineParam.LineColor[0],
- lineParam.LineColor[1],
- lineParam.LineColor[2]));
- BorderColorPickerControl.SetCheckedForColor(Color.FromRgb(
- lineParam.LineColor[0],
- lineParam.LineColor[1],
- lineParam.LineColor[2]));
- }
- if (lineParam.BgColor != null)
- {
- FillColorPickerControl.SetCheckedForColor(Color.FromRgb(
- lineParam.BgColor[0],
- lineParam.BgColor[1],
- lineParam.BgColor[2]));
- }
- if(lineParam.BorderStyle==C_BORDER_STYLE.BS_SOLID)
- {
- CPDFLineStyleControl.DashStyle = DashStyles.Solid;
- }
- else
- {
- CPDFLineStyleControl.DashStyle = DashStyles.Dash;
- }
- LineType lineType = new LineType()
- {
- HeadLineType = lineParam.HeadLineType,
- TailLineType = lineParam.TailLineType
- };
- CPDFArrowControl.LineType = lineType;
- }
- CPDFOpacityControl.OpacityValue = (int)(param.Transparency/255 * 100);
- NoteTextBox.Text = param.Content;
- }
- this.annotParam = param;
- this.annotCore = annot;
- this.viewControl = view;
- CPDFAnnotationPreviewerControl.DrawShapePreview(GetShapeData());
- }
- public void InitWhenRectAndRound()
- {
- FillColorStackPanel.Visibility = Visibility.Visible;
- ArrowStackPanel.Visibility = Visibility.Collapsed;
- FillColorPickerControl.ColorChanged += FillColorPickerControl_ColorChanged;
- CPDFArrowControl.ArrowChanged -= CPDFArrowControl_ArrowChanged;
- }
- public void InitWhenArrowAndLine()
- {
- FillColorStackPanel.Visibility = Visibility.Collapsed;
- ArrowStackPanel.Visibility = Visibility.Visible;
- CPDFArrowControl.ArrowChanged += CPDFArrowControl_ArrowChanged;
- FillColorPickerControl.ColorChanged -= FillColorPickerControl_ColorChanged;
- LineType lineType;
- if (currentAnnotationType == CPDFAnnotationType.Arrow)
- {
- lineType = new LineType()
- {
- HeadLineType = C_LINE_TYPE.LINETYPE_NONE,
- TailLineType = C_LINE_TYPE.LINETYPE_ARROW
- };
- }
- else
- {
- lineType = new LineType()
- {
- HeadLineType = C_LINE_TYPE.LINETYPE_NONE,
- TailLineType = C_LINE_TYPE.LINETYPE_NONE
- };
- }
- CPDFArrowControl.LineType = lineType;
- }
- public void InitWithAnnotationType(CPDFAnnotationType annotationType)
- {
- currentAnnotationType = annotationType;
- switch (annotationType)
- {
- case CPDFAnnotationType.Square:
- TitleTextBlock.Text = "Rectangle";
- InitWhenRectAndRound();
- break;
- case CPDFAnnotationType.Circle:
- TitleTextBlock.Text = "Circle";
- InitWhenRectAndRound();
- break;
- case CPDFAnnotationType.Arrow:
- TitleTextBlock.Text = "Arrow";
- InitWhenArrowAndLine();
- break;
- case CPDFAnnotationType.Line:
- TitleTextBlock.Text = "Line";
- InitWhenArrowAndLine();
- break;
- default:
- throw new ArgumentException("Not Excepted Argument");
- }
- CPDFAnnotationPreviewerControl.DrawShapePreview(GetShapeData());
- }
- }
- }
|