Exemplo n.º 1
0
        public CalibrationDialog(AnnAutomation automation)
        {
            if (automation == null)
            {
                throw new ArgumentNullException("automation");
            }

            InitializeComponent();

            _automation = automation;
            _mapper     = automation.ActiveContainer.Mapper;

            _polyRulerObject = automation.CurrentEditObject as AnnPolyRulerObject;
            _isPixelUnit     = (_polyRulerObject.MeasurementUnit == AnnUnit.Pixel);

            if (_isPixelUnit)
            {
                _polyRulerObject.MeasurementUnit = AnnUnit.SmartEnglish;
            }

            SetObjectLenghtLabelValue();
            _comboMesurementUnit.SelectedItem = _polyRulerObject.MeasurementUnit.ToString();

            if (_isPixelUnit)
            {
                _polyRulerObject.MeasurementUnit = AnnUnit.Pixel;
            }
        }
        public override void Render(AnnContainerMapper mapper, AnnObject annObject)
        {
            if (mapper == null)
            {
                ExceptionHelper.ArgumentNullException("mapper");
            }
            if (annObject == null)
            {
                ExceptionHelper.ArgumentNullException("annObject");
            }

            AnnProtractorObject firstProtractorObject = annObject.Clone() as AnnProtractorObject;

            firstProtractorObject.Points.Clear();
            firstProtractorObject.Points.Add(annObject.Points[0]);
            firstProtractorObject.Points.Add(annObject.Points[1]);
            firstProtractorObject.Points.Add(annObject.Points[2]);
            base.Render(mapper, firstProtractorObject);

            AnnProtractorObject secondProtractorObject = annObject.Clone() as AnnProtractorObject;

            secondProtractorObject.Points.Clear();
            secondProtractorObject.Points.Add(annObject.Points[1]);
            secondProtractorObject.Points.Add(annObject.Points[2]);
            secondProtractorObject.Points.Add(annObject.Points[3]);
            base.Render(mapper, secondProtractorObject);

            annObject.Labels["FirstAngle"]  = firstProtractorObject.Labels["AngleText"].Clone();
            annObject.Labels["SecondAngle"] = secondProtractorObject.Labels["AngleText"].Clone();
        }
