Jelajahi Sumber

测量-测量事件通知

zhuyi 10 bulan lalu
induk
melakukan
15251e3480

+ 164 - 91
Demo/Examples/Compdfkit_Tools/Common/BarControl/CPDFMeasureBarControl.xaml.cs

@@ -219,13 +219,13 @@ namespace Compdfkit_Tools.PDFControl
                         annotParam = CreateLine();
                         break;
                     case MeasureType.Multiline:
-                        //args = CreateMultiline();
+                        annotParam = CreateMultiline();
                         break;
                     case MeasureType.Polygonal:
-                        //args = CreatePolygonal();
+                        annotParam = CreatePolygonal();
                         break;
                     case MeasureType.Rectangles:
-                        //args = CreateRectangles();
+                        annotParam = CreateRectangles();
                         break;
                     default:
                         break;
@@ -245,23 +245,33 @@ namespace Compdfkit_Tools.PDFControl
 
         #endregion
 
-        //#region Create Form
+        #region Create Form
 
         private AnnotParam CreateLine()
         {
             pdfViewer.SetToolType(CPDFToolManager.ToolType.CreateAnnot);
             pdfViewer.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_LINE);
-            LineMeasureParam textBoxParam = new LineMeasureParam();
-            textBoxParam.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_LINE;
-            textBoxParam.LineColor = new byte[] { 255, 0, 0, };
-            textBoxParam.LineWidth = 2;
-            textBoxParam.Transparency = 1;
-            textBoxParam.FontColor = new byte[] { 255, 0, 0, };
-            textBoxParam.FontName = "Arial";
-            textBoxParam.FontSize = 14;
-            textBoxParam.HeadLineType = C_LINE_TYPE.LINETYPE_ARROW;
-            textBoxParam.TailLineType = C_LINE_TYPE.LINETYPE_ARROW; 
-            pdfViewer.SetAnnotParam(textBoxParam);
+            LineMeasureParam lineMeasureParam = new LineMeasureParam();
+            lineMeasureParam.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_LINE;
+            lineMeasureParam.LineColor = new byte[] { 255, 0, 0, };
+            lineMeasureParam.LineWidth = 2;
+            lineMeasureParam.Transparency = 1;
+            lineMeasureParam.FontColor = new byte[] { 255, 0, 0, };
+            lineMeasureParam.FontName = "Arial";
+            lineMeasureParam.FontSize = 14;
+            lineMeasureParam.HeadLineType = C_LINE_TYPE.LINETYPE_ARROW;
+            lineMeasureParam.TailLineType = C_LINE_TYPE.LINETYPE_ARROW;
+            lineMeasureParam.measureInfo = new CPDFMeasureInfo
+            {
+                Unit = CPDFMeasure.CPDF_CM,
+                Precision = CPDFMeasure.PRECISION_VALUE_TWO,
+                RulerBase = 1,
+                RulerBaseUnit = CPDFMeasure.CPDF_CM,
+                RulerTranslate = 1,
+                RulerTranslateUnit = CPDFMeasure.CPDF_CM,
+                CaptionType = CPDFCaptionType.CPDF_CAPTION_LENGTH,
+            };
+            pdfViewer.SetAnnotParam(lineMeasureParam);
             //pdfViewer?.ClearSelectAnnots();
             //pdfViewer?.SetMouseMode(MouseModes.AnnotCreate);
             //pdfViewer?.SetToolParam(lineMeasureArgs);
@@ -273,84 +283,147 @@ namespace Compdfkit_Tools.PDFControl
             //                MeasureSetting.RulerBaseUnit,
             //                MeasureSetting.RulerTranslate,
             //                MeasureSetting.RulerTranslateUnit));
