private void IncreaseCanvasSize() { // to accomodate extra space required by label characters //Debug.WriteLine(m_canvasExtents); double xMin = _modelExtents.Left; double xMax = _modelExtents.Right; double yMin = _modelExtents.Top; double yMax = _modelExtents.Bottom; foreach (AtomLabelCharacter alc in _atomLabelCharacters) { xMin = Math.Min(xMin, alc.Position.X); yMin = Math.Min(yMin, alc.Position.Y); if (alc.IsSubScript) { xMax = Math.Max(xMax, alc.Position.X + OoXmlHelper.ScaleCsTtfToCml(alc.Character.Width) * OoXmlHelper.SUBSCRIPT_SCALE_FACTOR); yMax = Math.Max(yMax, alc.Position.Y + OoXmlHelper.ScaleCsTtfToCml(alc.Character.Height) * OoXmlHelper.SUBSCRIPT_SCALE_FACTOR); } else { xMax = Math.Max(xMax, alc.Position.X + OoXmlHelper.ScaleCsTtfToCml(alc.Character.Width)); yMax = Math.Max(yMax, alc.Position.Y + OoXmlHelper.ScaleCsTtfToCml(alc.Character.Height)); } } // Create new canvas extents _canvasExtents = new Rect(xMin - OoXmlHelper.DRAWING_MARGIN, yMin - OoXmlHelper.DRAWING_MARGIN, xMax - xMin + (2 * OoXmlHelper.DRAWING_MARGIN), yMax - yMin + (2 * OoXmlHelper.DRAWING_MARGIN)); //Debug.WriteLine(m_canvasExtents); }
private Rect MoleculeExtents(Molecule mol) { var chars = _atomLabelCharacters.Where(m => m.ParentMolecule.Equals(mol.Id)); double xMin = mol.BoundingBox.Left; double xMax = mol.BoundingBox.Right; double yMin = mol.BoundingBox.Top; double yMax = mol.BoundingBox.Bottom; foreach (var c in chars) { xMin = Math.Min(xMin, c.Position.X); yMin = Math.Min(yMin, c.Position.Y); if (c.IsSubScript) { xMax = Math.Max(xMax, c.Position.X + OoXmlHelper.ScaleCsTtfToCml(c.Character.Width) * OoXmlHelper.SUBSCRIPT_SCALE_FACTOR); yMax = Math.Max(yMax, c.Position.Y + OoXmlHelper.ScaleCsTtfToCml(c.Character.Height) * OoXmlHelper.SUBSCRIPT_SCALE_FACTOR); } else { xMax = Math.Max(xMax, c.Position.X + OoXmlHelper.ScaleCsTtfToCml(c.Character.Width)); yMax = Math.Max(yMax, c.Position.Y + OoXmlHelper.ScaleCsTtfToCml(c.Character.Height)); } } return(new Rect(new Point(xMin, yMin), new Point(xMax, yMax))); }
private Wp.Inline CreateInline(A.GraphicData graphicData, Wpg.WordprocessingGroup wordprocessingGroup1) { UInt32Value inlineId = UInt32Value.FromUInt32((uint)_ooxmlId++); Int64Value width = OoXmlHelper.ScaleCmlToEmu(_canvasExtents.Width); Int64Value height = OoXmlHelper.ScaleCmlToEmu(_canvasExtents.Height); Wp.Inline inline1 = new Wp.Inline() { DistanceFromTop = (UInt32Value)0U, DistanceFromBottom = (UInt32Value)0U, DistanceFromLeft = (UInt32Value)0U, DistanceFromRight = (UInt32Value)0U }; Wp.Extent extent1 = new Wp.Extent() { Cx = width, Cy = height }; Wp.EffectExtent effectExtent1 = new Wp.EffectExtent() { LeftEdge = 0L, TopEdge = 0L, RightEdge = 0L, BottomEdge = 0L }; Wp.DocProperties docProperties1 = new Wp.DocProperties() { Id = inlineId, Name = "moleculeGroup" }; Wpg.NonVisualGroupDrawingShapeProperties nonVisualGroupDrawingShapeProperties1 = new Wpg.NonVisualGroupDrawingShapeProperties(); Wpg.NonVisualGraphicFrameProperties nonVisualGraphicFrameProperties = new Wpg.NonVisualGraphicFrameProperties(); A.GraphicFrameLocks gfl = new A.GraphicFrameLocks() { NoMove = true, NoSelection = true }; Wpg.GroupShapeProperties groupShapeProperties1 = new Wpg.GroupShapeProperties(); A.TransformGroup transformGroup1 = new A.TransformGroup(); A.Offset offset1 = new A.Offset() { X = 0L, Y = 0L }; A.Extents extents1 = new A.Extents() { Cx = width, Cy = height }; A.ChildOffset childOffset1 = new A.ChildOffset() { X = 0L, Y = 0L }; A.ChildExtents childExtents1 = new A.ChildExtents() { Cx = width, Cy = height }; transformGroup1.Append(offset1); transformGroup1.Append(extents1); transformGroup1.Append(childOffset1); transformGroup1.Append(childExtents1); groupShapeProperties1.Append(transformGroup1); wordprocessingGroup1.Append(nonVisualGroupDrawingShapeProperties1); wordprocessingGroup1.Append(groupShapeProperties1); inline1.Append(extent1); inline1.Append(effectExtent1); inline1.Append(docProperties1); inline1.Append(gfl); return inline1; }
private void DrawBox(Wpg.WordprocessingGroup wordprocessingGroup1, Rect extents, string colour, int thick) { UInt32Value bondLineId = UInt32Value.FromUInt32((uint)_ooxmlId++); string bondLineName = "diag-box-" + bondLineId; Int64Value width1 = OoXmlHelper.ScaleCmlToEmu(extents.Width); Int64Value height1 = OoXmlHelper.ScaleCmlToEmu(extents.Height); Int64Value top1 = OoXmlHelper.ScaleCmlToEmu(extents.Top); Int64Value left1 = OoXmlHelper.ScaleCmlToEmu(extents.Left); Point pp1 = new Point(left1, top1); Size ss2 = new Size(width1, height1); pp1.Offset(OoXmlHelper.ScaleCmlToEmu(-_canvasExtents.Left), OoXmlHelper.ScaleCmlToEmu(-_canvasExtents.Top)); Rect boundingBox = new Rect(pp1, ss2); Int64Value width = (Int64Value)boundingBox.Width; Int64Value height = (Int64Value)boundingBox.Height; Int64Value top = (Int64Value)boundingBox.Top; Int64Value left = (Int64Value)boundingBox.Left; Wps.WordprocessingShape wordprocessingShape1 = new Wps.WordprocessingShape(); Wps.NonVisualDrawingProperties nonVisualDrawingProperties1 = new Wps.NonVisualDrawingProperties() { Id = bondLineId, Name = bondLineName }; Wps.NonVisualDrawingShapeProperties nonVisualDrawingShapeProperties1 = new Wps.NonVisualDrawingShapeProperties(); Wps.ShapeProperties shapeProperties1 = new Wps.ShapeProperties(); A.Transform2D transform2D1 = new A.Transform2D(); A.Offset offset2 = new A.Offset() { X = left, Y = top }; A.Extents extents2 = new A.Extents() { Cx = width, Cy = height }; transform2D1.Append(offset2); transform2D1.Append(extents2); A.CustomGeometry customGeometry1 = new A.CustomGeometry(); A.AdjustValueList adjustValueList1 = new A.AdjustValueList(); A.Rectangle rectangle1 = new A.Rectangle() { Left = "l", Top = "t", Right = "r", Bottom = "b" }; A.PathList pathList1 = new A.PathList(); A.Path path1 = new A.Path() { Width = width, Height = height }; // Starting Point A.MoveTo moveTo1 = new A.MoveTo(); A.Point point1 = new A.Point() { X = "0", Y = "0" }; moveTo1.Append(point1); // Mid Point A.LineTo lineTo1 = new A.LineTo(); A.Point point2 = new A.Point() { X = boundingBox.Width.ToString("0"), Y = "0" }; lineTo1.Append(point2); // Mid Point A.LineTo lineTo2 = new A.LineTo(); A.Point point3 = new A.Point() { X = boundingBox.Width.ToString("0"), Y = boundingBox.Height.ToString("0") }; lineTo2.Append(point3); // Last Point A.LineTo lineTo3 = new A.LineTo(); A.Point point4 = new A.Point() { X = "0", Y = boundingBox.Height.ToString("0") }; lineTo3.Append(point4); // Back to Start Point A.LineTo lineTo4 = new A.LineTo(); A.Point point5 = new A.Point() { X = "0", Y = "0" }; lineTo4.Append(point5); path1.Append(moveTo1); path1.Append(lineTo1); path1.Append(lineTo2); path1.Append(lineTo3); path1.Append(lineTo4); pathList1.Append(path1); customGeometry1.Append(adjustValueList1); customGeometry1.Append(rectangle1); customGeometry1.Append(pathList1); A.Outline outline1 = new A.Outline() { Width = thick, CapType = A.LineCapValues.Round }; A.SolidFill solidFill1 = new A.SolidFill(); A.RgbColorModelHex rgbColorModelHex1 = new A.RgbColorModelHex() { Val = colour }; A.Alpha alpha1 = new A.Alpha() { Val = new Int32Value() { InnerText = "100%" } }; rgbColorModelHex1.Append(alpha1); solidFill1.Append(rgbColorModelHex1); outline1.Append(solidFill1); shapeProperties1.Append(transform2D1); shapeProperties1.Append(customGeometry1); shapeProperties1.Append(outline1); Wps.ShapeStyle shapeStyle1 = new Wps.ShapeStyle(); A.LineReference lineReference1 = new A.LineReference() { Index = (UInt32Value)0U }; A.FillReference fillReference1 = new A.FillReference() { Index = (UInt32Value)0U }; A.EffectReference effectReference1 = new A.EffectReference() { Index = (UInt32Value)0U }; A.FontReference fontReference1 = new A.FontReference() { Index = A.FontCollectionIndexValues.Minor }; shapeStyle1.Append(lineReference1); shapeStyle1.Append(fillReference1); shapeStyle1.Append(effectReference1); shapeStyle1.Append(fontReference1); Wps.TextBodyProperties textBodyProperties1 = new Wps.TextBodyProperties(); wordprocessingShape1.Append(nonVisualDrawingProperties1); wordprocessingShape1.Append(nonVisualDrawingShapeProperties1); wordprocessingShape1.Append(shapeProperties1); wordprocessingShape1.Append(shapeStyle1); wordprocessingShape1.Append(textBodyProperties1); wordprocessingGroup1.Append(wordprocessingShape1); }
private void ShrinkBondLinesPass2(Progress pb) { // so that they do not overlap label characters if (_atomLabelCharacters.Count > 1) { pb.Show(); } pb.Message = "Clipping Bond Lines - Pass 2"; pb.Value = 0; pb.Maximum = _atomLabelCharacters.Count; foreach (AtomLabelCharacter alc in _atomLabelCharacters) { pb.Increment(1); double width = OoXmlHelper.ScaleCsTtfToCml(alc.Character.Width); double height = OoXmlHelper.ScaleCsTtfToCml(alc.Character.Height); if (alc.IsSubScript) { // Shrink bounding box width = width * OoXmlHelper.SUBSCRIPT_SCALE_FACTOR; height = height * OoXmlHelper.SUBSCRIPT_SCALE_FACTOR; } // Create rectangle of the bounding box with a suitable clipping margin Rect cbb = new Rect(alc.Position.X - OoXmlHelper.CHARACTER_CLIPPING_MARGIN, alc.Position.Y - OoXmlHelper.CHARACTER_CLIPPING_MARGIN, width + (OoXmlHelper.CHARACTER_CLIPPING_MARGIN * 2), height + (OoXmlHelper.CHARACTER_CLIPPING_MARGIN * 2)); //Debug.WriteLine("Character: " + alc.Ascii + " Rectangle: " + a); // Just in case we end up splitting a line into two List <BondLine> extraBondLines = new List <BondLine>(); // Select Lines which may require trimming // By using LINQ to implement the following SQL // Where (L.Right Between Cbb.Left And Cbb.Right) // Or (L.Left Between Cbb.Left And Cbb.Right) // Or (L.Top Between Cbb.Top And Cbb.Botton) // Or (L.Bottom Between Cbb.Top And Cbb.Botton) var targeted = from l in _bondLines where (cbb.Left <= l.BoundingBox.Right & l.BoundingBox.Right <= cbb.Right) | (cbb.Left <= l.BoundingBox.Left & l.BoundingBox.Left <= cbb.Right) | (cbb.Top <= l.BoundingBox.Top & l.BoundingBox.Top <= cbb.Bottom) | (cbb.Top <= l.BoundingBox.Bottom & l.BoundingBox.Bottom <= cbb.Bottom) select l; foreach (BondLine bl in targeted) { //pb.Increment(1); Point start = new Point(bl.Start.X, bl.Start.Y); Point end = new Point(bl.End.X, bl.End.Y); //Debug.WriteLine(" Line From: " + start + " To: " + end); int attempts = 0; if (CohenSutherland.ClipLine(cbb, ref start, ref end, out attempts)) { //Debug.WriteLine(" Clipped Line Start Point: " + start); //Debug.WriteLine(" Clipped Line End Point: " + end); bool bClipped = false; if (Math.Abs(bl.Start.X - start.X) < EPSILON && Math.Abs(bl.Start.Y - start.Y) < EPSILON) { bl.Start = new Point(end.X, end.Y); bClipped = true; } if (Math.Abs(bl.End.X - end.X) < EPSILON && Math.Abs(bl.End.Y - end.Y) < EPSILON) { bl.End = new Point(start.X, start.Y); bClipped = true; } if (!bClipped) { // Line was clipped at both ends; // 1. Generate new line BondLine extraLine = new BondLine(new Point(end.X, end.Y), new Point(bl.End.X, bl.End.Y), bl.Type, bl.ParentBond, bl.ParentMolecule, bl.StartAtomId, bl.EndAtomId); extraBondLines.Add(extraLine); // 2. Trim existing line bl.End = new Point(start.X, start.Y); } } if (attempts >= 15) { Debug.WriteLine("Clipping failed !"); } } // Add any extra lines generated by this character into the List of Bond Lines foreach (BondLine bl in extraBondLines) { _bondLines.Add(bl); } } }
private void DrawShape(Wpg.WordprocessingGroup wordprocessingGroup1, Rect extents, A.ShapeTypeValues shape, string colour) { UInt32Value bondLineId = UInt32Value.FromUInt32((uint)_ooxmlId++); string bondLineName = "shape" + bondLineId; Int64Value width1 = OoXmlHelper.ScaleCmlToEmu(extents.Width); Int64Value height1 = OoXmlHelper.ScaleCmlToEmu(extents.Height); Int64Value top1 = OoXmlHelper.ScaleCmlToEmu(extents.Top); Int64Value left1 = OoXmlHelper.ScaleCmlToEmu(extents.Left); Point pp1 = new Point(left1, top1); Size ss2 = new Size(width1, height1); pp1.Offset(OoXmlHelper.ScaleCmlToEmu(-_canvasExtents.Left), OoXmlHelper.ScaleCmlToEmu(-_canvasExtents.Top)); Rect boundingBox = new Rect(pp1, ss2); Int64Value width = (Int64Value)boundingBox.Width; Int64Value height = (Int64Value)boundingBox.Height; Int64Value top = (Int64Value)boundingBox.Top; Int64Value left = (Int64Value)boundingBox.Left; A.Extents extents2 = null; A.PresetGeometry presetGeometry1 = null; extents2 = new A.Extents() { Cx = width, Cy = height }; presetGeometry1 = new A.PresetGeometry() { Preset = shape }; Wps.WordprocessingShape wordprocessingShape1 = new Wps.WordprocessingShape(); Wps.NonVisualDrawingProperties nonVisualDrawingProperties1 = new Wps.NonVisualDrawingProperties() { Id = bondLineId, Name = bondLineName }; Wps.NonVisualDrawingShapeProperties nonVisualDrawingShapeProperties1 = new Wps.NonVisualDrawingShapeProperties(); Wps.ShapeProperties shapeProperties1 = new Wps.ShapeProperties(); A.Transform2D transform2D1 = new A.Transform2D(); A.Offset offset2 = new A.Offset() { X = left, Y = top }; transform2D1.Append(offset2); transform2D1.Append(extents2); A.AdjustValueList adjustValueList1 = new A.AdjustValueList(); presetGeometry1.Append(adjustValueList1); A.SolidFill solidFill1 = new A.SolidFill(); A.RgbColorModelHex rgbColorModelHex1 = new A.RgbColorModelHex() { Val = colour }; A.Alpha alpha1 = new A.Alpha() { Val = new Int32Value() { InnerText = "100%" } }; solidFill1.Append(rgbColorModelHex1); shapeProperties1.Append(transform2D1); shapeProperties1.Append(presetGeometry1); shapeProperties1.Append(solidFill1); Wps.ShapeStyle shapeStyle1 = new Wps.ShapeStyle(); A.LineReference lineReference1 = new A.LineReference() { Index = (UInt32Value)0U }; A.FillReference fillReference1 = new A.FillReference() { Index = (UInt32Value)0U }; A.EffectReference effectReference1 = new A.EffectReference() { Index = (UInt32Value)0U }; A.FontReference fontReference1 = new A.FontReference() { Index = A.FontCollectionIndexValues.Minor }; shapeStyle1.Append(lineReference1); shapeStyle1.Append(fillReference1); shapeStyle1.Append(effectReference1); shapeStyle1.Append(fontReference1); Wps.TextBodyProperties textBodyProperties1 = new Wps.TextBodyProperties(); wordprocessingShape1.Append(nonVisualDrawingProperties1); wordprocessingShape1.Append(nonVisualDrawingShapeProperties1); wordprocessingShape1.Append(shapeProperties1); wordprocessingShape1.Append(shapeStyle1); wordprocessingShape1.Append(textBodyProperties1); wordprocessingGroup1.Append(wordprocessingShape1); }
private void DrawLine(Wpg.WordprocessingGroup wordprocessingGroup1, Rect extents, Point startPoint, Point endPoint, string colour, int thick) { UInt32Value bondLineId = UInt32Value.FromUInt32((uint)_ooxmlId++); string bondLineName = "diag-line-" + bondLineId; // Move Bond Line Extents and Points to have 0,0 Top Left Reference startPoint.Offset(-_canvasExtents.Left, -_canvasExtents.Top); endPoint.Offset(-_canvasExtents.Left, -_canvasExtents.Top); extents.Offset(-_canvasExtents.Left, -_canvasExtents.Top); // Move points into New Bond Line Extents startPoint.Offset(-extents.Left, -extents.Top); endPoint.Offset(-extents.Left, -extents.Top); Int64Value width = OoXmlHelper.ScaleCmlToEmu(extents.Width); Int64Value height = OoXmlHelper.ScaleCmlToEmu(extents.Height); Int64Value top = OoXmlHelper.ScaleCmlToEmu(extents.Top); Int64Value left = OoXmlHelper.ScaleCmlToEmu(extents.Left); Wps.WordprocessingShape wordprocessingShape1 = new Wps.WordprocessingShape(); Wps.NonVisualDrawingProperties nonVisualDrawingProperties1 = new Wps.NonVisualDrawingProperties() { Id = bondLineId, Name = bondLineName }; Wps.NonVisualDrawingShapeProperties nonVisualDrawingShapeProperties1 = new Wps.NonVisualDrawingShapeProperties(); Wps.ShapeProperties shapeProperties1 = new Wps.ShapeProperties(); A.Transform2D transform2D1 = new A.Transform2D(); A.Offset offset2 = new A.Offset() { X = left, Y = top }; A.Extents extents2 = new A.Extents() { Cx = width, Cy = height }; transform2D1.Append(offset2); transform2D1.Append(extents2); A.CustomGeometry customGeometry1 = new A.CustomGeometry(); A.AdjustValueList adjustValueList1 = new A.AdjustValueList(); A.Rectangle rectangle1 = new A.Rectangle() { Left = "l", Top = "t", Right = "r", Bottom = "b" }; A.PathList pathList1 = new A.PathList(); A.Path path1 = new A.Path() { Width = width, Height = height }; A.MoveTo moveTo1 = new A.MoveTo(); A.Point point1 = new A.Point() { X = OoXmlHelper.ScaleCmlToEmu(startPoint.X).ToString(), Y = OoXmlHelper.ScaleCmlToEmu(startPoint.Y).ToString() }; moveTo1.Append(point1); A.LineTo lineTo1 = new A.LineTo(); A.Point point2 = new A.Point() { X = OoXmlHelper.ScaleCmlToEmu(endPoint.X).ToString(), Y = OoXmlHelper.ScaleCmlToEmu(endPoint.Y).ToString() }; lineTo1.Append(point2); path1.Append(moveTo1); path1.Append(lineTo1); pathList1.Append(path1); customGeometry1.Append(adjustValueList1); customGeometry1.Append(rectangle1); customGeometry1.Append(pathList1); A.Outline outline1 = new A.Outline() { Width = thick, CapType = A.LineCapValues.Round }; A.SolidFill solidFill1 = new A.SolidFill(); A.RgbColorModelHex rgbColorModelHex1 = new A.RgbColorModelHex() { Val = colour }; A.Alpha alpha1 = new A.Alpha() { Val = new Int32Value() { InnerText = "100%" } }; rgbColorModelHex1.Append(alpha1); solidFill1.Append(rgbColorModelHex1); outline1.Append(solidFill1); shapeProperties1.Append(transform2D1); shapeProperties1.Append(customGeometry1); shapeProperties1.Append(outline1); Wps.ShapeStyle shapeStyle1 = new Wps.ShapeStyle(); A.LineReference lineReference1 = new A.LineReference() { Index = (UInt32Value)0U }; A.FillReference fillReference1 = new A.FillReference() { Index = (UInt32Value)0U }; A.EffectReference effectReference1 = new A.EffectReference() { Index = (UInt32Value)0U }; A.FontReference fontReference1 = new A.FontReference() { Index = A.FontCollectionIndexValues.Minor }; shapeStyle1.Append(lineReference1); shapeStyle1.Append(fillReference1); shapeStyle1.Append(effectReference1); shapeStyle1.Append(fontReference1); Wps.TextBodyProperties textBodyProperties1 = new Wps.TextBodyProperties(); wordprocessingShape1.Append(nonVisualDrawingProperties1); wordprocessingShape1.Append(nonVisualDrawingShapeProperties1); wordprocessingShape1.Append(shapeProperties1); wordprocessingShape1.Append(shapeStyle1); wordprocessingShape1.Append(textBodyProperties1); wordprocessingGroup1.Append(wordprocessingShape1); }