Exemplo n.º 1
0
        public void DoSmartTrimMarks(DoMarksProperties props, ShapeRange sr)
        {
            HashSet <FigureBBox> figureBBoxes = GetFigureBBoxes(sr, props);
            FigureBBox           overBBox     = GetOverlapBBox(figureBBoxes);
            HashSet <Mark>       marks        = LayoutMarks(figureBBoxes, overBBox, props);

            DrawMarks(marks, props);
        }
Exemplo n.º 2
0
        private void doSmartTrimMark(object sender, RoutedEventArgs e)
        {
            if (corelApp.Documents.Count == 0)
            {
                return;
            }

            corelApp.ActiveDocument.Unit = cdrUnit.cdrMillimeter;
            ShapeRange sr = new ShapeRange();

            sr = corelApp.ActiveSelectionRange;

            if (sr.Count == 0)
            {
                return;
            }

            if ((chxLeft.IsChecked ?? false) &&
                (chxRight.IsChecked ?? false) &&
                (chxTop.IsChecked ?? false) &&
                (chxBottom.IsChecked ?? false))
            {
                return;
            }

            SmartTrimMark smtm = new SmartTrimMark(corelApp);

            corelApp.Optimization = true;

            var props = new DoMarksProperties(
                tbOffset.Value,
                tbMarkHeight.Value,
                chxOneShootCut.IsChecked ?? false,
                chxCanDecrease.IsChecked ?? false,
                chxWhiteSubMark.IsChecked ?? false,
                chxLeft.IsChecked ?? false,
                chxRight.IsChecked ?? false,
                chxTop.IsChecked ?? false,
                chxBottom.IsChecked ?? false);

            smtm.DoSmartTrimMarks(props, sr);

            corelApp.ActiveDocument.ClearSelection();
            corelApp.Optimization = false;
            corelApp.ActiveWindow.Refresh();
            corelApp.Refresh();
        }
Exemplo n.º 3
0
 private bool PointOutside(FigureBBox box, double x, double y, DoMarksProperties props)
 {
     if (props.ExcludeLeftEdge && x < box.X + safeZone)
     {
         return(true);
     }
     if (props.ExcludeRightEdge && x > box.Right - safeZone)
     {
         return(true);
     }
     if (props.ExcludeTopEdge && y > box.Top - safeZone)
     {
         return(true);
     }
     if (props.ExcludeBottomEdge && y < box.Y + safeZone)
     {
         return(true);
     }
     return(false);
 }
Exemplo n.º 4
0
        private void DrawMarks(HashSet <Mark> marks, DoMarksProperties props)
        {
            ShapeRange sr = new ShapeRange();

            foreach (var item in marks)
            {
                sr.Add(DrawLine(item));
            }

            Shape groupMarks = sr.Group();

            if (props.WhiteSubMark)
            {
                Shape wsm = groupMarks.Duplicate();
                wsm.Outline.SetProperties(1, corelApp.OutlineStyles[0], corelApp.CreateCMYKColor(0, 0, 0, 0));
                wsm.OrderBackOne();
                ShapeRange tempSr = new ShapeRange();
                tempSr.Add(wsm);
                tempSr.Add(groupMarks);
                tempSr.Group();
            }
        }
Exemplo n.º 5
0
        private HashSet <FigureBBox> GetFigureBBoxes(ShapeRange sr, DoMarksProperties props)
        {
            HashSet <FigureBBox> result = new HashSet <FigureBBox>();

            foreach (corel.Shape item in sr)
            {
                if (!props.OneCutting)
                {
                    result.Add(new FigureBBox(item.BoundingBox));
                }
                else
                {
                    var bbox   = item.BoundingBox;
                    var x      = bbox.x - props.Offset;
                    var y      = bbox.y - props.Offset;
                    var width  = props.Offset * 2 + bbox.Width;
                    var height = props.Offset * 2 + bbox.Height;
                    result.Add(new FigureBBox(x, y, width, height));
                }
            }

            return(result);
        }
Exemplo n.º 6
0
        private void NewMark(HashSet <Mark> marks, HashSet <FigureBBox> bBoxes, FigureBBox overBBox, DoMarksProperties props, double sx, double sy, int directionX, int directionY)
        {
            if (PointOutside(overBBox, sx, sy, props))
            {
                return;
            }

            var height = props.MarkHeight;

            do
            {
                var ex = directionX * height + sx;
                var ey = directionY * height + sy;
                if (PointInside(bBoxes, ex, ey))
                {
                    if (props.CanDecrease)
                    {
                        height -= decrement;
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    marks.Add(new Mark(new Point(sx, sy), new Point(ex, ey)));
                    break;
                }
            } while (height > 0);
        }
Exemplo n.º 7
0
        private HashSet <Mark> LayoutMarks(HashSet <FigureBBox> bBoxes, FigureBBox overBBox, DoMarksProperties props)
        {
            var marks = new HashSet <Mark>();

            foreach (var bbox in bBoxes)
            {
                NewMark(marks, bBoxes, overBBox, props, bbox.X, bbox.Top - props.Offset, -1, 0);
                NewMark(marks, bBoxes, overBBox, props, bbox.X, bbox.Y + props.Offset, -1, 0);
                NewMark(marks, bBoxes, overBBox, props, bbox.X + props.Offset, bbox.Y, 0, -1);
                NewMark(marks, bBoxes, overBBox, props, bbox.Right - props.Offset, bbox.Y, 0, -1);
                NewMark(marks, bBoxes, overBBox, props, bbox.Right, bbox.Y + props.Offset, 1, 0);
                NewMark(marks, bBoxes, overBBox, props, bbox.Right, bbox.Top - props.Offset, 1, 0);
                NewMark(marks, bBoxes, overBBox, props, bbox.Right - props.Offset, bbox.Top, 0, 1);
                NewMark(marks, bBoxes, overBBox, props, bbox.X + props.Offset, bbox.Top, 0, 1);
            }
            return(marks);
        }