bool CreateMeasureRect() { if (CDWin == null || CDWin.ActiveSelection == null || CDWin.ActiveSelection.Shapes.Count == 0 || CDWin.ActiveSelection.Shapes[1].Type != CorelDRAW.cdrShapeType.cdrBitmapShape) { MessageBox.Show("No Image selected. Select an Image first"); return false; } CalMes = new CalibMeasure(); CalMes.img = CDWin.ActiveSelection.Shapes[1]; CalMes.mesRect = CDWin.ActiveLayer.CreateRectangle2( CDWin.ActiveWindow.ActiveView.OriginX, CDWin.ActiveWindow.ActiveView.OriginY, CDWin.ConvertUnits(3d, CorelDRAW.cdrUnit.cdrCentimeter, CDWin.ActiveDocument.Unit), CDWin.ConvertUnits(1d, CorelDRAW.cdrUnit.cdrCentimeter, CDWin.ActiveDocument.Unit) ); Color back = new Color(); back.CMYKAssign(0, 60, 100, 0); CalMes.mesRect.Selected = true; CalMes.mesRect.Outline.Width = 0; CalMes.mesRect.Fill.ApplyUniformFill(back); CalMes.mesRect.Transparency.ApplyUniformTransparency(0); CalMes.mesRect.Transparency.MergeMode = CorelDRAW.cdrMergeMode.cdrMergeXOR; return true; }
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; }