added monochrome print option

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2491 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
JKlingen 2013-02-17 07:58:58 +00:00
parent 9f86db6828
commit b537ae7e14
11 changed files with 1612 additions and 1480 deletions

View file

@ -168,6 +168,7 @@ namespace Greenshot.Configuration {
printoptions_allowrotate, printoptions_allowrotate,
printoptions_allowshrink, printoptions_allowshrink,
printoptions_dontaskagain, printoptions_dontaskagain,
printoptions_printmonochrome,
printoptions_timestamp, printoptions_timestamp,
printoptions_inverted, printoptions_inverted,
printoptions_title, printoptions_title,

View file

@ -106,42 +106,18 @@ namespace Greenshot.Destinations {
/// <param name="captureDetails"></param> /// <param name="captureDetails"></param>
/// <returns>ExportInformation</returns> /// <returns>ExportInformation</returns>
public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description); ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);
PrinterSettings printerSettings = null; PrinterSettings printerSettings = null;
if (!string.IsNullOrEmpty(printerName)) {
// Create the output settins printerSettings = new PrintHelper(surface, captureDetails).PrintTo(printerName);
SurfaceOutputSettings printOutputSettings = new SurfaceOutputSettings(OutputFormat.png, 100, false); } else if (!manuallyInitiated) {
PrinterSettings settings = new PrinterSettings();
// TODO: printerSettings = new PrintHelper(surface, captureDetails).PrintTo(settings.PrinterName);
// add effects here, e.g. Monochrome } else {
// printOutputSettings.Effects.Add(new MonochromeEffect()); printerSettings = new PrintHelper(surface, captureDetails).PrintWithDialog();
// Set the color reducing if needed, this should change the 24/32-> 8 (or later even 1) bpp
// printOutputSettings.ReduceColors = true;
// Moved this from the PrintHelper, the invert effect should probably be the last!
if (conf.OutputPrintInverted) {
printOutputSettings.Effects.Add(new InvertEffect());
} }
if (printerSettings != null) {
Image imageToPrint; exportInformation.ExportMade = true;
Boolean disposeImage = ImageOutput.CreateImageFromSurface(surface, printOutputSettings, out imageToPrint);
try {
if (!string.IsNullOrEmpty(printerName)) {
printerSettings = new PrintHelper(imageToPrint, captureDetails).PrintTo(printerName);
} else if (!manuallyInitiated) {
PrinterSettings settings = new PrinterSettings();
printerSettings = new PrintHelper(imageToPrint, captureDetails).PrintTo(settings.PrinterName);
} else {
printerSettings = new PrintHelper(imageToPrint, captureDetails).PrintWithDialog();
}
if (printerSettings != null) {
exportInformation.ExportMade = true;
}
} finally {
if (disposeImage && imageToPrint != null) {
imageToPrint.Dispose();
imageToPrint = null;
}
} }
ProcessExport(exportInformation, surface); ProcessExport(exportInformation, surface);

View file

