mirror of
https://github.com/greenshot/greenshot
synced 2025-07-31 04:00:13 -07:00
Cleanup of printer code
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1800 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
9ed8f5e191
commit
ca14e8365c
2 changed files with 14 additions and 25 deletions
|
@ -31,13 +31,6 @@ namespace Greenshot.Forms {
|
||||||
public partial class PrintOptionsDialog : BaseForm {
|
public partial class PrintOptionsDialog : BaseForm {
|
||||||
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||||
|
|
||||||
public bool AllowPrintCenter;
|
|
||||||
public bool AllowPrintEnlarge;
|
|
||||||
public bool AllowPrintRotate;
|
|
||||||
public bool AllowPrintShrink;
|
|
||||||
public bool PrintDateTime;
|
|
||||||
public bool PrintInverted;
|
|
||||||
|
|
||||||
public PrintOptionsDialog() {
|
public PrintOptionsDialog() {
|
||||||
//
|
//
|
||||||
// The InitializeComponent() call is required for Windows Forms designer support.
|
// The InitializeComponent() call is required for Windows Forms designer support.
|
||||||
|
|
|
@ -42,7 +42,6 @@ namespace Greenshot.Helpers {
|
||||||
private ICaptureDetails captureDetails;
|
private ICaptureDetails captureDetails;
|
||||||
private PrintDocument printDocument = new PrintDocument();
|
private PrintDocument printDocument = new PrintDocument();
|
||||||
private PrintDialog printDialog = new PrintDialog();
|
private PrintDialog printDialog = new PrintDialog();
|
||||||
private PrintOptionsDialog printOptionsDialog = null;
|
|
||||||
|
|
||||||
public PrintHelper(Image image, ICaptureDetails captureDetails) {
|
public PrintHelper(Image image, ICaptureDetails captureDetails) {
|
||||||
this.image = image;
|
this.image = image;
|
||||||
|
@ -84,14 +83,10 @@ namespace Greenshot.Helpers {
|
||||||
if (printDialog != null) {
|
if (printDialog != null) {
|
||||||
printDialog.Dispose();
|
printDialog.Dispose();
|
||||||
}
|
}
|
||||||
if (printOptionsDialog != null) {
|
|
||||||
printOptionsDialog.Dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
image = null;
|
image = null;
|
||||||
printDocument = null;
|
printDocument = null;
|
||||||
printDialog = null;
|
printDialog = null;
|
||||||
printOptionsDialog = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -102,11 +97,12 @@ namespace Greenshot.Helpers {
|
||||||
public PrinterSettings PrintTo(string printerName) {
|
public PrinterSettings PrintTo(string printerName) {
|
||||||
PrinterSettings returnPrinterSettings = null;
|
PrinterSettings returnPrinterSettings = null;
|
||||||
bool cancelled = false;
|
bool cancelled = false;
|
||||||
printOptionsDialog = new PrintOptionsDialog();
|
|
||||||
if (conf.OutputPrintPromptOptions) {
|
if (conf.OutputPrintPromptOptions) {
|
||||||
DialogResult result = printOptionsDialog.ShowDialog();
|
using (PrintOptionsDialog printOptionsDialog = new PrintOptionsDialog()) {
|
||||||
if (result != DialogResult.OK) {
|
DialogResult result = printOptionsDialog.ShowDialog();
|
||||||
cancelled = true;
|
if (result != DialogResult.OK) {
|
||||||
|
cancelled = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
@ -133,11 +129,12 @@ namespace Greenshot.Helpers {
|
||||||
PrinterSettings returnPrinterSettings = null;
|
PrinterSettings returnPrinterSettings = null;
|
||||||
if (printDialog.ShowDialog() == DialogResult.OK) {
|
if (printDialog.ShowDialog() == DialogResult.OK) {
|
||||||
bool cancelled = false;
|
bool cancelled = false;
|
||||||
printOptionsDialog = new PrintOptionsDialog();
|
|
||||||
if (conf.OutputPrintPromptOptions) {
|
if (conf.OutputPrintPromptOptions) {
|
||||||
DialogResult result = printOptionsDialog.ShowDialog();
|
using (PrintOptionsDialog printOptionsDialog = new PrintOptionsDialog()) {
|
||||||
if (result != DialogResult.OK) {
|
DialogResult result = printOptionsDialog.ShowDialog();
|
||||||
cancelled = true;
|
if (result != DialogResult.OK) {
|
||||||
|
cancelled = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
@ -157,8 +154,7 @@ namespace Greenshot.Helpers {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawImageForPrint(object sender, PrintPageEventArgs e) {
|
void DrawImageForPrint(object sender, PrintPageEventArgs e) {
|
||||||
PrintOptionsDialog pod = printOptionsDialog;
|
ContentAlignment alignment = conf.OutputPrintCenter ? ContentAlignment.MiddleCenter : ContentAlignment.TopLeft;
|
||||||
ContentAlignment alignment = pod.AllowPrintCenter ? ContentAlignment.MiddleCenter : ContentAlignment.TopLeft;
|
|
||||||
|
|
||||||
// prepare timestamp
|
// prepare timestamp
|
||||||
float footerStringWidth = 0;
|
float footerStringWidth = 0;
|
||||||
|
@ -181,7 +177,7 @@ namespace Greenshot.Helpers {
|
||||||
GraphicsUnit gu = GraphicsUnit.Pixel;
|
GraphicsUnit gu = GraphicsUnit.Pixel;
|
||||||
RectangleF imageRect = image.GetBounds(ref gu);
|
RectangleF imageRect = image.GetBounds(ref gu);
|
||||||
// rotate the image if it fits the page better
|
// rotate the image if it fits the page better
|
||||||
if (pod.AllowPrintRotate) {
|
if (conf.OutputPrintAllowRotate) {
|
||||||
if ((pageRect.Width > pageRect.Height && imageRect.Width < imageRect.Height) || (pageRect.Width < pageRect.Height && imageRect.Width > imageRect.Height)) {
|
if ((pageRect.Width > pageRect.Height && imageRect.Width < imageRect.Height) || (pageRect.Width < pageRect.Height && imageRect.Width > imageRect.Height)) {
|
||||||
image.RotateFlip(RotateFlipType.Rotate90FlipNone);
|
image.RotateFlip(RotateFlipType.Rotate90FlipNone);
|
||||||
imageRect = image.GetBounds(ref gu);
|
imageRect = image.GetBounds(ref gu);
|
||||||
|
@ -193,9 +189,9 @@ namespace Greenshot.Helpers {
|
||||||
|
|
||||||
RectangleF printRect = new RectangleF(0, 0, imageRect.Width, imageRect.Height);
|
RectangleF printRect = new RectangleF(0, 0, imageRect.Width, imageRect.Height);
|
||||||
// scale the image to fit the page better
|
// scale the image to fit the page better
|
||||||
if (pod.AllowPrintEnlarge || pod.AllowPrintShrink) {
|
if (conf.OutputPrintAllowEnlarge || conf.OutputPrintAllowShrink) {
|
||||||
SizeF resizedRect = ScaleHelper.GetScaledSize(imageRect.Size, pageRect.Size, false);
|
SizeF resizedRect = ScaleHelper.GetScaledSize(imageRect.Size, pageRect.Size, false);
|
||||||
if ((pod.AllowPrintShrink && resizedRect.Width < printRect.Width) || pod.AllowPrintEnlarge && resizedRect.Width > printRect.Width) {
|
if ((conf.OutputPrintAllowShrink && resizedRect.Width < printRect.Width) || conf.OutputPrintAllowEnlarge && resizedRect.Width > printRect.Width) {
|
||||||
printRect.Size = resizedRect;
|
printRect.Size = resizedRect;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue