Improvements to windows printing.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@38099 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Gregory John Casamento 2014-09-28 08:03:55 +00:00
parent ce5923f681
commit 70baf43d54
5 changed files with 153 additions and 83 deletions

View file

@ -1,11 +1,24 @@
2014-09-27 12:19-EDT Gregory John Casamento <greg.casamento@gmail.com>
2014-09-28 04:00-EDT Gregory John Casamento <greg.casamento@gmail.com>
* Printing/GNUmakefile: On windows only compile the GSWIN32
Printing backend
* Printing/GSWIN32/GSWIN32PrintPanel.m: Extract printer name
from results.
* Printing/GSWIN32/GSWIN32PrintOperation.m: Add code to
send raw data to the printer. Implement code to send
file to printer.
* Printing/GSWIN32/GSWIN32Printer.m: Add code to enumerate list of
available printers on Windows. Build dictionary for GSWIN32Printer
class.
2014-09-27 21:30-EDT Gregory John Casamento <greg.casamento@gmail.com>
* Printing/GSWIN32/GSWIN32PrinterOperation.m: Addition of function
to output to printer directly.
* Printing/GSWIN32/GNUmakefile: Change to correct linker issue
winspool was not being linked in the proper place so it was
causing unresolved references.
2014-09-16 12:19-EDT Gregory John Casamento <greg.casamento@gmail.com>
* Source/GSPrinting.m: Reorder printing backend load order.

View file

@ -43,7 +43,7 @@ SUBPROJECTS += GSCUPS
endif
ifeq ($(GNUSTEP_TARGET_OS),mingw32)
SUBPROJECTS += GSWIN32
SUBPROJECTS = GSWIN32
endif
include $(GNUSTEP_MAKEFILES)/aggregate.make

View file