@ -48,185 +48,203 @@ namespace Greenshot.Forms
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.checkbox_dontaskagain = new GreenshotPlugin.Controls.GreenshotCheckBox(); this.checkbox_dontaskagain = new GreenshotPlugin.Controls.GreenshotCheckBox();
this.checkboxAllowShrink = new GreenshotPlugin.Controls.GreenshotCheckBox(); this.checkboxAllowShrink = new GreenshotPlugin.Controls.GreenshotCheckBox();
this.checkboxAllowEnlarge = new GreenshotPlugin.Controls.GreenshotCheckBox(); this.checkboxAllowEnlarge = new GreenshotPlugin.Controls.GreenshotCheckBox();
this.checkboxAllowCenter = new GreenshotPlugin.Controls.GreenshotCheckBox(); this.checkboxAllowCenter = new GreenshotPlugin.Controls.GreenshotCheckBox();
this.checkboxAllowRotate = new GreenshotPlugin.Controls.GreenshotCheckBox(); this.checkboxAllowRotate = new GreenshotPlugin.Controls.GreenshotCheckBox();
this.button_ok = new GreenshotPlugin.Controls.GreenshotButton(); this.button_ok = new GreenshotPlugin.Controls.GreenshotButton();
this.checkboxDateTime = new GreenshotPlugin.Controls.GreenshotCheckBox(); this.checkboxDateTime = new GreenshotPlugin.Controls.GreenshotCheckBox();
this.button_cancel = new GreenshotPlugin.Controls.GreenshotButton(); this.button_cancel = new GreenshotPlugin.Controls.GreenshotButton();
this.checkboxPrintInverted = new GreenshotPlugin.Controls.GreenshotCheckBox(); this.checkboxPrintInverted = new GreenshotPlugin.Controls.GreenshotCheckBox();
this.checkbox_grayscale = new GreenshotPlugin.Controls.GreenshotCheckBox(); this.checkbox_grayscale = new GreenshotPlugin.Controls.GreenshotCheckBox();
this.SuspendLayout(); this.checkbox_monochrome = new GreenshotPlugin.Controls.GreenshotCheckBox();
// this.SuspendLayout();
// checkbox_dontaskagain //
// // checkbox_dontaskagain
this.checkbox_dontaskagain.AutoSize = true; //
this.checkbox_dontaskagain.CheckAlign = System.Drawing.ContentAlignment.TopLeft; this.checkbox_dontaskagain.AutoSize = true;
this.checkbox_dontaskagain.ImageAlign = System.Drawing.ContentAlignment.TopLeft; this.checkbox_dontaskagain.CheckAlign = System.Drawing.ContentAlignment.TopLeft;
this.checkbox_dontaskagain.LanguageKey = "printoptions_dontaskagain"; this.checkbox_dontaskagain.ImageAlign = System.Drawing.ContentAlignment.TopLeft;
this.checkbox_dontaskagain.Location = new System.Drawing.Point(12, 191); this.checkbox_dontaskagain.LanguageKey = "printoptions_dontaskagain";
this.checkbox_dontaskagain.Name = "checkbox_dontaskagain"; this.checkbox_dontaskagain.Location = new System.Drawing.Point(12, 214);
this.checkbox_dontaskagain.Size = new System.Drawing.Size(240, 17); this.checkbox_dontaskagain.Name = "checkbox_dontaskagain";
this.checkbox_dontaskagain.TabIndex = 19; this.checkbox_dontaskagain.Size = new System.Drawing.Size(240, 17);
this.checkbox_dontaskagain.Text = "Save options as default and do not ask again"; this.checkbox_dontaskagain.TabIndex = 19;
this.checkbox_dontaskagain.TextAlign = System.Drawing.ContentAlignment.TopLeft; this.checkbox_dontaskagain.Text = "Save options as default and do not ask again";
this.checkbox_dontaskagain.UseVisualStyleBackColor = true; this.checkbox_dontaskagain.TextAlign = System.Drawing.ContentAlignment.TopLeft;
// this.checkbox_dontaskagain.UseVisualStyleBackColor = true;
// checkboxAllowShrink //
// // checkboxAllowShrink
this.checkboxAllowShrink.AutoSize = true; //
this.checkboxAllowShrink.CheckAlign = System.Drawing.ContentAlignment.TopLeft; this.checkboxAllowShrink.AutoSize = true;
this.checkboxAllowShrink.ImageAlign = System.Drawing.ContentAlignment.TopLeft; this.checkboxAllowShrink.CheckAlign = System.Drawing.ContentAlignment.TopLeft;
this.checkboxAllowShrink.LanguageKey = "printoptions_allowshrink"; this.checkboxAllowShrink.ImageAlign = System.Drawing.ContentAlignment.TopLeft;
this.checkboxAllowShrink.Location = new System.Drawing.Point(12, 20); this.checkboxAllowShrink.LanguageKey = "printoptions_allowshrink";
this.checkboxAllowShrink.Name = "checkboxAllowShrink"; this.checkboxAllowShrink.Location = new System.Drawing.Point(12, 20);
this.checkboxAllowShrink.PropertyName = "OutputPrintAllowShrink"; this.checkboxAllowShrink.Name = "checkboxAllowShrink";
this.checkboxAllowShrink.Size = new System.Drawing.Size(168, 17); this.checkboxAllowShrink.PropertyName = "OutputPrintAllowShrink";
this.checkboxAllowShrink.TabIndex = 21; this.checkboxAllowShrink.Size = new System.Drawing.Size(168, 17);
this.checkboxAllowShrink.Text = "Shrink printout to fit paper size"; this.checkboxAllowShrink.TabIndex = 21;
this.checkboxAllowShrink.TextAlign = System.Drawing.ContentAlignment.TopLeft; this.checkboxAllowShrink.Text = "Shrink printout to fit paper size";
this.checkboxAllowShrink.UseVisualStyleBackColor = true; this.checkboxAllowShrink.TextAlign = System.Drawing.ContentAlignment.TopLeft;
// this.checkboxAllowShrink.UseVisualStyleBackColor = true;
// checkboxAllowEnlarge //
// // checkboxAllowEnlarge
this.checkboxAllowEnlarge.AutoSize = true; //
this.checkboxAllowEnlarge.CheckAlign = System.Drawing.ContentAlignment.TopLeft; this.checkboxAllowEnlarge.AutoSize = true;
this.checkboxAllowEnlarge.ImageAlign = System.Drawing.ContentAlignment.TopLeft; this.checkboxAllowEnlarge.CheckAlign = System.Drawing.ContentAlignment.TopLeft;
this.checkboxAllowEnlarge.LanguageKey = "printoptions_allowenlarge"; this.checkboxAllowEnlarge.ImageAlign = System.Drawing.ContentAlignment.TopLeft;
this.checkboxAllowEnlarge.Location = new System.Drawing.Point(12, 43); this.checkboxAllowEnlarge.LanguageKey = "printoptions_allowenlarge";
this.checkboxAllowEnlarge.Name = "checkboxAllowEnlarge"; this.checkboxAllowEnlarge.Location = new System.Drawing.Point(12, 43);
this.checkboxAllowEnlarge.PropertyName = "OutputPrintAllowEnlarge"; this.checkboxAllowEnlarge.Name = "checkboxAllowEnlarge";
this.checkboxAllowEnlarge.Size = new System.Drawing.Size(174, 17); this.checkboxAllowEnlarge.PropertyName = "OutputPrintAllowEnlarge";
this.checkboxAllowEnlarge.TabIndex = 22; this.checkboxAllowEnlarge.Size = new System.Drawing.Size(174, 17);
this.checkboxAllowEnlarge.Text = "Enlarge printout to fit paper size"; this.checkboxAllowEnlarge.TabIndex = 22;
this.checkboxAllowEnlarge.TextAlign = System.Drawing.ContentAlignment.TopLeft; this.checkboxAllowEnlarge.Text = "Enlarge printout to fit paper size";
this.checkboxAllowEnlarge.UseVisualStyleBackColor = true; this.checkboxAllowEnlarge.TextAlign = System.Drawing.ContentAlignment.TopLeft;
// this.checkboxAllowEnlarge.UseVisualStyleBackColor = true;
// checkboxAllowCenter //
// // checkboxAllowCenter
this.checkboxAllowCenter.AutoSize = true; //
this.checkboxAllowCenter.CheckAlign = System.Drawing.ContentAlignment.TopLeft; this.checkboxAllowCenter.AutoSize = true;
this.checkboxAllowCenter.ImageAlign = System.Drawing.ContentAlignment.TopLeft; this.checkboxAllowCenter.CheckAlign = System.Drawing.ContentAlignment.TopLeft;
this.checkboxAllowCenter.LanguageKey = "printoptions_allowcenter"; this.checkboxAllowCenter.ImageAlign = System.Drawing.ContentAlignment.TopLeft;
this.checkboxAllowCenter.Location = new System.Drawing.Point(12, 89); this.checkboxAllowCenter.LanguageKey = "printoptions_allowcenter";
this.checkboxAllowCenter.Name = "checkboxAllowCenter"; this.checkboxAllowCenter.Location = new System.Drawing.Point(12, 89);
this.checkboxAllowCenter.PropertyName = "OutputPrintCenter"; this.checkboxAllowCenter.Name = "checkboxAllowCenter";
this.checkboxAllowCenter.Size = new System.Drawing.Size(137, 17); this.checkboxAllowCenter.PropertyName = "OutputPrintCenter";
this.checkboxAllowCenter.TabIndex = 24; this.checkboxAllowCenter.Size = new System.Drawing.Size(137, 17);
this.checkboxAllowCenter.Text = "Center printout on page"; this.checkboxAllowCenter.TabIndex = 24;
this.checkboxAllowCenter.TextAlign = System.Drawing.ContentAlignment.TopLeft; this.checkboxAllowCenter.Text = "Center printout on page";
this.checkboxAllowCenter.UseVisualStyleBackColor = true; this.checkboxAllowCenter.TextAlign = System.Drawing.ContentAlignment.TopLeft;
// this.checkboxAllowCenter.UseVisualStyleBackColor = true;
// checkboxAllowRotate //
// // checkboxAllowRotate
this.checkboxAllowRotate.AutoSize = true; //
this.checkboxAllowRotate.CheckAlign = System.Drawing.ContentAlignment.TopLeft; this.checkboxAllowRotate.AutoSize = true;
this.checkboxAllowRotate.ImageAlign = System.Drawing.ContentAlignment.TopLeft; this.checkboxAllowRotate.CheckAlign = System.Drawing.ContentAlignment.TopLeft;
this.checkboxAllowRotate.LanguageKey = "printoptions_allowrotate"; this.checkboxAllowRotate.ImageAlign = System.Drawing.ContentAlignment.TopLeft;
this.checkboxAllowRotate.Location = new System.Drawing.Point(12, 66); this.checkboxAllowRotate.LanguageKey = "printoptions_allowrotate";
this.checkboxAllowRotate.Name = "checkboxAllowRotate"; this.checkboxAllowRotate.Location = new System.Drawing.Point(12, 66);
this.checkboxAllowRotate.PropertyName = "OutputPrintAllowRotate"; this.checkboxAllowRotate.Name = "checkboxAllowRotate";
this.checkboxAllowRotate.Size = new System.Drawing.Size(187, 17); this.checkboxAllowRotate.PropertyName = "OutputPrintAllowRotate";
this.checkboxAllowRotate.TabIndex = 23; this.checkboxAllowRotate.Size = new System.Drawing.Size(187, 17);
this.checkboxAllowRotate.Text = "Rotate printout to page orientation"; this.checkboxAllowRotate.TabIndex = 23;
this.checkboxAllowRotate.TextAlign = System.Drawing.ContentAlignment.TopLeft; this.checkboxAllowRotate.Text = "Rotate printout to page orientation";
this.checkboxAllowRotate.UseVisualStyleBackColor = true; this.checkboxAllowRotate.TextAlign = System.Drawing.ContentAlignment.TopLeft;
// this.checkboxAllowRotate.UseVisualStyleBackColor = true;
// button_ok //
// // button_ok
this.button_ok.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); //
this.button_ok.DialogResult = System.Windows.Forms.DialogResult.OK; this.button_ok.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.button_ok.LanguageKey = "OK"; this.button_ok.DialogResult = System.Windows.Forms.DialogResult.OK;
this.button_ok.Location = new System.Drawing.Point(187, 224); this.button_ok.LanguageKey = "OK";
this.button_ok.Name = "button_ok"; this.button_ok.Location = new System.Drawing.Point(187, 267);
this.button_ok.Size = new System.Drawing.Size(75, 23); this.button_ok.Name = "button_ok";
this.button_ok.TabIndex = 25; this.button_ok.Size = new System.Drawing.Size(75, 23);
this.button_ok.Text = "OK"; this.button_ok.TabIndex = 25;
this.button_ok.UseVisualStyleBackColor = true; this.button_ok.Text = "Ok";
this.button_ok.Click += new System.EventHandler(this.Button_okClick); this.button_ok.UseVisualStyleBackColor = true;
// this.button_ok.Click += new System.EventHandler(this.Button_okClick);
// checkboxDateTime //
// // checkboxDateTime
this.checkboxDateTime.AutoSize = true; //
this.checkboxDateTime.CheckAlign = System.Drawing.ContentAlignment.TopLeft; this.checkboxDateTime.AutoSize = true;
this.checkboxDateTime.ImageAlign = System.Drawing.ContentAlignment.TopLeft; this.checkboxDateTime.CheckAlign = System.Drawing.ContentAlignment.TopLeft;
this.checkboxDateTime.LanguageKey = "printoptions_timestamp"; this.checkboxDateTime.ImageAlign = System.Drawing.ContentAlignment.TopLeft;
this.checkboxDateTime.Location = new System.Drawing.Point(12, 112); this.checkboxDateTime.LanguageKey = "printoptions_timestamp";
this.checkboxDateTime.Name = "checkboxDateTime"; this.checkboxDateTime.Location = new System.Drawing.Point(12, 112);
this.checkboxDateTime.PropertyName = "OutputPrintFooter"; this.checkboxDateTime.Name = "checkboxDateTime";
this.checkboxDateTime.Size = new System.Drawing.Size(187, 17); this.checkboxDateTime.PropertyName = "OutputPrintFooter";
this.checkboxDateTime.TabIndex = 26; this.checkboxDateTime.Size = new System.Drawing.Size(187, 17);
this.checkboxDateTime.Text = "Print date / time at bottom of page"; this.checkboxDateTime.TabIndex = 26;
this.checkboxDateTime.TextAlign = System.Drawing.ContentAlignment.TopLeft; this.checkboxDateTime.Text = "Print date / time at bottom of page";
this.checkboxDateTime.UseVisualStyleBackColor = true; this.checkboxDateTime.TextAlign = System.Drawing.ContentAlignment.TopLeft;
// this.checkboxDateTime.UseVisualStyleBackColor = true;
// button_cancel //
// // button_cancel
this.button_cancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); //
this.button_cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.button_cancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.button_cancel.LanguageKey = "CANCEL"; this.button_cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.button_cancel.Location = new System.Drawing.Point(268, 224); this.button_cancel.LanguageKey = "CANCEL";
this.button_cancel.Name = "button_cancel"; this.button_cancel.Location = new System.Drawing.Point(268, 267);
this.button_cancel.Size = new System.Drawing.Size(75, 23); this.button_cancel.Name = "button_cancel";
this.button_cancel.TabIndex = 27; this.button_cancel.Size = new System.Drawing.Size(75, 23);
this.button_cancel.Text = "Cancel"; this.button_cancel.TabIndex = 27;
this.button_cancel.UseVisualStyleBackColor = true; this.button_cancel.Text = "Cancel";
// this.button_cancel.UseVisualStyleBackColor = true;
// checkboxPrintInverted //
// // checkboxPrintInverted
this.checkboxPrintInverted.AutoSize = true; //
this.checkboxPrintInverted.CheckAlign = System.Drawing.ContentAlignment.TopLeft; this.checkboxPrintInverted.AutoSize = true;
this.checkboxPrintInverted.ImageAlign = System.Drawing.ContentAlignment.TopLeft; this.checkboxPrintInverted.CheckAlign = System.Drawing.ContentAlignment.TopLeft;
this.checkboxPrintInverted.LanguageKey = "printoptions_inverted"; this.checkboxPrintInverted.ImageAlign = System.Drawing.ContentAlignment.TopLeft;
this.checkboxPrintInverted.Location = new System.Drawing.Point(12, 135); this.checkboxPrintInverted.LanguageKey = "printoptions_inverted";
this.checkboxPrintInverted.Name = "checkboxPrintInverted"; this.checkboxPrintInverted.Location = new System.Drawing.Point(12, 135);
this.checkboxPrintInverted.PropertyName = "OutputPrintInverted"; this.checkboxPrintInverted.Name = "checkboxPrintInverted";
this.checkboxPrintInverted.Size = new System.Drawing.Size(141, 17); this.checkboxPrintInverted.PropertyName = "OutputPrintInverted";
this.checkboxPrintInverted.TabIndex = 28; this.checkboxPrintInverted.Size = new System.Drawing.Size(141, 17);
this.checkboxPrintInverted.Text = "Print with inverted colors"; this.checkboxPrintInverted.TabIndex = 28;
this.checkboxPrintInverted.TextAlign = System.Drawing.ContentAlignment.TopLeft; this.checkboxPrintInverted.Text = "Print with inverted colors";
this.checkboxPrintInverted.UseVisualStyleBackColor = true; this.checkboxPrintInverted.TextAlign = System.Drawing.ContentAlignment.TopLeft;
// this.checkboxPrintInverted.UseVisualStyleBackColor = true;
// checkbox_grayscale //
// // checkbox_grayscale
this.checkbox_grayscale.AutoSize = true; //
this.checkbox_grayscale.CheckAlign = System.Drawing.ContentAlignment.TopLeft; this.checkbox_grayscale.AutoSize = true;
this.checkbox_grayscale.ImageAlign = System.Drawing.ContentAlignment.TopLeft; this.checkbox_grayscale.CheckAlign = System.Drawing.ContentAlignment.TopLeft;
this.checkbox_grayscale.LanguageKey = "printoptions_printgrayscale"; this.checkbox_grayscale.ImageAlign = System.Drawing.ContentAlignment.TopLeft;
this.checkbox_grayscale.Location = new System.Drawing.Point(12, 158); this.checkbox_grayscale.LanguageKey = "printoptions_printgrayscale";
this.checkbox_grayscale.Name = "checkbox_grayscale"; this.checkbox_grayscale.Location = new System.Drawing.Point(12, 158);
this.checkbox_grayscale.PropertyName = "OutputPrintGrayscale"; this.checkbox_grayscale.Name = "checkbox_grayscale";
this.checkbox_grayscale.Size = new System.Drawing.Size(138, 17); this.checkbox_grayscale.PropertyName = "OutputPrintGrayscale";
this.checkbox_grayscale.TabIndex = 29; this.checkbox_grayscale.Size = new System.Drawing.Size(138, 17);
this.checkbox_grayscale.Text = "Force grayscale printing"; this.checkbox_grayscale.TabIndex = 29;
this.checkbox_grayscale.TextAlign = System.Drawing.ContentAlignment.TopLeft; this.checkbox_grayscale.Text = "Force grayscale printing";
this.checkbox_grayscale.UseVisualStyleBackColor = true; this.checkbox_grayscale.TextAlign = System.Drawing.ContentAlignment.TopLeft;
// this.checkbox_grayscale.UseVisualStyleBackColor = true;
// PrintOptionsDialog //
// // checkbox_monochrome
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); //
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; this.checkbox_monochrome.AutoSize = true;
this.ClientSize = new System.Drawing.Size(355, 259); this.checkbox_monochrome.CheckAlign = System.Drawing.ContentAlignment.TopLeft;
this.Controls.Add(this.checkbox_grayscale); this.checkbox_monochrome.ImageAlign = System.Drawing.ContentAlignment.TopLeft;
this.Controls.Add(this.checkboxPrintInverted); this.checkbox_monochrome.LanguageKey = "printoptions_printmonochrome";
this.Controls.Add(this.button_cancel); this.checkbox_monochrome.Location = new System.Drawing.Point(12, 181);
this.Controls.Add(this.checkboxDateTime); this.checkbox_monochrome.Name = "checkbox_monochrome";
this.Controls.Add(this.button_ok); this.checkbox_monochrome.PropertyName = "OutputPrintMonochrome";
this.Controls.Add(this.checkbox_dontaskagain); this.checkbox_monochrome.Size = new System.Drawing.Size(149, 17);
this.Controls.Add(this.checkboxAllowCenter); this.checkbox_monochrome.TabIndex = 30;
this.Controls.Add(this.checkboxAllowRotate); this.checkbox_monochrome.Text = "Force black/white printing";
this.Controls.Add(this.checkboxAllowEnlarge); this.checkbox_monochrome.TextAlign = System.Drawing.ContentAlignment.TopLeft;
this.Controls.Add(this.checkboxAllowShrink); this.checkbox_monochrome.UseVisualStyleBackColor = true;
this.LanguageKey = "printoptions_title"; //
this.MaximizeBox = false; // PrintOptionsDialog
this.MinimizeBox = false; //
this.Name = "PrintOptionsDialog"; this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
this.Text = "Greenshot print options"; this.ClientSize = new System.Drawing.Size(355, 302);
this.ResumeLayout(false); this.Controls.Add(this.checkbox_monochrome);
this.PerformLayout(); this.Controls.Add(this.checkbox_grayscale);
this.Controls.Add(this.checkboxPrintInverted);
this.Controls.Add(this.button_cancel);
this.Controls.Add(this.checkboxDateTime);
this.Controls.Add(this.button_ok);
this.Controls.Add(this.checkbox_dontaskagain);
this.Controls.Add(this.checkboxAllowCenter);
this.Controls.Add(this.checkboxAllowRotate);
this.Controls.Add(this.checkboxAllowEnlarge);
this.Controls.Add(this.checkboxAllowShrink);
this.LanguageKey = "printoptions_title";
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "PrintOptionsDialog";
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.Text = "Greenshot print options";
this.ResumeLayout(false);
this.PerformLayout();
} }
private GreenshotPlugin.Controls.GreenshotCheckBox checkbox_grayscale; private GreenshotPlugin.Controls.GreenshotCheckBox checkbox_grayscale;
private GreenshotPlugin.Controls.GreenshotCheckBox checkboxPrintInverted; private GreenshotPlugin.Controls.GreenshotCheckBox checkboxPrintInverted;
@ -238,5 +256,6 @@ namespace Greenshot.Forms
private GreenshotPlugin.Controls.GreenshotCheckBox checkboxAllowEnlarge; private GreenshotPlugin.Controls.GreenshotCheckBox checkboxAllowEnlarge;
private GreenshotPlugin.Controls.GreenshotCheckBox checkboxAllowShrink; private GreenshotPlugin.Controls.GreenshotCheckBox checkboxAllowShrink;
private GreenshotPlugin.Controls.GreenshotCheckBox checkbox_dontaskagain; private GreenshotPlugin.Controls.GreenshotCheckBox checkbox_dontaskagain;
private GreenshotPlugin.Controls.GreenshotCheckBox checkbox_monochrome;
} }
} }

