Exemple #1
0
        void _rasterImageList_PostRender(object sender, Leadtools.Controls.ImageViewerRenderEventArgs e)
        {
            for (int i = 0; i < _rasterImageList.Items.Count; i++)
            {
                ImageViewerItem item = _rasterImageList.Items[i];

                LeadRectD itemLeadRect  = _rasterImageList.GetItemBounds(item, ImageViewerItemPart.Item);
                Rectangle itemRect      = new Rectangle((int)itemLeadRect.X, (int)itemLeadRect.Y, (int)itemLeadRect.Width, (int)itemLeadRect.Height);
                LeadSize  itemImageSize = _rasterImageList.GetItemImageSize(item, false);

                LeadRect imageRect = new LeadRect(
                    itemRect.Left + (itemRect.Width - itemImageSize.Width) / 2,
                    itemRect.Top + (itemRect.Height - itemImageSize.Height) / 2,
                    itemImageSize.Width,
                    itemImageSize.Height);

                itemLeadRect = ImageViewer.GetDestinationRectangle(item.Image.ImageWidth, item.Image.ImageHeight, imageRect, ControlSizeMode.None, ControlAlignment.Near, ControlAlignment.Near).ToLeadRectD();

                var destRect = LeadRectD.Create(itemLeadRect.X, itemLeadRect.Y, itemLeadRect.Width * 720.0 / 96.0, itemLeadRect.Height * 720.0 / 96.0);

                destRect.X = 0.0;
                destRect.Y = 0.0;

                //Get the graphic object from the item's image to draw (burn) annotations on it.
                Leadtools.Drawing.RasterImageGdiPlusGraphicsContainer GdiPlusGraphicsContainer = new RasterImageGdiPlusGraphicsContainer(item.Image);
                Graphics g = GdiPlusGraphicsContainer.Graphics;

                // Use anti-aliasing
                g.SmoothingMode = SmoothingMode.AntiAlias;

                // Now draw the annotation s on this rectangle
                if (_automationManager != null && _automation.Containers.Count > 0 && _automation.Containers.Count > i)
                {
                    AnnContainer container = _automation.Containers[i];

                    //Clear the old painting
                    g.Clear(Color.White);

                    //Burn the current annotations to the image list item
                    if (container != null)
                    {
                        AnnWinFormsRenderingEngine engine = new AnnWinFormsRenderingEngine();
                        engine.Resources = _automationManager.Resources;

                        // Save its visible state and set it to true (it is false if viewer is in single mode)
                        bool containerIsVisible = container.IsVisible;
                        container.IsVisible = true;

                        engine.Attach(container, g);
                        engine.BurnToRectWithDpi(destRect, 96, 96, 96, 96);
                        engine.Detach();

                        if (container.IsVisible != containerIsVisible)
                        {
                            container.IsVisible = containerIsVisible;
                        }
                    }
                }
            }
        }
Exemple #2
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
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #3
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]);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #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);

                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);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #5
0
        public AutomationTextBox(Control parent, AnnAutomation automation, AnnEditTextEventArgs editTextEvent, RemoveAction removeAction)
        {
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }
            if (editTextEvent == null)
            {
                throw new ArgumentNullException("editTextEvent");
            }

            _textObject = editTextEvent.TextObject;
            if (_textObject == null)
            {
                throw new InvalidOperationException("No annotation text object was found in the event");
            }

            _removeAction = removeAction;
            _automation   = automation;

            var rect = editTextEvent.Bounds.ToLeadRect();

            rect.Inflate(12, 12);

            this.SuspendLayout();
            this.Location = new Point(rect.X, rect.Y);
            this.Size     = new Size(rect.Width, rect.Height);
            this.AutoSize = false;
            this.Tag      = _textObject;
            this.Text     = _textObject.Text;
            this.Name     = "AnnotationsText";
            this.Font     = AnnWinFormsRenderingEngine.ToFont(_textObject.Font);

            var brush = _textObject.TextForeground as AnnSolidColorBrush;

            if (brush != null)
            {
                this.ForeColor = Color.FromName(brush.Color);
            }

            this.WordWrap      = false;
            this.AcceptsReturn = true;
            this.Multiline     = true;
            this.ResumeLayout();

            //this.LostFocus += new EventHandler(AutomationTextBox_LostFocus);
            //this.KeyPress += new KeyPressEventHandler(AutomationTextBox_KeyPress);

            parent.Controls.Add(this);

            this.Focus();
            this.SelectAll();
        }
