public void AspectRatioIsKept(int maxWidth, int maxHeight)
        {
            ConverterDxfRect src          = new ConverterDxfRect(0, 5, 0, 5);
            PdfMeasurement   pdfMaxWidth  = PdfMeasurement.Points(maxWidth);
            PdfMeasurement   pdfMaxHeight = PdfMeasurement.Points(maxHeight);
            ConverterPdfRect sut          = ConverterPdfRect.KeepAspectRatio(src, pdfMaxWidth, pdfMaxHeight);

            Assert.True(sut.Width.AsPoints() <= maxWidth);
            Assert.True(sut.Height.AsPoints() <= maxHeight);

            Assert.Equal(src.Width, src.Height); // otherwise test below is wrong
            if (maxWidth > maxHeight)
            {
                Assert.Equal(pdfMaxHeight, sut.Height);
            }
            else
            {
                Assert.Equal(pdfMaxWidth, sut.Width);
            }
        }
Exemple #2
0
        public override async Task Plot(Drawing drawing, ViewPort viewPort, Stream outputStream, Func <string, Task <byte[]> > contentResolver)
        {
            var converter    = new DxfToSvgConverter();
            var fileSettings = new DxfFileSettings()
            {
                FileVersion = DxfFileVersion.R2004,
            };
            var dxfFile       = DxfFileHandler.ToDxfFile(drawing, viewPort, fileSettings);
            var plotViewPort  = ViewModel.ViewPort;
            var viewPortWidth = ViewModel.DisplayWidth / ViewModel.DisplayHeight * plotViewPort.ViewHeight;
            var dxfRect       = new ConverterDxfRect(plotViewPort.BottomLeft.X, plotViewPort.BottomLeft.X + viewPortWidth, plotViewPort.BottomLeft.Y, plotViewPort.BottomLeft.Y + plotViewPort.ViewHeight);
            var svgRect       = new ConverterSvgRect(ViewModel.DisplayWidth, ViewModel.DisplayHeight);
            var options       = new DxfToSvgConverterOptions(dxfRect, svgRect, imageHrefResolver: DxfToSvgConverterOptions.CreateDataUriResolver(contentResolver));
            var xml           = await converter.Convert(dxfFile, options);

            xml.Attribute("width").Value  = $"{ViewModel.OutputWidth}";
            xml.Attribute("height").Value = $"{ViewModel.OutputHeight}";

            var writerSettings = new XmlWriterSettings()
            {
                Indent      = true,
                IndentChars = "  "
            };

            using (var writer = XmlWriter.Create(outputStream, writerSettings))
            {
                if (ViewModel.PlotAsDocument)
                {
                    var doc = new XDocument(
                        new XDocumentType("svg", "-//W3C//DTD SVG 1.1//EN", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd", null),
                        xml);
                    doc.WriteTo(writer);
                }
                else
                {
                    xml.WriteTo(writer);
                }

                writer.Flush();
            }
        }
Exemple #3
0
        public override async Task Plot(Drawing drawing, ViewPort viewPort, Stream outputStream, Func <string, Task <byte[]> > contentResolver)
        {
            var converter    = new DxfToPdfConverter();
            var fileSettings = new DxfFileSettings()
            {
                FileVersion = DxfFileVersion.R2004,
            };
            var dxfFile       = DxfFileHandler.ToDxfFile(drawing, viewPort, fileSettings);
            var pageWidth     = new PdfMeasurement(ViewModel.DisplayWidth, ViewModel.DisplayUnit);
            var pageHeight    = new PdfMeasurement(ViewModel.DisplayHeight, ViewModel.DisplayUnit);
            var plotViewPort  = ViewModel.ViewPort;
            var viewPortWidth = ViewModel.DisplayWidth / ViewModel.DisplayHeight * plotViewPort.ViewHeight;
            var dxfRect       = new ConverterDxfRect(plotViewPort.BottomLeft.X, plotViewPort.BottomLeft.X + viewPortWidth, plotViewPort.BottomLeft.Y, plotViewPort.BottomLeft.Y + plotViewPort.ViewHeight);
            var pdfRect       = new ConverterPdfRect(
                new PdfMeasurement(0.0, ViewModel.DisplayUnit),
                new PdfMeasurement(ViewModel.DisplayWidth, ViewModel.DisplayUnit),
                new PdfMeasurement(0.0, ViewModel.DisplayUnit),
                new PdfMeasurement(ViewModel.DisplayHeight, ViewModel.DisplayUnit));
            var options = new DxfToPdfConverterOptions(pageWidth, pageHeight, dxfRect, pdfRect, contentResolver: contentResolver);
            var pdfFile = await converter.Convert(dxfFile, options);

            pdfFile.Save(outputStream);
        }