-            return textBoxParam;
+            return lineMeasureParam;
+        }
+
+        private AnnotParam CreateMultiline()
+        {
+            pdfViewer.SetToolType(CPDFToolManager.ToolType.CreateAnnot);
+            pdfViewer.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE);
+            PolyLineMeasureParam polyLineMeasureParam = new PolyLineMeasureParam();
+            polyLineMeasureParam.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE;
+            polyLineMeasureParam.LineColor = new byte[] { 255, 0, 0, };
+            polyLineMeasureParam.LineWidth = 2;
+            polyLineMeasureParam.Transparency = 1;
+            polyLineMeasureParam.FontColor = new byte[] { 255, 0, 0, };
+            polyLineMeasureParam.FontName = "Arial";
+            polyLineMeasureParam.FontSize = 14;
+            polyLineMeasureParam.measureInfo = new CPDFMeasureInfo
+            {
+                Unit = CPDFMeasure.CPDF_CM,
+                Precision = CPDFMeasure.PRECISION_VALUE_TWO,
+                RulerBase = 1,
+                RulerBaseUnit = CPDFMeasure.CPDF_CM,
+                RulerTranslate = 1,
+                RulerTranslateUnit = CPDFMeasure.CPDF_CM,
+                CaptionType = CPDFCaptionType.CPDF_CAPTION_LENGTH,
+            };
+            pdfViewer.SetAnnotParam(polyLineMeasureParam);
+            //PolyLineMeasureArgs polyLineMeasureArgs = new PolyLineMeasureArgs();
+            //polyLineMeasureArgs.LineColor = Colors.Red;
+            //polyLineMeasureArgs.LineWidth = 2;
+            //polyLineMeasureArgs.Transparency = 1;
+            //polyLineMeasureArgs.FontColor = Colors.Red;
+            //polyLineMeasureArgs.FontName = "Arial";
+            //polyLineMeasureArgs.FontSize = 14;
+            //pdfViewer?.ClearSelectAnnots();
+            //pdfViewer?.SetMouseMode(MouseModes.AnnotCreate);
+            //pdfViewer?.SetToolParam(polyLineMeasureArgs);
+            //measureControl.SetMeasureInfoType(CPDFMeasureType.CPDF_PERIMETER_MEASURE);
+            //measureControl.SetInfoPanelVisble(true, false);
+            //measureControl.SetMeasureScale(CPDFMeasureType.CPDF_PERIMETER_MEASURE,
+            //   string.Format("{0}{1}={2}{3}",
+            //               MeasureSetting.RulerBase,
+            //               MeasureSetting.RulerBaseUnit,
+            //               MeasureSetting.RulerTranslate,
+            //               MeasureSetting.RulerTranslateUnit));
+            return polyLineMeasureParam;
+        }
+
+        private AnnotParam CreatePolygonal()
+        {
+            pdfViewer.SetToolType(CPDFToolManager.ToolType.CreateAnnot);
+            pdfViewer.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON);
+            PolygonMeasureParam polygonMeasureParam = new PolygonMeasureParam();
+            polygonMeasureParam.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON;
+            polygonMeasureParam.LineColor = new byte[] { 255, 0, 0, };
+            polygonMeasureParam.LineWidth = 2;
+            polygonMeasureParam.Transparency = 1;
+            polygonMeasureParam.FontColor = new byte[] { 255, 0, 0, };
+            polygonMeasureParam.FontName = "Arial";
+            polygonMeasureParam.FontSize = 14;
+            polygonMeasureParam.measureInfo = new CPDFMeasureInfo
+            {
+                Unit = CPDFMeasure.CPDF_CM,
+                Precision = CPDFMeasure.PRECISION_VALUE_TWO,
+                RulerBase = 1,
+                RulerBaseUnit = CPDFMeasure.CPDF_CM,
+                RulerTranslate = 1,
+                RulerTranslateUnit = CPDFMeasure.CPDF_CM,
+                CaptionType = CPDFCaptionType.CPDF_CAPTION_LENGTH | CPDFCaptionType.CPDF_CAPTION_AREA,
+            };
+            pdfViewer.SetAnnotParam(polygonMeasureParam);
+            //    PolygonMeasureArgs polygonMeasureArgs = new PolygonMeasureArgs();
+            //    polygonMeasureArgs.LineColor = Colors.Red;
+            //    polygonMeasureArgs.LineWidth = 2;
+            //    polygonMeasureArgs.Transparency = 1;
+            //    polygonMeasureArgs.FontColor = Colors.Red;
+            //    polygonMeasureArgs.FillColor = Colors.Transparent;
+            //    polygonMeasureArgs.FontName = "Arial";
+            //    polygonMeasureArgs.FontSize = 14;
+            //    pdfViewer?.ClearSelectAnnots();
+            //    pdfViewer?.SetMouseMode(MouseModes.AnnotCreate);
+            //    pdfViewer?.SetToolParam(polygonMeasureArgs);
+            //    measureControl.SetMeasureInfoType(CPDFMeasureType.CPDF_AREA_MEASURE);
+            //    measureControl.SetInfoPanelVisble(true, false);
+            //    measureControl.SetMeasureScale(CPDFMeasureType.CPDF_AREA_MEASURE,
+            //      string.Format("{0}{1}={2}{3}",
+            //                  MeasureSetting.RulerBase,
+            //                  MeasureSetting.RulerBaseUnit,
+            //                  MeasureSetting.RulerTranslate,
+            //                  MeasureSetting.RulerTranslateUnit));
+            //    return polygonMeasureArgs;
+            return polygonMeasureParam;
+        }
+
+        private AnnotParam CreateRectangles()
+        {
+            pdfViewer.SetToolType(CPDFToolManager.ToolType.CreateAnnot);
+            pdfViewer.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON);
+            PolygonMeasureParam polygonMeasureParam = new PolygonMeasureParam();
+            polygonMeasureParam.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON;
+            polygonMeasureParam.LineColor = new byte[] { 255, 0, 0, };
+            polygonMeasureParam.LineWidth = 2;
+            polygonMeasureParam.Transparency = 1;
+            polygonMeasureParam.FontColor = new byte[] { 255, 0, 0, };
+            polygonMeasureParam.FontName = "Arial";
+            polygonMeasureParam.FontSize = 14;
+            polygonMeasureParam.measureInfo = new CPDFMeasureInfo
+            {
+                Unit = CPDFMeasure.CPDF_CM,
+                Precision = CPDFMeasure.PRECISION_VALUE_TWO,
+                RulerBase = 1,
+                RulerBaseUnit = CPDFMeasure.CPDF_CM,
+                RulerTranslate = 1,
+                RulerTranslateUnit = CPDFMeasure.CPDF_CM,
+                CaptionType = CPDFCaptionType.CPDF_CAPTION_LENGTH | CPDFCaptionType.CPDF_CAPTION_AREA,
+            };
+            pdfViewer.SetAnnotParam(polygonMeasureParam);
+            //    PolygonMeasureArgs rectPolygonMeasureArgs = new PolygonMeasureArgs();
+            //    rectPolygonMeasureArgs.LineColor = Colors.Red;
+            //    rectPolygonMeasureArgs.IsOnlyDrawRect = true;
+            //    rectPolygonMeasureArgs.LineWidth = 2;
+            //    rectPolygonMeasureArgs.Transparency = 1;
+            //    rectPolygonMeasureArgs.FontColor = Colors.Red;
+            //    rectPolygonMeasureArgs.FillColor = Colors.Transparent;
+            //    rectPolygonMeasureArgs.FontName = "Arial";
+            //    rectPolygonMeasureArgs.FontSize = 14;
+            //    pdfViewer?.ClearSelectAnnots();
+            //    pdfViewer?.SetMouseMode(MouseModes.AnnotCreate);
+            //    pdfViewer?.SetToolParam(rectPolygonMeasureArgs);
+            //    measureControl.SetMeasureInfoType(CPDFMeasureType.CPDF_AREA_MEASURE);
+            //    measureControl.SetInfoPanelVisble(true, false);
+            //    measureControl.SetMeasureScale(CPDFMeasureType.CPDF_AREA_MEASURE,
+            //     string.Format("{0}{1}={2}{3}",
+            //                 MeasureSetting.RulerBase,
+            //                 MeasureSetting.RulerBaseUnit,
+            //                 MeasureSetting.RulerTranslate,
+            //                 MeasureSetting.RulerTranslateUnit));
+            //    return rectPolygonMeasureArgs;
+            return polygonMeasureParam;
         }
 
