Exemplo n.º 1
0
        private void decorateShape(semImage curShape)
        {
            ShapeRange SR = new ShapeRange();
            ShapeRange TextShapes = new ShapeRange();
            Shape Brect, Lrect, Wline, Ttext, Gr;
            double LmarginH, LmarginV, TmarginH, TmarginV, Theight;
            double Lwidth, Wwidth, Wheight, Lheight;
            double Left, Bottom, Width, Height;
            double oldCenterX, oldCenterY;
            double cimgratio;
            bool NoBar = false;
            Shape s = curShape.imgShape;
            semImageData d = curShape.imgData;
            double OffsetResolution = s.Bitmap.SizeWidth / s.SizeWidth;
            double bCut = 1d - d.CutBottom;
            Color White, Black;

            White = new Color();
            Black = new Color();
            Black.CMYKAssign(0, 0, 0, 100);
            White.CMYKAssign(0, 0, 0, 0);

            oldCenterX = s.CenterX;
            oldCenterY = s.CenterY;

            Left = s.LeftX;
            Bottom = s.BottomY;

            cimgratio = (s.SizeHeight * bCut) / s.SizeWidth;

            if (d.Width == 0d && d.Height == 0d)
            {
                Width = s.SizeWidth;
                Height = s.SizeHeight * bCut;
            }
            else if (d.Width == 0d)
            {
                Height = cmToUnit(d.Height);
                Width = Height / cimgratio;
            }
            else if (d.Height == 0d)
            {
                Width = cmToUnit(d.Width);
                Height = Width * cimgratio;
            }
            else
            {
                Width = cmToUnit(d.Width);
                Height = cmToUnit(d.Height);
            }
            double newRatio = Height / Width;

            if (newRatio <= cimgratio)
            {
                s.SizeWidth = Width;
                s.SizeHeight = (Width * cimgratio) / bCut;
            }
            else
            {
                s.SizeHeight = Height / bCut;
                s.SizeWidth = Height / cimgratio;
            }
            s.LeftX = Left;
            s.BottomY = Bottom;

            if (d.Mode == (int)CreateMode.Calib)
            {
                curShape.calcScale();
            }
            else if (d.Width == 0 || d.BarText == "")
            {
                NoBar = true;
            }

            Lwidth = cmToUnit(curShape.imgData.BarLength);

            Lheight = ptToUnit(8);
            LmarginH = ptToUnit(8);
            LmarginV = ptToUnit(4);
            TmarginH = ptToUnit(4);
            TmarginV = ptToUnit(4);

            Theight = ptToUnit(d.FontSize);
            Wwidth = Lwidth + 2 * LmarginH;
            Wheight = Lheight + LmarginV + TmarginV;

            Brect = CDWin.ActiveLayer.CreateRectangle2(Left, Bottom, Width, Height);
            Brect.Outline.Color = Black;
            Brect.Outline.Width = ptToUnit(d.BorderWidth);

            s.Name = "semItemContent";
            s.AlignToShape(CorelDRAW.cdrAlignType.cdrAlignTop, Brect);
            s.AddToPowerClip(Brect, CorelDRAW.cdrTriState.cdrFalse);

            if (d.ValInBar == true)
            {
                Wheight = Theight + 2 * TmarginV;
            }

            if (!NoBar)
            {
                Lrect = CDWin.ActiveLayer.CreateRectangle2(Left + Width - Wwidth, Bottom, Wwidth, Wheight + ((d.ValInBar != true) ? Theight : 0));
                Wline = CDWin.ActiveLayer.CreateLineSegment(Left + Width - LmarginH - Lwidth, Bottom + Wheight / 2, Left + Width - LmarginH, Bottom + Wheight / 2);
                Ttext = CDWin.ActiveLayer.CreateArtisticText(Left + Width - Wwidth / 2, Bottom + Wheight / 2 + TmarginV, d.BarText, Alignment: CorelDRAW.cdrAlignment.cdrCenterAlignment, Size: d.FontSize, Font: d.FontName);
                //Ttext.Text.Story.Font

                Ttext.Text.Story.Bold = d.TextBold == true;
                Lrect.Outline.Width = 0;
                Lrect.Fill.ApplyUniformFill(White);

                Wline.Outline.Width = ptToUnit(d.BarWidth);
                Wline.Outline.Color = Black;
                Wline.Outline.EndArrow = CDWin.ArrowHeads[59];
                Wline.Outline.StartArrow = CDWin.ArrowHeads[59];

                if (d.ValInBar == true)
                {
                    Shape Trect;
                    Trect = CDWin.ActiveLayer.CreateRectangle2(Left + Width, Bottom, 2d * TmarginH + Ttext.SizeWidth, Ttext.SizeHeight);
                    Ttext.AlignToShape(CorelDRAW.cdrAlignType.cdrAlignVCenter, Wline, CorelDRAW.cdrTextAlignOrigin.cdrTextAlignBoundingBox);
                    Ttext.AlignToShape(CorelDRAW.cdrAlignType.cdrAlignHCenter, Wline, CorelDRAW.cdrTextAlignOrigin.cdrTextAlignBoundingBox);
                    Trect.AlignToShape(CorelDRAW.cdrAlignType.cdrAlignVCenter, Ttext);
                    Trect.AlignToShape(CorelDRAW.cdrAlignType.cdrAlignHCenter, Ttext);
                    Trect.Fill.ApplyUniformFill(White);
                    Trect.Outline.Width = 0;
                    Trect.OrderBackOf(Ttext);
                    SR.Add(Trect);
                }

                SR.Add(Lrect);
                SR.Add(Wline);
                SR.Add(Ttext);
                Gr = SR.Group();
                Gr.AddToPowerClip(Brect, CorelDRAW.cdrTriState.cdrFalse);
            }

            if (d.ULtext.Trim() != "")
            {
                Shape back, text;
                text = CDWin.ActiveLayer.CreateArtisticText(Left + TmarginH, Bottom + Height - Theight - TmarginV, d.ULtext, Alignment: CorelDRAW.cdrAlignment.cdrLeftAlignment, Size: d.FontSize, Font: d.FontName);
                back = CDWin.ActiveLayer.CreateRectangle2(Left, Bottom + Height - Theight - 2d * TmarginV, text.SizeWidth + 2d * TmarginH, Theight + 2 * TmarginV);
                back.Fill.ApplyUniformFill(White);
                text.AlignToShape(CorelDRAW.cdrAlignType.cdrAlignHCenter, back);
                text.AlignToShape(CorelDRAW.cdrAlignType.cdrAlignBottom, back, CorelDRAW.cdrTextAlignOrigin.cdrTextAlignFirstBaseline);
                text.BottomY += TmarginV;
                back.Outline.Width = 0;
                back.OrderBackOf(text);
                text.Text.Story.Bold = d.TextBold == true;
                TextShapes.Add(text);
                TextShapes.Add(back);
            }

            if (d.URtext != "")
            {
                Shape back, text;
                text = CDWin.ActiveLayer.CreateArtisticText(Left + Width - TmarginH, Bottom + Height - Theight - TmarginV, d.URtext, Alignment: CorelDRAW.cdrAlignment.cdrRightAlignment, Size: d.FontSize, Font: d.FontName);
                back = CDWin.ActiveLayer.CreateRectangle2(Left + Width - text.SizeWidth - 2 * TmarginH, Bottom + Height - Theight - 2 * TmarginV, text.SizeWidth + 2 * TmarginH, Theight + 2 * TmarginV);
                back.Fill.ApplyUniformFill(White);
                text.AlignToShape(CorelDRAW.cdrAlignType.cdrAlignHCenter, back);
                text.AlignToShape(CorelDRAW.cdrAlignType.cdrAlignBottom, back, CorelDRAW.cdrTextAlignOrigin.cdrTextAlignFirstBaseline);
                text.BottomY += TmarginV;
                back.Outline.Width = 0;
                back.OrderBackOf(text);
                text.Text.Story.Bold = d.TextBold == true;
                TextShapes.Add(text);
                TextShapes.Add(back);
            }

            if (d.BLtext != "")
            {
                Shape back, text;
                text = CDWin.ActiveLayer.CreateArtisticText(Left + TmarginH, Bottom + TmarginV, d.BLtext, Alignment: CorelDRAW.cdrAlignment.cdrLeftAlignment, Size: d.FontSize, Font: d.FontName);
                back = CDWin.ActiveLayer.CreateRectangle2(Left, Bottom, text.SizeWidth + 2 * TmarginH, Theight + 2 * TmarginV);
                back.Fill.ApplyUniformFill(White);
                text.AlignToShape(CorelDRAW.cdrAlignType.cdrAlignHCenter, back);
                text.AlignToShape(CorelDRAW.cdrAlignType.cdrAlignBottom, back, CorelDRAW.cdrTextAlignOrigin.cdrTextAlignFirstBaseline);
                text.BottomY += TmarginV;
                back.Outline.Width = 0;
                back.OrderBackOf(text);
                text.Text.Story.Bold = d.TextBold == true;
                TextShapes.Add(text);
                TextShapes.Add(back);
            }

            TextShapes.AddToPowerClip(Brect, CorelDRAW.cdrTriState.cdrFalse);

            Brect.Properties["semItem", 0] = true;
            Brect.Properties["semItem", 1] = curShape.imgData.ToString();
            if (d.filename != "") Brect.Name = d.filename;

            Brect.CenterX = oldCenterX;
            Brect.CenterY = oldCenterY;

            CDWin.ActiveWindow.Refresh();
            CDWin.Application.Refresh();
            CDWin.ActiveDocument.ClearSelection();

            Brect.Selected = true;
        }