@ -1,20 +1,12 @@
/*
GWIN32SPrintOperation.m
GWIN32PrintOperation.m
Controls operations generating EPS, PDF or PS print jobs.
Controls operations generating windows print
Copyright (C) 2014 Free Software Foundation, Inc.
Author: Gregory John Casamento <greg.casamento@gmail.com>
Date 2014
Author: Scott Christley <scottc@net-community.com>
Date: 1996
Author: Fred Kiefer <FredKiefer@gmx.de>
Date: November 2000
Started implementation.
Modified for Printing Backend Support
Author: Chad Hardin
Date: June 2004
This file is part of the GNUstep GUI Library.
@ -42,6 +34,7 @@
#import <Foundation/NSString.h>
#import <Foundation/NSTask.h>
#import <Foundation/NSValue.h>
#import <Foundation/NSData.h>
#import "AppKit/NSGraphicsContext.h"
#import "AppKit/NSView.h"
#import "AppKit/NSPrinter.h"
@ -154,35 +147,36 @@ BOOL RawDataToPrinter(LPSTR szPrinterName, LPBYTE lpData, DWORD dwCount)
- (BOOL) _deliverSpooledResult
{
int copies;
NSDictionary *dict;
NSTask *task;
NSString *name, *status;
NSMutableArray *args;
NSString *name = nil;
NSData *fileData = nil;
LPSTR szPrinterName = NULL;
DWORD dwCount = 0;
LPBYTE lpData = NULL;
BOOL result = FALSE;
name = [[[self printInfo] printer] name];
status = [NSString stringWithFormat: _(@"Spooling to printer %@."), name];
[[self printPanel] _setStatusStringValue: status];
dict = [[self printInfo] dictionary];
args = [NSMutableArray array];
copies = [[dict objectForKey: NSPrintCopies] intValue];
if (copies > 1)
[args addObject: [NSString stringWithFormat: @"-#%0d", copies]];
if ([name isEqual: @"Unknown"] == NO)
if(name != nil)
{
[args addObject: @"-P"];
[args addObject: name];
szPrinterName = (LPSTR)[name cString];
fileData = [NSData dataWithContentsOfFile:_path];
if(fileData != nil)
{
dwCount = (DWORD)[fileData length];
lpData = (LPBYTE)[fileData bytes];
result = RawDataToPrinter(szPrinterName, lpData, dwCount);
}
else
{
NSLog(@"File is blank");
}
}
else
{
NSLog(@"No printer name supplied");
}
[args addObject: _path];
task = [NSTask new];
[task setLaunchPath: @"lpr"];
[task setArguments: args];
[task launch];
[task waitUntilExit];
AUTORELEASE(task);
return YES;
return (result ? YES : NO); // Paranoid conversion to ObjC type...
}
- (NSGraphicsContext*)createContext

View file

@ -50,26 +50,14 @@
- (NSInteger) runModalWithPrintInfo: (NSPrintInfo *)printInfo
{
int retVal;
// NSMutableDictionary *info = [printInfo dictionary];
PRINTDLG printDlg;
// GSWIN32Printer *printer = [info objectForKey:@"NSPrinter"];
int windowNumber = [[[NSApplication sharedApplication] mainWindow] windowNumber];
/*
NSLog(@"==== Printer info ");
NSLog(@"Names: %@",[GSWIN32Printer printerNames]);
NSLog(@"Info: %@",info);
NSLog(@"Host: %@",[printer host]);
NSLog(@"Name: %@",[printer name]);
NSLog(@"Note: %@",[printer note]);
NSLog(@"Type: %@",[printer type]);
NSLog(@"==== End Printer info ");
*/
printDlg.lStructSize = sizeof(PRINTDLG);
printDlg.hwndOwner = (HWND)windowNumber;
printDlg.hDevMode = NULL;
printDlg.hDevNames = NULL;
printDlg.Flags = PD_RETURNDC | PD_USEDEVMODECOPIESANDCOLLATE;
printDlg.hDC = NULL;
printDlg.lCustData = 0;
printDlg.lpfnPrintHook = NULL;
@ -78,12 +66,11 @@
printDlg.lpSetupTemplateName = NULL;
printDlg.hPrintTemplate = NULL;
printDlg.hSetupTemplate = NULL;
printDlg.Flags = PD_RETURNDC | PD_COLLATE; // | PD_ENABLEPRINTHOOK;
printDlg.nFromPage = 1;
printDlg.nToPage = 1;
printDlg.nFromPage = 0; //0xFFFF;
printDlg.nToPage = 0; //0xFFFF;
printDlg.nMinPage = 1;
printDlg.nMaxPage = 1;
printDlg.nMaxPage = 0xFFFF;
printDlg.nCopies = 1;
printDlg.hInstance = NULL;
@ -94,10 +81,20 @@
}
else
{
// Get specifics from the data returned
DEVMODE *devMode = printDlg.hDevMode;
NSString *printerName = [NSString stringWithCString:(const char *)(devMode->dmDeviceName)];
DEVNAMES *pDevNames = (DEVNAMES *)GlobalLock(printDlg.hDevNames);
LPCTSTR szDevice = NULL;
NSString *printerName = nil;
NSPrinter *printer = nil;
szDevice = (LPCTSTR)pDevNames + pDevNames->wDeviceOffset;
printerName = [NSString stringWithCString:(const char *)szDevice];
NSLog(@"Printer Name = %@",printerName);
printer = [NSPrinter printerWithName:printerName];
if(printer != nil)
{
[printInfo setPrinter:printer];
}
}
return NSOKButton;

View file