-        //private AnnotHandlerEventArgs CreateMultiline()
-        //{
-
-        //    PolyLineMeasureArgs polyLineMeasureArgs = new PolyLineMeasureArgs();
-        //    polyLineMeasureArgs.LineColor = Colors.Red;
-        //    polyLineMeasureArgs.LineWidth = 2;
-        //    polyLineMeasureArgs.Transparency = 1;
-        //    polyLineMeasureArgs.FontColor = Colors.Red;
-        //    polyLineMeasureArgs.FontName = "Arial";
-        //    polyLineMeasureArgs.FontSize = 14;
-        //    pdfViewer?.ClearSelectAnnots();
-        //    pdfViewer?.SetMouseMode(MouseModes.AnnotCreate);
-        //    pdfViewer?.SetToolParam(polyLineMeasureArgs);
-        //    measureControl.SetMeasureInfoType(CPDFMeasureType.CPDF_PERIMETER_MEASURE);
-        //    measureControl.SetInfoPanelVisble(true, false);
-        //    measureControl.SetMeasureScale(CPDFMeasureType.CPDF_PERIMETER_MEASURE,
-        //       string.Format("{0}{1}={2}{3}",
-        //                   MeasureSetting.RulerBase,
-        //                   MeasureSetting.RulerBaseUnit,
-        //                   MeasureSetting.RulerTranslate,
-        //                   MeasureSetting.RulerTranslateUnit));
-        //    return polyLineMeasureArgs;
-        //}
-
-        //private AnnotHandlerEventArgs CreatePolygonal()
-        //{
-        //    PolygonMeasureArgs polygonMeasureArgs = new PolygonMeasureArgs();
-        //    polygonMeasureArgs.LineColor = Colors.Red;
-        //    polygonMeasureArgs.LineWidth = 2;
-        //    polygonMeasureArgs.Transparency = 1;
-        //    polygonMeasureArgs.FontColor = Colors.Red;
-        //    polygonMeasureArgs.FillColor = Colors.Transparent;
-        //    polygonMeasureArgs.FontName = "Arial";
-        //    polygonMeasureArgs.FontSize = 14;
-        //    pdfViewer?.ClearSelectAnnots();
-        //    pdfViewer?.SetMouseMode(MouseModes.AnnotCreate);
-        //    pdfViewer?.SetToolParam(polygonMeasureArgs);
-        //    measureControl.SetMeasureInfoType(CPDFMeasureType.CPDF_AREA_MEASURE);
-        //    measureControl.SetInfoPanelVisble(true, false);
-        //    measureControl.SetMeasureScale(CPDFMeasureType.CPDF_AREA_MEASURE,
-        //      string.Format("{0}{1}={2}{3}",
-        //                  MeasureSetting.RulerBase,
-        //                  MeasureSetting.RulerBaseUnit,
-        //                  MeasureSetting.RulerTranslate,
-        //                  MeasureSetting.RulerTranslateUnit));
-        //    return polygonMeasureArgs;
-        //}
-
-        //private AnnotHandlerEventArgs CreateRectangles()
-        //{
-
-        //    PolygonMeasureArgs rectPolygonMeasureArgs = new PolygonMeasureArgs();
-        //    rectPolygonMeasureArgs.LineColor = Colors.Red;
-        //    rectPolygonMeasureArgs.IsOnlyDrawRect = true;
-        //    rectPolygonMeasureArgs.LineWidth = 2;
-        //    rectPolygonMeasureArgs.Transparency = 1;
-        //    rectPolygonMeasureArgs.FontColor = Colors.Red;
-        //    rectPolygonMeasureArgs.FillColor = Colors.Transparent;
-        //    rectPolygonMeasureArgs.FontName = "Arial";
-        //    rectPolygonMeasureArgs.FontSize = 14;
-        //    pdfViewer?.ClearSelectAnnots();
-        //    pdfViewer?.SetMouseMode(MouseModes.AnnotCreate);
-        //    pdfViewer?.SetToolParam(rectPolygonMeasureArgs);
-        //    measureControl.SetMeasureInfoType(CPDFMeasureType.CPDF_AREA_MEASURE);
-        //    measureControl.SetInfoPanelVisble(true, false);
-        //    measureControl.SetMeasureScale(CPDFMeasureType.CPDF_AREA_MEASURE,
-        //     string.Format("{0}{1}={2}{3}",
-        //                 MeasureSetting.RulerBase,
-        //                 MeasureSetting.RulerBaseUnit,
-        //                 MeasureSetting.RulerTranslate,
-        //                 MeasureSetting.RulerTranslateUnit));
-        //    return rectPolygonMeasureArgs;
-        //}
-
-        //#endregion
+#endregion
 
 
     }