Exemplo n.º 3
0
        public override void Render(AnnContainerMapper mapper, AnnObject annObject)
        {
            if (mapper == null)
            {
                ExceptionHelper.ArgumentNullException("mapper");
            }
            if (annObject == null)
            {
                ExceptionHelper.ArgumentNullException("annObject");
            }

            IAnnDrawEngine engine = RenderingEngine as IAnnDrawEngine;

            if (engine != null)
            {
                base.Render(mapper, annObject);

                AnnIntersectionPointObject annIntersectionPointObject = annObject as AnnIntersectionPointObject;
                if (annIntersectionPointObject != null)
                {
                    int count = annIntersectionPointObject.Points.Count;
                    if (count < 2)
                    {
                        return;
                    }

                    LeadPointD[] leadPoints = mapper.PointsFromContainerCoordinates(annIntersectionPointObject.Points.ToArray(), annIntersectionPointObject.FixedStateOperations);

                    if (annIntersectionPointObject.SupportsStroke && annIntersectionPointObject.Stroke != null)
                    {
                        AnnStroke stroke = AnnStroke.Create(AnnSolidColorBrush.Create("Blue"), annIntersectionPointObject.Stroke.StrokeThickness);
                        stroke.StrokeDashArray = new double[] { 3, 1, 1, 1, 1, 1 }; // DashDotDot

                        IAnnDrawPen pen = engine.ToPen(mapper.StrokeFromContainerCoordinates(stroke, annIntersectionPointObject.FixedStateOperations), annIntersectionPointObject.Opacity);
                        try
                        {
                            if (leadPoints.Length > 2)
                            {
                                LeadPointD intersectionPoint = annIntersectionPointObject.IntersectionPoint;
                                intersectionPoint = mapper.PointFromContainerCoordinates(intersectionPoint, annIntersectionPointObject.FixedStateOperations);

                                double radius = mapper.LengthFromContainerCoordinates(annIntersectionPointObject.IntersectionPointRadius, annIntersectionPointObject.FixedStateOperations);
                                DrawPoint(annIntersectionPointObject, engine, intersectionPoint, radius);

                                if (leadPoints.Length < 5 && annIntersectionPointObject.IntersectionInsideContainer)
                                {
                                    engine.DrawLine(pen, leadPoints[3], intersectionPoint);
                                }
                            }
                        }
                        finally
                        {
                            engine.Destroy(pen);
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        public override void Render(AnnContainerMapper mapper, AnnObject annObject)
        {
            if (mapper == null)
            {
                ExceptionHelper.ArgumentNullException("mapper");
            }
            if (annObject == null)
            {
                ExceptionHelper.ArgumentNullException("annObject");
            }

            AnnWinFormsRenderingEngine engine = RenderingEngine as AnnWinFormsRenderingEngine;

            if (engine != null && engine.Context != null)
            {
                base.Render(mapper, annObject);

                AnnMidlineObject annMidlineObject = annObject as AnnMidlineObject;
                if (annMidlineObject != null)
                {
                    LeadPointD[] leadPoints = annMidlineObject.Points.ToArray();
                    int          linesCount = leadPoints.Length / 2;
                    if (linesCount > 0)
                    {
                        PointF[] linesCenters = new PointF[linesCount];
                        leadPoints = mapper.PointsFromContainerCoordinates(leadPoints, annMidlineObject.FixedStateOperations);
                        PointF[] points = AnnWinFormsRenderingEngine.ToPoints(leadPoints);

                        if (annMidlineObject.SupportsStroke && annMidlineObject.Stroke != null)
                        {
                            double radius = mapper.LengthFromContainerCoordinates(annMidlineObject.CenterPointRadius, annMidlineObject.FixedStateOperations);
                            using (Pen pen = AnnWinFormsRenderingEngine.ToPen(mapper.StrokeFromContainerCoordinates(annMidlineObject.Stroke, annMidlineObject.FixedStateOperations), annMidlineObject.Opacity))
                            {
                                for (int i = 0; i < linesCount; ++i)
                                {
                                    PointF firstPoint  = points[2 * i];
                                    PointF secondPoint = points[2 * i + 1];

                                    PointF center = new PointF((firstPoint.X + secondPoint.X) / 2, (firstPoint.Y + secondPoint.Y) / 2);
                                    DrawPoint(annMidlineObject, engine.Context, center, radius);

                                    linesCenters[i] = center;
                                }

                                if (linesCount > 1)
                                {
                                    int count = linesCount - 1;
                                    for (int i = 0; i < count; ++i)
                                    {
                                        engine.Context.DrawLine(pen, linesCenters[i], linesCenters[i + 1]); // draw midline
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        public override void Render(AnnContainerMapper mapper, AnnObject annObject)
        {
            if (mapper == null)
            {
                ExceptionHelper.ArgumentNullException("mapper");
            }
            if (annObject == null)
            {
                ExceptionHelper.ArgumentNullException("annObject");
            }

            AnnWinFormsRenderingEngine engine = RenderingEngine as AnnWinFormsRenderingEngine;

            if (engine != null && engine.Context != null)
            {
                LeadPointD[] leadPoints = annObject.Points.ToArray();
                int          linesCount = leadPoints.Length / 2;
                if (linesCount > 0)
                {
                    if (annObject.SupportsStroke && annObject.Stroke != null)
                    {
                        leadPoints = mapper.PointsFromContainerCoordinates(leadPoints, annObject.FixedStateOperations);
                        PointF[] points = AnnWinFormsRenderingEngine.ToPoints(leadPoints);

                        using (Pen pen = AnnWinFormsRenderingEngine.ToPen(mapper.StrokeFromContainerCoordinates(annObject.Stroke, annObject.FixedStateOperations), annObject.Opacity))
                        {
                            for (int i = 0; i < linesCount; ++i)
                            {
                                if (_linesAsRulers)
                                {
                                    AnnPolyRulerObject ruler = new AnnPolyRulerObject();
                                    ruler.Stroke               = annObject.Stroke.Clone();
                                    ruler.TickMarksStroke      = ruler.Stroke;
                                    ruler.Opacity              = annObject.Opacity;
                                    ruler.FixedStateOperations = annObject.FixedStateOperations;

                                    ruler.Points.Clear();
                                    ruler.Points.Add(annObject.Points[2 * i]);
                                    ruler.Points.Add(annObject.Points[2 * i + 1]);

                                    annObject.Labels["angle" + i.ToString()] = ruler.Labels["RulerLength"];

                                    AnnPolyRulerObjectRenderer renderer = new AnnPolyRulerObjectRenderer();
                                    renderer.Initialize(engine);
                                    renderer.Render(mapper, ruler);
                                }
                                else
                                {
                                    engine.Context.DrawLine(pen, points[2 * i], points[2 * i + 1]);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 6
0
        public override void Render(AnnContainerMapper mapper, AnnObject annObject)
        {
            if (mapper == null)
            {
                ExceptionHelper.ArgumentNullException("mapper");
            }
            if (annObject == null)
            {
                ExceptionHelper.ArgumentNullException("annObject");
            }

            AnnWinFormsRenderingEngine engine = RenderingEngine as AnnWinFormsRenderingEngine;

            if (engine != null && engine.Context != null)
            {
                base.Render(mapper, annObject);

                AnnIntersectionPointObject annIntersectionPointObject = annObject as AnnIntersectionPointObject;
                if (annIntersectionPointObject != null)
                {
                    int count = annIntersectionPointObject.Points.Count;
                    if (count < 2)
                    {
                        return;
                    }

                    LeadPointD[] leadPoints = mapper.PointsFromContainerCoordinates(annIntersectionPointObject.Points.ToArray(), annIntersectionPointObject.FixedStateOperations);
                    PointF[]     points     = AnnWinFormsRenderingEngine.ToPoints(leadPoints);

                    if (annIntersectionPointObject.SupportsStroke && annIntersectionPointObject.Stroke != null)
                    {
                        using (Pen pen = AnnWinFormsRenderingEngine.ToPen(mapper.StrokeFromContainerCoordinates(annIntersectionPointObject.Stroke, annIntersectionPointObject.FixedStateOperations), annIntersectionPointObject.Opacity))
                        {
                            if (points.Length > 2)
                            {
                                LeadPointD LeadIntersectionPoint = annIntersectionPointObject.IntersectionPoint;
                                LeadIntersectionPoint = mapper.PointFromContainerCoordinates(LeadIntersectionPoint, annIntersectionPointObject.FixedStateOperations);
                                PointF intersectionPoint = new PointF((float)LeadIntersectionPoint.X, (float)LeadIntersectionPoint.Y);

                                double radius = mapper.LengthFromContainerCoordinates(annIntersectionPointObject.IntersectionPointRadius, annIntersectionPointObject.FixedStateOperations);
                                DrawPoint(annIntersectionPointObject, engine.Context, intersectionPoint, radius);

                                if (points.Length < 5 && annIntersectionPointObject.IntersectionInsideContainer)
                                {
                                    pen.Brush     = Brushes.Blue;
                                    pen.DashStyle = DashStyle.DashDotDot;
                                    engine.Context.DrawLine(pen, points[3], intersectionPoint);
                                }
                            }
                        }
                    }
                }
            }
        }
        public override LeadRectD GetInvalidateRect(AnnContainerMapper mapper, IAnnObjectRenderer renderer)
        {
            LeadRectD invalidateRect = base.GetInvalidateRect(mapper, renderer);

            // Add angle label to the invalidate rect
            IAnnLabelRenderer labelRenderer = renderer.LabelRenderer;

            if (labelRenderer != null && labelRenderer.RenderingEngine != null && Labels.ContainsKey("CobbAngle"))
            {
                AnnLabel  label       = Labels["CobbAngle"];
                LeadRectD lablebounds = labelRenderer.GetBounds(mapper, label, FixedStateOperations);
                invalidateRect = LeadRectD.UnionRects(lablebounds, invalidateRect);
            }

            return(invalidateRect);
        }
        public override void Render(AnnContainerMapper mapper, AnnObject annObject)
        {
            ZoneAnnotationObject zoneObject = annObject as ZoneAnnotationObject;
             if (_ocrPage != null && zoneObject.ZoneIndex >= 0 && zoneObject.ZoneIndex < _ocrPage.Zones.Count)
             {
            AnnWinFormsRenderingEngine engine = RenderingEngine as AnnWinFormsRenderingEngine;

            if (engine != null && engine.Context != null && zoneObject != null && zoneObject.Cells != null)
            {
               Graphics graphics = engine.Context;
               OcrZone zone = _ocrPage.Zones[zoneObject.ZoneIndex];
               OcrZoneCell[] cells = null;
               cells = _ocrPage.Zones.GetZoneCells(zone);

               if (_ocrPage.TableZoneManager != null && zone.ZoneType == OcrZoneType.Table && cells != null && cells.Length > 0 && CellPen != null)
               {
                  GraphicsState gState = graphics.Save();
                  if (gState != null)
                  {
                     foreach (OcrZoneCell cell in zoneObject.Cells)
                     {
                        LeadRectD rc = new LeadRectD(cell.Bounds.X, cell.Bounds.Y, cell.Bounds.Width, cell.Bounds.Height);
                        rc = mapper.RectFromContainerCoordinates(rc, AnnFixedStateOperations.None);

                        if (!rc.IsEmpty)
                        {
                           // Draw cells borders as lines in order not to draw the borders with 0 width
                           DrawLine(graphics, OcrCellBorder.Left, cell.LeftBorderStyle, cell.LeftBorderWidth, (float)rc.Left, (float)rc.Top, (float)rc.Left, (float)rc.Bottom);
                           DrawLine(graphics, OcrCellBorder.Top, cell.TopBorderStyle, cell.TopBorderWidth, (float)rc.Left, (float)rc.Top, (float)rc.Right, (float)rc.Top);
                           DrawLine(graphics, OcrCellBorder.Right, cell.RightBorderStyle, cell.RightBorderWidth, (float)rc.Right, (float)rc.Top, (float)rc.Right, (float)rc.Bottom);
                           DrawLine(graphics, OcrCellBorder.Bottom, cell.BottomBorderStyle, cell.BottomBorderWidth, (float)rc.Left, (float)rc.Bottom, (float)rc.Right, (float)rc.Bottom);
                        }
                     }

                     graphics.Restore(gState);
                  }
               }
            }
             }

             base.Render(mapper, annObject);
        }
        public override void Render(AnnContainerMapper mapper, AnnObject annObject)
        {
            if (mapper == null)
            {
                ExceptionHelper.ArgumentNullException("mapper");
            }
            if (annObject == null)
            {
                ExceptionHelper.ArgumentNullException("annObject");
            }

            IAnnDrawEngine engine = RenderingEngine as IAnnDrawEngine;

            if (engine != null)
            {
                LeadPointD[] leadPoints = annObject.Points.ToArray();
                int          linesCount = leadPoints.Length / 2;
                if (linesCount > 0)
                {
                    if (annObject.SupportsStroke && annObject.Stroke != null)
                    {
                        leadPoints = mapper.PointsFromContainerCoordinates(leadPoints, annObject.FixedStateOperations);

                        IAnnDrawPen pen = engine.ToPen(mapper.StrokeFromContainerCoordinates(annObject.Stroke, annObject.FixedStateOperations), annObject.Opacity);
                        try
                        {
                            for (int i = 0; i < linesCount; ++i)
                            {
                                LeadPointD firstPoint  = leadPoints[2 * i];
                                LeadPointD secondPoint = leadPoints[2 * i + 1];

                                engine.DrawLine(pen, firstPoint, secondPoint);
                            }
                        }
                        finally
                        {
                            engine.Destroy(pen);
                        }
                    }
                }
            }
        }
Exemplo n.º 10
0
        public override void Render(AnnContainerMapper mapper, AnnObject annObject)
        {
            if (mapper == null)
            {
                ExceptionHelper.ArgumentNullException("mapper");
            }
            if (annObject == null)
            {
                ExceptionHelper.ArgumentNullException("annObject");
            }

            AnnWinFormsRenderingEngine engine = RenderingEngine as AnnWinFormsRenderingEngine;

            if (engine != null && engine.Context != null)
            {
                AnnSignatureObject signatureObject = annObject as AnnSignatureObject;
                if (signatureObject != null)
                {
                    if (signatureObject.IsSelected)
                    {
                        base.Render(mapper, signatureObject);
                    }
                    //When the mouse is over the "SignatureObject" this property set to true, check its value to draw a border around it.
                    else if (signatureObject.DrawBorder)
                    {
                        Pen pen = new Pen(new SolidBrush(Color.Black), 1);
                        pen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDotDot;

                        LeadRectD leadRect = mapper.RectFromContainerCoordinates(signatureObject.Rect, signatureObject.FixedStateOperations);
                        Rectangle rect     = new Rectangle(
                            (int)leadRect.X,
                            (int)leadRect.Y,
                            (int)leadRect.Width,
                            (int)leadRect.Height
                            );

                        engine.Context.DrawRectangle(pen, rect);
                    }
                }
            }
        }
Exemplo n.º 11
0
 private void _txtLogoPosition_TextChanged(object sender, EventArgs e)
 {
     try
     {
         if (_currentBatesStamp != null)
         {
             AnnBatesStampLogo  logo         = _currentBatesStamp.Logo;
             AnnContainerMapper mapper       = _automation.Container.Mapper;
             LeadRectD          logoPosition = mapper.RectFromContainerCoordinates(logo.LogoRect, AnnFixedStateOperations.None);
             logoPosition.X      = double.Parse(_txtLogoPositionX.Text);
             logoPosition.Y      = double.Parse(_txtLogoPositionY.Text);
             logoPosition.Width  = double.Parse(_txtLogoPositionWidth.Text);
             logoPosition.Height = double.Parse(_txtLogoPositionHeight.Text);
             logo.LogoRect       = mapper.RectToContainerCoordinates(logoPosition);
             UpdateControls();
         }
     }
     catch
     {
     }
 }
Exemplo n.º 12
0
        public override void Render(AnnContainerMapper mapper, AnnObject annObject)
        {
            if (mapper == null)
            {
                ExceptionHelper.ArgumentNullException("mapper");
            }
            if (annObject == null)
            {
                ExceptionHelper.ArgumentNullException("annObject");
            }

            IAnnDrawEngine engine = RenderingEngine as IAnnDrawEngine;

            if (engine != null)
            {
                int count = annObject.Points.Count / 2;

                if (count > 1)
                {
                    LeadPointD[] tmpPoints = mapper.PointsFromContainerCoordinates(annObject.Points.ToArray(), annObject.FixedStateOperations);

                    if (annObject.SupportsStroke && annObject.Stroke != null)
                    {
                        IAnnDrawPen pen = engine.ToPen(mapper.StrokeFromContainerCoordinates(annObject.Stroke, annObject.FixedStateOperations), annObject.Opacity);
                        try
                        {
                            for (int i = 0; i < count; i++)
                            {
                                int index = 2 * i;
                                engine.DrawLine(pen, tmpPoints[index], tmpPoints[index + 1]);
                            }
                        }
                        finally
                        {
                            engine.Destroy(pen);
                        }
                    }
                }
            }
        }
Exemplo n.º 13
0
        public override LeadRectD GetInvalidateRect(AnnContainerMapper mapper, IAnnObjectRenderer renderer)
        {
            LeadRectD invalidate = GetBoundingRectangle();

            if (_linesAsRulers)
            {
                int linesCount = Points.Count / 2;

                for (int i = 0; i < linesCount; ++i)
                {
                    AnnPolyRulerObject ruler = new AnnPolyRulerObject();
                    ruler.Points.Clear();
                    ruler.Points.Add(Points[2 * i]);
                    ruler.Points.Add(Points[2 * i + 1]);
                    invalidate = LeadRectD.UnionRects(invalidate, ruler.GetInvalidateRect(mapper, renderer));
                }
            }

            invalidate = LeadRectD.UnionRects(base.GetInvalidateRect(mapper, renderer), invalidate);

            return(invalidate);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Called by the main form to set the new raster image and OCR page
        /// </summary>
        /// <param name="image"></param>
        /// <param name="ocrPage"></param>
        public void SetImageAndPage(RasterImage image, IOcrPage ocrPage)
        {
            _ocrPage = ocrPage;
            var options = _rasterImageViewer.AutoResetOptions; // save

            _rasterImageViewer.AutoResetOptions = ImageViewerAutoResetOptions.None;
            _rasterImageViewer.Image            = image;
            _rasterImageViewer.AutoResetOptions = options;

            if (image != null)
            {
                AnnContainerMapper saveMapper     = _annAutomation.Container.Mapper.Clone();
                AnnContainerMapper identityMapper = new AnnContainerMapper(saveMapper.SourceDpiX, saveMapper.SourceDpiY, saveMapper.SourceDpiX, saveMapper.SourceDpiY);
                identityMapper.UpdateTransform(LeadMatrix.Identity);

                _annAutomation.Container.Mapper = identityMapper;

                //Set Container Size
                if (_annAutomation != null)
                {
                    _annAutomation.Container.Size = identityMapper.SizeToContainerCoordinates(LeadSizeD.Create(image.ImageWidth, image.ImageHeight));
                }

                _annAutomation.Container.Mapper = saveMapper;

                // Converts the zones to annotation objects
                ZonesUpdated();

                _rasterImageViewer.ViewBorderThickness = 1;
            }
            else
            {
                _rasterImageViewer.ViewBorderThickness = 0;
            }

            UpdateTitle();
            UpdateUIState();
        }
        public override void Render(AnnContainerMapper mapper, AnnObject annObject)
        {
            if (mapper == null)
            {
                ExceptionHelper.ArgumentNullException("mapper");
            }
            if (annObject == null)
            {
                ExceptionHelper.ArgumentNullException("annObject");
            }

            AnnWinFormsRenderingEngine engine = RenderingEngine as AnnWinFormsRenderingEngine;

            if (engine != null && engine.Context != null)
            {
                Graphics context = engine.Context;
                int      count   = annObject.Points.Count / 2;

                if (count > 1)
                {
                    LeadPointD[] tmpPoints = mapper.PointsFromContainerCoordinates(annObject.Points.ToArray(), annObject.FixedStateOperations);
                    PointF[]     points    = AnnWinFormsRenderingEngine.ToPoints(tmpPoints);

                    if (annObject.SupportsStroke && annObject.Stroke != null)
                    {
                        using (Pen pen = AnnWinFormsRenderingEngine.ToPen(mapper.StrokeFromContainerCoordinates(annObject.Stroke, annObject.FixedStateOperations), annObject.Opacity))
                        {
                            for (int i = 0; i < count; i++)
                            {
                                int index = 2 * i;
                                context.DrawLine(pen, points[index], points[index + 1]);
                            }
                        }
                    }
                }
            }
        }
        public override void Render(AnnContainerMapper mapper, AnnObject annObject)
        {
            if (mapper == null)
            {
                ExceptionHelper.ArgumentNullException("mapper");
            }
            if (annObject == null)
            {
                ExceptionHelper.ArgumentNullException("annObject");
            }

            IAnnDrawEngine engine = RenderingEngine as IAnnDrawEngine;

            if (engine != null)
            {
                base.Render(mapper, annObject);

                AnnCobbAngleObject annCobbAngleObject = annObject as AnnCobbAngleObject;
                if (annCobbAngleObject != null)
                {
                    int count = annCobbAngleObject.Points.Count;
                    if (count < 2)
                    {
                        return;
                    }

                    LeadPointD[] leadPoints = mapper.PointsFromContainerCoordinates(annCobbAngleObject.Points.ToArray(), annCobbAngleObject.FixedStateOperations);

                    if (annCobbAngleObject.SupportsStroke && annCobbAngleObject.Stroke != null)
                    {
                        AnnStroke stroke = AnnStroke.Create(AnnSolidColorBrush.Create("Blue"), annCobbAngleObject.Stroke.StrokeThickness);
                        stroke.StrokeDashArray = new double[] { 4, 2, 2, 2, 2, 2 };
                        IAnnDrawPen pen = engine.ToPen(mapper.StrokeFromContainerCoordinates(annCobbAngleObject.Stroke, annCobbAngleObject.FixedStateOperations), annCobbAngleObject.Opacity);
                        try
                        {
                            if (leadPoints.Length > 3)
                            {
                                AnnCobbAngleData cobbAngleData     = annCobbAngleObject.CobbAngleData;
                                LeadPointD       firstPoint        = mapper.PointFromContainerCoordinates(cobbAngleData.FirstPoint, annCobbAngleObject.FixedStateOperations);
                                LeadPointD       secondPoint       = mapper.PointFromContainerCoordinates(cobbAngleData.SecondPoint, annCobbAngleObject.FixedStateOperations);
                                LeadPointD       intersectionPoint = mapper.PointFromContainerCoordinates(cobbAngleData.IntersectionPoint, annCobbAngleObject.FixedStateOperations);

                                engine.DrawLine(pen, firstPoint, intersectionPoint);
                                engine.DrawLine(pen, secondPoint, intersectionPoint);

                                //Draw angle label
                                if (annCobbAngleObject.Labels.ContainsKey("CobbAngle"))
                                {
                                    AnnLabel label = annCobbAngleObject.Labels["CobbAngle"];
                                    if (label != null)
                                    {
                                        string precisionFormat = string.Format("XXX:F{0}", annCobbAngleObject.AnglePrecision);
                                        precisionFormat = precisionFormat.Replace("XXX", "{0");
                                        precisionFormat = string.Format("{0}{1}", precisionFormat, "}");

                                        string angle = string.Format(precisionFormat, cobbAngleData.Angle);

                                        label.Text             = angle;
                                        label.Foreground       = AnnSolidColorBrush.Create("Blue");
                                        label.OriginalPosition = cobbAngleData.IntersectionPoint;
                                    }
                                }
                            }
                        }
                        finally
                        {
                            engine.Destroy(pen);
                        }
                    }
                }
            }
        }
Exemplo n.º 17
0
        public override void Render(AnnContainerMapper mapper, AnnObject annObject)
        {
            if (mapper == null)
            {
                ExceptionHelper.ArgumentNullException("mapper");
            }
            if (annObject == null)
            {
                ExceptionHelper.ArgumentNullException("annObject");
            }

            AnnWinFormsRenderingEngine engine = RenderingEngine as AnnWinFormsRenderingEngine;

            if (engine != null && engine.Context != null)
            {
                base.Render(mapper, annObject);

                AnnCobbAngleObject annCobbAngleObject = annObject as AnnCobbAngleObject;
                if (annCobbAngleObject != null)
                {
                    base.LinesAsRulers = annCobbAngleObject.LinesAsRulers;

                    int count = annCobbAngleObject.Points.Count;
                    if (count < 2)
                    {
                        return;
                    }

                    LeadPointD[] leadPoints = mapper.PointsFromContainerCoordinates(annCobbAngleObject.Points.ToArray(), annCobbAngleObject.FixedStateOperations);
                    PointF[]     points     = AnnWinFormsRenderingEngine.ToPoints(leadPoints);

                    if (annCobbAngleObject.SupportsStroke && annCobbAngleObject.Stroke != null)
                    {
                        using (Pen pen = AnnWinFormsRenderingEngine.ToPen(mapper.StrokeFromContainerCoordinates(annCobbAngleObject.Stroke, annCobbAngleObject.FixedStateOperations), annCobbAngleObject.Opacity))
                        {
                            if (points.Length > 3)
                            {
                                AnnCobbAngleData cobbAngleData     = annCobbAngleObject.CobbAngleData;
                                LeadPointD       firstPoint        = mapper.PointFromContainerCoordinates(cobbAngleData.FirstPoint, annCobbAngleObject.FixedStateOperations);
                                LeadPointD       secondPoint       = mapper.PointFromContainerCoordinates(cobbAngleData.SecondPoint, annCobbAngleObject.FixedStateOperations);
                                LeadPointD       intersectionPoint = mapper.PointFromContainerCoordinates(cobbAngleData.IntersectionPoint, annCobbAngleObject.FixedStateOperations);

                                pen.Brush       = Brushes.Blue;
                                pen.DashPattern = new float[] { 4, 2, 2, 2, 2, 2 };
                                engine.Context.DrawLine(pen, new PointF((float)firstPoint.X, (float)firstPoint.Y), new PointF((float)intersectionPoint.X, (float)intersectionPoint.Y));
                                engine.Context.DrawLine(pen, new PointF((float)secondPoint.X, (float)secondPoint.Y), new PointF((float)intersectionPoint.X, (float)intersectionPoint.Y));

                                //Draw angle label
                                if (annCobbAngleObject.Labels.ContainsKey("CobbAngle"))
                                {
                                    AnnLabel label = annCobbAngleObject.Labels["CobbAngle"];
                                    if (label != null)
                                    {
                                        string precisionFormat = string.Format("XXX:F{0}", annCobbAngleObject.AnglePrecision);
                                        precisionFormat = precisionFormat.Replace("XXX", "{0");
                                        precisionFormat = string.Format("{0}{1}", precisionFormat, "}");

                                        string angle = string.Format(precisionFormat, cobbAngleData.Angle);
                                        angle = string.Format("{0} {1}", angle, "\u00B0");

                                        label.Text             = angle;
                                        label.Foreground       = AnnSolidColorBrush.Create("White");
                                        label.Background       = AnnSolidColorBrush.Create("Blue");
                                        label.OriginalPosition = cobbAngleData.IntersectionPoint;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 18
0
        public override void Render(AnnContainerMapper mapper, AnnObject annObject)
        {
            if (mapper == null)
            {
                ExceptionHelper.ArgumentNullException("mapper");
            }
            if (annObject == null)
            {
                ExceptionHelper.ArgumentNullException("annObject");
            }

            base.Render(mapper, annObject);
            AnnRichTextObject annRichTextObject = annObject as AnnRichTextObject;

            if (annRichTextObject != null && !String.IsNullOrEmpty(annRichTextObject.Rtf))
            {
                AnnWinFormsRenderingEngine engine = RenderingEngine as AnnWinFormsRenderingEngine;
                if (engine != null && engine.Context != null)
                {
                    AnnRectangleObject tempRect = new AnnRectangleObject();
                    tempRect.Points.Clear();
                    foreach (LeadPointD pt in GetRenderPoints(mapper, annRichTextObject))
                    {
                        tempRect.Points.Add(pt);
                    }

                    double rotation = tempRect.Angle;
                    if (rotation == 180)
                    {
                        rotation = 0;
                    }

                    LeadRectD          boundsPixels   = tempRect.Rect.Clone();
                    AnnContainerMapper identityMapper = mapper.Clone();
                    identityMapper.UpdateTransform(LeadMatrix.Identity);
                    identityMapper.MapResolutions(mapper.SourceDpiX, mapper.SourceDpiY, mapper.SourceDpiX, mapper.SourceDpiY);
                    boundsPixels = identityMapper.RectFromContainerCoordinates(boundsPixels, annRichTextObject.FixedStateOperations);
                    if (tempRect.Stroke != null)
                    {
                        boundsPixels.Inflate(-tempRect.Stroke.StrokeThickness.Value, -tempRect.Stroke.StrokeThickness.Value);
                    }

                    string rtf = annRichTextObject.Rtf;
                    IntPtr hemfDC;
                    if (_richTextBox == null)
                    {
                        _richTextBox = new InternalRichTextEdit();
                    }

                    try
                    {
                        _richTextBox.Rtf = rtf;
                    }
                    catch
                    {
                        using (RichTextBox richTextBox = new RichTextBox())
                        {
                            richTextBox.Text      = rtf;
                            annRichTextObject.Rtf = richTextBox.Rtf;
                            _richTextBox.Rtf      = richTextBox.Rtf;
                        }
                    }

                    Graphics graphics = engine.Context;
                    double   dpiX     = 96;
                    double   dpiY     = 96;

                    _richTextBox.Location = new Point((int)boundsPixels.Location.X, (int)boundsPixels.Location.Y);
                    _richTextBox.Size     = new Size((int)boundsPixels.Size.Width, (int)boundsPixels.Size.Height);
                    IntPtr hdc = graphics.GetHdc();

                    Win32.RECT rc = new Win32.RECT();

                    rc.left   = _richTextBox.ClientRectangle.Left;
                    rc.top    = _richTextBox.ClientRectangle.Top;
                    rc.right  = (int)boundsPixels.Width;
                    rc.bottom = (int)boundsPixels.Height;

                    int iWidthMM    = SafeNativeMethods.GetDeviceCaps(hdc, Win32.HORZSIZE);
                    int iHeightMM   = SafeNativeMethods.GetDeviceCaps(hdc, Win32.VERTSIZE);
                    int iWidthPels  = SafeNativeMethods.GetDeviceCaps(hdc, Win32.HORZRES);
                    int iHeightPels = SafeNativeMethods.GetDeviceCaps(hdc, Win32.VERTRES);

                    rc.left   = (rc.left * iWidthMM * 100) / iWidthPels;
                    rc.top    = (rc.top * iHeightMM * 100) / iHeightPels;
                    rc.right  = (rc.right * iWidthMM * 100) / iWidthPels;
                    rc.bottom = (rc.bottom * iHeightMM * 100) / iHeightPels;

                    hemfDC = SafeNativeMethods.CreateEnhMetaFile(hdc, null, ref rc, null);

                    Win32.RECT emfRect = new Win32.RECT();
                    emfRect.right  = (int)boundsPixels.Width;
                    emfRect.bottom = (int)boundsPixels.Height;

                    IntPtr brush = SafeNativeMethods.GetStockObject(5);
                    SafeNativeMethods.SetBkMode(hemfDC, 1);
                    SafeNativeMethods.FillRect(hemfDC, ref emfRect, brush);
                    SafeNativeMethods.DeleteObject(brush);

                    Print(_richTextBox, _richTextBox.ClientRectangle, hemfDC, (int)dpiX, (int)dpiY, false);
                    IntPtr hemf = SafeNativeMethods.CloseEnhMetaFile(hemfDC);

                    using (Metafile metaFile = new Metafile(hemf, true))
                    {
                        graphics.ReleaseHdc();
                        GraphicsState state = graphics.Save();

                        //the mapper transform dosent contain dpi effect so we will add dpi effect .
                        LeadMatrix matrix = mapper.Transform;
                        //add dpi effect to the transform
                        matrix.Scale((float)(mapper.TargetDpiX / mapper.SourceDpiX), (float)(mapper.TargetDpiY / mapper.SourceDpiY));

                        if ((annRichTextObject.FixedStateOperations & AnnFixedStateOperations.Scrolling) == AnnFixedStateOperations.Scrolling)
                        {
                            matrix.Translate(-matrix.OffsetX, -matrix.OffsetY);
                        }

                        if ((annRichTextObject.FixedStateOperations & AnnFixedStateOperations.Zooming) == AnnFixedStateOperations.Zooming)
                        {
                            double offsetX = matrix.OffsetX;
                            double offsetY = matrix.OffsetY;
                            double scaleX  = 1.0;
                            double scaleY  = 1.0;
                            if (matrix.M11 != 0 && matrix.M22 != 0)
                            {
                                scaleX = 1.0 / Math.Abs(matrix.M11);
                                scaleY = 1.0 / Math.Abs(matrix.M22);
                            }

                            matrix.Scale(scaleX, scaleY);
                        }

                        using (Matrix transform = new Matrix((float)matrix.M11, (float)matrix.M12, (float)matrix.M21, (float)matrix.M22, (float)matrix.OffsetX, (float)matrix.OffsetY))
                        {
                            graphics.MultiplyTransform(transform);
                            graphics.DrawImage(metaFile, new Point((int)boundsPixels.Left, (int)boundsPixels.Top));
                        }
                        graphics.Restore(state);
                    }
                }

                //EndDraw(graphics, gState);
            }
        }