Exemple #6
0
        private void DrawPoint(AnnMidlineObject annObject, Graphics context, PointF point, double radius)
        {
            LeadRectD  pointBounds = new LeadRectD(point.X - radius, point.Y - radius, radius * 2, radius * 2);
            LeadPointD topLeft     = pointBounds.TopLeft;
            LeadPointD topRight    = pointBounds.TopRight;
            LeadPointD bottomLeft  = pointBounds.BottomLeft;
            LeadPointD bottomRight = pointBounds.BottomRight;

            using (Pen pen = AnnWinFormsRenderingEngine.ToPen(AnnStroke.Create(AnnSolidColorBrush.Create("blue"), annObject.Stroke.StrokeThickness), annObject.Opacity))
            {
                context.DrawLine(pen, new PointF((float)topLeft.X, (float)topLeft.Y), new PointF((float)bottomRight.X, (float)bottomRight.Y));
                context.DrawLine(pen, new PointF((float)bottomLeft.X, (float)bottomLeft.Y), new PointF((float)topRight.X, (float)topRight.Y));
                context.DrawLine(pen, new PointF((float)point.X, (float)(point.Y - pointBounds.Width / 2)), new PointF((float)point.X, (float)(point.Y + pointBounds.Width / 2)));
                context.DrawLine(pen, new PointF((float)point.X - (float)pointBounds.Width / 2, (float)(point.Y)), new PointF((float)point.X + (float)pointBounds.Width / 2, (float)(point.Y)));
            }
        }
        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);
        }
Exemple #8
0
        private static void RenderContainer(PaintEventArgs e, AnnWinFormsRenderingEngine engine, AnnContainer container, bool runMode)
        {
            // Attach to the current container and graphics.
            var context       = e.Graphics;
            var clipRectangle = e.ClipRectangle;

            engine.Attach(container, context);

            try
            {
                // Render the annotatirons
                var rc = LeadRectD.Create(clipRectangle.X, clipRectangle.Y, clipRectangle.Width, clipRectangle.Height);
                rc = container.Mapper.RectToContainerCoordinates(rc);
                engine.Render(rc, runMode);
            }
            finally
            {
                engine.Detach();
            }
        }
        private void RenderContainer(PaintEventArgs e, AnnWinFormsRenderingEngine engine, AnnContainer container)
        {
            // Attach to the current container and graphics.
            Graphics  graphics      = e.Graphics;
            Rectangle clipRectangle = e.ClipRectangle;

            try
            {
                engine.Attach(container, graphics);

                // Render the annotatirons
                LeadRectD rc = LeadRectD.Create(clipRectangle.X, clipRectangle.Y, clipRectangle.Width, clipRectangle.Height);
                rc = container.Mapper.RectToContainerCoordinates(rc);
                engine.Render(rc, true);
            }
            finally
            {
                engine.Detach();
            }
        }
Exemple #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);
                    }
                }
            }
        }
Exemple #11
0
        private void _btnChangeFont_Click(object sender, EventArgs e)
        {
            using (FontDialog fontDialog = new FontDialog())
            {
                fontDialog.ShowColor = true;
                fontDialog.Font      = _lblBatesText.Font;
                fontDialog.Color     = _lblBatesText.ForeColor;

                if (fontDialog.ShowDialog() == DialogResult.OK)
                {
                    _lblBatesText.Font      = fontDialog.Font;
                    _lblBatesText.ForeColor = fontDialog.Color;

                    Font font = _lblBatesText.Font;
                    _currentBatesStamp.Font       = AnnWinFormsRenderingEngine.FromFont(font);
                    _currentBatesStamp.Logo.Font  = AnnWinFormsRenderingEngine.FromFont(font);
                    _currentBatesStamp.Foreground = AnnSolidColorBrush.Create(_lblBatesText.ForeColor.Name);
                }

                UpdateControls();
            }
        }
Exemple #12
0
        void automation_EditText(object sender, AnnEditTextEventArgs e)
        {
            TextBox   text = new TextBox();
            Rectangle rc   = new Rectangle((int)e.Bounds.Left, (int)e.Bounds.Top, (int)e.Bounds.Width, (int)e.Bounds.Height);

            rc.Inflate(12, 12);
            text.Location      = rc.Location;
            text.Size          = rc.Size;
            text.AutoSize      = false;
            text.Tag           = e.TextObject;
            text.Text          = e.TextObject.Text;
            text.ForeColor     = Color.FromName((e.TextObject.TextForeground as AnnSolidColorBrush).Color);
            text.Font          = AnnWinFormsRenderingEngine.ToFont(e.TextObject.Font);
            text.WordWrap      = false;
            text.AcceptsReturn = true;
            text.Multiline     = true;
            text.Tag           = e.TextObject;

            text.LostFocus += new EventHandler(text_LostFocus);
            _imageViewer.Controls.Add(text);
            text.Focus();
            text.SelectAll();
        }
        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]);
                            }
                        }
                    }
                }
            }
        }
        // Paint the annotations using the rendering engine (with anti-alias support)
        protected override void OnPostImagePaint(PaintEventArgs e)
        {
            if (IsAutomationAttached)
            {
                AnnWinFormsRenderingEngine engine = _engine as AnnWinFormsRenderingEngine;

                try
                {
                    // Set the anti alias mode
                    e.Graphics.SmoothingMode = AntiAlias ? SmoothingMode.AntiAlias : SmoothingMode.None;


                    // Render all containers
                    if (_automationGetContainersCallback != null)
                    {
                        // Using multi-containers
                        AnnContainerCollection containers = _automationGetContainersCallback();
                        foreach (AnnContainer container in containers)
                        {
                            RenderContainer(e, engine, container);
                        }
                    }
                    else
                    {
                        // Using single-containers, just render the active
                        RenderContainer(e, engine, _container);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

            base.OnPostImagePaint(e);
        }
        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);
            }
        }
        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;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #17