File diff suppressed because it is too large Load diff

View file

@ -112,15 +112,15 @@
<value>2.0</value> <value>2.0</value>
</resheader> </resheader>
<resheader name="reader"> <resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<metadata name="folderBrowserDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="folderBrowserDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>116, 17</value> <value>116, 17</value>
</metadata> </metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> <assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="colorButton_window_background.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> <data name="colorButton_window_background.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value> <value>
iVBORw0KGgoAAAANSUhEUgAAABcAAAAYCAYAAAARfGZ1AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6 iVBORw0KGgoAAAANSUhEUgAAABcAAAAYCAYAAAARfGZ1AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6

View file

@ -29,6 +29,7 @@ using Greenshot.Forms;
using Greenshot.Plugin; using Greenshot.Plugin;
using GreenshotPlugin.Core; using GreenshotPlugin.Core;
using Greenshot.IniFile; using Greenshot.IniFile;
using Greenshot.Core;
namespace Greenshot.Helpers { namespace Greenshot.Helpers {
/// <summary> /// <summary>
@ -38,13 +39,13 @@ namespace Greenshot.Helpers {
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(PrintHelper)); private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(PrintHelper));
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>(); private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
private Image image; private ISurface surface;
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();
public PrintHelper(Image image, ICaptureDetails captureDetails) { public PrintHelper(ISurface surface, ICaptureDetails captureDetails) {
this.image = image; this.surface = surface;
this.captureDetails = captureDetails; this.captureDetails = captureDetails;
printDialog.UseEXDialog = true; printDialog.UseEXDialog = true;
printDocument.DocumentName = FilenameHelper.GetFilenameWithoutExtensionFromPattern(conf.OutputFileFilenamePattern, captureDetails); printDocument.DocumentName = FilenameHelper.GetFilenameWithoutExtensionFromPattern(conf.OutputFileFilenamePattern, captureDetails);
@ -74,8 +75,8 @@ namespace Greenshot.Helpers {
*/ */
protected virtual void Dispose(bool disposing) { protected virtual void Dispose(bool disposing) {
if (disposing) { if (disposing) {
if (image != null) { if (surface != null) {
image.Dispose(); surface.Dispose();
} }
if (printDocument != null) { if (printDocument != null) {
printDocument.Dispose(); printDocument.Dispose();
@ -84,7 +85,7 @@ namespace Greenshot.Helpers {
printDialog.Dispose(); printDialog.Dispose();
} }
} }
image = null; surface = null;
printDocument = null; printDocument = null;
printDialog = null; printDialog = null;
} }
@ -100,7 +101,7 @@ namespace Greenshot.Helpers {
try { try {
if (printOptionsResult == null || printOptionsResult == DialogResult.OK) { if (printOptionsResult == null || printOptionsResult == DialogResult.OK) {
printDocument.PrinterSettings.PrinterName = printerName; printDocument.PrinterSettings.PrinterName = printerName;
if (conf.OutputPrintGrayscale) { if (!IsColorPrint()) {
printDocument.DefaultPageSettings.Color = false; printDocument.DefaultPageSettings.Color = false;
} }
printDocument.Print(); printDocument.Print();
@ -110,8 +111,8 @@ namespace Greenshot.Helpers {
LOG.Error("An error ocurred while trying to print", e); LOG.Error("An error ocurred while trying to print", e);
MessageBox.Show(Language.GetString(LangKey.print_error), Language.GetString(LangKey.error)); MessageBox.Show(Language.GetString(LangKey.print_error), Language.GetString(LangKey.error));
} }
image.Dispose(); surface.Dispose();
image = null; surface = null;
return returnPrinterSettings; return returnPrinterSettings;
} }
@ -126,7 +127,7 @@ namespace Greenshot.Helpers {
DialogResult? printOptionsResult = ShowPrintOptionsDialog(); DialogResult? printOptionsResult = ShowPrintOptionsDialog();
try { try {
if (printOptionsResult == null || printOptionsResult == DialogResult.OK) { if (printOptionsResult == null || printOptionsResult == DialogResult.OK) {
if (conf.OutputPrintGrayscale) { if (IsColorPrint()) {
printDocument.DefaultPageSettings.Color = false; printDocument.DefaultPageSettings.Color = false;
} }
printDocument.Print(); printDocument.Print();
@ -138,11 +139,15 @@ namespace Greenshot.Helpers {
} }
} }
image.Dispose(); surface.Dispose();
image = null; surface = null;
return returnPrinterSettings; return returnPrinterSettings;
} }
private bool IsColorPrint() {
return !conf.OutputPrintGrayscale && !conf.OutputPrintMonochrome;
}
/// <summary> /// <summary>
/// display print options dialog (if the user has not configured Greenshot not to) /// display print options dialog (if the user has not configured Greenshot not to)
/// </summary> /// </summary>
@ -158,62 +163,95 @@ namespace Greenshot.Helpers {
} }
void DrawImageForPrint(object sender, PrintPageEventArgs e) { void DrawImageForPrint(object sender, PrintPageEventArgs e) {
ContentAlignment alignment = conf.OutputPrintCenter ? ContentAlignment.MiddleCenter : ContentAlignment.TopLeft;
// prepare timestamp
float footerStringWidth = 0; // Create the output settins
float footerStringHeight = 0; SurfaceOutputSettings printOutputSettings = new SurfaceOutputSettings(OutputFormat.png, 100, false);
string footerString = null; //DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString();
if (conf.OutputPrintFooter) { ApplyEffects(printOutputSettings);
footerString = FilenameHelper.FillPattern(conf.OutputPrintFooterPattern, captureDetails, false);
using (Font f = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular)) { Image image;
footerStringWidth = e.Graphics.MeasureString(footerString, f).Width; Boolean disposeImage = ImageOutput.CreateImageFromSurface(surface, printOutputSettings, out image);
footerStringHeight = e.Graphics.MeasureString(footerString, f).Height; try {
ContentAlignment alignment = conf.OutputPrintCenter ? ContentAlignment.MiddleCenter : ContentAlignment.TopLeft;
// prepare timestamp
float footerStringWidth = 0;
float footerStringHeight = 0;
string footerString = null; //DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString();
if (conf.OutputPrintFooter) {
footerString = FilenameHelper.FillPattern(conf.OutputPrintFooterPattern, captureDetails, false);
using (Font 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
RectangleF pageRect = e.PageSettings.PrintableArea;
if(e.PageSettings.Landscape) {
float 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;
GraphicsUnit gu = GraphicsUnit.Pixel;
RectangleF imageRect = image.GetBounds(ref gu);
// rotate the image if it fits the page better
if (conf.OutputPrintAllowRotate) {
if ((pageRect.Width > pageRect.Height && imageRect.Width < imageRect.Height) || (pageRect.Width < pageRect.Height && imageRect.Width > imageRect.Height)) {
image.RotateFlip(RotateFlipType.Rotate90FlipNone);
imageRect = image.GetBounds(ref gu);
if (alignment.Equals(ContentAlignment.TopLeft)) {
alignment = ContentAlignment.TopRight;
}
}
}
RectangleF printRect = new RectangleF(0, 0, imageRect.Width, imageRect.Height);
// scale the image to fit the page better
if (conf.OutputPrintAllowEnlarge || conf.OutputPrintAllowShrink) {
SizeF resizedRect = ScaleHelper.GetScaledSize(imageRect.Size, pageRect.Size, false);
if ((conf.OutputPrintAllowShrink && resizedRect.Width < printRect.Width) || conf.OutputPrintAllowEnlarge && resizedRect.Width > printRect.Width) {
printRect.Size = resizedRect;
}
}
// align the image
printRect = ScaleHelper.GetAlignedRectangle(printRect, new RectangleF(0, 0, pageRect.Width, pageRect.Height), alignment);
if (conf.OutputPrintFooter) {
//printRect = new RectangleF(0, 0, printRect.Width, printRect.Height - (dateStringHeight * 2));
using (Font 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(image, printRect, imageRect, GraphicsUnit.Pixel);
} finally {
if (disposeImage && image != null) {
image.Dispose();
image = null;
} }
} }
// Get a rectangle representing the printable Area
RectangleF pageRect = e.PageSettings.PrintableArea;
if(e.PageSettings.Landscape) {
float 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;
GraphicsUnit gu = GraphicsUnit.Pixel;
RectangleF imageRect = image.GetBounds(ref gu);
// rotate the image if it fits the page better
if (conf.OutputPrintAllowRotate) {
if ((pageRect.Width > pageRect.Height && imageRect.Width < imageRect.Height) || (pageRect.Width < pageRect.Height && imageRect.Width > imageRect.Height)) {
image.RotateFlip(RotateFlipType.Rotate90FlipNone);
imageRect = image.GetBounds(ref gu);
if (alignment.Equals(ContentAlignment.TopLeft)) {
alignment = ContentAlignment.TopRight;
}
}
}
RectangleF printRect = new RectangleF(0, 0, imageRect.Width, imageRect.Height);
// scale the image to fit the page better
if (conf.OutputPrintAllowEnlarge || conf.OutputPrintAllowShrink) {
SizeF resizedRect = ScaleHelper.GetScaledSize(imageRect.Size, pageRect.Size, false);
if ((conf.OutputPrintAllowShrink && resizedRect.Width < printRect.Width) || conf.OutputPrintAllowEnlarge && resizedRect.Width > printRect.Width) {
printRect.Size = resizedRect;
}
}
// align the image
printRect = ScaleHelper.GetAlignedRectangle(printRect, new RectangleF(0, 0, pageRect.Width, pageRect.Height), alignment);
if (conf.OutputPrintFooter) {
//printRect = new RectangleF(0, 0, printRect.Width, printRect.Height - (dateStringHeight * 2));
using (Font 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(image, printRect, imageRect, GraphicsUnit.Pixel);
} }
private void ApplyEffects(SurfaceOutputSettings printOutputSettings)
{
// TODO:
// add effects here
if (conf.OutputPrintMonochrome) {
byte threshold = conf.OutputPrintMonochromeThreshold;
printOutputSettings.Effects.Add(new MonochromeEffect(threshold));
printOutputSettings.ReduceColors = true;
}
// the invert effect should probably be the last
if (conf.OutputPrintInverted) {
printOutputSettings.Effects.Add(new InvertEffect());
}
}
} }
} }

View file

@ -198,7 +198,8 @@ Please check write accessibility of the selected storage location.</resource>
<resource name="printoptions_dontaskagain">Save options as default and do not ask again</resource> <resource name="printoptions_dontaskagain">Save options as default and do not ask again</resource>
<resource name="printoptions_inverted">Print with inverted colors</resource> <resource name="printoptions_inverted">Print with inverted colors</resource>
<resource name="printoptions_printgrayscale">Force grayscale printing</resource> <resource name="printoptions_printgrayscale">Force grayscale printing</resource>
<resource name="printoptions_timestamp">Print date / time at bottom of page</resource> <resource name="printoptions_printmonochrome">Force black/white printing</resource>
<resource name="printoptions_timestamp">Print date / time at bottom of page</resource>
<resource name="printoptions_title">Greenshot print options</resource> <resource name="printoptions_title">Greenshot print options</resource>
<resource name="qualitydialog_dontaskagain">Save as default quality and do not ask again</resource> <resource name="qualitydialog_dontaskagain">Save as default quality and do not ask again</resource>
<resource name="qualitydialog_title">Greenshot quality</resource> <resource name="qualitydialog_title">Greenshot quality</resource>

View file

@ -11,6 +11,7 @@ Features:
* General: Added Special-Folder support for the OutputPath/Filenames, now one can use the following values: MyPictures, MyMusic, MyDocuments, Personal, Desktop, ApplicationData, LocalApplicationData. Meaning one can now set the output path to e.g. ${MyPictures} * General: Added Special-Folder support for the OutputPath/Filenames, now one can use the following values: MyPictures, MyMusic, MyDocuments, Personal, Desktop, ApplicationData, LocalApplicationData. Meaning one can now set the output path to e.g. ${MyPictures}
* Editor: The capture is now displayed in the center of the editor, the code for this was supplied by Viktar Karpach. * Editor: The capture is now displayed in the center of the editor, the code for this was supplied by Viktar Karpach.
* Editor: Added horizontal and vertical alignment for text boxes. * Editor: Added horizontal and vertical alignment for text boxes.
* Printing: Added option to force monochrome (black/white) print
* Plug-in: Added Photobucket plugin * Plug-in: Added Photobucket plugin
* Plug-in: Removed unneeded code from the Confluence Plug-in, this makes the Greenshot installer / .zip a bit smaller. * Plug-in: Removed unneeded code from the Confluence Plug-in, this makes the Greenshot installer / .zip a bit smaller.

View file

@ -137,9 +137,13 @@ namespace GreenshotPlugin.Core {
public bool OutputPrintCenter; public bool OutputPrintCenter;
[IniProperty("OutputPrintInverted", LanguageKey="printoptions_inverted", Description="Print image inverted (use e.g. for console captures)", DefaultValue="false")] [IniProperty("OutputPrintInverted", LanguageKey="printoptions_inverted", Description="Print image inverted (use e.g. for console captures)", DefaultValue="false")]
public bool OutputPrintInverted; public bool OutputPrintInverted;
[IniProperty("OutputPrintGrayscale", LanguageKey = "printoptions_printgrayscale", Description = "Force grayscale printing", DefaultValue = "false")] [IniProperty("OutputPrintGrayscale", LanguageKey = "printoptions_printgrayscale", Description = "Force grayscale printing", DefaultValue = "false")]
public bool OutputPrintGrayscale; public bool OutputPrintGrayscale;
[IniProperty("OutputPrintFooter", LanguageKey = "printoptions_timestamp", Description = "Print footer on print?", DefaultValue = "true")] [IniProperty("OutputPrintMonochrome", LanguageKey = "printoptions_printmonochrome", Description = "Force monorchrome printing", DefaultValue = "false")]
public bool OutputPrintMonochrome;
[IniProperty("OutputPrintMonochromeThreshold", Description = "Threshold for monochrome filter (0 - 255), lower value means less black", DefaultValue = "127")]
public byte OutputPrintMonochromeThreshold;
[IniProperty("OutputPrintFooter", LanguageKey = "printoptions_timestamp", Description = "Print footer on print?", DefaultValue = "true")]
public bool OutputPrintFooter; public bool OutputPrintFooter;
[IniProperty("OutputPrintFooterPattern", Description = "Footer pattern", DefaultValue = "${capturetime:d\"D\"} ${capturetime:d\"T\"} - ${title}")] [IniProperty("OutputPrintFooterPattern", Description = "Footer pattern", DefaultValue = "${capturetime:d\"D\"} ${capturetime:d\"T\"} - ${title}")]
public string OutputPrintFooterPattern; public string OutputPrintFooterPattern;

View file

@ -105,9 +105,14 @@ namespace Greenshot.Core {
/// MonochromeEffect /// MonochromeEffect
/// </summary> /// </summary>
public class MonochromeEffect : IEffect { public class MonochromeEffect : IEffect {
private byte threshold;
/// <param name="threshold">Threshold for monochrome filter (0 - 255), lower value means less black</param>
public MonochromeEffect(byte threshold) {
this.threshold = threshold;
}
public Image Apply(Image sourceImage, out Point offsetChange) { public Image Apply(Image sourceImage, out Point offsetChange) {
offsetChange = Point.Empty; offsetChange = Point.Empty;
return ImageHelper.CreateMonochrome(sourceImage); return ImageHelper.CreateMonochrome(sourceImage, threshold);
} }
} }

View file

@ -883,15 +883,16 @@ namespace GreenshotPlugin.Core {
/// <summary> /// <summary>
/// Returns a b/w of Bitmap /// Returns a b/w of Bitmap
/// </summary> /// </summary>
/// <param name="sourceImage">Bitmap to create a b/w off</param> /// <param name="sourceImage">Bitmap to create a b/w of</param>
/// <param name="threshold">Threshold for monochrome filter (0 - 255), lower value means less black</param>
/// <returns>b/w bitmap</returns> /// <returns>b/w bitmap</returns>
public static Bitmap CreateMonochrome(Image sourceImage) { public static Bitmap CreateMonochrome(Image sourceImage, byte threshold) {
using (IFastBitmap fastBitmap = FastBitmap.CreateCloneOf(sourceImage, sourceImage.PixelFormat)) { using (IFastBitmap fastBitmap = FastBitmap.CreateCloneOf(sourceImage, sourceImage.PixelFormat)) {
fastBitmap.Lock(); fastBitmap.Lock();
for (int y = 0; y < fastBitmap.Height; y++) { for (int y = 0; y < fastBitmap.Height; y++) {
for (int x = 0; x < fastBitmap.Width; x++) { for (int x = 0; x < fastBitmap.Width; x++) {
Color color = fastBitmap.GetColorAt(x, y); Color color = fastBitmap.GetColorAt(x, y);
int colorBrightness = (color.R + color.G + color.B > 382) ? 255 : 0; int colorBrightness = ((color.R + color.G + color.B) / 3 > threshold) ? 255 : 0;
Color monoColor = Color.FromArgb(color.A, colorBrightness, colorBrightness, colorBrightness); Color monoColor = Color.FromArgb(color.A, colorBrightness, colorBrightness, colorBrightness);
fastBitmap.SetColorAt(x, y, monoColor); fastBitmap.SetColorAt(x, y, monoColor);
} }