diff --git a/src/Examples/Images/arrow.png b/src/Examples/Images/arrow.png new file mode 100644 index 0000000..b6d7040 Binary files /dev/null and b/src/Examples/Images/arrow.png differ diff --git a/src/Examples/TestExamples.cs b/src/Examples/TestExamples.cs index 7830c58..672f44d 100644 --- a/src/Examples/TestExamples.cs +++ b/src/Examples/TestExamples.cs @@ -1,3 +1,6 @@ +using System; +using System.IO; +using System.Runtime.CompilerServices; using IxMilia.Dwg; using IxMilia.Dwg.Objects; using Xunit; @@ -72,28 +75,58 @@ public void WriteCustomLineType() } [Fact] - public void WriteBlock() - { - var drawing = new DwgDrawing(); - drawing.CurrentEntityLineType = drawing.ByLayerLineType; - drawing.FileHeader.Version = DwgVersionId.R14; - - // create a block with a line from (0,0) to (1,1) - var line = new DwgLine(new DwgPoint(0.0, 0.0, 0.0), new DwgPoint(1.0, 1.0, 0.0)); - line.Layer = drawing.CurrentLayer; - - var blockHeader = DwgBlockHeader.CreateBlockRecordWithName("my-block", drawing.CurrentLayer); - blockHeader.Entities.Add(line); - drawing.BlockHeaders.Add(blockHeader); - - // insert a copy of the block at location (3,3); the result is a line from (3,3) to (4,4) - var insert = new DwgInsert(blockHeader); - insert.Location = new DwgPoint(3.0, 3.0, 0.0); - insert.Layer = drawing.CurrentLayer; - - drawing.ModelSpaceBlockRecord.Entities.Add(insert); - - drawing.SaveExample(); + public void WriteBlock() + { + var drawing = new DwgDrawing(); + drawing.CurrentEntityLineType = drawing.ByLayerLineType; + drawing.FileHeader.Version = DwgVersionId.R14; + + // create a block with a line from (0,0) to (1,1) + var line = new DwgLine(new DwgPoint(0.0, 0.0, 0.0), new DwgPoint(1.0, 1.0, 0.0)); + line.Layer = drawing.CurrentLayer; + + var blockHeader = DwgBlockHeader.CreateBlockRecordWithName("my-block", drawing.CurrentLayer); + blockHeader.Entities.Add(line); + drawing.BlockHeaders.Add(blockHeader); + + // insert a copy of the block at location (3,3); the result is a line from (3,3) to (4,4) + var insert = new DwgInsert(blockHeader); + insert.Location = new DwgPoint(3.0, 3.0, 0.0); + insert.Layer = drawing.CurrentLayer; + + drawing.ModelSpaceBlockRecord.Entities.Add(insert); + + drawing.SaveExample(); + } + + [Fact] + public void WriteImage() + { + var drawing = new DwgDrawing(); + drawing.FileHeader.Version = DwgVersionId.R14; + + // create an image object + var fourtyFiveDegrees = Math.PI / 4.0; + var image = new DwgImage( + filePath: GetSampleImagePath(), + insertionPoint: new DwgPoint(2.0, 2.0, 0.0), // where the bottom left corner of the original image will be + widthInPixels: 16, // should be pulled directly from the image + heightInPixels: 16, + displayWidth: 1.0, // in drawing units + displayHeight: 1.0, + rotationAngleInRadians: fourtyFiveDegrees); // counter-clockwise rotation + image.Layer = drawing.CurrentLayer; + drawing.ModelSpaceBlockRecord.Entities.Add(image); + + drawing.SaveExample(); + } + + private static string GetSampleImagePath([CallerFilePath] string testFilePath = null) + { + var thisDirectory = Path.GetDirectoryName(testFilePath); + var sampleImagesDirectory = Path.Combine(thisDirectory, "Images"); + var sampleImagePath = Path.Combine(sampleImagesDirectory, "arrow.png"); + return sampleImagePath; } } } diff --git a/src/IxMilia.Dwg.Generator/Spec/Objects.xml b/src/IxMilia.Dwg.Generator/Spec/Objects.xml index ddeec3d..65480e7 100644 --- a/src/IxMilia.Dwg.Generator/Spec/Objects.xml +++ b/src/IxMilia.Dwg.Generator/Spec/Objects.xml @@ -1282,7 +1282,7 @@ - + @@ -1314,14 +1314,19 @@ + + + + + - - + +