Exemplo n.º 2
0
        private void DoDecorate()
        {
            try
            {
                locked = true;
                if (CDWin == null || CDWin.ActiveDocument == null)
                {
                    MessageBox.Show("No open document");
                    return;
                }
                if (tabMode.SelectedIndex == 0 && _TiffItems.Count > 0)
                {
                    editShapes.Clear();
                    foreach (TIFFitem item in TiffItems)
                    {
                        CDWin.ActiveDocument.ClearSelection();
                        CDWin.ActiveDocument.ActiveLayer.Import(item.path);
                        CorelDRAW.Shape impShape = CDWin.ActiveSelection.Shapes[1];
                        impShape.AlignToPoint(CorelDRAW.cdrAlignType.cdrAlignVCenter, CDWin.Application.ActiveWindow.ActiveView.OriginX, CDWin.Application.ActiveWindow.ActiveView.OriginY);
                        impShape.AlignToPoint(CorelDRAW.cdrAlignType.cdrAlignHCenter, CDWin.Application.ActiveWindow.ActiveView.OriginX, CDWin.Application.ActiveWindow.ActiveView.OriginY);
                        semImage imp = new semImage(CDWin, currentSettings.Clone(), impShape);
                        imp.imgData.filename = Path.GetFileName(item.path);
                        imp.imgData.Calibration = item.calibration;
                        imp.imgData.Mode = (int)CreateMode.Calib;
                        imp.imgData.CutBottom = item.cutBottom / (double)imp.imgShape.Bitmap.SizeHeight;
                        editShapes.Add(imp);
                    }
                    _TiffItems.Clear();
                }
                else if (tabMode.SelectedIndex > 0 && CDWin.ActiveSelection.Shapes.Count > 0)
                {
                    foreach (Shape sh in CDWin.ActiveSelection.Shapes)
                    {
                        if (sh.Properties.Exists("semItem", 0))
                        {
                            foreach (Shape sh_child in sh.PowerClip.Shapes)
                            {
                                if (sh_child.Name == "semItemContent")
                                {
                                    editShapes.Add(new semImage(CDWin, currentSettings.Clone(), sh_child));
                                }
                                else
                                {
                                    sh_child.Delete();
                                }
                            }
                            sh.PowerClip.ExtractShapes();
                            sh.Delete();
                        }
                        else
                        {
                            editShapes.Add(new semImage(CDWin, currentSettings.Clone(), sh));
                        }
                    }
                }
                else
                {
                    MessageBox.Show("No image selected");
                    return;
                }

                try
                {
                    CDWin.Application.Optimization = true;
                    CDWin.ActiveDocument.BeginCommandGroup("SEM-Group");
                    foreach (semImage img in editShapes)
                    {
                        decorateShape(img);
                    }
                    editShapes.Clear();
                    CDWin.ActiveDocument.EndCommandGroup();
                    CDWin.Application.Optimization = false;
                }
                catch
                {
                    editShapes.Clear();
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            locked = false;
        }