示例#1
0
 public ConverterPdfRect(PdfMeasurement left, PdfMeasurement right, PdfMeasurement bottom, PdfMeasurement top)
 {
     if (left.AsPoints() >= right.AsPoints())
     {
         throw new ArgumentOutOfRangeException(nameof(left), left, "left >= right");
     }
     if (bottom.AsPoints() >= top.AsPoints())
     {
         throw new ArgumentOutOfRangeException(nameof(bottom), bottom, "bottom >= top (PDF 'bottom' is zero)");
     }
     this.Left   = left;
     this.Right  = right;
     this.Bottom = bottom;
     this.Top    = top;
 }
示例#2
0
        /// <summary>
        /// Creates a PDF destination rectangle from the given DXF rectangle and keeps the aspect ratio.
        /// Optionally, a <paramref name="margin"/> can be defined.
        /// </summary>
        /// <param name="srcRect">The DXF source rectangle.</param>
        /// <param name="maxWidth">The maximum width of the PDF output including <paramref name="margin"/>.</param>
        /// <param name="maxHeight">The maximum height of the PDF output including <paramref name="margin"/>.</param>
        /// <param name="margin">[optional] The margin.</param>
        /// <returns>The PDF destination rectangle.</returns>
        public static ConverterPdfRect KeepAspectRatio(ConverterDxfRect srcRect, PdfMeasurement maxWidth,
                                                       PdfMeasurement maxHeight, PdfMeasurement margin = default(PdfMeasurement))
        {
            double maxWidthPts  = maxWidth.AsPoints();
            double maxHeightPts = maxHeight.AsPoints();
            double marginPts    = margin.AsPoints();

            double scaleX = (maxWidthPts - 2 * marginPts) / srcRect.Width;
            double scaleY = (maxHeightPts - 2 * marginPts) / srcRect.Height;
            double scale  = Math.Min(scaleX, scaleY);

            PdfMeasurement left   = margin;
            PdfMeasurement right  = PdfMeasurement.Points(marginPts + scale * srcRect.Width);
            PdfMeasurement bottom = margin;
            PdfMeasurement top    = PdfMeasurement.Points(marginPts + scale * srcRect.Height);

            return(new ConverterPdfRect(left, right, bottom, top));
        }