@ -45,9 +45,81 @@
#import <Foundation/NSString.h>
#import <Foundation/NSUserDefaults.h>
#import <Foundation/NSValue.h>
#import "GSWIN32Printer.h"
#import "GNUstepGUI/GSPrinting.h"
NSMutableDictionary *EnumeratePrinters(DWORD flags)
{
PRINTER_INFO_2* prninfo=NULL;
DWORD needed, returned;
NSMutableDictionary *printers = nil;
//find required size for the buffer
EnumPrinters(flags, NULL, 2, NULL, 0, &needed, &returned);
//allocate array of PRINTER_INFO structures
prninfo = (PRINTER_INFO_2*) GlobalAlloc(GPTR,needed);
//call again
if (!EnumPrinters(flags, NULL,
2, (LPBYTE) prninfo, needed, &needed, &returned))
{
NSLog(@"Error: %s\n", GetLastError());
}
else
{
int i = 0;
printers = [NSMutableDictionary dictionary];
NSLog(@"Printers found: %d\n\n",returned);
for (i = 0; i < returned; i++)
{
NSMutableDictionary *entry = [NSMutableDictionary dictionary];
NSString *printerName =
[NSString stringWithCString:prninfo[i].pPrinterName
encoding:NSASCIIStringEncoding];
if (printerName != nil)
{
NSString *portName =
[NSString stringWithCString:prninfo[i].pPortName
encoding:NSASCIIStringEncoding];
if (portName != nil)
{
[entry setObject:portName
forKey:@"Host"];
[entry setObject:[NSString stringWithFormat:@"Current Status: %d",prninfo[i].Status]
forKey:@"Note"];
[entry setObject:@"Generic Postscript Printer"
forKey:@"Type"];
[printers setObject:entry
forKey:printerName];
/*
NSLog(@"%s on %s, Status = %d, jobs=%d\n",
prninfo[i].pPrinterName,
prninfo[i].pPortName,
prninfo[i].Status,
prninfo[i].cJobs);
*/
}
else
{
NSLog(@"Port name is nil for %@",printerName);
}
}
else
{
NSLog(@"Printer name is nil");
}
}
}
GlobalFree(prninfo);
return printers;
}
@implementation GSWIN32Printer
@ -97,7 +169,7 @@
withHost: [printerEntry objectForKey: @"Host"]
withNote: [printerEntry objectForKey: @"Note"]];
[printer parsePPDAtPath: [printerEntry objectForKey: @"PPDPath"]];
// [printer parsePPDAtPath: [printerEntry objectForKey: @"PPDPath"]];
return AUTORELEASE(printer);
}
@ -109,58 +181,52 @@
}
//
// Load the printer setup from NSUserDefaults
// Load the printer setup
//
+ (NSDictionary*) printersDictionary
{
static BOOL didWarn;
NSUserDefaults* defaults;
NSDictionary *printers;
defaults = [NSUserDefaults standardUserDefaults];
printers = [defaults dictionaryForKey: @"GSWIN32Printers"];
printers = EnumeratePrinters(PRINTER_ENUM_LOCAL);
if (!printers) //Not set, make a default printer because we are nice.
{
NSString *ppdPath;
NSMutableDictionary *printerEntry;
printers = [NSMutableDictionary dictionary];
printerEntry = [NSMutableDictionary dictionary];
ppdPath = [NSBundle
pathForLibraryResource: @"Generic-PostScript_Printer-Postscript"
ofType: @"ppd"
inDirectory: @"PostScript/PPD"];
pathForLibraryResource: @"Generic-PostScript_Printer-Postscript"
ofType: @"ppd"
inDirectory: @"PostScript/PPD"];
NSAssert(ppdPath,
@"Couldn't find the PPD file for the fallback printer.");
[printerEntry setObject: ppdPath
forKey: @"PPDPath"];
[printerEntry setObject: @"localhost"
forKey: @"Host"];
forKey: @"Host"];
[printerEntry setObject: @"Automatically Generated"
forKey: @"Note"];
forKey: @"Note"];
[printerEntry setObject: @"Unknown"
forKey: @"Type"];
forKey: @"Type"];
[(NSMutableDictionary*)printers setObject: printerEntry
forKey: @"Unnamed"];
[defaults setObject: printers forKey: @"GSWIN32Printers"];
[defaults synchronize];
forKey: @"Unnamed"];
if (!didWarn)
{
NSLog(@"Creating a default printer since no printer has been set "
@"in the user defaults (under the GSWIN32Printers key).");
@"in the user defaults (under the GSWIN32Printers key).");
didWarn = YES;
}
}
return printers;
}