/// <summary> /// unscale the supplied NativeSizeFloat according to the supplied dpi /// </summary> /// <param name="size">NativeSizeFloat to resize</param> /// <param name="dpi">current dpi, normal is 96.</param> /// <param name="scaleModifier">A function which can modify the scale factor</param> /// <returns>NativeSize unscaled</returns> public static NativeSizeFloat UnscaleWithDpi(NativeSizeFloat size, uint dpi, Func <double, double> scaleModifier = null) { var dpiUnscaleFactor = DpiUnscaleFactor(dpi); if (scaleModifier != null) { dpiUnscaleFactor = scaleModifier(dpiUnscaleFactor); } return(new NativeSizeFloat(dpiUnscaleFactor * size.Width, dpiUnscaleFactor * size.Height)); }
private void Test_NativeSizeFloat_Operators() { var nativeSize1 = new NativeSizeFloat(123, 456); var nativeSize2 = new NativeSizeFloat(123, 456); var drawingSize = new System.Drawing.Size(123, 456); var windowsSize = new System.Windows.Size(123, 456); var drawingSizeNotEqual = new System.Drawing.Size(456, 123); var windowsSizeNotEqual = new System.Windows.Size(456, 123); Assert.True(nativeSize1 == nativeSize2); Assert.True(nativeSize1 == drawingSize); Assert.True(drawingSize == nativeSize1); Assert.False(nativeSize1 != drawingSize); Assert.False(drawingSize != nativeSize1); Assert.True(drawingSizeNotEqual != nativeSize1); Assert.True(nativeSize1 == windowsSize); Assert.True(windowsSize == nativeSize1); Assert.False(nativeSize1 != windowsSize); Assert.False(windowsSize != nativeSize1); Assert.True(windowsSizeNotEqual != nativeSize1); }
public static NativeSize Round(this NativeSizeFloat size) { return(new NativeSize((int)Math.Round(size.Width), (int)Math.Round(size.Height))); }
public static NativeSizeFloat ChangeHeight(this NativeSizeFloat size, float height) { return(new NativeSizeFloat(size.Width, height)); }
public static NativeSizeFloat ChangeWidth(this NativeSizeFloat size, float width) { return(new NativeSizeFloat(width, size.Height)); }
/// <summary> /// Unscale the supplied NativeSizeFloat to the current dpi /// </summary> /// <param name="size">NativeSizeFloat to unscale</param> /// <param name="scaleModifier">A function which can modify the scale factor</param> /// <returns>NativeSizeFloat unscaled</returns> public NativeSizeFloat UnscaleWithCurrentDpi(NativeSizeFloat size, Func <double, double> scaleModifier = null) { return(UnscaleWithDpi(size, Dpi, scaleModifier)); }
public static NativeRectFloat Resize(this NativeRectFloat rect, NativeSizeFloat size) { return(new NativeRectFloat(rect.Location, size)); }
private void DrawImageForPrint(object sender, PrintPageEventArgs e) { // Create the output settins var printOutputSettings = new SurfaceOutputSettings(OutputFormats.png, 100, false); ApplyEffects(printOutputSettings); var disposeImage = ImageOutput.CreateBitmapFromSurface(_surface, printOutputSettings, out var bitmap); try { var alignment = _coreConfig.OutputPrintCenter ? ContentAlignment.MiddleCenter : ContentAlignment.TopLeft; // prepare timestamp float footerStringWidth = 0; float footerStringHeight = 0; string footerString = null; //DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString(); if (_coreConfig.OutputPrintFooter) { footerString = FilenameHelper.FillPattern(_coreConfig.OutputPrintFooterPattern, _captureDetails, false); using (var f = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular)) { footerStringWidth = e.Graphics.MeasureString(footerString, f).Width; footerStringHeight = e.Graphics.MeasureString(footerString, f).Height; } } // Get a rectangle representing the printable Area var pageRect = e.PageSettings.PrintableArea; if (e.PageSettings.Landscape) { var origWidth = pageRect.Width; pageRect.Width = pageRect.Height; pageRect.Height = origWidth; } // Subtract the dateString height from the available area, this way the area stays free pageRect.Height -= footerStringHeight; var gu = GraphicsUnit.Pixel; var imageRect = bitmap.GetBounds(ref gu); // rotate the image if it fits the page better if (_coreConfig.OutputPrintAllowRotate) { if (pageRect.Width > pageRect.Height && imageRect.Width < imageRect.Height || pageRect.Width < pageRect.Height && imageRect.Width > imageRect.Height) { bitmap.RotateFlip(RotateFlipType.Rotate270FlipNone); imageRect = bitmap.GetBounds(ref gu); if (alignment.Equals(ContentAlignment.TopLeft)) { alignment = ContentAlignment.TopRight; } } } NativeSizeFloat size = imageRect.Size; var printRect = new NativeRect(0, 0, size.Round()); // scale the image to fit the page better if (_coreConfig.OutputPrintAllowEnlarge || _coreConfig.OutputPrintAllowShrink) { var resizedRect = ScaleHelper.GetScaledSize(imageRect.Size, pageRect.Size, false); if (_coreConfig.OutputPrintAllowShrink && resizedRect.Width < printRect.Width || _coreConfig.OutputPrintAllowEnlarge && resizedRect.Width > printRect.Width) { printRect = printRect.Resize(resizedRect.Round()); } } // align the image printRect = ScaleHelper.GetAlignedRectangle(printRect, new NativeRect(0, 0, new NativeSizeFloat(pageRect.Width, pageRect.Height).Round()), alignment).Round(); if (_coreConfig.OutputPrintFooter) { //printRect = new NativeRect(0, 0, printRect.Width, printRect.Height - (dateStringHeight * 2)); using (var f = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular)) { e.Graphics.DrawString(footerString, f, Brushes.Black, pageRect.Width / 2 - footerStringWidth / 2, pageRect.Height); } } e.Graphics.DrawImage(bitmap, printRect, imageRect, GraphicsUnit.Pixel); } finally { if (disposeImage) { bitmap?.Dispose(); } } }