0
        private void UpdateControls()
        {
            if (_listBoxContainerStamps.SelectedIndex != -1)
            {
                _btnRemoveStamp.Enabled         = true;
                _groupBoxStampText.Enabled      = true;
                _groupBoxStampAlignment.Enabled = true;
                _groupBoxStampLogo.Enabled      = true;
                _groupBoxStampElements.Enabled  = true;
            }
            else
            {
                _btnRemoveStamp.Enabled         = false;
                _groupBoxStampText.Enabled      = false;
                _groupBoxStampAlignment.Enabled = false;
                _groupBoxStampLogo.Enabled      = false;
                _groupBoxStampElements.Enabled  = false;
                _txtElements.Text            = string.Empty;
                _checkBoxStretchLogo.Checked = false;
            }

            if (_checkBoxStretchLogo.Checked)
            {
                _groupBoxLogoPosition.Enabled = false;
            }
            else
            {
                _groupBoxLogoPosition.Enabled = true;
            }

            _currentBatesStamp = _listBoxContainerStamps.SelectedItem as AnnBatesStamp;

            if (_currentBatesStamp != null)
            {
                AnnBatesStampLogo logo = _currentBatesStamp.Logo;

                _lblBatesText.Font = AnnWinFormsRenderingEngine.ToFont(_currentBatesStamp.Font);
                AnnSolidColorBrush solidBrush = _currentBatesStamp.Foreground as AnnSolidColorBrush;
                _lblBatesText.ForeColor = ColorTranslator.FromHtml(solidBrush.Color);
                _lblBatesText.Text      = _currentBatesStamp.AsString(_automation.Container);
                _comboHorizontalAlignment.SelectedIndex = (int)_currentBatesStamp.HorizontalAlignment;
                _comboVerticalAlignment.SelectedIndex   = (int)_currentBatesStamp.VerticalAlignment;

                AnnPicture logoPicture = logo.Picture;
                if (_logoPictureBox.Image != null)
                {
                    _logoPictureBox.Image.Dispose();
                }

                if (logoPicture != null && logoPicture.PictureData != null)
                {
                    using (MemoryStream memoryStream = new MemoryStream(Convert.FromBase64String(logoPicture.PictureData)))
                    {
                        _logoPictureBox.Image = Image.FromStream(memoryStream);
                    }
                }
                else
                {
                    _logoPictureBox.Image = null;
                }

                LeadRectD logoPosition = _automation.Container.Mapper.RectFromContainerCoordinates(logo.LogoRect, AnnFixedStateOperations.None);
                _txtLogoPositionX.Text      = Math.Max(0, logoPosition.X).ToString();
                _txtLogoPositionY.Text      = Math.Max(0, logoPosition.Y).ToString();
                _txtLogoPositionWidth.Text  = Math.Round(logoPosition.Width, 1).ToString();
                _txtLogoPositionHeight.Text = Math.Round(logoPosition.Height, 1).ToString();

                _txtLogoOpacity.Text       = logo.Opacity.ToString();
                _txtLogoText.Text          = logo.Text;
                _txtLogoRotationAngle.Text = logo.Angle.ToString();

                _checkBoxStretchLogo.Checked = logo.StretchLogo;

                _txtElements.Text = _translator.WriteElementsToString(_currentBatesStamp.Elements.ToArray());
            }
            else //set default values
            {
                _lblBatesText.Font      = new Font(new FontFamily("Microsoft Sans Serif"), 8);
                _lblBatesText.ForeColor = Color.Black;
                _lblBatesText.Text      = string.Empty;
                _comboHorizontalAlignment.SelectedIndex = -1;
                _comboVerticalAlignment.SelectedIndex   = -1;
                _logoPictureBox.Image       = null;
                _txtLogoPositionX.Text      = "0";
                _txtLogoPositionY.Text      = "0";
                _txtLogoPositionWidth.Text  = "0";
                _txtLogoPositionHeight.Text = "0";
                _txtLogoOpacity.Text        = "1";
                _txtLogoText.Text           = string.Empty;
                _txtLogoRotationAngle.Text  = "0";
            }

            _btnDeleteLogoPicture.Enabled = (_logoPictureBox.Image != null);
            _automation.Invalidate(LeadRectD.Empty);
        }