Author: gcasa
Date: Sun Sep 28 10:03:55 2014
New Revision: 38099
URL: http://svn.gna.org/viewcvs/gnustep?rev=38099&view=rev
Log:
Improvements to windows printing.
Modified:
libs/gui/trunk/ChangeLog
libs/gui/trunk/Printing/GNUmakefile
libs/gui/trunk/Printing/GSWIN32/GSWIN32PrintOperation.m
libs/gui/trunk/Printing/GSWIN32/GSWIN32PrintPanel.m
libs/gui/trunk/Printing/GSWIN32/GSWIN32Printer.m
Modified: libs/gui/trunk/ChangeLog
URL:
http://svn.gna.org/viewcvs/gnustep/libs/gui/trunk/ChangeLog?rev=38099&r1=38098&r2=38099&view=diff
==============================================================================
--- libs/gui/trunk/ChangeLog (original)
+++ libs/gui/trunk/ChangeLog Sun Sep 28 10:03:55 2014
@@ -1,11 +1,24 @@
-2014-09-27 12:19-EDT Gregory John Casamento <[email protected]>
+2014-09-28 04:00-EDT Gregory John Casamento <[email protected]>
+
+ * 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 <[email protected]>
* 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 <[email protected]>
* Source/GSPrinting.m: Reorder printing backend load order.
Modified: libs/gui/trunk/Printing/GNUmakefile
URL:
http://svn.gna.org/viewcvs/gnustep/libs/gui/trunk/Printing/GNUmakefile?rev=38099&r1=38098&r2=38099&view=diff
==============================================================================
--- libs/gui/trunk/Printing/GNUmakefile (original)
+++ libs/gui/trunk/Printing/GNUmakefile Sun Sep 28 10:03:55 2014
@@ -43,7 +43,7 @@
endif
ifeq ($(GNUSTEP_TARGET_OS),mingw32)
-SUBPROJECTS += GSWIN32
+SUBPROJECTS = GSWIN32
endif
include $(GNUSTEP_MAKEFILES)/aggregate.make
Modified: libs/gui/trunk/Printing/GSWIN32/GSWIN32PrintOperation.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/gui/trunk/Printing/GSWIN32/GSWIN32PrintOperation.m?rev=38099&r1=38098&r2=38099&view=diff
==============================================================================
--- libs/gui/trunk/Printing/GSWIN32/GSWIN32PrintOperation.m (original)
+++ libs/gui/trunk/Printing/GSWIN32/GSWIN32PrintOperation.m Sun Sep 28
10:03:55 2014
@@ -1,20 +1,12 @@
/*
- GWIN32SPrintOperation.m
-
- Controls operations generating EPS, PDF or PS print jobs.
+ GWIN32PrintOperation.m
+
+ Controls operations generating windows print
Copyright (C) 2014 Free Software Foundation, Inc.
Author: Gregory John Casamento <[email protected]>
Date 2014
- Author: Scott Christley <[email protected]>
- Date: 1996
- Author: Fred Kiefer <[email protected]>
- 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) _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)
- {
- [args addObject: @"-P"];
- [args addObject: name];
- }
- [args addObject: _path];
-
- task = [NSTask new];
- [task setLaunchPath: @"lpr"];
- [task setArguments: args];
- [task launch];
- [task waitUntilExit];
- AUTORELEASE(task);
- return YES;
+
+ if(name != nil)
+ {
+ 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");
+ }
+
+ return (result ? YES : NO); // Paranoid conversion to ObjC type...
}
- (NSGraphicsContext*)createContext
Modified: libs/gui/trunk/Printing/GSWIN32/GSWIN32PrintPanel.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/gui/trunk/Printing/GSWIN32/GSWIN32PrintPanel.m?rev=38099&r1=38098&r2=38099&view=diff
==============================================================================
--- libs/gui/trunk/Printing/GSWIN32/GSWIN32PrintPanel.m (original)
+++ libs/gui/trunk/Printing/GSWIN32/GSWIN32PrintPanel.m Sun Sep 28 10:03:55 2014
@@ -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;
Modified: libs/gui/trunk/Printing/GSWIN32/GSWIN32Printer.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/gui/trunk/Printing/GSWIN32/GSWIN32Printer.m?rev=38099&r1=38098&r2=38099&view=diff
==============================================================================
--- libs/gui/trunk/Printing/GSWIN32/GSWIN32Printer.m (original)
+++ libs/gui/trunk/Printing/GSWIN32/GSWIN32Printer.m Sun Sep 28 10:03:55 2014
@@ -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;
}
_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs